Test and fix for Issue#42: Creature with undying didn't forget -1/-1 after dying and returning from graveyard

This commit is contained in:
magenoxx 2012-08-16 00:53:42 +04:00
parent 9d99029c75
commit 7d9b338328
4 changed files with 35 additions and 0 deletions

View file

@ -27,6 +27,26 @@ public class UndyingTest extends CardTestPlayerBase {
assertPowerToughness(playerA, "Geralf's Messenger", 4, 3);
}
/**
* Tests boost weren't be applied second time when creature back to battlefield
*/
@Test
public void testWithMassBoost() {
addCard(Constants.Zone.BATTLEFIELD, playerA, "Strangleroot Geist");
addCard(Constants.Zone.BATTLEFIELD, playerB, "Swamp", 3);
addCard(Constants.Zone.HAND, playerB, "Cower in Fear");
castSpell(2, Constants.PhaseStep.PRECOMBAT_MAIN, playerB, "Cower in Fear");
setStopAt(2, Constants.PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Strangleroot Geist", 1);
// dies then returned with +1/+1 counter (and boost doesn't work anymore)
assertPowerToughness(playerA, "Strangleroot Geist", 3, 2);
}
/**
* Tests "Target creature gains undying until end of turn"
*/

View file

@ -35,6 +35,8 @@ import mage.abilities.Ability;
import mage.game.Game;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
*
@ -55,4 +57,5 @@ public interface ContinuousEffect<T extends ContinuousEffect<T>> extends Effect<
public Layer getLayer();
public SubLayer getSublayer();
public void overrideRuleText(String text);
public List<UUID> getAffectedObjects();
}

View file

@ -185,4 +185,8 @@ public abstract class ContinuousEffectImpl<T extends ContinuousEffectImpl<T>> ex
return false;
}
@Override
public List<UUID> getAffectedObjects() {
return this.objects;
}
}

View file

@ -29,6 +29,7 @@
package mage.game.permanent;
import mage.Constants.Zone;
import mage.abilities.effects.ContinuousEffect;
import mage.cards.Card;
import mage.cards.LevelerCard;
import mage.game.Game;
@ -172,6 +173,13 @@ public class PermanentCard extends PermanentImpl<PermanentCard> {
if (controller != null && controller.removeFromBattlefield(this, game)) {
ZoneChangeEvent event = new ZoneChangeEvent(this, sourceId, controllerId, fromZone, toZone);
if (!game.replaceEvent(event)) {
if (event.getFromZone().equals(Zone.BATTLEFIELD)) {
for (ContinuousEffect effect : game.getContinuousEffects().getLayeredEffects(game)) {
if (effect.getAffectedObjects().contains(getId())) {
effect.getAffectedObjects().remove(getId());
}
}
}
Player owner = game.getPlayer(ownerId);
game.rememberLKI(objectId, Zone.BATTLEFIELD, this);
if (owner != null) {