use of mage.game.permanent.token.GoldToken in project mage by magefree.
the class CurseOfOpulenceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
if (enchantment == null) {
return false;
}
Player enchantedPlayer = game.getPlayer(enchantment.getAttachedTo());
if (enchantedPlayer == null) {
return false;
}
Set<UUID> players = new HashSet<>();
for (UUID attacker : game.getCombat().getAttackers()) {
UUID defender = game.getCombat().getDefenderId(attacker);
if (defender.equals(enchantedPlayer.getId()) && game.getPlayer(source.getControllerId()).hasOpponent(game.getPermanent(attacker).getControllerId(), game)) {
players.add(game.getPermanent(attacker).getControllerId());
}
}
players.add(source.getControllerId());
for (UUID player : players) {
game.getPlayer(player);
Effect effect = new CreateTokenTargetEffect(new GoldToken());
effect.setTargetPointer(new FixedTarget(player));
effect.apply(game, source);
}
return true;
}
Aggregations