Search in sources :

Example 1 with FilterCreatureForCombat

use of mage.filter.common.FilterCreatureForCombat in project mage by magefree.

the class PlayerImpl method getAvailableAttackers.

@Override
public List<Permanent> getAvailableAttackers(UUID defenderId, Game game) {
    FilterCreatureForCombat filter = new FilterCreatureForCombat();
    List<Permanent> attackers = game.getBattlefield().getAllActivePermanents(filter, playerId, game);
    attackers.removeIf(entry -> !entry.canAttack(defenderId, game));
    return attackers;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) TargetPermanent(mage.target.TargetPermanent) FilterCreatureForCombat(mage.filter.common.FilterCreatureForCombat)

Example 2 with FilterCreatureForCombat

use of mage.filter.common.FilterCreatureForCombat in project mage by magefree.

the class HumanPlayer method selectAttackers.

@Override
public void selectAttackers(Game game, UUID attackingPlayerId) {
    if (gameInCheckPlayableState(game)) {
        return;
    }
    FilterCreatureForCombat filter = filterCreatureForCombat.copy();
    filter.add(new ControllerIdPredicate(attackingPlayerId));
    while (canRespond()) {
        java.util.List<UUID> possibleAttackers = new ArrayList<>();
        for (Permanent possibleAttacker : game.getBattlefield().getActivePermanents(filter, attackingPlayerId, game)) {
            if (possibleAttacker.canAttack(null, game)) {
                possibleAttackers.add(possibleAttacker.getId());
            }
        }
        // - other: on disabled option skipped
        if (passedAllTurns || passedUntilEndStepBeforeMyTurn || (!getControllingPlayersUserData(game).getUserSkipPrioritySteps().isStopOnDeclareAttackers() && (passedTurn || passedTurnSkipStack || passedUntilEndOfTurn || passedUntilNextMain))) {
            if (checkIfAttackersValid(game)) {
                return;
            }
        }
        /*
            // new version:
            // - all: on disabled option skipped (if attackers selected)
            if (!getControllingPlayersUserData(game)
                    .getUserSkipPrioritySteps()
                    .isStopOnDeclareAttackers()
                    && (possibleAttackers.size() > 0)) {
                if (checkIfAttackersValid(game)) {
                    return;
                }
            }
             */
        Map<String, Serializable> options = new HashMap<>();
        options.put(Constants.Option.POSSIBLE_ATTACKERS, (Serializable) possibleAttackers);
        if (!possibleAttackers.isEmpty()) {
            options.put(Constants.Option.SPECIAL_BUTTON, "All attack");
        }
        updateGameStatePriority("selectAttackers", game);
        prepareForResponse(game);
        if (!isExecutingMacro()) {
            game.fireSelectEvent(playerId, "Select attackers", options);
        }
        waitForResponse(game);
        UUID responseId = getFixedResponseUUID(game);
        if (response.getString() != null && response.getString().equals("special")) {
            // All attack
            setStoredBookmark(game.bookmarkState());
            UUID attackedDefender = null;
            if (game.getCombat().getDefenders().size() > 1) {
                attackedDefender = selectDefenderForAllAttack(game.getCombat().getDefenders(), game);
            } else if (game.getCombat().getDefenders().size() == 1) {
                attackedDefender = game.getCombat().getDefenders().iterator().next();
            }
            for (Permanent attacker : game.getBattlefield().getAllActivePermanents(filterCreatureForCombat, getId(), game)) {
                if (game.getContinuousEffects().checkIfThereArePayCostToAttackBlockEffects(new DeclareAttackerEvent(attackedDefender, attacker.getId(), attacker.getControllerId()), game)) {
                    continue;
                }
                // if attacker needs a specific defender to attack so select that one instead
                if (game.getCombat().getCreaturesForcedToAttack().containsKey(attacker.getId())) {
                    Set<UUID> possibleDefenders = game.getCombat().getCreaturesForcedToAttack().get(attacker.getId());
                    if (!possibleDefenders.isEmpty() && !possibleDefenders.contains(attackedDefender)) {
                        declareAttacker(attacker.getId(), possibleDefenders.iterator().next(), game, false);
                        continue;
                    }
                }
                // attack selected default defender
                declareAttacker(attacker.getId(), attackedDefender, game, false);
            }
        } else if (response.getInteger() != null) {
            // F-Key
            if (checkIfAttackersValid(game)) {
                return;
            }
        } else if (response.getBoolean() != null) {
            // ok button
            if (checkIfAttackersValid(game)) {
                return;
            }
        } else if (responseId != null) {
            Permanent attacker = game.getPermanent(responseId);
            if (attacker != null) {
                if (filterCreatureForCombat.match(attacker, null, playerId, game)) {
                    selectDefender(game.getCombat().getDefenders(), attacker.getId(), game);
                } else if (filterAttack.match(attacker, null, playerId, game) && game.getStack().isEmpty()) {
                    removeAttackerIfPossible(game, attacker);
                }
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) DeclareAttackerEvent(mage.game.events.DeclareAttackerEvent) java.util(java.util) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterCreatureForCombat(mage.filter.common.FilterCreatureForCombat)

Aggregations

FilterCreatureForCombat (mage.filter.common.FilterCreatureForCombat)2 Permanent (mage.game.permanent.Permanent)2 TargetPermanent (mage.target.TargetPermanent)2 Serializable (java.io.Serializable)1 java.util (java.util)1 FilterPermanent (mage.filter.FilterPermanent)1 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)1 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)1 DeclareAttackerEvent (mage.game.events.DeclareAttackerEvent)1