diff --git a/Mage.Sets/src/mage/cards/d/DackFayden.java b/Mage.Sets/src/mage/cards/d/DackFayden.java index 42c2af272a..71cc828ce7 100644 --- a/Mage.Sets/src/mage/cards/d/DackFayden.java +++ b/Mage.Sets/src/mage/cards/d/DackFayden.java @@ -27,9 +27,6 @@ */ package mage.cards.d; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.LoyaltyAbility; import mage.abilities.SpellAbility; @@ -59,6 +56,11 @@ import mage.players.Player; import mage.target.Target; import mage.target.TargetPlayer; import mage.target.common.TargetArtifactPermanent; +import mage.target.targetpointer.FixedTargets; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; /** * @@ -135,7 +137,7 @@ class DackFaydenEmblemTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { boolean returnValue = false; - List targettedPermanents = new ArrayList<>(0); + List targetedPermanentIds = new ArrayList<>(0); Player player = game.getPlayer(this.getControllerId()); if (player != null) { if (event.getPlayerId().equals(this.getControllerId())) { @@ -147,7 +149,7 @@ class DackFaydenEmblemTriggeredAbility extends TriggeredAbilityImpl { for (UUID targetId : target.getTargets()) { if (game.getBattlefield().containsPermanent(targetId)) { returnValue = true; - targettedPermanents.add(targetId); + targetedPermanentIds.add(targetId); } } } @@ -156,7 +158,7 @@ class DackFaydenEmblemTriggeredAbility extends TriggeredAbilityImpl { for (UUID targetId : effect.getTargetPointer().getTargets(game, spellAbility)) { if (game.getBattlefield().containsPermanent(targetId)) { returnValue = true; - targettedPermanents.add(targetId); + targetedPermanentIds.add(targetId); } } } @@ -166,7 +168,15 @@ class DackFaydenEmblemTriggeredAbility extends TriggeredAbilityImpl { for (Effect effect : this.getEffects()) { if (effect instanceof DackFaydenEmblemEffect) { DackFaydenEmblemEffect dackEffect = (DackFaydenEmblemEffect) effect; - dackEffect.setPermanents(targettedPermanents); + List permanents = new ArrayList<>(); + for(UUID permanentId : targetedPermanentIds) { + Permanent permanent = game.getPermanent(permanentId); + if(permanent != null) { + permanents.add(permanent); + } + } + + dackEffect.setTargets(permanents, game); } } return returnValue; @@ -180,7 +190,7 @@ class DackFaydenEmblemTriggeredAbility extends TriggeredAbilityImpl { class DackFaydenEmblemEffect extends ContinuousEffectImpl { - protected List permanents; + protected FixedTargets fixedTargets; DackFaydenEmblemEffect() { super(Duration.EndOfGame, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl); @@ -189,7 +199,7 @@ class DackFaydenEmblemEffect extends ContinuousEffectImpl { DackFaydenEmblemEffect(final DackFaydenEmblemEffect effect) { super(effect); - this.permanents = effect.permanents; + this.fixedTargets = effect.fixedTargets; } @Override @@ -199,7 +209,7 @@ class DackFaydenEmblemEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - for (UUID permanentId : this.permanents) { + for (UUID permanentId : fixedTargets.getTargets(game, source)) { Permanent permanent = game.getPermanent(permanentId); if (permanent != null) { permanent.changeControllerId(source.getControllerId(), game); @@ -208,7 +218,7 @@ class DackFaydenEmblemEffect extends ContinuousEffectImpl { return true; } - public void setPermanents(List targettedPermanents) { - this.permanents = new ArrayList<>(targettedPermanents); + public void setTargets(List targetedPermanents, Game game) { + this.fixedTargets = new FixedTargets(targetedPermanents, game); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/control/DackFaydenTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/control/DackFaydenTest.java new file mode 100644 index 0000000000..ec07d31058 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/control/DackFaydenTest.java @@ -0,0 +1,73 @@ +package org.mage.test.cards.control; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.counters.CounterType; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +public class DackFaydenTest extends CardTestPlayerBase { + + @Test + public void testDackFaydenEmblem() { + + addCard(Zone.BATTLEFIELD, playerA, "Dack Fayden"); + + addCard(Zone.BATTLEFIELD, playerB, "Ornithopter"); + + addCard(Zone.HAND, playerA, "Gut Shot"); + + + for(int i = 1; i < 8; i+= 2) { + activateAbility(i, PhaseStep.PRECOMBAT_MAIN, playerA,"+1: Target player draws two cards, then discards two cards.", playerB); + } + + activateAbility(9, PhaseStep.PRECOMBAT_MAIN, playerA, + "-6: You get an emblem with \"Whenever you cast a spell that targets one or more permanents, gain control of those permanents.\""); + + castSpell(10, PhaseStep.PRECOMBAT_MAIN, playerA, "Gut Shot", "Ornithopter"); + + setStopAt(10, PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 18); + assertLife(playerB, 20); + + assertCounterCount("Dack Fayden", CounterType.LOYALTY, 1); + assertPermanentCount(playerA, "Ornithopter", 1); + } + + //Ensure that if a permanent moves to a different zone and comes back, + //it won't still be under the controller of Dack's Emblem. + @Test + public void testDackFaydenEmblemAcrossZones() { + addCard(Zone.BATTLEFIELD, playerA, "Dack Fayden"); + + addCard(Zone.BATTLEFIELD, playerB, "Ornithopter"); + + addCard(Zone.HAND, playerA, "Gut Shot"); + + addCard(Zone.HAND, playerA, "Unsummon"); + addCard(Zone.BATTLEFIELD, playerA, "Island"); + + for(int i = 1; i < 8; i+= 2) { + activateAbility(i, PhaseStep.PRECOMBAT_MAIN, playerA,"+1: Target player draws two cards, then discards two cards.", playerB); + } + + activateAbility(9, PhaseStep.PRECOMBAT_MAIN, playerA, + "-6: You get an emblem with \"Whenever you cast a spell that targets one or more permanents, gain control of those permanents.\""); + + castSpell(10, PhaseStep.PRECOMBAT_MAIN, playerA, "Gut Shot", "Ornithopter"); + castSpell(10, PhaseStep.PRECOMBAT_MAIN, playerA, "Unsummon", "Ornithopter", "Gut Shot", StackClause.WHILE_NOT_ON_STACK); + castSpell(10, PhaseStep.PRECOMBAT_MAIN, playerB, "Ornithopter"); + + setStopAt(10, PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 18); + assertLife(playerB, 20); + + assertCounterCount("Dack Fayden", CounterType.LOYALTY, 1); + assertPermanentCount(playerB, "Ornithopter", 1); + } +}