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;
}
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;
}
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;
}
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;
}
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());
}
}
Aggregations