mirror of
https://github.com/correl/mage.git
synced 2024-11-24 19:19:56 +00:00
Test for Copied Gilded Drake reverting control when killed (#9198)
This commit is contained in:
parent
5d11bab6dd
commit
c34c6a59df
5 changed files with 85 additions and 30 deletions
|
@ -72,24 +72,23 @@ class GildedDrakeEffect extends OneShotEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
|
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
if (controller != null) {
|
if (controller == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Permanent sourceObject = game.getPermanent(source.getSourceId());
|
Permanent sourceObject = game.getPermanent(source.getSourceId());
|
||||||
if (sourceObject != null) {
|
if (sourceObject == null) {
|
||||||
if (targetPointer.getFirst(game, source) != null) {
|
return false;
|
||||||
Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
|
}
|
||||||
if (targetPermanent != null) {
|
|
||||||
|
if (targetPointer.getFirst(game, source) == null || game.getPermanent(targetPointer.getFirst(game, source)) == null) {
|
||||||
|
sourceObject.sacrifice(source, game);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
ContinuousEffect effect = new ExchangeControlTargetEffect(Duration.EndOfGame, "", true);
|
ContinuousEffect effect = new ExchangeControlTargetEffect(Duration.EndOfGame, "", true);
|
||||||
effect.setTargetPointer(targetPointer);
|
effect.setTargetPointer(targetPointer);
|
||||||
game.addEffect(effect, source);
|
game.addEffect(effect, source);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sourceObject.sacrifice(source, game);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -84,18 +84,14 @@ class KikiJikiMirrorBreakerEffect extends OneShotEffect {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
|
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
|
||||||
if (permanent != null) {
|
if (permanent == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true);
|
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true);
|
||||||
effect.setTargetPointer(new FixedTarget(permanent, game));
|
effect.setTargetPointer(new FixedTarget(permanent, game));
|
||||||
effect.apply(game, source);
|
effect.apply(game, source);
|
||||||
for (Permanent addedToken : effect.getAddedPermanents()) {
|
effect.sacrificeTokensCreatedAtNextEndStep(game, source);
|
||||||
SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("Sacrifice the token at the beginning of the next end step", source.getControllerId());
|
|
||||||
sacrificeEffect.setTargetPointer(new FixedTarget(addedToken.getId()));
|
|
||||||
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect), source);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import mage.filter.common.FilterControlledCreaturePermanent;
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.filter.predicate.mageobject.AnotherPredicate;
|
import mage.filter.predicate.mageobject.AnotherPredicate;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
import mage.game.permanent.Permanent;
|
||||||
import mage.target.TargetPermanent;
|
import mage.target.TargetPermanent;
|
||||||
import mage.target.targetpointer.FixedTarget;
|
import mage.target.targetpointer.FixedTarget;
|
||||||
|
|
||||||
|
@ -82,6 +83,11 @@ class ReflectionOfKikiJikiEffect extends OneShotEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
|
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
|
||||||
|
if (permanent == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(null, null, true);
|
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(null, null, true);
|
||||||
effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
|
effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
|
||||||
effect.apply(game, source);
|
effect.apply(game, source);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import mage.constants.PhaseStep;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||||
|
|
||||||
|
@ -277,6 +278,56 @@ public class ExchangeControlTest extends CardTestPlayerBase {
|
||||||
assertGraveyardCount(playerB, "Lightning Bolt", 1);
|
assertGraveyardCount(playerB, "Lightning Bolt", 1);
|
||||||
assertGraveyardCount(playerB, "Silvercoat Lion", 1);
|
assertGraveyardCount(playerB, "Silvercoat Lion", 1);
|
||||||
assertGraveyardCount(playerA, "Gilded Drake", 1);
|
assertGraveyardCount(playerA, "Gilded Drake", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. Kiki-Jiki copied Gilded Drake.
|
||||||
|
* 2. Gilded Drake copy is exchanged for another creature.
|
||||||
|
* 3. After the exchange occurs, Gilded Drake is killed by any means.
|
||||||
|
* 4. Exchange creature is returned to previous controller (possible owner) during the next phase.
|
||||||
|
* <p>
|
||||||
|
* See https://github.com/magefree/mage/issues/8742
|
||||||
|
*/
|
||||||
|
@Ignore
|
||||||
|
@Test
|
||||||
|
public void testGildedDrakeCopyExchange() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Kiki-Jiki, Mirror Breaker");
|
||||||
|
addCard(Zone.HAND, playerA, "Gilded Drake");
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Island", 2);
|
||||||
|
|
||||||
|
addCard(Zone.HAND, playerA, "Lightning Bolt", 2);
|
||||||
|
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Dwarven Trader"); // Exchange target
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); // Exchange target
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Gilded Drake");
|
||||||
|
addTarget(playerA, "Dwarven Trader"); // Target for Gilded Drake
|
||||||
|
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, true); // Skip the cast and grab the ETB
|
||||||
|
|
||||||
|
// Copy the drake
|
||||||
|
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}", "Gilded Drake", "When {this}");
|
||||||
|
addTarget(playerA, "Silvercoat Lion"); // Target for Gilded Drake
|
||||||
|
|
||||||
|
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
|
||||||
|
|
||||||
|
// Destroy both of the Drakes
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt");
|
||||||
|
addTarget(playerA, "Gilded Drake");
|
||||||
|
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt");
|
||||||
|
addTarget(playerA, "Gilded Drake");
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
execute();
|
||||||
|
assertAllCommandsUsed();
|
||||||
|
|
||||||
|
assertPermanentCount(playerA, "Kiki-Jiki, Mirror Breaker", 1);
|
||||||
|
assertPermanentCount(playerA, "Dwarven Trader", 1); // Original's exhange target
|
||||||
|
assertPermanentCount(playerA, "Silvercoat Lion", 1); // Copy's exchange target
|
||||||
|
|
||||||
|
assertPermanentCount(playerA, "Gilded Drake", 0);
|
||||||
|
assertPermanentCount(playerB, "Gilded Drake", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class ExchangeControlTargetEffect extends ContinuousEffectImpl {
|
||||||
private boolean withSecondTarget;
|
private boolean withSecondTarget;
|
||||||
private boolean destroyAttachedAuras;
|
private boolean destroyAttachedAuras;
|
||||||
private Map<UUID, Integer> zoneChangeCounter = new HashMap<>();
|
private Map<UUID, Integer> zoneChangeCounter = new HashMap<>();
|
||||||
private Map<UUID, UUID> lockedControllers = new HashMap<>();
|
private Map<UUID, UUID> lockedControllers = new HashMap<>(); // Controllers for each permanent that is enforced by this effect
|
||||||
|
|
||||||
public ExchangeControlTargetEffect(Duration duration, String rule) {
|
public ExchangeControlTargetEffect(Duration duration, String rule) {
|
||||||
this(duration, rule, false);
|
this(duration, rule, false);
|
||||||
|
@ -102,9 +102,11 @@ public class ExchangeControlTargetEffect extends ContinuousEffectImpl {
|
||||||
discard();
|
discard();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Meant to be swapped since this enforced the
|
||||||
this.lockedControllers.put(permanent1.getId(), permanent2.getControllerId());
|
this.lockedControllers.put(permanent1.getId(), permanent2.getControllerId());
|
||||||
this.zoneChangeCounter.put(permanent1.getId(), permanent1.getZoneChangeCounter(game));
|
|
||||||
this.lockedControllers.put(permanent2.getId(), permanent1.getControllerId());
|
this.lockedControllers.put(permanent2.getId(), permanent1.getControllerId());
|
||||||
|
|
||||||
|
this.zoneChangeCounter.put(permanent1.getId(), permanent1.getZoneChangeCounter(game));
|
||||||
this.zoneChangeCounter.put(permanent2.getId(), permanent2.getZoneChangeCounter(game));
|
this.zoneChangeCounter.put(permanent2.getId(), permanent2.getZoneChangeCounter(game));
|
||||||
} else {
|
} else {
|
||||||
// discard if there are less than 2 permanents
|
// discard if there are less than 2 permanents
|
||||||
|
@ -118,7 +120,7 @@ public class ExchangeControlTargetEffect extends ContinuousEffectImpl {
|
||||||
for (Map.Entry<UUID, Integer> entry : zoneChangeCounter.entrySet()) {
|
for (Map.Entry<UUID, Integer> entry : zoneChangeCounter.entrySet()) {
|
||||||
Permanent permanent = game.getPermanent(entry.getKey());
|
Permanent permanent = game.getPermanent(entry.getKey());
|
||||||
if (permanent == null || permanent.getZoneChangeCounter(game) != entry.getValue()) {
|
if (permanent == null || permanent.getZoneChangeCounter(game) != entry.getValue()) {
|
||||||
// controll effect cease if the same permanent is no longer on the battlefield
|
// Control effect cease if the same permanent is no longer on the battlefield
|
||||||
toDelete.add(entry.getKey());
|
toDelete.add(entry.getKey());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -138,6 +140,7 @@ public class ExchangeControlTargetEffect extends ContinuousEffectImpl {
|
||||||
if (!toDelete.isEmpty()) {
|
if (!toDelete.isEmpty()) {
|
||||||
for (UUID uuid : toDelete) {
|
for (UUID uuid : toDelete) {
|
||||||
zoneChangeCounter.remove(uuid);
|
zoneChangeCounter.remove(uuid);
|
||||||
|
lockedControllers.remove(uuid);
|
||||||
}
|
}
|
||||||
if (zoneChangeCounter.isEmpty()) {
|
if (zoneChangeCounter.isEmpty()) {
|
||||||
discard();
|
discard();
|
||||||
|
|
Loading…
Reference in a new issue