From 96d1c1c6dbdc63ad65cde15ec72f97a23993a1ae Mon Sep 17 00:00:00 2001 From: Hanmac Date: Sun, 17 Jul 2016 20:12:40 +0000 Subject: [PATCH] CombatUtil: add MustBeBlockedBy for Slayer's Cleaver --- .../java/forge/game/combat/CombatUtil.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/forge-game/src/main/java/forge/game/combat/CombatUtil.java b/forge-game/src/main/java/forge/game/combat/CombatUtil.java index c86ffc454c6..2ae36d1bc03 100644 --- a/forge-game/src/main/java/forge/game/combat/CombatUtil.java +++ b/forge-game/src/main/java/forge/game/combat/CombatUtil.java @@ -755,6 +755,17 @@ public class CombatUtil { || (attacker.hasStartOfKeyword("CARDNAME must be blocked if able.") && combat.getBlockers(attacker).isEmpty())) { attackersWithLure.add(attacker); + } else { + for (String keyword : attacker.getKeywords()) { + // MustBeBlockedBy + if (keyword.startsWith("MustBeBlockedBy ")) { + final String valid = keyword.substring("MustBeBlockedBy ".length()); + if (blocker.isValid(valid, null, null, null) && + CardLists.getValidCardCount(combat.getBlockers(attacker), valid, null, null) == 0) { + attackersWithLure.add(attacker); + } + } + } } } @@ -855,6 +866,19 @@ public class CombatUtil { return false; } + boolean mustBeBlockedBy = false; + for (String keyword : attacker.getKeywords()) { + // MustBeBlockedBy + if (keyword.startsWith("MustBeBlockedBy ")) { + final String valid = keyword.substring("MustBeBlockedBy ".length()); + if (blocker.isValid(valid, null, null, null) && + CardLists.getValidCardCount(combat.getBlockers(attacker), valid, null, null) == 0) { + mustBeBlockedBy = true; + break; + } + } + } + // if the attacker has no lure effect, but the blocker can block another // attacker with lure, the blocker can't block the former if (!attacker.hasKeyword("All creatures able to block CARDNAME do so.") @@ -862,6 +886,7 @@ public class CombatUtil { && !(attacker.hasStartOfKeyword("All creatures with flying able to block CARDNAME do so.") && blocker.hasKeyword("Flying")) && !(attacker.hasKeyword("CARDNAME must be blocked if able.") && combat.getBlockers(attacker).isEmpty()) && !(blocker.getMustBlockCards() != null && blocker.getMustBlockCards().contains(attacker)) + && !mustBeBlockedBy && CombatUtil.mustBlockAnAttacker(blocker, combat)) { return false; }