public void addBlocker(UUID blockerId, UUID playerId, Game game) { for (UUID attackerId : attackers) { if (game.replaceEvent( GameEvent.getEvent( GameEvent.EventType.DECLARE_BLOCKER, attackerId, blockerId, playerId))) { return; } } Permanent blocker = game.getPermanent(blockerId); if (blockerId != null && blocker != null) { blocker.setBlocking(blocker.getBlocking() + 1); blockers.add(blockerId); blockerOrder.add(blockerId); this.blocked = true; this.players.put(blockerId, playerId); } }
public boolean checkBlockRestrictions(Game game, int blockersCount) { boolean blockWasLegal = true; if (attackers.isEmpty()) { return blockWasLegal; } if (blockersCount == 1) { List<UUID> toBeRemoved = new ArrayList<>(); for (UUID blockerId : getBlockers()) { Permanent blocker = game.getPermanent(blockerId); if (blocker != null && blocker.getAbilities().containsKey(CantBlockAloneAbility.getInstance().getId())) { blockWasLegal = false; game.informPlayers(blocker.getLogName() + " can't block alone. Removing it from combat."); toBeRemoved.add(blockerId); } } for (UUID blockerId : toBeRemoved) { game.getCombat().removeBlocker(blockerId, game); } if (blockers.isEmpty()) { this.blocked = false; } } for (UUID uuid : attackers) { Permanent attacker = game.getPermanent(uuid); // Check if there are enough blockers to have a legal block if (attacker != null && this.blocked && attacker.getMinBlockedBy() > 1 && blockers.size() > 0 && blockers.size() < attacker.getMinBlockedBy()) { for (UUID blockerId : blockers) { Permanent blocker = game.getPermanent(blockerId); if (blocker != null) { blocker.setBlocking(blocker.getBlocking() - 1); } } blockers.clear(); blockerOrder.clear(); this.blocked = false; game.informPlayers( attacker.getLogName() + " can't be blocked except by " + attacker.getMinBlockedBy() + " or more creatures. Blockers discarded."); blockWasLegal = false; } // Check if there are to many blockers (maxBlockedBy = 0 means no restrictions) if (attacker != null && this.blocked && attacker.getMaxBlockedBy() > 0 && attacker.getMaxBlockedBy() < blockers.size()) { for (UUID blockerId : blockers) { Permanent blocker = game.getPermanent(blockerId); if (blocker != null) { blocker.setBlocking(blocker.getBlocking() - 1); } } blockers.clear(); blockerOrder.clear(); this.blocked = false; game.informPlayers( new StringBuilder(attacker.getLogName()) .append(" can't be blocked by more than ") .append(attacker.getMaxBlockedBy()) .append(attacker.getMaxBlockedBy() == 1 ? " creature." : " creatures.") .append(" Blockers discarded.") .toString()); blockWasLegal = false; } } return blockWasLegal; }