fixed the LastTimeCounterRemovedCondition, moved the Chronozoa test to fit the package convention, added a test case

This commit is contained in:
glerman 2015-06-24 12:20:38 +03:00 committed by Gal Lerman
parent 15e3101bf4
commit 9b44c9a087
4 changed files with 91 additions and 20 deletions

View file

@ -28,6 +28,7 @@
package mage.sets.planarchaos;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.common.EntersBattlefieldAbility;

View file

@ -1,17 +0,0 @@
package mage.sets.planarchaos;
import mage.abilities.condition.common.LastTimeCounterRemovedCondition;
import org.junit.Test;
import java.util.UUID;
public class ChronozoaTest {
@Test
public void test() throws Exception {
final Chronozoa chronozoa = new Chronozoa(UUID.randomUUID());
final LastTimeCounterRemovedCondition cond = new LastTimeCounterRemovedCondition();
}
}

View file

@ -0,0 +1,79 @@
package org.mage.test.cards.single;
import java.util.List;
import mage.constants.CardType;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.Counter;
import mage.counters.CounterType;
import mage.counters.Counters;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* Created by glerman on 22/6/15.
*/
public class ChronozoaTest extends CardTestPlayerBase {
/**
* Test that time counters are removed before the draw phase
*/
@Test
public void testVanishing() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 4);
// Flying
// Vanishing 3
// When Chronozoa dies, if it had no time counters on it, put two tokens that are copies of it onto the battlefield.
addCard(Zone.HAND, playerA, "Chronozoa");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa");
setStopAt(5, PhaseStep.DRAW);
execute();
// Make sure one time counter was removed at beginning of playerA turn num 3
assertCounterCount("Chronozoa", CounterType.TIME, 1);
}
/**
* Test that the tokens are put to battlefield if the last time counter is removed
*/
@Test
public void testDuplicationEffect() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 4);
// Flying
// Vanishing 3
// When Chronozoa dies, if it had no time counters on it, put two tokens that are copies of it onto the battlefield.
addCard(Zone.HAND, playerA, "Chronozoa");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa");
setStopAt(9, PhaseStep.PRECOMBAT_MAIN);
execute();
// The original Chronozoa card should be in graveyard
assertGraveyardCount(playerA, 1);
final List<Permanent> creatures = currentGame.getBattlefield().getAllActivePermanents(CardType.CREATURE);
Assert.assertEquals(2, creatures.size());
for (final Permanent creature : creatures) {
// Make sure the creatures are Chronozoa tokens
Assert.assertEquals("Chronozoa", creature.getName());
Assert.assertEquals("Chronozoa has to be a token", true, creature instanceof PermanentToken);
// Make sure each token has 2 time counters
final Counters counters = creature.getCounters();
Assert.assertEquals(1, counters.size());
for(final Counter counter : counters.values()) {
Assert.assertEquals(CounterType.TIME.getName(), counter.getName());
Assert.assertEquals(2, counter.getCount());
}
}
}
}

View file

@ -2,6 +2,7 @@ package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -20,8 +21,15 @@ public class LastTimeCounterRemovedCondition implements Condition{
@Override
public boolean apply(Game game, Ability source) {
final Permanent p = game.getPermanent(source.getSourceId());
final int timeCounters = p.getCounters().getCount(CounterType.TIME);
return timeCounters == 0;
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
if (permanent != null) {
final int timeCounters = permanent.getCounters().getCount(CounterType.TIME);
return timeCounters == 0;
} else {
return false;
}
}
}