Search in sources :

Example 1 with DragonToken

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

the class DescentOfTheDragonsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<UUID, Integer> playersWithTargets = new HashMap<>();
        for (Target target : source.getTargets()) {
            for (UUID permanentId : target.getTargets()) {
                Permanent permanent = game.getPermanent(permanentId);
                if (permanent != null) {
                    UUID controllerOfTargetId = permanent.getControllerId();
                    if (permanent.destroy(source, game, false)) {
                        int count = playersWithTargets.getOrDefault(controllerOfTargetId, 0);
                        playersWithTargets.put(controllerOfTargetId, count + 1);
                    }
                }
            }
        }
        DragonToken dragonToken = new DragonToken();
        for (Map.Entry<UUID, Integer> amountTokensPerPlayer : playersWithTargets.entrySet()) {
            dragonToken.putOntoBattlefield(amountTokensPerPlayer.getValue(), game, source, amountTokensPerPlayer.getKey());
        }
        return true;
    }
    return false;
}
Also used : DragonToken(mage.game.permanent.token.DragonToken) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) HashMap(java.util.HashMap) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Permanent (mage.game.permanent.Permanent)1 DragonToken (mage.game.permanent.token.DragonToken)1 Player (mage.players.Player)1 Target (mage.target.Target)1 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)1