[M21] fixed Hooded Blightfang triggered ability (fixes #7935)

This commit is contained in:
Evan Kranzler 2021-06-24 08:33:40 -04:00
parent 9a4489b47f
commit f27f59603c
2 changed files with 81 additions and 11 deletions

View file

@ -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.";
}
}

View file

@ -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);
}
}