use of mage.game.permanent.token.Boar2Token in project mage by magefree.
the class CurseOfTheSwineEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Cards creaturesToExile = new CardsImpl();
if (controller != null) {
Map<UUID, Integer> playersWithTargets = new HashMap<>();
for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
Permanent creature = game.getPermanent(targetId);
// TODO implement a way to verify that tokens are indeed exiled from the battlefield
if (creature instanceof PermanentToken) {
playersWithTargets.put(creature.getControllerId(), playersWithTargets.getOrDefault(creature.getControllerId(), 0) + 1);
}
if (creature != null) {
creaturesToExile.add(creature);
}
}
// move creatures to exile all at once
controller.moveCards(creaturesToExile, Zone.EXILED, source, game);
// Count all creatures actually exiled and add them to the player's count
for (Card card : creaturesToExile.getCards(game)) {
Permanent lkiP = game.getPermanentOrLKIBattlefield(card.getId());
// note that tokens have no LKI once they are moved from the battlefield so they are handled earlier
if (lkiP != null && game.getState().getZone(lkiP.getId()) == Zone.EXILED) {
playersWithTargets.put(lkiP.getControllerId(), playersWithTargets.getOrDefault(lkiP.getControllerId(), 0) + 1);
}
}
Boar2Token swineToken = new Boar2Token();
for (Map.Entry<UUID, Integer> exiledByController : playersWithTargets.entrySet()) {
swineToken.putOntoBattlefield(exiledByController.getValue(), game, source, exiledByController.getKey());
}
return true;
}
return false;
}
Aggregations