From 27ae91a1cfeb1438ec31da244f937e282527e1be Mon Sep 17 00:00:00 2001 From: Sloth Date: Thu, 4 Apr 2013 06:59:03 +0000 Subject: [PATCH] - Cleanup of Combat class. - Added some infrastructure for "BecomesBlocked" effects. --- src/main/java/forge/game/phase/Combat.java | 35 ++++++++----------- .../java/forge/game/phase/CombatUtil.java | 16 --------- 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/main/java/forge/game/phase/Combat.java b/src/main/java/forge/game/phase/Combat.java index acc7d96ad0e..8bbede8cdad 100644 --- a/src/main/java/forge/game/phase/Combat.java +++ b/src/main/java/forge/game/phase/Combat.java @@ -51,7 +51,7 @@ public class Combat { private final Map> blockerMap = new TreeMap>(); private final Set blocked = new HashSet(); - private final HashMap> unblockedMap = new HashMap>(); + private final Set unblocked = new HashSet(); private final HashMap defendingDamageMap = new HashMap(); // Defenders are the Defending Player + Each controlled Planeswalker @@ -83,7 +83,7 @@ public class Combat { this.resetAttackers(); this.blocked.clear(); - this.unblockedMap.clear(); + this.unblocked.clear(); this.defendingDamageMap.clear(); this.attackingPlayer = null; @@ -453,6 +453,13 @@ public class Combat { return this.blocked.contains(attacker); } + public final void setBlocked(final Card attacker) { + if (!this.blocked.contains(attacker)) { + this.blocked.add(attacker); + this.unblocked.remove(attacker); + } + } + /** *

* addBlocker. @@ -771,8 +778,6 @@ public class Combat { public void dealAssignedDamage() { // This function handles both Regular and First Strike combat assignment - final boolean bFirstStrike = Singletons.getModel().getGame().getPhaseHandler().is(PhaseType.COMBAT_FIRST_STRIKE_DAMAGE); - final HashMap defMap = this.getDefendingDamageMap(); for (final Entry entry : defMap.entrySet()) { @@ -784,18 +789,6 @@ public class Combat { } } - final List unblocked = new ArrayList(bFirstStrike ? this.getUnblockedAttackers() : this.getUnblockedFirstStrikeAttackers()); - - for (int j = 0; j < unblocked.size(); j++) { - if (bFirstStrike) { - CombatUtil.checkUnblockedAttackers(unblocked.get(j)); - } else { - if (!unblocked.get(j).hasFirstStrike() && !unblocked.get(j).hasDoubleStrike()) { - CombatUtil.checkUnblockedAttackers(unblocked.get(j)); - } - } - } - // this can be much better below here... final List combatants = new ArrayList(); @@ -840,7 +833,7 @@ public class Combat { * @return a boolean. */ public final boolean isUnblocked(final Card att) { - return this.unblockedMap.containsKey(att); + return this.unblocked.contains(att); } /** @@ -852,7 +845,7 @@ public class Combat { */ public final List getUnblockedAttackers() { final List out = new ArrayList(); - for (Card c : this.unblockedMap.keySet()) { + for (Card c : this.unblocked) { if (!c.hasFirstStrike()) { out.add(c); } @@ -869,7 +862,7 @@ public class Combat { */ public final List getUnblockedFirstStrikeAttackers() { final List out = new ArrayList(); - for (Card c : this.unblockedMap.keySet()) { // only add creatures without firstStrike to this + for (Card c : this.unblocked) { // only add creatures without firstStrike to this if (c.hasFirstStrike() || c.hasDoubleStrike()) { out.add(c); } @@ -886,7 +879,9 @@ public class Combat { * a {@link forge.Card} object. */ public final void addUnblockedAttacker(final Card c) { - this.unblockedMap.put(c, new ArrayList()); + if (!this.unblocked.contains(c)) { + this.unblocked.add(c); + } } public boolean isPlayerAttacked(Player priority) { diff --git a/src/main/java/forge/game/phase/CombatUtil.java b/src/main/java/forge/game/phase/CombatUtil.java index ef107e4a8a9..f1e674fe80e 100644 --- a/src/main/java/forge/game/phase/CombatUtil.java +++ b/src/main/java/forge/game/phase/CombatUtil.java @@ -1293,22 +1293,6 @@ public class CombatUtil { c.getController().incrementAttackersDeclaredThisTurn(); } // checkDeclareAttackers - /** - *

- * checkUnblockedAttackers. - *

- * - * @param c - * a {@link forge.Card} object. - */ - public static void checkUnblockedAttackers(final Card c) { - - // Run triggers - final HashMap runParams = new HashMap(); - runParams.put("Card", c); - Singletons.getModel().getGame().getTriggerHandler().runTrigger(TriggerType.AttackerUnblocked, runParams, false); - } - /** *

* checkDeclareBlockers.