Search in sources :

Example 11 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class AuraFinesseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent aura = game.getPermanent(source.getFirstTarget());
        Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
        if (aura != null && creature != null) {
            Permanent oldCreature = game.getPermanent(aura.getAttachedTo());
            if (oldCreature != null && !oldCreature.equals(creature)) {
                Target auraTarget = aura.getSpellAbility().getTargets().get(0);
                if (!auraTarget.canTarget(creature.getId(), game)) {
                    game.informPlayers(aura.getLogName() + " was not attched to " + creature.getLogName() + " because it's no legal target for the aura");
                } else if (oldCreature.removeAttachment(aura.getId(), source, game)) {
                    game.informPlayers(aura.getLogName() + " was unattached from " + oldCreature.getLogName() + " and attached to " + creature.getLogName());
                    creature.addAttachment(aura.getId(), source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Example 12 with Permanent

use of mage.game.permanent.Permanent 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 13 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class AureliasFuryDamagedByWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    AureliasFuryDamagedByWatcher watcher = game.getState().getWatcher(AureliasFuryDamagedByWatcher.class, source.getSourceId());
    if (watcher != null) {
        for (UUID creatureId : watcher.getDamagedCreatures()) {
            Permanent permanent = game.getPermanent(creatureId);
            if (permanent != null) {
                permanent.tap(source, game);
            }
        }
        for (UUID playerId : watcher.getDamagedPlayers()) {
            ContinuousEffect effect = new AureliasFuryCantCastEffect();
            effect.setTargetPointer(new FixedTarget(playerId));
            game.addEffect(effect, source);
        }
        watcher.reset();
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID)

Example 14 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class BattlefieldThaumaturgeSpellsCostReductionEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    int reduceAmount = 0;
    if (game.inCheckPlayableState()) {
        // checking state (search max possible targets)
        reduceAmount = getMaxPossibleTargetCreatures(abilityToModify, game);
    } else {
        // real cast check
        Set<UUID> creaturesTargeted = new HashSet<>();
        for (Target target : abilityToModify.getAllSelectedTargets()) {
            if (target.isNotTarget()) {
                continue;
            }
            for (UUID uuid : target.getTargets()) {
                Permanent permanent = game.getPermanent(uuid);
                if (permanent != null && permanent.isCreature(game)) {
                    creaturesTargeted.add(permanent.getId());
                }
            }
        }
        reduceAmount = creaturesTargeted.size();
    }
    CardUtil.reduceCost(abilityToModify, reduceAmount);
    return true;
}
Also used : Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 15 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class BattlefieldThaumaturgeSpellsCostReductionEffect method getMaxPossibleTargetCreatures.

private int getMaxPossibleTargetCreatures(Ability ability, Game game) {
    // checks only one mode, so it can be wrong in rare use cases with multi-modes (example: mode one gives +2 and mode two gives another +1 -- total +3)
    int maxAmount = 0;
    for (Mode mode : ability.getModes().values()) {
        for (Target target : mode.getTargets()) {
            if (target.isNotTarget()) {
                continue;
            }
            Set<UUID> possibleList = target.possibleTargets(ability.getSourceId(), ability.getControllerId(), game);
            possibleList.removeIf(id -> {
                Permanent permanent = game.getPermanent(id);
                return permanent == null || !permanent.isCreature(game);
            });
            int possibleAmount = Math.min(possibleList.size(), target.getMaxNumberOfTargets());
            maxAmount = Math.max(maxAmount, possibleAmount);
        }
    }
    return maxAmount;
}
Also used : Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) Mode(mage.abilities.Mode) UUID(java.util.UUID)

Aggregations

Permanent (mage.game.permanent.Permanent)3269 Player (mage.players.Player)1706 UUID (java.util.UUID)665 TargetPermanent (mage.target.TargetPermanent)571 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)541 FixedTarget (mage.target.targetpointer.FixedTarget)496 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)467 FilterPermanent (mage.filter.FilterPermanent)466 Card (mage.cards.Card)425 MageObject (mage.MageObject)246 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)226 Target (mage.target.Target)225 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)217 ContinuousEffect (mage.abilities.effects.ContinuousEffect)207 Effect (mage.abilities.effects.Effect)183 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)179 Test (org.junit.Test)179 OneShotEffect (mage.abilities.effects.OneShotEffect)175 FilterCard (mage.filter.FilterCard)158 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)153