diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/HuntmasterOfTheFellsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/HuntmasterOfTheFellsTest.java index 86d0e89e24..882947e517 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/HuntmasterOfTheFellsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/HuntmasterOfTheFellsTest.java @@ -6,7 +6,7 @@ import org.mage.test.serverside.base.CardTestPlayerBase; /** * - * @author BetaSteward + * @author BetaSteward, noxx */ public class HuntmasterOfTheFellsTest extends CardTestPlayerBase { @@ -28,5 +28,31 @@ public class HuntmasterOfTheFellsTest extends CardTestPlayerBase { assertPermanentCount(playerA, "Ravager of the Fells", 1); assertPermanentCount(playerB, "Ornithopter", 0); } - + + /** + * Tests first trigger happens both on enter battlefield and transform events + */ + @Test + public void testCard2() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest", 3); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain"); + addCard(Constants.Zone.HAND, playerA, "Huntmaster of the Fells"); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Ornithopter"); + + addCard(Constants.Zone.BATTLEFIELD, playerB, "Mountain", 2); + addCard(Constants.Zone.HAND, playerB, "Lightning Bolt", 2); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Huntmaster of the Fells"); + castSpell(3, Constants.PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", playerA); + castSpell(3, Constants.PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", playerA); + setStopAt(4, Constants.PhaseStep.DRAW); + execute(); + + assertLife(playerA, 18); // -6 damage, +4 life + assertLife(playerB, 18); + assertPermanentCount(playerA, "Wolf", 2); + assertPermanentCount(playerA, "Ravager of the Fells", 0); // transformed back + assertPermanentCount(playerA, "Huntmaster of the Fells", 1); + assertPermanentCount(playerB, "Ornithopter", 0); + } } diff --git a/Mage/src/mage/abilities/TriggeredAbilities.java b/Mage/src/mage/abilities/TriggeredAbilities.java index aaa8c92710..b4e2516dd5 100644 --- a/Mage/src/mage/abilities/TriggeredAbilities.java +++ b/Mage/src/mage/abilities/TriggeredAbilities.java @@ -32,6 +32,7 @@ import mage.MageObject; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; +import mage.game.permanent.PermanentCard; import java.util.HashMap; import java.util.Map; @@ -54,26 +55,47 @@ public class TriggeredAbilities extends HashMap { public void checkTriggers(GameEvent event, Game game) { for (TriggeredAbility ability: this.values()) { if (ability.isInUseableZone(game, true)) { - MageObject object = game.getPermanent(ability.getSourceId()); - if (object == null) { - object = game.getLastKnownInformation(ability.getSourceId(), event.getZone()); - if (object == null) { - object = game.getObject(ability.getSourceId()); - } - } - if (object != null && object.getAbilities().contains(ability)) { - if (object instanceof Permanent) { - ability.setControllerId(((Permanent) object).getControllerId()); - } - if (ability.checkTrigger(event, game)) { - UUID controllerId = ability.getControllerId(); - ability.trigger(game, controllerId); + MageObject object = getMageObject(event, game, ability); + if (object != null) { + if (checkAbilityStillExists(ability, object)) { + if (object instanceof Permanent) { + ability.setControllerId(((Permanent) object).getControllerId()); + } + if (ability.checkTrigger(event, game)) { + UUID controllerId = ability.getControllerId(); + ability.trigger(game, controllerId); + } } } } } } + private boolean checkAbilityStillExists(TriggeredAbility ability, MageObject object) { + boolean exists = true; + if (!object.getAbilities().contains(ability)) { + exists = false; + if (object instanceof PermanentCard) { + PermanentCard permanent = (PermanentCard)object; + if (permanent.canTransform()) { + exists = permanent.getCard().getAbilities().contains(ability); + } + } + } + return exists; + } + + private MageObject getMageObject(GameEvent event, Game game, TriggeredAbility ability) { + MageObject object = game.getPermanent(ability.getSourceId()); + if (object == null) { + object = game.getLastKnownInformation(ability.getSourceId(), event.getZone()); + if (object == null) { + object = game.getObject(ability.getSourceId()); + } + } + return object; + } + public void add(TriggeredAbility ability) { this.put(ability.getId(), ability); }