Search in sources :

Example 1 with CreateTokenEvent

use of mage.game.events.CreateTokenEvent in project mage by magefree.

the class ChatterfangSquirrelGeneralReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    if (event instanceof CreateTokenEvent) {
        CreateTokenEvent tokenEvent = (CreateTokenEvent) event;
        SquirrelToken squirrelToken = null;
        int amount = 0;
        Map<Token, Integer> tokens = tokenEvent.getTokens();
        for (Map.Entry<Token, Integer> entry : tokens.entrySet()) {
            amount += entry.getValue();
            if (entry.getKey() instanceof SquirrelToken) {
                squirrelToken = (SquirrelToken) entry.getKey();
            }
        }
        if (squirrelToken == null) {
            squirrelToken = new SquirrelToken();
        }
        tokens.put(squirrelToken, tokens.getOrDefault(squirrelToken, 0) + amount);
    }
    return false;
}
Also used : SquirrelToken(mage.game.permanent.token.SquirrelToken) Token(mage.game.permanent.token.Token) Map(java.util.Map) SquirrelToken(mage.game.permanent.token.SquirrelToken) CreateTokenEvent(mage.game.events.CreateTokenEvent)

Example 2 with CreateTokenEvent

use of mage.game.events.CreateTokenEvent in project mage by magefree.

the class XornReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    if (event instanceof CreateTokenEvent) {
        CreateTokenEvent tokenEvent = (CreateTokenEvent) event;
        TreasureToken treasureToken = null;
        Map<Token, Integer> tokens = tokenEvent.getTokens();
        for (Token token : tokens.keySet()) {
            if (token instanceof TreasureToken) {
                treasureToken = (TreasureToken) token;
                break;
            }
        }
        if (treasureToken == null) {
            treasureToken = new TreasureToken();
        }
        tokens.put(treasureToken, tokens.getOrDefault(treasureToken, 0) + 1);
    }
    return false;
}
Also used : TreasureToken(mage.game.permanent.token.TreasureToken) Token(mage.game.permanent.token.Token) TreasureToken(mage.game.permanent.token.TreasureToken) CreateTokenEvent(mage.game.events.CreateTokenEvent)

Example 3 with CreateTokenEvent

use of mage.game.events.CreateTokenEvent in project mage by magefree.

the class EsixFractalBloomWatcher method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(0, 1, filter, true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    if (event instanceof CreateTokenEvent) {
        CreateTokenEvent tokenEvent = (CreateTokenEvent) event;
        int amount = tokenEvent.getAmount();
        tokenEvent.getTokens().clear();
        tokenEvent.getTokens().put(copyPermanentToToken(permanent, game, source), amount);
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) CreateTokenEvent(mage.game.events.CreateTokenEvent)

Example 4 with CreateTokenEvent

use of mage.game.events.CreateTokenEvent in project mage by magefree.

the class TokenImpl method putOntoBattlefield.

@Override
public boolean putOntoBattlefield(int amount, Game game, Ability source, UUID controllerId, boolean tapped, boolean attacking, UUID attackedPlayer, boolean created) {
    Player controller = game.getPlayer(controllerId);
    if (controller == null) {
        return false;
    }
    if (amount == 0) {
        return false;
    }
    lastAddedTokenIds.clear();
    CreateTokenEvent event = new CreateTokenEvent(source, controllerId, amount, this);
    if (!created || !game.replaceEvent(event)) {
        int currentTokens = game.getBattlefield().countTokens(event.getPlayerId());
        int tokenSlots = Math.max(MAX_TOKENS_PER_GAME - currentTokens, 0);
        int amountToRemove = event.getAmount() - tokenSlots;
        if (amountToRemove > 0) {
            game.informPlayers("The token limit per player is " + MAX_TOKENS_PER_GAME + ", " + controller.getName() + " will only create " + tokenSlots + " tokens.");
            Iterator<Map.Entry<Token, Integer>> it = event.getTokens().entrySet().iterator();
            while (it.hasNext() && amountToRemove > 0) {
                Map.Entry<Token, Integer> entry = it.next();
                int newValue = entry.getValue() - amountToRemove;
                if (newValue > 0) {
                    entry.setValue(newValue);
                    break;
                }
                amountToRemove -= entry.getValue();
                it.remove();
            }
        }
        putOntoBattlefieldHelper(event, game, source, tapped, attacking, attackedPlayer, created);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) PermanentToken(mage.game.permanent.PermanentToken) CreateTokenEvent(mage.game.events.CreateTokenEvent)

Example 5 with CreateTokenEvent

use of mage.game.events.CreateTokenEvent in project mage by magefree.

the class DivineVisitationEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    if (event instanceof CreateTokenEvent) {
        int amount = 0;
        CreateTokenEvent tokenEvent = (CreateTokenEvent) event;
        Iterator<Map.Entry<Token, Integer>> it = tokenEvent.getTokens().entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<Token, Integer> entry = it.next();
            if (entry.getKey().isCreature(game)) {
                amount += entry.getValue();
                it.remove();
            }
        }
        if (amount > 0) {
            tokenEvent.getTokens().put(new AngelVigilanceToken(), amount);
        }
    }
    return false;
}
Also used : Token(mage.game.permanent.token.Token) AngelVigilanceToken(mage.game.permanent.token.AngelVigilanceToken) AngelVigilanceToken(mage.game.permanent.token.AngelVigilanceToken) Map(java.util.Map) CreateTokenEvent(mage.game.events.CreateTokenEvent)

Aggregations

CreateTokenEvent (mage.game.events.CreateTokenEvent)6 Token (mage.game.permanent.token.Token)4 Map (java.util.Map)3 TreasureToken (mage.game.permanent.token.TreasureToken)2 Player (mage.players.Player)2 FilterPermanent (mage.filter.FilterPermanent)1 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)1 Permanent (mage.game.permanent.Permanent)1 PermanentToken (mage.game.permanent.PermanentToken)1 AngelVigilanceToken (mage.game.permanent.token.AngelVigilanceToken)1 ClueArtifactToken (mage.game.permanent.token.ClueArtifactToken)1 FoodToken (mage.game.permanent.token.FoodToken)1 SquirrelToken (mage.game.permanent.token.SquirrelToken)1 TargetPermanent (mage.target.TargetPermanent)1