Search in sources :

Example 6 with StackAbility

use of mage.game.stack.StackAbility in project mage by magefree.

the class CantBeTargetedTargetEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (getTargetPointer().getTargets(game, source).contains(event.getTargetId())) {
        if (targetController == TargetController.OPPONENT && !game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
            return false;
        }
        StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
        MageObject sourceObject;
        if (stackObject instanceof StackAbility) {
            sourceObject = ((StackAbility) stackObject).getSourceObject(game);
        } else {
            sourceObject = stackObject;
        }
        if (filterSource.match(sourceObject, game)) {
            return true;
        }
    }
    return false;
}
Also used : StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) StackAbility(mage.game.stack.StackAbility)

Example 7 with StackAbility

use of mage.game.stack.StackAbility in project mage by magefree.

the class HopeOfGhirapurCombatDamageWatcher method playerGotCombatDamage.

/**
 * Checks if the current object has damaged the player during the current
 * turn.
 *
 * @param objectId
 * @param playerId
 * @return
 */
public boolean playerGotCombatDamage(UUID objectId, UUID playerId, Game game) {
    StackObject stackObject = game.getState().getStack().getStackObject(objectId);
    MageObjectReference mor;
    if (stackObject instanceof StackAbility) {
        // This is neccessary because the source object was sacrificed as cost and the correct zone change counter for target calid check can only be get from stack
        mor = new MageObjectReference(objectId, ((StackAbility) stackObject).getSourceObjectZoneChangeCounter(), game);
    } else {
        mor = new MageObjectReference(objectId, game);
    }
    if (combatDamagedPlayers.containsKey(mor)) {
        return combatDamagedPlayers.get(mor).contains(playerId);
    }
    return false;
}
Also used : StackObject(mage.game.stack.StackObject) MageObjectReference(mage.MageObjectReference) StackAbility(mage.game.stack.StackAbility)

Example 8 with StackAbility

use of mage.game.stack.StackAbility in project mage by magefree.

the class TawnosUrzasApprenticeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (stackAbility != null) {
        Player controller = game.getPlayer(source.getControllerId());
        Permanent sourcePermanent = game.getPermanent(source.getSourceId());
        if (controller != null && sourcePermanent != null) {
            stackAbility.createCopyOnStack(game, source, source.getControllerId(), true);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) StackAbility(mage.game.stack.StackAbility)

Example 9 with StackAbility

use of mage.game.stack.StackAbility in project mage by magefree.

the class VodalianWarMachineWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
        if (event.getSourceId() != null) {
            Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
            if (sourcePermanent != null) {
                StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
                if (stackAbility != null) {
                    Ability ability = stackAbility.getStackAbility();
                    if (ability != null) {
                        for (Cost cost : ability.getCosts()) {
                            if (cost instanceof TapTargetCost && cost.isPaid()) {
                                TapTargetCost tapCost = (TapTargetCost) cost;
                                if (tapCost.getTarget().isChosen()) {
                                    MageObjectReference mor = new MageObjectReference(sourcePermanent.getId(), sourcePermanent.getZoneChangeCounter(game), game);
                                    Set<MageObjectReference> toAdd;
                                    if (tappedMerfolkIds.get(mor) == null) {
                                        toAdd = new HashSet<>();
                                    } else {
                                        toAdd = tappedMerfolkIds.get(mor);
                                    }
                                    for (UUID targetId : tapCost.getTarget().getTargets()) {
                                        toAdd.add(new MageObjectReference(targetId, game));
                                    }
                                    tappedMerfolkIds.put(mor, toAdd);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) DiesSourceTriggeredAbility(mage.abilities.common.DiesSourceTriggeredAbility) StackAbility(mage.game.stack.StackAbility) DefenderAbility(mage.abilities.keyword.DefenderAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TapTargetCost(mage.abilities.costs.common.TapTargetCost) TapTargetCost(mage.abilities.costs.common.TapTargetCost) Cost(mage.abilities.costs.Cost) StackAbility(mage.game.stack.StackAbility) MageObjectReference(mage.MageObjectReference)

Example 10 with StackAbility

use of mage.game.stack.StackAbility in project mage by magefree.

the class SimulatedPlayer2 method triggerAbility.

@Override
public boolean triggerAbility(TriggeredAbility source, Game game) {
    Ability ability = source.copy();
    List<Ability> options = getPlayableOptions(ability, game);
    if (options.isEmpty()) {
        logger.debug("simulating -- triggered ability:" + ability);
        game.getStack().push(new StackAbility(ability, playerId));
        if (ability.activate(game, false) && ability.isUsesStack()) {
            game.fireEvent(new GameEvent(GameEvent.EventType.TRIGGERED_ABILITY, ability.getId(), ability, ability.getControllerId()));
        }
        game.applyEffects();
        game.getPlayers().resetPassed();
    } else {
        SimulationNode2 parent = (SimulationNode2) game.getCustomData();
        int depth = parent.getDepth() - 1;
        if (depth == 0) {
            return true;
        }
        logger.debug("simulating -- triggered ability - adding children:" + options.size());
        for (Ability option : options) {
            addAbilityNode(parent, option, depth, game);
        }
    }
    return true;
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) TriggeredAbility(mage.abilities.TriggeredAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) GameEvent(mage.game.events.GameEvent) StackAbility(mage.game.stack.StackAbility)

Aggregations

StackAbility (mage.game.stack.StackAbility)42 Permanent (mage.game.permanent.Permanent)15 StackObject (mage.game.stack.StackObject)12 Player (mage.players.Player)11 Target (mage.target.Target)9 MageObject (mage.MageObject)8 Ability (mage.abilities.Ability)7 Spell (mage.game.stack.Spell)7 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)6 GameEvent (mage.game.events.GameEvent)6 Game (mage.game.Game)5 UUID (java.util.UUID)4 MageObjectReference (mage.MageObjectReference)4 PassAbility (mage.abilities.common.PassAbility)4 Mode (mage.abilities.Mode)3 Card (mage.cards.Card)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 ActivatedAbility (mage.abilities.ActivatedAbility)2 LoyaltyAbility (mage.abilities.LoyaltyAbility)2 SpellAbility (mage.abilities.SpellAbility)2