Search in sources :

Example 76 with Ability

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

the class ComputerPlayer6 method act.

protected void act(Game game) {
    if (actions == null || actions.isEmpty()) {
        pass(game);
    } else {
        boolean usedStack = false;
        while (actions.peek() != null) {
            Ability ability = actions.poll();
            // example: ===> SELECTED ACTION for PlayerA: Play Swamp
            logger.info(String.format("===> SELECTED ACTION for %s: %s", getName(), ability.toString() + listTargets(game, ability.getTargets(), " (targeting %s)", "")));
            if (!ability.getTargets().isEmpty()) {
                for (Target target : ability.getTargets()) {
                    for (UUID id : target.getTargets()) {
                        target.updateTarget(id, game);
                        if (!target.isNotTarget()) {
                            game.addSimultaneousEvent(GameEvent.getEvent(GameEvent.EventType.TARGETED, id, ability, ability.getControllerId()));
                        }
                    }
                }
                Player player = game.getPlayer(ability.getFirstTarget());
                if (player != null) {
                    logger.info("targets = " + player.getName());
                }
            }
            this.activateAbility((ActivatedAbility) ability, game);
            if (ability.isUsesStack()) {
                usedStack = true;
            }
            if (!suggestedActions.isEmpty() && !(ability instanceof PassAbility)) {
                Iterator<String> it = suggestedActions.iterator();
                while (it.hasNext()) {
                    String action = it.next();
                    Card card = game.getCard(ability.getSourceId());
                    if (card != null && action.equals(card.getName())) {
                        logger.info("-> removed from suggested=" + action);
                        it.remove();
                    }
                }
            }
        }
        if (usedStack) {
            pass(game);
        }
    }
}
Also used : StaticAbility(mage.abilities.StaticAbility) ActivatedAbility(mage.abilities.ActivatedAbility) PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Target(mage.target.Target) Player(mage.players.Player) PassAbility(mage.abilities.common.PassAbility) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 77 with Ability

use of mage.abilities.Ability 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 78 with Ability

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

the class SimulatedPlayer2 method optimizeOptions.

protected List<Ability> optimizeOptions(Game game, List<Ability> options, Ability ability) {
    if (options.isEmpty()) {
        return options;
    }
    // determine if all effects are bad or good
    Iterator<Ability> iterator = options.iterator();
    boolean bad = true;
    boolean good = true;
    // TODO: add custom outcome from ability?
    for (Effect effect : ability.getEffects()) {
        if (effect.getOutcome().isGood()) {
            bad = false;
        } else {
            good = false;
        }
    }
    if (bad) {
        // remove its own creatures, player itself for bad effects with one target
        while (iterator.hasNext()) {
            Ability ability1 = iterator.next();
            if (ability1.getTargets().size() == 1 && ability1.getTargets().get(0).getTargets().size() == 1) {
                Permanent permanent = game.getPermanent(ability1.getFirstTarget());
                if (permanent != null && !game.getOpponents(playerId).contains(permanent.getControllerId())) {
                    iterator.remove();
                    continue;
                }
                if (ability1.getFirstTarget().equals(playerId)) {
                    iterator.remove();
                }
            }
        }
    }
    if (good) {
        // remove opponent creatures and opponent for only good effects with one target
        while (iterator.hasNext()) {
            Ability ability1 = iterator.next();
            if (ability1.getTargets().size() == 1 && ability1.getTargets().get(0).getTargets().size() == 1) {
                Permanent permanent = game.getPermanent(ability1.getFirstTarget());
                if (permanent != null && game.getOpponents(playerId).contains(permanent.getControllerId())) {
                    iterator.remove();
                    continue;
                }
                if (game.getOpponents(playerId).contains(ability1.getFirstTarget())) {
                    iterator.remove();
                }
            }
        }
    }
    return options;
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) TriggeredAbility(mage.abilities.TriggeredAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) Effect(mage.abilities.effects.Effect)

Example 79 with Ability

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

the class SimulatedPlayer2 method simulateOptions.

protected void simulateOptions(Game game) {
    List<ActivatedAbility> playables = game.getPlayer(playerId).getPlayable(game, isSimulatedPlayer);
    playables = filterAbilities(game, playables, suggested);
    for (ActivatedAbility ability : playables) {
        if (ability.getAbilityType() == AbilityType.MANA) {
            continue;
        }
        List<Ability> options = game.getPlayer(playerId).getPlayableOptions(ability, game);
        options = filterOptions(game, options, ability, suggested);
        options = optimizeOptions(game, options, ability);
        if (options.isEmpty()) {
            allActions.add(ability);
        } else {
            for (Ability option : options) {
                allActions.add(option);
            }
        }
    }
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) TriggeredAbility(mage.abilities.TriggeredAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) ActivatedAbility(mage.abilities.ActivatedAbility)

Example 80 with Ability

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

the class SimulatedPlayer2 method simulatePriority.

public List<Ability> simulatePriority(Game game) {
    allActions = new ConcurrentLinkedQueue<>();
    Game sim = game.copy();
    sim.setSimulation(true);
    forced = false;
    simulateOptions(sim);
    List<Ability> list = new ArrayList<>(allActions);
    Collections.reverse(list);
    if (!forced) {
        list.add(pass);
    }
    if (logger.isTraceEnabled()) {
        for (Ability a : allActions) {
            logger.info("ability==" + a);
            if (!a.getTargets().isEmpty()) {
                MageObject mageObject = game.getObject(a.getFirstTarget());
                if (mageObject != null) {
                    logger.info("   target=" + mageObject.getName());
                } else {
                    Player player = game.getPlayer(a.getFirstTarget());
                    if (player != null) {
                        logger.info("   target=" + player.getName());
                    }
                }
            }
        }
    }
    return list;
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) TriggeredAbility(mage.abilities.TriggeredAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) MatchPlayer(mage.game.match.MatchPlayer) Player(mage.players.Player) Game(mage.game.Game) MageObject(mage.MageObject)

Aggregations

Ability (mage.abilities.Ability)359 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)134 UUID (java.util.UUID)126 Game (mage.game.Game)123 OneShotEffect (mage.abilities.effects.OneShotEffect)98 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)87 CardSetInfo (mage.cards.CardSetInfo)87 CardImpl (mage.cards.CardImpl)85 CardType (mage.constants.CardType)78 Outcome (mage.constants.Outcome)76 Card (mage.cards.Card)72 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)64 MageObject (mage.MageObject)57 MageInt (mage.MageInt)47 SpellAbility (mage.abilities.SpellAbility)43 Objects (java.util.Objects)38 Zone (mage.constants.Zone)38 mage.constants (mage.constants)37 FilterCard (mage.filter.FilterCard)35