Search in sources :

Example 1 with TetraviteToken

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

the class TetravusPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (player == null || permanent == null) {
        return false;
    }
    int countersToRemove = permanent.getCounters(game).getCount(CounterType.P1P1);
    if (countersToRemove == 0) {
        return false;
    }
    countersToRemove = player.getAmount(0, countersToRemove, "Choose an amount of counters to remove", game);
    Cost cost = new RemoveCountersSourceCost(CounterType.P1P1.createInstance(countersToRemove));
    if (cost.pay(source, game, source, source.getControllerId(), true)) {
        CreateTokenEffect effect = new CreateTokenEffect(new TetraviteToken(), countersToRemove);
        effect.apply(game, source);
        Object object = game.getState().getValue(CardUtil.getObjectZoneString("_tokensCreated", permanent, game));
        Set<UUID> tokensCreated;
        if (object != null) {
            tokensCreated = (Set<UUID>) object;
        } else {
            tokensCreated = new HashSet<>();
        }
        for (UUID tokenId : effect.getLastAddedTokenIds()) {
            if (tokenId != null) {
                tokensCreated.add(tokenId);
            }
        }
        game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
    }
    return false;
}
Also used : Player(mage.players.Player) RemoveCountersSourceCost(mage.abilities.costs.common.RemoveCountersSourceCost) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) TetraviteToken(mage.game.permanent.token.TetraviteToken) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) ExileTargetCost(mage.abilities.costs.common.ExileTargetCost) RemoveCountersSourceCost(mage.abilities.costs.common.RemoveCountersSourceCost)

Aggregations

UUID (java.util.UUID)1 Cost (mage.abilities.costs.Cost)1 ExileTargetCost (mage.abilities.costs.common.ExileTargetCost)1 RemoveCountersSourceCost (mage.abilities.costs.common.RemoveCountersSourceCost)1 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)1 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)1 Permanent (mage.game.permanent.Permanent)1 TetraviteToken (mage.game.permanent.token.TetraviteToken)1 Player (mage.players.Player)1 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)1