Search in sources :

Example 1 with GameEvent

use of mage.game.events.GameEvent 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;
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) GameEvent(mage.game.events.GameEvent) StackAbility(mage.game.stack.StackAbility)

Example 2 with GameEvent

use of mage.game.events.GameEvent 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 3 with GameEvent

use of mage.game.events.GameEvent 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 4 with GameEvent

use of mage.game.events.GameEvent in project mage by magefree.

the class ComputerPlayer3 method simulateCombat.

protected int simulateCombat(Game game, SimulationNode node, int alpha, int beta, boolean counter) {
    Integer val = null;
    if (Thread.interrupted()) {
        Thread.currentThread().interrupt();
        logger.debug(indent(node.depth) + "interrupted");
        return GameStateEvaluator.evaluate(playerId, game);
    }
    if (game.getTurn().getStepType() != PhaseStep.DECLARE_BLOCKERS) {
        game.getTurn().setPhase(new CombatPhase());
        if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
            simulateStep(game, new BeginCombatStep());
            game.getPhase().setStep(new DeclareAttackersStep());
            if (!game.getStep().skipStep(game, game.getActivePlayerId())) {
                game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE, null, null, game.getActivePlayerId()));
                if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_ATTACKERS, game.getActivePlayerId(), game.getActivePlayerId()))) {
                    val = simulateAttackers(game, node, game.getActivePlayerId(), alpha, beta, counter);
                }
            } else if (!counter) {
                val = simulatePostCombatMain(game, node, alpha, beta);
            }
        }
    } else {
        if (!game.getStep().skipStep(game, game.getActivePlayerId())) {
            game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_PRE, null, null, game.getActivePlayerId()));
            if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_BLOCKERS, game.getActivePlayerId(), game.getActivePlayerId()))) {
                // only suitable for two player games - only simulates blocks for 1st defender
                val = simulateBlockers(game, node, game.getCombat().getDefenders().iterator().next(), alpha, beta, counter);
            }
        } else if (!counter) {
            finishCombat(game);
            val = simulateCounterAttack(game, node, alpha, beta);
        }
    }
    if (val == null)
        val = GameStateEvaluator.evaluate(playerId, game);
    if (logger.isDebugEnabled())
        logger.debug(indent(node.depth) + "returning -- combat score: " + val + " depth:" + node.depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
    return val;
}
Also used : GameEvent(mage.game.events.GameEvent)

Example 5 with GameEvent

use of mage.game.events.GameEvent in project mage by magefree.

the class AuriokReplicaEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
    if (!game.replaceEvent(preventEvent)) {
        int damage = event.getAmount();
        event.setAmount(0);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
    }
    return true;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Aggregations

GameEvent (mage.game.events.GameEvent)82 Permanent (mage.game.permanent.Permanent)28 Player (mage.players.Player)24 PreventDamageEvent (mage.game.events.PreventDamageEvent)23 PreventedDamageEvent (mage.game.events.PreventedDamageEvent)23 Game (mage.game.Game)22 Ability (mage.abilities.Ability)15 MageInt (mage.MageInt)13 CardImpl (mage.cards.CardImpl)13 CardSetInfo (mage.cards.CardSetInfo)13 java.util (java.util)12 OneShotEffect (mage.abilities.effects.OneShotEffect)12 Watcher (mage.watchers.Watcher)12 MageObjectReference (mage.MageObjectReference)11 Card (mage.cards.Card)11 UUID (java.util.UUID)10 TriggeredAbilityImpl (mage.abilities.TriggeredAbilityImpl)10 mage.constants (mage.constants)10 MageObject (mage.MageObject)9 Spell (mage.game.stack.Spell)9