diff --git a/Mage.Sets/src/mage/sets/magic2012/VengefulPharaoh.java b/Mage.Sets/src/mage/sets/magic2012/VengefulPharaoh.java index 44bc3e9619..10abb1aac2 100644 --- a/Mage.Sets/src/mage/sets/magic2012/VengefulPharaoh.java +++ b/Mage.Sets/src/mage/sets/magic2012/VengefulPharaoh.java @@ -28,22 +28,24 @@ package mage.sets.magic2012; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Rarity; -import mage.constants.Zone; import mage.MageInt; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.DeathtouchAbility; import mage.cards.Card; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.game.Game; import mage.game.events.DamagedEvent; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; +import mage.game.turn.Step; import mage.players.Player; import mage.target.common.TargetAttackingCreature; @@ -58,11 +60,13 @@ public class VengefulPharaoh extends CardImpl { this.expansionSetCode = "M12"; this.subtype.add("Zombie"); - this.color.setBlack(true); this.power = new MageInt(5); this.toughness = new MageInt(4); + // Deathtouch (Any amount of damage this deals to a creature is enough to destroy it.) this.addAbility(DeathtouchAbility.getInstance()); + + // Whenever combat damage is dealt to you or a planeswalker you control, if Vengeful Pharaoh is in your graveyard, destroy target attacking creature, then put Vengeful Pharaoh on top of your library. this.addAbility(new VengefulPharaohTriggeredAbility()); } @@ -78,6 +82,12 @@ public class VengefulPharaoh extends CardImpl { class VengefulPharaohTriggeredAbility extends TriggeredAbilityImpl { + Step stepTriggeredPlayer; + int turnTriggeredPlayer; + + Step stepTriggeredPlansewalker; + int turnTriggeredPlaneswalker; + public VengefulPharaohTriggeredAbility() { super(Zone.GRAVEYARD, new VengefulPharaohEffect(), false); this.addTarget(new TargetAttackingCreature()); @@ -85,6 +95,10 @@ class VengefulPharaohTriggeredAbility extends TriggeredAbilityImpl { public VengefulPharaohTriggeredAbility(final VengefulPharaohTriggeredAbility ability) { super(ability); + this.stepTriggeredPlansewalker = ability.stepTriggeredPlansewalker; + this.turnTriggeredPlaneswalker = ability.turnTriggeredPlaneswalker; + this.stepTriggeredPlayer = ability.stepTriggeredPlayer; + this.turnTriggeredPlayer = ability.turnTriggeredPlayer; } @Override @@ -92,16 +106,41 @@ class VengefulPharaohTriggeredAbility extends TriggeredAbilityImpl { return new VengefulPharaohTriggeredAbility(this); } + @Override + public boolean checkInterveningIfClause(Game game) { + // 9/22/2011 - If multiple creatures deal combat damage to you and to a planeswalker you control + // simultaneously, Vengeful Pharaoh will trigger twice. The first trigger will cause Vengeful Pharaoh + // to be put on top of your library. The second trigger will then do nothing, as Vengeful Pharaoh is + // no longer in your graveyard when it tries to resolve. Note that the second trigger will do nothing + // even if Vengeful Pharaoh is put back into your graveyard before it tries to resolve, as it's a + // different Vengeful Pharaoh than the one that was there before. + MageObjectReference mor = new MageObjectReference(getSourceId(), game); + return mor.refersTo(this.getSourceObject(game)); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == EventType.DAMAGED_PLAYER || event.getType() == EventType.DAMAGED_PLANESWALKER; + } + @Override public boolean checkTrigger(GameEvent event, Game game) { if ((event.getType() == EventType.DAMAGED_PLAYER && event.getTargetId().equals(this.getControllerId())) && ((DamagedEvent) event).isCombatDamage()) { - return true; + if (!game.getPhase().getStep().equals(stepTriggeredPlayer) || game.getTurnNum() != turnTriggeredPlayer) { + stepTriggeredPlayer = game.getPhase().getStep(); + turnTriggeredPlayer = game.getTurnNum(); + return true; + } } if (event.getType() == EventType.DAMAGED_PLANESWALKER && ((DamagedEvent) event).isCombatDamage()) { Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent != null && permanent.getControllerId().equals(this.getControllerId())) { - return true; + if (!game.getPhase().getStep().equals(stepTriggeredPlansewalker) || game.getTurnNum() != turnTriggeredPlaneswalker) { + stepTriggeredPlansewalker = game.getPhase().getStep(); + turnTriggeredPlaneswalker = game.getTurnNum(); + return true; + } } } return false; @@ -131,19 +170,16 @@ class VengefulPharaohEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - boolean applied = false; - Permanent permanent = game.getPermanent(source.getFirstTarget()); - if (permanent != null) { - permanent.destroy(source.getSourceId(), game, false); - applied = true; - } - Player player = game.getPlayer(source.getControllerId()); + Player controller = game.getPlayer(source.getControllerId()); Card card = game.getCard(source.getSourceId()); - if (card != null && player != null) { - player.getGraveyard().remove(card); - card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true); - applied = true; + if (card != null && controller != null) { + Permanent permanent = game.getPermanent(source.getFirstTarget()); + if (permanent != null) { + permanent.destroy(source.getSourceId(), game, false); + } + controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.GRAVEYARD, true, true); + return true; } - return applied; + return false; } }