Search in sources :

Example 1 with Target

use of mage.target.Target in project mage by magefree.

the class SimulatedPlayer method addAbilityNode.

protected void addAbilityNode(SimulationNode parent, Ability ability, Game game) {
    Game sim = game.copy();
    sim.getStack().push(new StackAbility(ability, playerId));
    ability.activate(sim, false);
    if (ability.activate(sim, false) && ability.isUsesStack()) {
        game.fireEvent(new GameEvent(GameEvent.EventType.TRIGGERED_ABILITY, ability.getId(), ability, ability.getControllerId()));
    }
    sim.applyEffects();
    SimulationNode newNode = new SimulationNode(parent, sim, playerId);
    logger.debug(indent(newNode.getDepth()) + "simulating -- node #:" + SimulationNode.getCount() + " triggered ability option");
    for (Target target : ability.getTargets()) {
        for (UUID targetId : target.getTargets()) {
            newNode.getTargets().add(targetId);
        }
    }
    parent.children.add(newNode);
}
Also used : Target(mage.target.Target) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) StackAbility(mage.game.stack.StackAbility)

Example 2 with Target

use of mage.target.Target 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 3 with Target

use of mage.target.Target 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 4 with Target

use of mage.target.Target 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 5 with Target

use of mage.target.Target 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

Target (mage.target.Target)385 Player (mage.players.Player)291 Permanent (mage.game.permanent.Permanent)223 UUID (java.util.UUID)155 Card (mage.cards.Card)86 TargetPermanent (mage.target.TargetPermanent)80 FilterCard (mage.filter.FilterCard)62 FilterPermanent (mage.filter.FilterPermanent)56 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)54 FixedTarget (mage.target.targetpointer.FixedTarget)49 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)45 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)45 MageObject (mage.MageObject)43 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)42 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)38 TargetOpponent (mage.target.common.TargetOpponent)35 CardsImpl (mage.cards.CardsImpl)32 ArrayList (java.util.ArrayList)31 ContinuousEffect (mage.abilities.effects.ContinuousEffect)31 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)30