diff --git a/Mage.Sets/src/mage/cards/h/HoodedBlightfang.java b/Mage.Sets/src/mage/cards/h/HoodedBlightfang.java index f3eb71472d..f0dc0bfeee 100644 --- a/Mage.Sets/src/mage/cards/h/HoodedBlightfang.java +++ b/Mage.Sets/src/mage/cards/h/HoodedBlightfang.java @@ -2,8 +2,9 @@ package mage.cards.h; import mage.MageInt; import mage.abilities.Ability; +import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.AttacksCreatureYouControlTriggeredAbility; -import mage.abilities.common.DestroyPlaneswalkerWhenDamagedTriggeredAbility; +import mage.abilities.effects.common.DestroyTargetEffect; import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.effects.common.LoseLifeOpponentsEffect; import mage.abilities.keyword.DeathtouchAbility; @@ -11,18 +12,24 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; +import mage.constants.Zone; +import mage.filter.StaticFilters; import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.predicate.mageobject.AbilityPredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.target.targetpointer.FixedTarget; import java.util.UUID; /** - * * @author htrajan */ public final class HoodedBlightfang extends CardImpl { - private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("a creature you control with deathtouch"); + static final FilterControlledCreaturePermanent filter + = new FilterControlledCreaturePermanent("a creature you control with deathtouch"); static { filter.add(new AbilityPredicate(DeathtouchAbility.class)); @@ -30,7 +37,7 @@ public final class HoodedBlightfang extends CardImpl { public HoodedBlightfang(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}"); - + this.subtype.add(SubType.SNAKE); this.power = new MageInt(1); this.toughness = new MageInt(4); @@ -39,12 +46,14 @@ public final class HoodedBlightfang extends CardImpl { this.addAbility(DeathtouchAbility.getInstance()); // Whenever a creature you control with deathtouch attacks, each opponent loses 1 life and you gain 1 life. - Ability ability = new AttacksCreatureYouControlTriggeredAbility(new LoseLifeOpponentsEffect(1), false, filter); - ability.addEffect(new GainLifeEffect(1).setText("and you gain 1 life")); + Ability ability = new AttacksCreatureYouControlTriggeredAbility( + new LoseLifeOpponentsEffect(1), false, filter + ); + ability.addEffect(new GainLifeEffect(1).concatBy("and")); this.addAbility(ability); // Whenever a creature you control with deathtouch deals damage to a planeswalker, destroy that planeswalker. - this.addAbility(new DestroyPlaneswalkerWhenDamagedTriggeredAbility(filter)); + this.addAbility(new HoodedBlightfangTriggeredAbility()); } private HoodedBlightfang(final HoodedBlightfang card) { @@ -56,3 +65,43 @@ public final class HoodedBlightfang extends CardImpl { return new HoodedBlightfang(this); } } + +class HoodedBlightfangTriggeredAbility extends TriggeredAbilityImpl { + + HoodedBlightfangTriggeredAbility() { + super(Zone.BATTLEFIELD, new DestroyTargetEffect(), false); + } + + private HoodedBlightfangTriggeredAbility(final HoodedBlightfangTriggeredAbility ability) { + super(ability); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DAMAGED_PERMANENT; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId()); + Permanent damaged = game.getPermanentOrLKIBattlefield(event.getTargetId()); + if (permanent == null + || damaged == null + || !StaticFilters.FILTER_PERMANENT_PLANESWALKER.match(damaged, game) + || !HoodedBlightfang.filter.match(permanent, this.getSourceId(), this.getControllerId(), game)) { + return false; + } + this.getEffects().setTargetPointer(new FixedTarget(damaged.getId(), damaged.getZoneChangeCounter(game))); + return true; + } + + @Override + public HoodedBlightfangTriggeredAbility copy() { + return new HoodedBlightfangTriggeredAbility(this); + } + + @Override + public String getRule() { + return "Whenever a creature you control with deathtouch deals damage to a planeswalker, destroy that planeswalker."; + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/m21/HoodedBlightfangTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/m21/HoodedBlightfangTest.java index 9180aa4901..29d83f6c5e 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/m21/HoodedBlightfangTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/m21/HoodedBlightfangTest.java @@ -7,13 +7,18 @@ import org.mage.test.serverside.base.CardTestPlayerBase; public class HoodedBlightfangTest extends CardTestPlayerBase { + private static final String blightfang = "Hooded Blightfang"; + private static final String goblin = "Raging Goblin"; + private static final String bow = "Bow of Nylea"; + private static final String jace = "Jace Beleren"; + @Test public void testBowOfNylea() { - addCard(Zone.BATTLEFIELD, playerA, "Hooded Blightfang"); - addCard(Zone.BATTLEFIELD, playerA, "Raging Goblin"); - addCard(Zone.BATTLEFIELD, playerA, "Bow of Nylea"); + addCard(Zone.BATTLEFIELD, playerA, blightfang); + addCard(Zone.BATTLEFIELD, playerA, goblin); + addCard(Zone.BATTLEFIELD, playerA, bow); - attack(1, playerA, "Raging Goblin"); + attack(1, playerA, goblin); setStopAt(2, PhaseStep.END_TURN); execute(); assertAllCommandsUsed(); @@ -21,4 +26,20 @@ public class HoodedBlightfangTest extends CardTestPlayerBase { assertLife(playerA, 20 + 1); assertLife(playerB, 20 - 1 - 1); } + + @Test + public void testDeathtouchPlaneswalker() { + addCard(Zone.BATTLEFIELD, playerA, blightfang); + addCard(Zone.BATTLEFIELD, playerA, goblin); + addCard(Zone.BATTLEFIELD, playerA, bow); + addCard(Zone.BATTLEFIELD, playerB, jace); + + attack(1, playerA, goblin, jace); + setStopAt(2, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertPermanentCount(playerB, jace, 0); + assertGraveyardCount(playerB, jace, 1); + } }