Search in sources :

Example 1 with GoldToken

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;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) CreateTokenTargetEffect(mage.abilities.effects.common.CreateTokenTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) CreateTokenTargetEffect(mage.abilities.effects.common.CreateTokenTargetEffect) Effect(mage.abilities.effects.Effect) AttachEffect(mage.abilities.effects.common.AttachEffect) UUID(java.util.UUID) HashSet(java.util.HashSet) GoldToken(mage.game.permanent.token.GoldToken)

Aggregations

HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 AttachEffect (mage.abilities.effects.common.AttachEffect)1 CreateTokenTargetEffect (mage.abilities.effects.common.CreateTokenTargetEffect)1 Permanent (mage.game.permanent.Permanent)1 GoldToken (mage.game.permanent.token.GoldToken)1 Player (mage.players.Player)1 TargetPlayer (mage.target.TargetPlayer)1 FixedTarget (mage.target.targetpointer.FixedTarget)1