use of mage.game.permanent.PermanentToken in project mage by magefree.
the class ChronozoaTest method testDuplicationEffect.
/**
* 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);
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, currentGame);
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(currentGame);
Assert.assertEquals(1, counters.size());
for (final Counter counter : counters.values()) {
Assert.assertEquals(CounterType.TIME.getName(), counter.getName());
Assert.assertEquals(2, counter.getCount());
}
}
}
use of mage.game.permanent.PermanentToken in project mage by magefree.
the class CurseOfTheSwineEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Cards creaturesToExile = new CardsImpl();
if (controller != null) {
Map<UUID, Integer> playersWithTargets = new HashMap<>();
for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
Permanent creature = game.getPermanent(targetId);
// TODO implement a way to verify that tokens are indeed exiled from the battlefield
if (creature instanceof PermanentToken) {
playersWithTargets.put(creature.getControllerId(), playersWithTargets.getOrDefault(creature.getControllerId(), 0) + 1);
}
if (creature != null) {
creaturesToExile.add(creature);
}
}
// move creatures to exile all at once
controller.moveCards(creaturesToExile, Zone.EXILED, source, game);
// Count all creatures actually exiled and add them to the player's count
for (Card card : creaturesToExile.getCards(game)) {
Permanent lkiP = game.getPermanentOrLKIBattlefield(card.getId());
// note that tokens have no LKI once they are moved from the battlefield so they are handled earlier
if (lkiP != null && game.getState().getZone(lkiP.getId()) == Zone.EXILED) {
playersWithTargets.put(lkiP.getControllerId(), playersWithTargets.getOrDefault(lkiP.getControllerId(), 0) + 1);
}
}
Boar2Token swineToken = new Boar2Token();
for (Map.Entry<UUID, Integer> exiledByController : playersWithTargets.entrySet()) {
swineToken.putOntoBattlefield(exiledByController.getValue(), game, source, exiledByController.getKey());
}
return true;
}
return false;
}
use of mage.game.permanent.PermanentToken in project mage by magefree.
the class MimicVatCreateTokenEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
// make sure card is on battlefield
UUID sourceCardId = getSourceId();
if (game.getPermanent(sourceCardId) == null) {
// or it is being removed
if (game.getLastKnownInformation(sourceCardId, Zone.BATTLEFIELD) == null) {
return false;
}
}
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
Permanent permanent = zEvent.getTarget();
if (permanent != null && zEvent.isDiesEvent() && !(permanent instanceof PermanentToken) && permanent.isCreature(game)) {
getEffects().get(0).setTargetPointer(new FixedTarget(permanent.getId(), game));
return true;
}
return false;
}
use of mage.game.permanent.PermanentToken in project mage by magefree.
the class MageBook method addToken.
private void addToken(Token token, BigCard bigCard, UUID gameId, Rectangle rectangle) {
if (cardDimension == null) {
cardDimension = new Dimension(ClientDefaultSettings.dimensions.getFrameWidth(), ClientDefaultSettings.dimensions.getFrameHeight());
}
PermanentToken newToken = new PermanentToken(token, null, token.getOriginalExpansionSetCode(), null);
newToken.removeSummoningSickness();
PermanentView theToken = new PermanentView(newToken, null, null, null);
theToken.setInViewerOnly(true);
final MageCard cardImg = Plugins.instance.getMagePermanent(theToken, bigCard, new CardIconRenderSettings(), cardDimension, gameId, true, PreferencesDialog.getRenderMode(), true);
cardImg.setCardContainerRef(jLayeredPane);
jLayeredPane.add(cardImg, JLayeredPane.DEFAULT_LAYER, 10);
cardImg.update(theToken);
cardImg.setCardBounds(rectangle.x, rectangle.y, cardDimensions.getFrameWidth(), cardDimensions.getFrameHeight());
}
use of mage.game.permanent.PermanentToken in project mage by magefree.
the class FloodOfTearsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
List<Permanent> nonlands = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), source.getSourceId(), game);
Cards cards = new CardsImpl();
if (!nonlands.isEmpty()) {
nonlands.forEach(cards::add);
boolean putIntoPlay = nonlands.stream().filter(permanent -> permanent.isControlledBy(player.getId())).filter(permanent -> !(permanent instanceof PermanentToken)).count() > 3;
player.moveCards(cards, Zone.HAND, source, game);
if (putIntoPlay) {
new PutCardFromHandOntoBattlefieldEffect().apply(game, source);
}
return true;
}
return false;
}
Aggregations