Search in sources :

Example 1 with TargetAddress

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

the class MoveTargetAuraEffect method apply.

@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
    Permanent potentialAttachment = input.getObject();
    for (TargetAddress addr : TargetAddress.walk(aura)) {
        Target target = addr.getTarget(aura);
        Filter filter = target.getFilter();
        return filter.match(potentialAttachment, game);
    }
    return false;
}
Also used : Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Filter(mage.filter.Filter) TargetAddress(mage.util.TargetAddress)

Example 2 with TargetAddress

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

the class InkTreaderNephilimEffect method checkInterveningIfClause.

@Override
public boolean checkInterveningIfClause(Game game) {
    Spell spell = (Spell) getEffects().get(0).getValue("triggeringSpell");
    if (spell == null) {
        return false;
    }
    boolean flag = false;
    for (TargetAddress addr : TargetAddress.walk(spell)) {
        Target targetInstance = addr.getTarget(spell);
        for (UUID target : targetInstance.getTargets()) {
            if (target == null) {
                continue;
            }
            Permanent permanent = game.getPermanent(target);
            if (permanent == null || !permanent.getId().equals(getSourceId())) {
                return false;
            }
            if (getSourceObjectZoneChangeCounter() != 0 && getSourceObjectZoneChangeCounter() != permanent.getZoneChangeCounter(game)) {
                return false;
            }
            flag = true;
        }
    }
    return flag;
}
Also used : Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetAddress(mage.util.TargetAddress) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 3 with TargetAddress

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

the class MirrorwingDragonCopySpellEffect method checkSpell.

private boolean checkSpell(Spell spell, Game game) {
    if (spell == null || !spell.isInstantOrSorcery(game)) {
        return false;
    }
    boolean noTargets = true;
    for (TargetAddress addr : TargetAddress.walk(spell)) {
        if (addr == null) {
            continue;
        }
        noTargets = false;
        Target targetInstance = addr.getTarget(spell);
        if (targetInstance == null) {
            continue;
        }
        for (UUID target : targetInstance.getTargets()) {
            if (target == null) {
                continue;
            }
            Permanent permanent = game.getPermanent(target);
            if (permanent == null || !permanent.getId().equals(getSourceId())) {
                return false;
            }
        }
    }
    if (noTargets) {
        return false;
    }
    getEffects().setValue("triggeringSpell", spell);
    return true;
}
Also used : Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetAddress(mage.util.TargetAddress) UUID(java.util.UUID)

Example 4 with TargetAddress

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

the class ZadaHedronGrinderCopySpellEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!isControlledBy(event.getPlayerId())) {
        return false;
    }
    Spell spell = game.getSpell(event.getTargetId());
    if (spell == null || !spell.isInstantOrSorcery(game)) {
        return false;
    }
    boolean noTargets = true;
    for (TargetAddress addr : TargetAddress.walk(spell)) {
        if (addr == null) {
            continue;
        }
        noTargets = false;
        Target targetInstance = addr.getTarget(spell);
        if (targetInstance == null) {
            continue;
        }
        for (UUID target : targetInstance.getTargets()) {
            if (target == null) {
                continue;
            }
            Permanent permanent = game.getPermanent(target);
            if (permanent == null || !permanent.getId().equals(getSourceId())) {
                return false;
            }
        }
    }
    if (noTargets) {
        return false;
    }
    getEffects().setValue("triggeringSpell", spell);
    return true;
}
Also used : Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetAddress(mage.util.TargetAddress) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 5 with TargetAddress

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

the class SpellWithOnlySingleTargetPredicate method apply.

@Override
public boolean apply(ObjectSourcePlayer<Spell> input, Game game) {
    Spell spell = input.getObject();
    if (spell == null) {
        return false;
    }
    UUID singleTarget = null;
    for (TargetAddress addr : TargetAddress.walk(spell)) {
        Target targetInstance = addr.getTarget(spell);
        for (UUID targetId : targetInstance.getTargets()) {
            if (singleTarget == null) {
                singleTarget = targetId;
            } else if (!singleTarget.equals(targetId)) {
                return false;
            }
        }
    }
    return singleTarget != null;
}
Also used : Target(mage.target.Target) TargetAddress(mage.util.TargetAddress) UUID(java.util.UUID) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

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