public static List<Permanent> canKillOpponent(Game game, List<Permanent> attackersList, List<Permanent> blockersList, Player defender) { List<Permanent> blockableAttackers = new ArrayList<>(blockersList); List<Permanent> unblockableAttackers = new ArrayList<>(); for (Permanent attacker : attackersList) { if (!canBeBlocked(game, attacker, blockersList)) { unblockableAttackers.add(attacker); blockableAttackers.remove(attacker); } } sortByPower(blockableAttackers, true); // imagine that most powerful will be blocked as 1-vs-1 List<Permanent> attackersThatWontBeBlocked = new ArrayList<>(blockableAttackers); for (int i = 0; (i < blockersList.size() && i < blockableAttackers.size()); i++) { attackersThatWontBeBlocked.remove(blockableAttackers.get(i)); } attackersThatWontBeBlocked.addAll(unblockableAttackers); // now count if it is possible to win the game by this attack using unblockable attackers and // those attackers that won't be blocked for sure (as player will block other creatures) if (sumDamage(attackersThatWontBeBlocked, defender) >= defender.getLife() && defender.isLifeTotalCanChange() && defender.canLose(game) && defender.getLife() > 0) { blockableAttackers.addAll(unblockableAttackers); return blockableAttackers; } if (sumPoisonDamage(attackersThatWontBeBlocked, defender) >= 10 - defender.getCounters().getCount(CounterType.POISON)) { blockableAttackers.addAll(unblockableAttackers); return blockableAttackers; } return emptyList; }
if (!player1.isLifeTotalCanChange() || !player2.isLifeTotalCanChange()) { return false;
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getFirstTarget()); if (controller != null && player != null) { int lifeController = controller.getLife(); int lifePlayer = player.getLife(); if (lifeController == lifePlayer) { return false; } if (!controller.isLifeTotalCanChange() || !player.isLifeTotalCanChange()) { return false; } if (lifeController < lifePlayer && (!controller.isCanGainLife() || !player.isCanLoseLife())) { return false; } if (lifeController > lifePlayer && (!controller.isCanLoseLife() || !player.isCanGainLife())) { return false; } controller.setLife(lifePlayer, game, source); player.setLife(lifeController, game, source); return true; } return false; }
if (!player1.isLifeTotalCanChange() || !player2.isLifeTotalCanChange()) { return false;
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player != null && player.isLifeTotalCanChange()) { Permanent perm = game.getPermanent(source.getSourceId()); if (perm != null) { int amount = perm.getPower().getValue(); int life = player.getLife(); if (life == amount) { return false; } if (life < amount && !player.isCanGainLife()) { return false; } if (life > amount && !player.isCanLoseLife()) { return false; } player.setLife(amount, game, source); game.addEffect(new SetPowerToughnessSourceEffect(life, Integer.MIN_VALUE, Duration.Custom, SubLayer.SetPT_7b), source); return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player != null && player.isLifeTotalCanChange()) { Permanent perm = game.getPermanent(source.getSourceId()); if (perm != null) { int amount = perm.getToughness().getValue(); int life = player.getLife(); if (life == amount) { return false; } if (life < amount && !player.isCanGainLife()) { return false; } if (life > amount && !player.isCanLoseLife()) { return false; } player.setLife(amount, game, source); game.addEffect(new SetPowerToughnessSourceEffect(Integer.MIN_VALUE, life, Duration.Custom, SubLayer.SetPT_7b), source); return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { Player opponent = game.getPlayer(source.getFirstTarget()); if (opponent != null && opponent.isLifeTotalCanChange()) { Permanent perm = game.getPermanent(source.getSourceId()); if (perm != null) { int amount = perm.getToughness().getValue(); int life = opponent.getLife(); if (life == amount) { return false; } if (life < amount && !opponent.isCanGainLife()) { return false; } if (life > amount && !opponent.isCanLoseLife()) { return false; } opponent.setLife(amount, game, source); perm.getToughness().modifyBaseValue(life); // game.addEffect(new SetPowerToughnessSourceEffect(Integer.MIN_VALUE, life, Duration.Custom, SubLayer.SetPT_7b), source); return true; } } return false; }