Test and fix for Oblivion Ring and Planeswalkers interaction

This commit is contained in:
magenoxx 2012-06-29 15:56:04 +04:00
parent 5541fe4163
commit 3f14fdc0ca
3 changed files with 30 additions and 4 deletions

View file

@ -2,7 +2,6 @@ package org.mage.test.cards.triggers;
import mage.Constants; import mage.Constants;
import org.junit.Test; import org.junit.Test;
import org.mage.test.serverside.base.CardTestBase;
import org.mage.test.serverside.base.CardTestPlayerBase; import org.mage.test.serverside.base.CardTestPlayerBase;
/** /**
@ -77,4 +76,27 @@ public class OblivionRingTest extends CardTestPlayerBase {
assertPermanentCount(playerA, "Oblivion Ring", 0); assertPermanentCount(playerA, "Oblivion Ring", 0);
assertPermanentCount(playerB, "Craw Wurm", 1); assertPermanentCount(playerB, "Craw Wurm", 1);
} }
/**
* Tests that when Oblivion Ring gets destroyed planeswalker returns with new counters and can be used second time at the same turn
*/
@Test
public void testExilePlaneswalker() {
addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 5);
addCard(Constants.Zone.HAND, playerA, "Oblivion Ring");
addCard(Constants.Zone.BATTLEFIELD, playerA, "Jace Beleren");
addCard(Constants.Zone.HAND, playerA, "Revoke Existence");
activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "-1: Target player draws 1 card", playerA);
castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Oblivion Ring");
castSpell(1, Constants.PhaseStep.POSTCOMBAT_MAIN, playerA, "Revoke Existence", "Oblivion Ring");
activateAbility(1, Constants.PhaseStep.POSTCOMBAT_MAIN, playerA, "-1: Target player draws 1 card", playerA);
setStopAt(1, Constants.PhaseStep.END_TURN);
execute();
assertPermanentCount(playerA, "Oblivion Ring", 0);
assertPermanentCount(playerA, "Jace Beleren", 1); // returns back
assertHandCount(playerA, 2); // can use ability twice
}
} }

View file

@ -69,8 +69,10 @@ public class EntersBattlefieldEffect extends ReplacementEffectImpl<EntersBattlef
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD && event.getTargetId().equals(source.getSourceId())) { if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD) {
return true; if (event.getTargetId().equals(source.getSourceId())) {
return true;
}
} }
return false; return false;
} }

View file

@ -254,6 +254,7 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
} }
game.rememberLKI(objectId, event.getFromZone(), this); game.rememberLKI(objectId, event.getFromZone(), this);
} }
updateZoneChangeCounter();
switch (event.getToZone()) { switch (event.getToZone()) {
case GRAVEYARD: case GRAVEYARD:
game.getPlayer(ownerId).putInGraveyard(this, game, !flag); game.getPlayer(ownerId).putInGraveyard(this, game, !flag);
@ -276,6 +277,8 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
case BATTLEFIELD: case BATTLEFIELD:
PermanentCard permanent = new PermanentCard(this, ownerId); PermanentCard permanent = new PermanentCard(this, ownerId);
game.addPermanent(permanent); game.addPermanent(permanent);
game.setZone(objectId, Zone.BATTLEFIELD);
game.applyEffects();
permanent.entersBattlefield(sourceId, game); permanent.entersBattlefield(sourceId, game);
game.applyEffects(); game.applyEffects();
if (flag) if (flag)
@ -287,7 +290,6 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
return false; return false;
} }
setControllerId(ownerId); setControllerId(ownerId);
updateZoneChangeCounter();
game.setZone(objectId, event.getToZone()); game.setZone(objectId, event.getToZone());
game.fireEvent(event); game.fireEvent(event);
return game.getState().getZone(objectId) == toZone; return game.getState().getZone(objectId) == toZone;