Search in sources :

Example 1 with SaprolingToken

use of mage.game.permanent.token.SaprolingToken in project mage by magefree.

the class FertileImaginationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (player != null && opponent != null && sourceObject != null) {
        Choice choiceImpl = new ChoiceImpl();
        choiceImpl.setChoices(choice);
        if (player.choose(Outcome.Neutral, choiceImpl, game)) {
            CardType type = null;
            String choosenType = choiceImpl.getChoice();
            if (choosenType.equals(CardType.ARTIFACT.toString())) {
                type = CardType.ARTIFACT;
            } else if (choosenType.equals(CardType.LAND.toString())) {
                type = CardType.LAND;
            } else if (choosenType.equals(CardType.CREATURE.toString())) {
                type = CardType.CREATURE;
            } else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
                type = CardType.ENCHANTMENT;
            } else if (choosenType.equals(CardType.INSTANT.toString())) {
                type = CardType.INSTANT;
            } else if (choosenType.equals(CardType.SORCERY.toString())) {
                type = CardType.SORCERY;
            } else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
                type = CardType.PLANESWALKER;
            } else if (choosenType.equals(CardType.TRIBAL.toString())) {
                type = CardType.TRIBAL;
            }
            if (type != null) {
                Cards hand = opponent.getHand();
                SaprolingToken saprolingToken = new SaprolingToken();
                opponent.revealCards(sourceObject.getIdName(), hand, game);
                Set<Card> cards = hand.getCards(game);
                int tokensToMake = 0;
                for (Card card : cards) {
                    if (card != null && card.getCardType(game).contains(type)) {
                        tokensToMake += 2;
                    }
                }
                game.informPlayers(sourceObject.getLogName() + " creates " + (tokensToMake == 0 ? "no" : "" + tokensToMake) + " 1/1 green Saproling creature tokens.");
                saprolingToken.putOntoBattlefield(tokensToMake, game, source, source.getControllerId());
                return true;
            }
        }
    }
    return false;
}
Also used : SaprolingToken(mage.game.permanent.token.SaprolingToken) Player(mage.players.Player) Choice(mage.choices.Choice) CardType(mage.constants.CardType) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) Cards(mage.cards.Cards) Card(mage.cards.Card)

Example 2 with SaprolingToken

use of mage.game.permanent.token.SaprolingToken in project mage by magefree.

the class FlashFoliageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Token token = new SaprolingToken();
        token.putOntoBattlefield(1, game, source, source.getControllerId());
        Permanent attackingCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (attackingCreature != null && game.getState().getCombat() != null) {
            // Possible ruling (see Aetherplasm)
            // The token you created is blocking the attacking creature,
            // even if the block couldn't legally be declared (for example, if that creature
            // enters the battlefield tapped, or it can't block, or the attacking creature
            // has protection from it)
            CombatGroup combatGroup = game.getState().getCombat().findGroup(attackingCreature.getId());
            if (combatGroup != null) {
                for (UUID tokenId : token.getLastAddedTokenIds()) {
                    Permanent saprolingToken = game.getPermanent(tokenId);
                    if (saprolingToken != null) {
                        combatGroup.addBlocker(tokenId, source.getControllerId(), game);
                        game.getCombat().addBlockingGroup(tokenId, attackingCreature.getId(), controller.getId(), game);
                    }
                }
                combatGroup.pickBlockerOrder(attackingCreature.getControllerId(), game);
            }
        }
        return true;
    }
    return false;
}
Also used : SaprolingToken(mage.game.permanent.token.SaprolingToken) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) SaprolingToken(mage.game.permanent.token.SaprolingToken) Token(mage.game.permanent.token.Token) UUID(java.util.UUID) CombatGroup(mage.game.combat.CombatGroup)

Example 3 with SaprolingToken

use of mage.game.permanent.token.SaprolingToken in project mage by magefree.

the class DruidicSatchelEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = controller.getLibrary().getFromTop(game);
    if (card != null) {
        controller.revealCards(source, new CardsImpl(card), game);
        if (card.isCreature(game)) {
            new SaprolingToken().putOntoBattlefield(1, game, source, source.getControllerId());
        }
        if (card.isLand(game)) {
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
        if (!card.isCreature(game) && !card.isLand(game)) {
            controller.gainLife(2, game, source);
        }
    }
    return true;
}
Also used : SaprolingToken(mage.game.permanent.token.SaprolingToken) Player(mage.players.Player) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 4 with SaprolingToken

use of mage.game.permanent.token.SaprolingToken in project mage by magefree.

the class LastStandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Target opponent loses 2 life for each Swamp you control
        Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (opponent != null) {
            int swamps = game.getBattlefield().count(filterSwamp, source.getSourceId(), source.getControllerId(), game);
            opponent.loseLife(swamps * 2, game, source, false);
        }
        // Last Stand deals damage equal to the number of Mountains you control to target creature.
        Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
        if (creature != null) {
            int mountains = game.getBattlefield().count(filterMountain, source.getSourceId(), source.getControllerId(), game);
            if (mountains > 0) {
                creature.damage(mountains, source.getSourceId(), source, game, false, true);
            }
        }
        // Create a 1/1 green Saproling creature token for each Forest you control.
        int forests = game.getBattlefield().count(filterForest, source.getSourceId(), source.getControllerId(), game);
        if (forests > 0) {
            new CreateTokenEffect(new SaprolingToken(), forests).apply(game, source);
        }
        // You gain 2 life for each Plains you control.
        int plains = game.getBattlefield().count(filterPlains, source.getSourceId(), source.getControllerId(), game);
        controller.gainLife(plains * 2, game, source);
        // Draw a card for each Island you control, then discard that many cards
        int islands = game.getBattlefield().count(filterIsland, source.getSourceId(), source.getControllerId(), game);
        if (islands > 0) {
            controller.drawCards(islands, source, game);
            controller.discard(islands, false, false, source, game);
        }
    }
    return false;
}
Also used : SaprolingToken(mage.game.permanent.token.SaprolingToken) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect)

Example 5 with SaprolingToken

use of mage.game.permanent.token.SaprolingToken in project mage by magefree.

the class RithTheAwakenerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    ChoiceColor choice = new ChoiceColor();
    if (controller.choose(outcome, choice, game)) {
        game.informPlayers(controller.getLogName() + " chooses " + choice.getColor());
        FilterPermanent filter = new FilterPermanent();
        filter.add(new ColorPredicate(choice.getColor()));
        int cardsWithColor = game.getBattlefield().count(filter, source.getSourceId(), controller.getId(), game);
        if (cardsWithColor > 0) {
            new CreateTokenEffect(new SaprolingToken(), cardsWithColor).apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) SaprolingToken(mage.game.permanent.token.SaprolingToken) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) ChoiceColor(mage.choices.ChoiceColor)

Aggregations

SaprolingToken (mage.game.permanent.token.SaprolingToken)7 Player (mage.players.Player)6 Card (mage.cards.Card)3 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)2 Permanent (mage.game.permanent.Permanent)2 Token (mage.game.permanent.token.Token)2 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)2 UUID (java.util.UUID)1 MageObject (mage.MageObject)1 Cards (mage.cards.Cards)1 CardsImpl (mage.cards.CardsImpl)1 Choice (mage.choices.Choice)1 ChoiceColor (mage.choices.ChoiceColor)1 ChoiceImpl (mage.choices.ChoiceImpl)1 CardType (mage.constants.CardType)1 FilterCard (mage.filter.FilterCard)1 FilterPermanent (mage.filter.FilterPermanent)1 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)1 FilterCreatureCard (mage.filter.common.FilterCreatureCard)1 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)1