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;
}
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);
}
}
}
}
}
Aggregations