Fix Dack Fayden Emblem.

The emblem's effect was referencing the permanent directly.
This meant that if the permanent left and came back, the control effect
would start working again.
This commit is contained in:
Nathaniel Brandes 2017-03-09 02:24:34 -08:00
parent 964f2fb9d0
commit dd0c89db1d
2 changed files with 95 additions and 12 deletions

View file

@ -27,9 +27,6 @@
*/ */
package mage.cards.d; package mage.cards.d;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility; import mage.abilities.LoyaltyAbility;
import mage.abilities.SpellAbility; import mage.abilities.SpellAbility;
@ -59,6 +56,11 @@ import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
import mage.target.common.TargetArtifactPermanent; 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 @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
boolean returnValue = false; boolean returnValue = false;
List<UUID> targettedPermanents = new ArrayList<>(0); List<UUID> targetedPermanentIds = new ArrayList<>(0);
Player player = game.getPlayer(this.getControllerId()); Player player = game.getPlayer(this.getControllerId());
if (player != null) { if (player != null) {
if (event.getPlayerId().equals(this.getControllerId())) { if (event.getPlayerId().equals(this.getControllerId())) {
@ -147,7 +149,7 @@ class DackFaydenEmblemTriggeredAbility extends TriggeredAbilityImpl {
for (UUID targetId : target.getTargets()) { for (UUID targetId : target.getTargets()) {
if (game.getBattlefield().containsPermanent(targetId)) { if (game.getBattlefield().containsPermanent(targetId)) {
returnValue = true; returnValue = true;
targettedPermanents.add(targetId); targetedPermanentIds.add(targetId);
} }
} }
} }
@ -156,7 +158,7 @@ class DackFaydenEmblemTriggeredAbility extends TriggeredAbilityImpl {
for (UUID targetId : effect.getTargetPointer().getTargets(game, spellAbility)) { for (UUID targetId : effect.getTargetPointer().getTargets(game, spellAbility)) {
if (game.getBattlefield().containsPermanent(targetId)) { if (game.getBattlefield().containsPermanent(targetId)) {
returnValue = true; returnValue = true;
targettedPermanents.add(targetId); targetedPermanentIds.add(targetId);
} }
} }
} }
@ -166,7 +168,15 @@ class DackFaydenEmblemTriggeredAbility extends TriggeredAbilityImpl {
for (Effect effect : this.getEffects()) { for (Effect effect : this.getEffects()) {
if (effect instanceof DackFaydenEmblemEffect) { if (effect instanceof DackFaydenEmblemEffect) {
DackFaydenEmblemEffect dackEffect = (DackFaydenEmblemEffect) effect; DackFaydenEmblemEffect dackEffect = (DackFaydenEmblemEffect) effect;
dackEffect.setPermanents(targettedPermanents); List<Permanent> permanents = new ArrayList<>();
for(UUID permanentId : targetedPermanentIds) {
Permanent permanent = game.getPermanent(permanentId);
if(permanent != null) {
permanents.add(permanent);
}
}
dackEffect.setTargets(permanents, game);
} }
} }
return returnValue; return returnValue;
@ -180,7 +190,7 @@ class DackFaydenEmblemTriggeredAbility extends TriggeredAbilityImpl {
class DackFaydenEmblemEffect extends ContinuousEffectImpl { class DackFaydenEmblemEffect extends ContinuousEffectImpl {
protected List<UUID> permanents; protected FixedTargets fixedTargets;
DackFaydenEmblemEffect() { DackFaydenEmblemEffect() {
super(Duration.EndOfGame, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl); super(Duration.EndOfGame, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl);
@ -189,7 +199,7 @@ class DackFaydenEmblemEffect extends ContinuousEffectImpl {
DackFaydenEmblemEffect(final DackFaydenEmblemEffect effect) { DackFaydenEmblemEffect(final DackFaydenEmblemEffect effect) {
super(effect); super(effect);
this.permanents = effect.permanents; this.fixedTargets = effect.fixedTargets;
} }
@Override @Override
@ -199,7 +209,7 @@ class DackFaydenEmblemEffect extends ContinuousEffectImpl {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
for (UUID permanentId : this.permanents) { for (UUID permanentId : fixedTargets.getTargets(game, source)) {
Permanent permanent = game.getPermanent(permanentId); Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) { if (permanent != null) {
permanent.changeControllerId(source.getControllerId(), game); permanent.changeControllerId(source.getControllerId(), game);
@ -208,7 +218,7 @@ class DackFaydenEmblemEffect extends ContinuousEffectImpl {
return true; return true;
} }
public void setPermanents(List<UUID> targettedPermanents) { public void setTargets(List<Permanent> targetedPermanents, Game game) {
this.permanents = new ArrayList<>(targettedPermanents); this.fixedTargets = new FixedTargets(targetedPermanents, game);
} }
} }

View file

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