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