Search in sources :

Example 11 with PermanentToken

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());
        }
    }
}
Also used : Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) Counters(mage.counters.Counters) Test(org.junit.Test)

Example 12 with PermanentToken

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;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) HashMap(java.util.HashMap) PermanentToken(mage.game.permanent.PermanentToken) Card(mage.cards.Card) UUID(java.util.UUID) Boar2Token(mage.game.permanent.token.Boar2Token) HashMap(java.util.HashMap) Map(java.util.Map) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 13 with PermanentToken

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;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) UUID(java.util.UUID)

Example 14 with PermanentToken

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());
}
Also used : PermanentToken(mage.game.permanent.PermanentToken) MageCard(mage.cards.MageCard) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings)

Example 15 with PermanentToken

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;
}
Also used : StaticFilters(mage.filter.StaticFilters) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) PutCardFromHandOntoBattlefieldEffect(mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) PutCardFromHandOntoBattlefieldEffect(mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Aggregations

PermanentToken (mage.game.permanent.PermanentToken)40 Permanent (mage.game.permanent.Permanent)30 Player (mage.players.Player)14 ZoneChangeEvent (mage.game.events.ZoneChangeEvent)8 Test (org.junit.Test)8 UUID (java.util.UUID)7 MageObject (mage.MageObject)7 Card (mage.cards.Card)7 PermanentCard (mage.game.permanent.PermanentCard)6 Ability (mage.abilities.Ability)5 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)4 FixedTarget (mage.target.targetpointer.FixedTarget)4 Cards (mage.cards.Cards)3 CardsImpl (mage.cards.CardsImpl)3 CardType (mage.constants.CardType)3 Outcome (mage.constants.Outcome)3 Zone (mage.constants.Zone)3 Counters (mage.counters.Counters)3 FilterCard (mage.filter.FilterCard)3 ExileZone (mage.game.ExileZone)3