use of mage.game.stack.StackAbility in project mage by magefree.
the class SimulatedPlayerMCTS method triggerAbility.
@Override
public boolean triggerAbility(TriggeredAbility source, Game game) {
// logger.info("trigger");
if (source != null && source.canChooseTarget(game, playerId)) {
Ability ability;
List<Ability> options = getPlayableOptions(source, game);
if (options.isEmpty()) {
ability = source;
} else {
if (options.size() == 1) {
ability = options.get(0);
} else {
ability = options.get(RandomUtil.nextInt(options.size()));
}
}
if (ability.isUsesStack()) {
game.getStack().push(new StackAbility(ability, playerId));
if (ability.activate(game, false)) {
game.fireEvent(new GameEvent(GameEvent.EventType.TRIGGERED_ABILITY, ability.getId(), ability, ability.getControllerId()));
actionCount++;
return true;
}
} else {
if (ability.activate(game, false)) {
ability.resolve(game);
actionCount++;
return true;
}
}
}
return false;
}
use of mage.game.stack.StackAbility 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);
}
use of mage.game.stack.StackAbility 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.game.stack.StackAbility in project mage by magefree.
the class HauntingWindTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (permanent == null || !permanent.isArtifact(game)) {
return false;
}
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility == null) {
return false;
}
String abilityText = stackAbility.getRule(true);
if (abilityText.contains("{T}:") || abilityText.contains("{T},") || abilityText.contains("{T} or")) {
return false;
}
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(permanent.getControllerId(), game));
}
return true;
}
if (event.getType() == GameEvent.EventType.TAPPED) {
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (permanent == null || !permanent.isArtifact(game)) {
return false;
}
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(permanent.getControllerId(), game));
}
return true;
}
return false;
}
use of mage.game.stack.StackAbility in project mage by magefree.
the class CopyStackAbilityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
StackAbility ability = (StackAbility) getValue("stackAbility");
if (controller == null || ability == null) {
return false;
}
ability.createCopyOnStack(game, source, source.getControllerId(), true);
return true;
}
Aggregations