* Fixed a bug of Exchange control were activated abilities got the wrong controller.

This commit is contained in:
LevelX2 2014-12-27 02:18:29 +01:00
parent 6c93ba1285
commit 18e4bc7f18
4 changed files with 60 additions and 3 deletions

View file

@ -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) {

View file

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

View file

@ -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) {

View file

@ -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