Search in sources :

Example 36 with PermanentToken

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

the class OneOrMoreTest method test_ChooseModes_AsCardOrder.

/**
 * Sublime Epiphany can bounce and
 * copy the same creature. This is because legality of targets is checked
 * only as the spell begins to resolve, not in between modes, and because
 * the games can use last known info of the legal target.
 */
@Test
public void test_ChooseModes_AsCardOrder() {
    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, "3");
    setModeChoice(playerA, "4");
    setModeChoice(playerA, "5");
    // 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)

Example 37 with PermanentToken

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

the class CardView method fillEmpty.

private void fillEmpty(Card card, boolean controlled) {
    this.name = "Face Down";
    this.displayName = name;
    this.displayFullName = name;
    this.rules = new ArrayList<>();
    this.power = "";
    this.toughness = "";
    this.loyalty = "";
    this.startingLoyalty = "";
    this.cardTypes = new ArrayList<>();
    this.subTypes = new SubTypes();
    this.superTypes = EnumSet.noneOf(SuperType.class);
    this.color = new ObjectColor();
    this.frameColor = new ObjectColor();
    this.frameStyle = FrameStyle.M15_NORMAL;
    this.manaCostLeftStr = "";
    this.manaCostRightStr = "";
    this.manaValue = 0;
    // the controller can see more information (e.g. enlarged image) than other players for face down cards (e.g. Morph played face down)
    if (!controlled) {
        this.rarity = Rarity.COMMON;
        this.expansionSetCode = "";
        this.cardNumber = "0";
    } else {
        this.rarity = card.getRarity();
    }
    if (card != null) {
        if (card instanceof Permanent) {
            this.mageObjectType = MageObjectType.PERMANENT;
        } else if (card.isCopy()) {
            this.mageObjectType = MageObjectType.COPY_CARD;
        } else {
            this.mageObjectType = MageObjectType.CARD;
        }
        if (card instanceof PermanentToken) {
            this.mageObjectType = MageObjectType.TOKEN;
        }
        if (card instanceof Spell) {
            this.mageObjectType = MageObjectType.SPELL;
        }
    }
}
Also used : SubTypes(mage.util.SubTypes) Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor) PermanentToken(mage.game.permanent.PermanentToken) Spell(mage.game.stack.Spell)

Example 38 with PermanentToken

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

the class CollisionOfRealmsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Player> players = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, playerId, game);
        boolean hasNonToken = permanents.stream().filter(permanent -> !(permanent instanceof PermanentToken)).anyMatch(permanent -> permanent.isCreature(game));
        player.putCardsOnBottomOfLibrary(new CardsImpl(permanents), game, source, false);
        player.shuffleLibrary(source, game);
        if (hasNonToken) {
            players.add(player);
        }
    }
    for (Player player : players) {
        Cards cards = new CardsImpl();
        Card creature = revealUntilCreature(cards, player, game);
        player.revealCards(source, cards, game);
        if (creature != null) {
            player.moveCards(creature, Zone.BATTLEFIELD, source, game);
        }
        cards.retainZone(Zone.LIBRARY, game);
        player.putCardsOnBottomOfLibrary(cards, game, source, false);
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) Zone(mage.constants.Zone) mage.cards(mage.cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Player(mage.players.Player) ArrayList(java.util.ArrayList) Game(mage.game.Game) List(java.util.List) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) PermanentToken(mage.game.permanent.PermanentToken) UUID(java.util.UUID)

Example 39 with PermanentToken

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

the class DayOfTheDragonsLeavesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null) {
        for (Permanent dragon : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
            if (dragon != null) {
                dragon.sacrifice(source, game);
            }
        }
        int zoneChangeCounter = source.getSourceObjectZoneChangeCounter();
        if (zoneChangeCounter > 0 && !(sourceObject instanceof PermanentToken)) {
            zoneChangeCounter--;
        }
        ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), zoneChangeCounter));
        if (exile != null) {
            controller.moveCards(exile, Zone.BATTLEFIELD, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) PermanentToken(mage.game.permanent.PermanentToken)

Example 40 with PermanentToken

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

the class AetherspoutsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    game.getPlayerList();
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        PlayerList playerList = game.getPlayerList().copy();
        playerList.setCurrent(game.getActivePlayerId());
        Player player = game.getPlayer(game.getActivePlayerId());
        Player activePlayer = player;
        do {
            List<Permanent> permanentsToTop = new ArrayList<>();
            List<Permanent> permanentsToBottom = new ArrayList<>();
            for (Permanent permanent : game.getState().getBattlefield().getActivePermanents(new FilterAttackingCreature(), player.getId(), source.getSourceId(), game)) {
                if (permanent.isOwnedBy(player.getId())) {
                    if (player.chooseUse(outcome, "Put " + permanent.getLogName() + " to the top? (else it goes to bottom)", source, game)) {
                        permanentsToTop.add(permanent);
                        game.informPlayers(permanent.getLogName() + " goes to the top of " + player.getLogName() + "'s library");
                    } else {
                        permanentsToBottom.add(permanent);
                        game.informPlayers(permanent.getLogName() + " goes to the bottom of " + player.getLogName() + "'s library");
                    }
                }
            }
            // cards to top
            Cards cards = new CardsImpl();
            List<Permanent> toLibrary = new ArrayList<>();
            for (Permanent permanent : permanentsToTop) {
                if (permanent instanceof PermanentToken) {
                    toLibrary.add(permanent);
                } else {
                    Card card = game.getCard(permanent.getId());
                    if (card != null) {
                        cards.add(card);
                    }
                }
            }
            TargetCard target = new TargetCard(Zone.BATTLEFIELD, new FilterCard("order to put on the top of library (last choosen will be the top most)"));
            while (cards.size() > 1) {
                if (!player.canRespond()) {
                    return false;
                }
                player.choose(Outcome.Neutral, cards, target, game);
                Card card = cards.get(target.getFirstTarget(), game);
                if (card != null) {
                    cards.remove(card);
                    Permanent permanent = game.getPermanent(card.getId());
                    if (permanent != null) {
                        toLibrary.add(permanent);
                    }
                }
                target.clearChosen();
            }
            if (cards.size() == 1) {
                Card card = cards.get(cards.iterator().next(), game);
                Permanent permanent = game.getPermanent(card.getId());
                if (permanent != null) {
                    toLibrary.add(permanent);
                }
            }
            // move all permanents to lib at the same time
            for (Permanent permanent : toLibrary) {
                player.moveCardToLibraryWithInfo(permanent, source, game, Zone.BATTLEFIELD, true, false);
            }
            // cards to bottom
            cards.clear();
            toLibrary.clear();
            for (Permanent permanent : permanentsToBottom) {
                if (permanent instanceof PermanentToken) {
                    toLibrary.add(permanent);
                } else {
                    Card card = game.getCard(permanent.getId());
                    if (card != null) {
                        cards.add(card);
                    }
                }
            }
            target = new TargetCard(Zone.BATTLEFIELD, new FilterCard("order to put on bottom of library (last choosen will be bottommost card)"));
            while (player.canRespond() && cards.size() > 1) {
                player.choose(Outcome.Neutral, cards, target, game);
                Card card = cards.get(target.getFirstTarget(), game);
                if (card != null) {
                    cards.remove(card);
                    Permanent permanent = game.getPermanent(card.getId());
                    if (permanent != null) {
                        toLibrary.add(permanent);
                    }
                }
                target.clearChosen();
            }
            if (cards.size() == 1) {
                Card card = cards.get(cards.iterator().next(), game);
                Permanent permanent = game.getPermanent(card.getId());
                if (permanent != null) {
                    toLibrary.add(permanent);
                }
            }
            // move all permanents to lib at the same time
            for (Permanent permanent : toLibrary) {
                player.moveCardToLibraryWithInfo(permanent, source, game, Zone.BATTLEFIELD, false, false);
            }
            player = playerList.getNext(game, false);
        } while (player != null && !player.getId().equals(game.getActivePlayerId()) && activePlayer.canRespond());
        return true;
    }
    return false;
}
Also used : FilterAttackingCreature(mage.filter.common.FilterAttackingCreature) FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) PlayerList(mage.players.PlayerList) ArrayList(java.util.ArrayList) PermanentToken(mage.game.permanent.PermanentToken) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

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