public boolean canBlock(Permanent blocker, Game game) { return blocker.canBlock(attacker.id, game); }
public static boolean canBlock(Game game, Permanent blocker) { boolean canBlock = true; if (!blocker.isTapped()) { try { canBlock = blocker.canBlock(null, game); } catch (Exception e) { //e.printStackTrace(); } } return canBlock; }
public boolean canBlock(Permanent blocker, Game game) { // player can't block if another player is attacked if (!defendingPlayerId.equals(blocker.getControllerId())) { return false; } for (UUID attackerId : attackers) { if (!blocker.canBlock(attackerId, game)) { return false; } } return true; }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { return permanent.canBlock(source.getSourceId(), game); }
private List<Permanent> filterOutNonblocking(Game game, List<Permanent> attackers, List<Permanent> blockers) { List<Permanent> blockersLeft = new ArrayList<>(); for (Permanent blocker : blockers) { for (Permanent attacker : attackers) { if (blocker.canBlock(attacker.getId(), game)) { blockersLeft.add(blocker); break; } } } return blockersLeft; }
/** * Determines what blockers from the list can block the attacker * * @param game Game * @param attacker Attacker to check * @param blockersList Blockers to try to block the attacker with. * @return true if attacker can be blocked by any blocker */ public static List<Permanent> getPossibleBlockers(Game game, Permanent attacker, List<Permanent> blockersList) { List<Permanent> canBlock = new ArrayList<>(); for (Permanent blocker : blockersList) { if (blocker.canBlock(attacker.getId(), game)) { canBlock.add(blocker); } } return canBlock; }
/** * Checks that attacker can be blocked by any blocker from the list. * * @param game Game * @param attacker Attacker to check * @param blockersList Blockers to try to block the attacker with. * @return true if attacker can be blocked by any blocker */ public static boolean canBeBlocked(Game game, Permanent attacker, List<Permanent> blockersList) { for (Permanent blocker : blockersList) { if (blocker.canBlock(attacker.getId(), game)) { return true; } } return false; }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { return permanent.canBlock(source.getSourceId(), game) && permanent.hasSubtype(SubType.ELDRAZI, game); }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { return permanent.canBlock(this.getTargetPointer().getFirst(game, source), game); }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { if (permanent.getId().equals(source.getTargets().get(1).getFirstTarget())) { return permanent.canBlock(source.getFirstTarget(), game); } return false; }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { if (permanent.getId().equals(source.getFirstTarget())) { Permanent equipment = game.getPermanent(source.getSourceId()); if (equipment != null && equipment.getAttachedTo() != null) { return permanent.canBlock(equipment.getAttachedTo(), game); } } return false; }
private boolean getRestrictions(CombatGroup chosenGroup, Permanent blocker, Set<Permanent> attackers, Permanent sourcePermanent, Player controller, Game game) { for (UUID attackerId : chosenGroup.getAttackers()) { Permanent attacker = game.getPermanent(attackerId); if (attacker != null) { if (blocker.canBlock(attackerId, game) && (blocker.getMaxBlocks() == 0 || chosenGroup.getAttackers().size() <= blocker.getMaxBlocks())) { attackers.add(attacker); } else { game.informPlayer(controller, "Illegal block detected (" + blocker.getName() + "), effect of " + sourcePermanent.getName() + " doesn't apply."); return false; } } } return true; }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { Permanent sourceCreature = game.getPermanent(source.getSourceId()); if (sourceCreature != null && sourceCreature.isAttacking() && filter.match(permanent, game)) { return permanent.canBlock(source.getSourceId(), game); } return false; }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { Permanent sourceCreature = game.getPermanent(source.getSourceId()); if (sourceCreature != null && sourceCreature.isAttacking()) { return permanent.getAbilities().contains(FlyingAbility.getInstance()) && permanent.canBlock(source.getSourceId(), game); } return false; }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { Permanent attachment = game.getPermanent(source.getSourceId()); if (attachment != null && attachment.getAttachedTo() != null) { Permanent attachedCreature = game.getPermanent(attachment.getAttachedTo()); if (attachedCreature != null && attachedCreature.isAttacking()) { return permanent.canBlock(attachment.getAttachedTo(), game); } } return false; }
UUID attackingCreatureId = requirementEntry.getKey().mustBlockAttacker(ability, game); Player defender = game.getPlayer(possibleBlocker.getControllerId()); if (attackingCreatureId != null && defender != null && possibleBlocker.canBlock(attackingCreatureId, game)) { Permanent attackingCreature = game.getPermanent(attackingCreatureId); if (attackingCreature == null || !attackingCreature.isAttacking()) {
@Override public boolean applies(Permanent permanent, Ability source, Game game) { if (permanent.getId().equals(this.getTargetPointer().getFirst(game, source))) { Permanent blocker = game.getPermanent(this.getTargetPointer().getFirst(game, source)); if (blocker != null && blocker.canBlock(source.getSourceId(), game)) { Permanent attacker = (Permanent) source.getSourceObjectIfItStillExists(game); if (attacker != null) { BlockedAttackerWatcher blockedAttackerWatcher = game.getState().getWatcher(BlockedAttackerWatcher.class); if (blockedAttackerWatcher != null && blockedAttackerWatcher.creatureHasBlockedAttacker(attacker, blocker, game)) { // has already blocked this turn, so no need to do again return false; } return true; } else { discard(); } } } return false; }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { Permanent attackingCreature = game.getPermanent(this.getTargetPointer().getFirst(game, source)); if (attackingCreature != null && attackingCreature.isAttacking()) { if (source.getAbilityType() != AbilityType.STATIC) { BlockedAttackerWatcher blockedAttackerWatcher = game.getState().getWatcher(BlockedAttackerWatcher.class); if (blockedAttackerWatcher != null && blockedAttackerWatcher.creatureHasBlockedAttacker(attackingCreature, permanent, game)) { // has already blocked this turn, so no need to do again return false; } } return permanent.canBlock(this.getTargetPointer().getFirst(game, source), game); } return false; }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { if (permanent.getId().equals(source.getTargets().get(0).getFirstTarget())) { Permanent blocker = game.getPermanent(source.getTargets().get(0).getFirstTarget()); if (blocker != null && blocker.canBlock(source.getTargets().get(1).getFirstTarget(), game)) { Permanent attacker = game.getPermanent(source.getTargets().get(1).getFirstTarget()); if (attacker != null) { BlockedAttackerWatcher blockedAttackerWatcher = game.getState().getWatcher(BlockedAttackerWatcher.class); if (blockedAttackerWatcher != null && blockedAttackerWatcher.creatureHasBlockedAttacker(attacker, blocker, game)) { // has already blocked this turn, so no need to do again return false; } return true; } else { discard(); } } } return false; }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { if (permanent.getId().equals(source.getTargets().get(0).getFirstTarget())) { Permanent blocker = game.getPermanent(source.getTargets().get(0).getFirstTarget()); if (blocker != null && blocker.canBlock(source.getTargets().get(1).getFirstTarget(), game)) { Permanent attacker = game.getPermanent(source.getTargets().get(1).getFirstTarget()); if (attacker != null) { BlockedAttackerWatcher blockedAttackerWatcher = game.getState().getWatcher(BlockedAttackerWatcher.class); if (blockedAttackerWatcher != null && blockedAttackerWatcher.creatureHasBlockedAttacker(attacker, blocker, game)) { // has already blocked this turn, so no need to do again return false; } return true; } else { discard(); } } } return false; }