Search in sources :

Example 1 with CombatInfo

use of mage.player.ai.util.CombatInfo in project mage by magefree.

the class ComputerPlayer6 method declareBlockers.

private void declareBlockers(Game game, UUID activePlayerId) {
    game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_PRE, null, null, activePlayerId));
    if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_BLOCKERS, activePlayerId, activePlayerId))) {
        List<Permanent> attackers = getAttackers(game);
        if (attackers == null) {
            return;
        }
        List<Permanent> possibleBlockers = super.getAvailableBlockers(game);
        possibleBlockers = filterOutNonblocking(game, attackers, possibleBlockers);
        if (possibleBlockers.isEmpty()) {
            return;
        }
        attackers = filterOutUnblockable(game, attackers, possibleBlockers);
        if (attackers.isEmpty()) {
            return;
        }
        CombatUtil.sortByPower(attackers, false);
        CombatInfo combatInfo = CombatUtil.blockWithGoodTrade2(game, attackers, possibleBlockers);
        Player player = game.getPlayer(playerId);
        boolean blocked = false;
        for (Map.Entry<Permanent, List<Permanent>> entry : combatInfo.getCombat().entrySet()) {
            UUID attackerId = entry.getKey().getId();
            List<Permanent> blockers = entry.getValue();
            if (blockers != null) {
                for (Permanent blocker : blockers) {
                    player.declareBlocker(player.getId(), blocker.getId(), attackerId, game);
                    blocked = true;
                }
            }
        }
        if (blocked) {
            game.getPlayers().resetPassed();
        }
    }
}
Also used : CombatInfo(mage.player.ai.util.CombatInfo) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) GameEvent(mage.game.events.GameEvent)

Aggregations

GameEvent (mage.game.events.GameEvent)1 Permanent (mage.game.permanent.Permanent)1 CombatInfo (mage.player.ai.util.CombatInfo)1 Player (mage.players.Player)1