From 18e4bc7f18988e08c96f6c2df97a1973c528834b Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 27 Dec 2014 02:18:29 +0100 Subject: [PATCH] * Fixed a bug of Exchange control were activated abilities got the wrong controller. --- .../src/mage/sets/urzassaga/GildedDrake.java | 2 +- .../cards/control/ExchangeControlTest.java | 57 +++++++++++++++++++ .../ExchangeControlTargetEffect.java | 1 + Mage/src/mage/game/GameImpl.java | 3 +- 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/Mage.Sets/src/mage/sets/urzassaga/GildedDrake.java b/Mage.Sets/src/mage/sets/urzassaga/GildedDrake.java index 6c0f8f4597c..09d3cb09b4b 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/GildedDrake.java +++ b/Mage.Sets/src/mage/sets/urzassaga/GildedDrake.java @@ -106,7 +106,7 @@ class GildedDrakeEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Permanent sourceObject = game.getPermanent(source.getSourceId()); - Permanent targetPermanent = null; + Permanent targetPermanent; Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { if (targetPointer.getFirst(game, source) != null) { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/control/ExchangeControlTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/control/ExchangeControlTest.java index 0ea98553a08..d432d853eec 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/control/ExchangeControlTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/control/ExchangeControlTest.java @@ -1,7 +1,10 @@ package org.mage.test.cards.control; +import mage.abilities.keyword.FlyingAbility; import mage.constants.PhaseStep; import mage.constants.Zone; +import mage.game.permanent.Permanent; +import org.junit.Assert; import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; @@ -178,4 +181,58 @@ public class ExchangeControlTest extends CardTestPlayerBase { // War Falcon can't attack assertLife(playerA, 20); } + + /** + * An control exchanged creature gets an copy effect from + * an creature with an activated ability to the by exchange controlled creature. + * Check that the activated ability is controlled by the new controller of the copy target. + */ + @Test + public void testExchangeAnCopyEffect() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 6); + // Gilded Drake {1}{U} Creature - Drake + // Flying + // When Gilded Drake enters the battlefield, exchange control of Gilded Drake and up to one target + // creature an opponent controls. If you don't make an exchange, sacrifice Gilded Drake. This ability + // can't be countered except by spells and abilities. (This effect lasts indefinitely.) + addCard(Zone.HAND, playerA, "Gilded Drake"); + // Polymorphous Rush {2}{U} - Instant + // Strive — Polymorphous Rush costs {1}{U} more to cast for each target beyond the first. + // Choose a creature on the battlefield. Any number of target creatures you control each become a copy of that creature until end of turn. + addCard(Zone.HAND, playerA, "Polymorphous Rush"); + // {U}: Manta Riders gains flying until end of turn. + addCard(Zone.BATTLEFIELD, playerB, "Manta Riders"); + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); + + // exchange control between Gilded Drake and Silvercoat Lion + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Gilded Drake"); + addTarget(playerA, "Silvercoat Lion"); + // Let your Silvercoat Lion now be a copy of the Manta Riders + castSpell(1, PhaseStep.BEGIN_COMBAT, playerA, "Polymorphous Rush","Silvercoat Lion"); + addTarget(playerA, "Manta Riders"); + + // now use the activated ability to make the "Silvercoat Lions" (that became Mana Riders) flying + activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "{U}: {this} gains Flying until end of turn."); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + // check creatures change their controllers + assertPermanentCount(playerB, "Gilded Drake", 1); + assertGraveyardCount(playerA, "Polymorphous Rush", 1); + + assertPermanentCount(playerB, "Silvercoat Lion", 0); + assertPermanentCount(playerA, "Silvercoat Lion", 0); + + assertPermanentCount(playerB, "Manta Riders", 1); + assertPermanentCount(playerA, "Manta Riders", 1); + + Permanent controlledMantas = getPermanent("Manta Riders", playerA.getId()); + Assert.assertTrue("Manta Riders should have flying ability", controlledMantas.getAbilities().contains(FlyingAbility.getInstance())); + + } + } diff --git a/Mage/src/mage/abilities/effects/common/continious/ExchangeControlTargetEffect.java b/Mage/src/mage/abilities/effects/common/continious/ExchangeControlTargetEffect.java index 08dd94104bb..6ebf8c7cf19 100644 --- a/Mage/src/mage/abilities/effects/common/continious/ExchangeControlTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/ExchangeControlTargetEffect.java @@ -133,6 +133,7 @@ public class ExchangeControlTargetEffect extends ContinuousEffectImpl { continue; } permanent.changeControllerId(lockedControllers.get(permanent.getId()), game); + permanent.getAbilities().setControllerId(lockedControllers.get(permanent.getId())); } if (!toDelete.isEmpty()) { for(UUID uuid: toDelete) { diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index c5f3f6d67a0..83b777ba94e 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -1292,11 +1292,10 @@ public abstract class GameImpl implements Game, Serializable { } applier.apply(this, permanent); - Ability newAbility = source.copy(); - CopyEffect newEffect = new CopyEffect(duration, permanent, copyToPermanent.getId()); newEffect.newId(); newEffect.setApplier(applier); + Ability newAbility = source.copy(); newEffect.init(newAbility, this); // handle copies of copies