Search in sources :

Example 1 with TriggeredAbility

use of mage.abilities.TriggeredAbility in project mage by magefree.

the class SimulatedPlayer method triggerAbility.

@Override
public boolean triggerAbility(TriggeredAbility source, Game game) {
    Ability ability = source.copy();
    List<Ability> options = getPlayableOptions(ability, game);
    if (options.isEmpty()) {
        if (logger.isDebugEnabled())
            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 {
        SimulationNode parent = (SimulationNode) game.getCustomData();
        if (parent.getDepth() == maxDepth)
            return true;
        logger.debug(indent(parent.getDepth()) + "simulating -- triggered ability - adding children:" + options.size());
        for (Ability option : options) {
            addAbilityNode(parent, option, game);
        }
    }
    return true;
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) TriggeredAbility(mage.abilities.TriggeredAbility) SpellAbility(mage.abilities.SpellAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) GameEvent(mage.game.events.GameEvent) StackAbility(mage.game.stack.StackAbility)

Example 2 with TriggeredAbility

use of mage.abilities.TriggeredAbility in project mage by magefree.

the class ManaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = getPlayer(game, source);
    if (player == null) {
        return false;
    }
    if (game.inCheckPlayableState()) {
        // So it's important if ManaEffects overwrite the apply method to take care for this.
        if (source instanceof TriggeredAbility) {
            player.addAvailableTriggeredMana(getNetMana(game, source));
        }
        // No need to add mana to pool during checkPlayable
        return true;
    }
    Mana manaToAdd = produceMana(game, source);
    if (manaToAdd != null && manaToAdd.count() > 0) {
        checkToFirePossibleEvents(manaToAdd, game, source);
        addManaToPool(player, manaToAdd, game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) TriggeredAbility(mage.abilities.TriggeredAbility)

Example 3 with TriggeredAbility

use of mage.abilities.TriggeredAbility 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)

Example 4 with TriggeredAbility

use of mage.abilities.TriggeredAbility in project mage by magefree.

the class SanctuaryInterveningIfTriggeredAbility method makeTrigger.

private static TriggeredAbility makeTrigger(OneShotEffect effect1, OneShotEffect effect2, ObjectColor color1, ObjectColor color2) {
    TriggeredAbility ability = new BeginningOfUpkeepTriggeredAbility(new ConditionalOneShotEffect(effect1, new InvertCondition(makeAndCondition(color1, color2))), TargetController.YOU, false);
    ability.addEffect(new ConditionalOneShotEffect(effect2, makeAndCondition(color1, color2)));
    return ability;
}
Also used : InvertCondition(mage.abilities.condition.InvertCondition) TriggeredAbility(mage.abilities.TriggeredAbility) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect)

Example 5 with TriggeredAbility

use of mage.abilities.TriggeredAbility in project mage by magefree.

the class TraceUtil method traceTriggeredAbilities.

/**
 * Prints out a status of the currently existing triggered abilities
 * @param game
 */
public static void traceTriggeredAbilities(Game game) {
    log.info("-------------------------------------------------------------------------------------------------");
    log.info("Turn: " + game.getTurnNum() + " - currently existing triggered abilities: " + game.getState().getTriggers().size());
    Map<String, String> orderedAbilities = new TreeMap<>();
    for (Map.Entry<String, TriggeredAbility> entry : game.getState().getTriggers().entrySet()) {
        Player controller = game.getPlayer(entry.getValue().getControllerId());
        MageObject source = game.getObject(entry.getValue().getSourceId());
        orderedAbilities.put((controller == null ? "no controller" : controller.getName()) + (source == null ? "no source" : source.getIdName()) + entry.getKey(), entry.getKey());
    }
    String playerName = "";
    for (Map.Entry<String, String> entry : orderedAbilities.entrySet()) {
        TriggeredAbility trAbility = game.getState().getTriggers().get(entry.getValue());
        Player controller = game.getPlayer(trAbility.getControllerId());
        MageObject source = game.getObject(trAbility.getSourceId());
        if (!controller.getName().equals(playerName)) {
            playerName = controller.getName();
            log.info("--- Player: " + playerName + "  --------------------------------");
        }
        log.info((source == null ? "no source" : source.getIdName()) + " -> " + trAbility.getRule());
    }
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TriggeredAbility(mage.abilities.TriggeredAbility)

Aggregations

TriggeredAbility (mage.abilities.TriggeredAbility)9 Ability (mage.abilities.Ability)4 Permanent (mage.game.permanent.Permanent)3 Player (mage.players.Player)3 ActivatedAbility (mage.abilities.ActivatedAbility)2 PassAbility (mage.abilities.common.PassAbility)2 GameEvent (mage.game.events.GameEvent)2 StackAbility (mage.game.stack.StackAbility)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 MageObject (mage.MageObject)1 MageObjectReference (mage.MageObjectReference)1 Mana (mage.Mana)1 SpellAbility (mage.abilities.SpellAbility)1 BecomesTargetTriggeredAbility (mage.abilities.common.BecomesTargetTriggeredAbility)1 BeginningOfEndStepTriggeredAbility (mage.abilities.common.BeginningOfEndStepTriggeredAbility)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 InvertCondition (mage.abilities.condition.InvertCondition)1 ConditionalInterveningIfTriggeredAbility (mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility)1