Search in sources :

Example 6 with TargetAddress

use of mage.util.TargetAddress in project mage by magefree.

the class PrecursorGolemCopySpellEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Spell spell = game.getStack().getSpell(event.getTargetId());
    if (spell == null || !spell.isInstantOrSorcery(game)) {
        return false;
    }
    UUID targetGolem = null;
    for (TargetAddress addr : TargetAddress.walk(spell)) {
        Target targetInstance = addr.getTarget(spell);
        for (UUID target : targetInstance.getTargets()) {
            Permanent permanent = game.getPermanent(target);
            if (permanent == null || !permanent.hasSubtype(SubType.GOLEM, game)) {
                return false;
            }
            if (targetGolem == null) {
                targetGolem = target;
            } else // If a spell has multiple targets, but it's targeting the same Golem with all of them, Precursor Golem's last ability will trigger
            {
                if (!targetGolem.equals(target)) {
                    return false;
                }
            }
        }
    }
    if (targetGolem == null) {
        return false;
    }
    getEffects().setValue("triggeringSpell", spell);
    getEffects().setValue("targetedGolem", targetGolem);
    return true;
}
Also used : Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetAddress(mage.util.TargetAddress) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Aggregations

Target (mage.target.Target)6 TargetAddress (mage.util.TargetAddress)6 UUID (java.util.UUID)5 Permanent (mage.game.permanent.Permanent)5 Spell (mage.game.stack.Spell)4 FilterPermanent (mage.filter.FilterPermanent)2 Filter (mage.filter.Filter)1 FilterSpell (mage.filter.FilterSpell)1 TargetPermanent (mage.target.TargetPermanent)1 TargetSpell (mage.target.TargetSpell)1