Search in sources :

Example 16 with PermanentToken

use of mage.game.permanent.PermanentToken in project mage by magefree.

the class UnholyIndentureReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // copy from ReturnToBattlefieldUnderYourControlAttachedEffect
    Object object = getValue("attachedTo");
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && object instanceof Permanent && !(object instanceof PermanentToken)) {
        // not token
        Card card = game.getCard(((Permanent) object).getId());
        // Move the card only, if it is still in the next zone after the battlefield
        if (card != null && card.getZoneChangeCounter(game) == ((Permanent) object).getZoneChangeCounter(game) + 1) {
            Counters countersToAdd = new Counters();
            countersToAdd.addCounter(CounterType.P1P1.createInstance());
            game.setEnterWithCounters(card.getId(), countersToAdd);
            controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, false, null);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PermanentToken(mage.game.permanent.PermanentToken) Counters(mage.counters.Counters) Card(mage.cards.Card)

Example 17 with PermanentToken

use of mage.game.permanent.PermanentToken in project mage by magefree.

the class AetherSnapEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards tokens = new CardsImpl();
    for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getSourceId(), game)) {
        if (permanent instanceof PermanentToken) {
            tokens.add(permanent);
        }
        if (permanent.getCounters(game).isEmpty()) {
            continue;
        }
        Counters counters = permanent.getCounters(game).copy();
        for (Counter counter : counters.values()) {
            permanent.removeCounters(counter, source, game);
        }
    }
    controller.moveCards(tokens, Zone.EXILED, source, game);
    return true;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) Counters(mage.counters.Counters) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 18 with PermanentToken

use of mage.game.permanent.PermanentToken in project mage by magefree.

the class ArboriaEffect method canAttack.

@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
    if (defenderId == null) {
        return true;
    }
    CastSpellYourLastTurnWatcher watcher = game.getState().getWatcher(CastSpellYourLastTurnWatcher.class);
    if (watcher != null && watcher.getAmountOfSpellsCastOnPlayersTurn(defenderId) > 0) {
        return true;
    }
    PermanentsEnteredBattlefieldYourLastTurnWatcher watcher2 = game.getState().getWatcher(PermanentsEnteredBattlefieldYourLastTurnWatcher.class);
    if (watcher2 != null && watcher2.getPermanentsEnteringOnPlayersLastTurn(game, defenderId) != null) {
        for (Permanent permanent : watcher2.getPermanentsEnteringOnPlayersLastTurn(game, defenderId)) {
            if (permanent != null && !(permanent instanceof PermanentToken)) {
                return true;
            }
        }
    }
    return false;
}
Also used : CastSpellYourLastTurnWatcher(mage.watchers.common.CastSpellYourLastTurnWatcher) PermanentsEnteredBattlefieldYourLastTurnWatcher(mage.watchers.common.PermanentsEnteredBattlefieldYourLastTurnWatcher) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken)

Example 19 with PermanentToken

use of mage.game.permanent.PermanentToken in project mage by magefree.

the class DeclarationInStoneEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (targetPermanent != null) {
            Set<Card> cardsToExile = new HashSet<>();
            int nonTokenCount = 0;
            if (CardUtil.haveEmptyName(targetPermanent)) {
                // face down creature
                cardsToExile.add(targetPermanent);
                if (!(targetPermanent instanceof PermanentToken)) {
                    nonTokenCount++;
                }
            } else {
                if (cardsToExile.add(targetPermanent) && !(targetPermanent instanceof PermanentToken)) {
                    nonTokenCount++;
                }
                for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, targetPermanent.getControllerId(), game)) {
                    if (!permanent.getId().equals(targetPermanent.getId()) && CardUtil.haveSameNames(permanent, targetPermanent)) {
                        cardsToExile.add(permanent);
                        // exiled count only matters for non-tokens
                        if (!(permanent instanceof PermanentToken)) {
                            nonTokenCount++;
                        }
                    }
                }
            }
            controller.moveCards(cardsToExile, Zone.EXILED, source, game);
            game.getState().processAction(game);
            if (nonTokenCount > 0) {
                new ClueArtifactToken().putOntoBattlefield(nonTokenCount, game, source, targetPermanent.getControllerId(), false, false);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ClueArtifactToken(mage.game.permanent.token.ClueArtifactToken) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) MageObject(mage.MageObject) PermanentToken(mage.game.permanent.PermanentToken) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 20 with PermanentToken

use of mage.game.permanent.PermanentToken in project mage by magefree.

the class OneOrMoreTest method test_ChooseModes_AsCustomOrder.

@Test
public void test_ChooseModes_AsCustomOrder() {
    // user can select modes in any order, but resolves/targets must be standard (in same order as card's text)
    addCard(Zone.BATTLEFIELD, playerA, "Island", 6);
    // Choose one or more —
    // 1 • Counter target spell
    // 2 • Counter target activated or triggered ability.
    // 3 • Return target nonland permanent to its owner's hand.
    // 4 • Create a token that's a copy of target creature you control.
    // 5 • Target player draws a card.
    // Instant {4}{U}{U}
    addCard(Zone.HAND, playerA, "Sublime Epiphany");
    addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion");
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Sublime Epiphany");
    setModeChoice(playerA, "4");
    setModeChoice(playerA, "5");
    setModeChoice(playerA, "3");
    // for 3
    addTarget(playerA, "Silvercoat Lion");
    // for 4
    addTarget(playerA, "Silvercoat Lion");
    // for 5
    addTarget(playerA, playerB);
    setModeChoice(playerA, null);
    setStrictChooseMode(true);
    setStopAt(1, PhaseStep.BEGIN_COMBAT);
    execute();
    assertAllCommandsUsed();
    assertHandCount(playerB, 1);
    assertHandCount(playerA, "Silvercoat Lion", 1);
    assertPowerToughness(playerA, "Silvercoat Lion", 2, 2);
    Permanent perm = getPermanent("Silvercoat Lion");
    Assert.assertTrue("Silvercoat Lion has to be a Token", perm instanceof PermanentToken);
}
Also used : Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) Test(org.junit.Test)

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