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;
}
Aggregations