Search in sources :

Example 1 with Boar2Token

use of mage.game.permanent.token.Boar2Token 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)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Card (mage.cards.Card)1 Cards (mage.cards.Cards)1 CardsImpl (mage.cards.CardsImpl)1 Permanent (mage.game.permanent.Permanent)1 PermanentToken (mage.game.permanent.PermanentToken)1 Boar2Token (mage.game.permanent.token.Boar2Token)1 Player (mage.players.Player)1 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)1