From 053e4bbe8f291a0c8b49101747cf2961f4252ccd Mon Sep 17 00:00:00 2001 From: North Date: Thu, 18 Aug 2011 22:45:05 +0300 Subject: [PATCH] Fixed Warstorm Surge --- .../mage/sets/magic2012/WarstormSurge.java | 63 +++++++++++++++---- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2012/WarstormSurge.java b/Mage.Sets/src/mage/sets/magic2012/WarstormSurge.java index a7982af681..d772b0d78d 100644 --- a/Mage.Sets/src/mage/sets/magic2012/WarstormSurge.java +++ b/Mage.Sets/src/mage/sets/magic2012/WarstormSurge.java @@ -31,16 +31,18 @@ import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Outcome; import mage.Constants.Rarity; -import mage.MageInt; +import mage.Constants.Zone; import mage.abilities.Ability; -import mage.abilities.common.CreatureEntersBattlefieldTriggeredAbility; +import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.common.TargetCreatureOrPlayer; -import mage.target.common.TargetCreaturePermanent; /** * @@ -54,9 +56,7 @@ public class WarstormSurge extends CardImpl { this.color.setRed(true); - // Whenever a creature enters the battlefield under your control, it deals damage equal to its power to target creature or player. - Ability ability = new CreatureEntersBattlefieldTriggeredAbility(new WarstormSurgeEffect()); - ability.addTarget(new TargetCreaturePermanent()); + Ability ability = new WarstormSurgeTriggeredAbility(); ability.addTarget(new TargetCreatureOrPlayer()); this.addAbility(ability); } @@ -71,6 +71,41 @@ public class WarstormSurge extends CardImpl { } } +class WarstormSurgeTriggeredAbility extends TriggeredAbilityImpl { + + public WarstormSurgeTriggeredAbility() { + super(Zone.BATTLEFIELD, new WarstormSurgeEffect(), false); + } + + public WarstormSurgeTriggeredAbility(WarstormSurgeTriggeredAbility ability) { + super(ability); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == EventType.ZONE_CHANGE) { + Permanent permanent = game.getPermanent(event.getTargetId()); + if (((ZoneChangeEvent) event).getToZone() == Zone.BATTLEFIELD + && permanent.getCardType().contains(CardType.CREATURE) + && permanent.getControllerId().equals(this.controllerId)) { + game.getState().setValue(sourceId.toString(), event.getTargetId()); + return true; + } + } + return false; + } + + @Override + public String getRule() { + return "Whenever a creature enters the battlefield under your control, it deals damage equal to its power to target creature or player."; + } + + @Override + public WarstormSurgeTriggeredAbility copy() { + return new WarstormSurgeTriggeredAbility(this); + } +} + class WarstormSurgeEffect extends OneShotEffect { public WarstormSurgeEffect() { @@ -89,18 +124,22 @@ class WarstormSurgeEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Permanent creature = game.getPermanent(source.getFirstTarget()); + UUID creatureId = (UUID) game.getState().getValue(source.getSourceId().toString()); + Permanent creature = game.getPermanent(creatureId); + if (creature == null) { + creature = (Permanent) game.getLastKnownInformation(creatureId, Zone.BATTLEFIELD); + } if (creature != null) { int amount = creature.getPower().getValue(); - UUID target = source.getTargets().get(1).getFirstTarget(); - Permanent permanent = game.getPermanent(target); - if (permanent != null) { - permanent.damage(amount, source.getSourceId(), game, true, false); + UUID target = source.getTargets().getFirstTarget(); + Permanent targetCreature = game.getPermanent(target); + if (targetCreature != null) { + targetCreature.damage(amount, creature.getId(), game, true, false); return true; } Player player = game.getPlayer(target); if (player != null) { - player.damage(amount, source.getSourceId(), game, false, true); + player.damage(amount, creature.getId(), game, false, true); return true; } }