From 46a249a2386d6eb9b5c8c7f7200bb82ba1e96d2d Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Sun, 2 Jun 2013 09:25:57 +0000 Subject: [PATCH] temporarily inlined PhaseUtil.handleDeclareAttackers and handleAttackingTriggers, fixed multiple triggering for Souverigns of the Lost Alara, extracted method for their 2nd ability --- .../java/forge/game/phase/CombatUtil.java | 97 +++++++++---------- .../java/forge/game/phase/PhaseHandler.java | 57 ++++++++++- src/main/java/forge/game/phase/PhaseUtil.java | 75 -------------- 3 files changed, 101 insertions(+), 128 deletions(-) diff --git a/src/main/java/forge/game/phase/CombatUtil.java b/src/main/java/forge/game/phase/CombatUtil.java index e646da48d96..3cdaf590b8e 100644 --- a/src/main/java/forge/game/phase/CombatUtil.java +++ b/src/main/java/forge/game/phase/CombatUtil.java @@ -1300,62 +1300,57 @@ public class CombatUtil { game.getStack().addSimultaneousStackEntry(ability); } + } - final Player phasingPlayer = c.getController(); - - if (phasingPlayer.getCardsIn(ZoneType.Battlefield, "Sovereigns of Lost Alara").size() > 0) { - for (int i = 0; i < phasingPlayer.getCardsIn(ZoneType.Battlefield, "Sovereigns of Lost Alara").size(); i++) { - final Card attacker = c; - final Ability ability4 = new Ability(c, ManaCost.ZERO) { + public static void souverignsOfAlara2ndAbility(final Game game, final Card attacker) { + final Ability ability4 = new Ability(attacker, ManaCost.ZERO) { + @Override + public void resolve() { + List enchantments = + CardLists.filter(attacker.getController().getCardsIn(ZoneType.Library), new Predicate() { @Override - public void resolve() { - List enchantments = - CardLists.filter(attacker.getController().getCardsIn(ZoneType.Library), new Predicate() { - @Override - public boolean apply(final Card c) { - if (attacker.hasKeyword("Protection from enchantments") - || (attacker.hasKeyword("Protection from everything"))) { - return false; - } - return (c.isEnchantment() && c.hasKeyword("Enchant creature") && !CardFactoryUtil - .hasProtectionFrom(c, attacker)); - } - }); - final Player player = attacker.getController(); - Card enchantment = null; - if (player.isHuman()) { - final Card[] target = new Card[enchantments.size()]; - for (int j = 0; j < enchantments.size(); j++) { - final Card crd = enchantments.get(j); - target[j] = crd; - } - final Object check = GuiChoose.oneOrNone( - "Select enchantment to enchant exalted creature", target); - if (check != null) { - enchantment = ((Card) check); - } - } else { - enchantment = ComputerUtilCard.getBestEnchantmentAI(enchantments, this, false); + public boolean apply(final Card c) { + if (attacker.hasKeyword("Protection from enchantments") + || (attacker.hasKeyword("Protection from everything"))) { + return false; } - if ((enchantment != null) && attacker.isInPlay()) { - game.getAction().changeZone(game.getZoneOf(enchantment), - enchantment.getOwner().getZone(ZoneType.Battlefield), enchantment, null); - enchantment.enchantEntity(attacker); - } - attacker.getController().shuffle(); - } // resolve - }; // ability4 + return (c.isEnchantment() && c.hasKeyword("Enchant creature") && !CardFactoryUtil + .hasProtectionFrom(c, attacker)); + } + }); + final Player player = attacker.getController(); + Card enchantment = null; + if (player.isHuman()) { + final Card[] target = new Card[enchantments.size()]; + for (int j = 0; j < enchantments.size(); j++) { + final Card crd = enchantments.get(j); + target[j] = crd; + } + final Object check = GuiChoose.oneOrNone( + "Select enchantment to enchant exalted creature", target); + if (check != null) { + enchantment = ((Card) check); + } + } else { + enchantment = ComputerUtilCard.getBestEnchantmentAI(enchantments, this, false); + } + if ((enchantment != null) && attacker.isInPlay()) { + game.getAction().changeZone(game.getZoneOf(enchantment), + enchantment.getOwner().getZone(ZoneType.Battlefield), enchantment, null); + enchantment.enchantEntity(attacker); + } + attacker.getController().shuffle(); + } // resolve + }; // ability4 - final StringBuilder sb4 = new StringBuilder(); - sb4.append(c).append( - " - (Exalted) searches library for an Aura card that could enchant that creature, "); - sb4.append("put it onto the battlefield attached to that creature, then shuffles library."); - ability4.setDescription(sb4.toString()); - ability4.setStackDescription(sb4.toString()); + final StringBuilder sb4 = new StringBuilder(); + sb4.append(attacker).append( + " - (Exalted) searches library for an Aura card that could enchant that creature, "); + sb4.append("put it onto the battlefield attached to that creature, then shuffles library."); + ability4.setDescription(sb4.toString()); + ability4.setStackDescription(sb4.toString()); - game.getStack().addSimultaneousStackEntry(ability4); - } // For - } + game.getStack().addSimultaneousStackEntry(ability4); } /** diff --git a/src/main/java/forge/game/phase/PhaseHandler.java b/src/main/java/forge/game/phase/PhaseHandler.java index 0adc37d60a1..8596ebe39b6 100644 --- a/src/main/java/forge/game/phase/PhaseHandler.java +++ b/src/main/java/forge/game/phase/PhaseHandler.java @@ -268,10 +268,63 @@ public class PhaseHandler implements java.io.Serializable { playerTurn.getController().declareAttackers(); - PhaseUtil.handleDeclareAttackers(game); + game.getCombat().verifyCreaturesInPlay(); + + // Handles removing cards like Mogg Flunkies from combat if group attack + // didn't occur + for (Card c1 : game.getCombat().getAttackers()) { + if (c1.hasKeyword("CARDNAME can't attack or block alone.") && c1.isAttacking()) { + if (game.getCombat().getAttackers().size() < 2) { + game.getCombat().removeFromCombat(c1); + } + } + } + + + // TODO move propaganda to happen as the Attacker is Declared + + for (final Card c2 : game.getCombat().getAttackers()) { + boolean canAttack = CombatUtil.checkPropagandaEffects(game, c2); + if ( canAttack ) { + if (!c2.hasKeyword("Vigilance")) + c2.tap(); + } else { + game.getCombat().removeFromCombat(c2); + } + } + + + // Then run other Attacker bonuses + // check for exalted: + if (game.getCombat().getAttackers().size() == 1) { + final Player attackingPlayer = game.getCombat().getAttackingPlayer(); + final Card attacker = game.getCombat().getAttackers().get(0); + for (Card card : attackingPlayer.getCardsIn(ZoneType.Battlefield)) { + int exaltedMagnitude = card.getKeywordAmount("Exalted"); + if (exaltedMagnitude > 0) { + CombatUtil.executeExaltedAbility(game, attacker, exaltedMagnitude, card); + // Make sure exalted effects get applied only once per combat + } + + if ("Sovereigns of Lost Alara".equals(card.getName())) { + CombatUtil.souverignsOfAlara2ndAbility(game, attacker); + } + } + } + + game.getGameLog().addCombatAttackers(game.getCombat()); + + final HashMap runParams = new HashMap(); + runParams.put("Attackers", game.getCombat().getAttackers()); + runParams.put("AttackingPlayer", game.getCombat().getAttackingPlayer()); + game.getTriggerHandler().runTrigger(TriggerType.AttackersDeclared, runParams, false); + + for (final Card c : game.getCombat().getAttackers()) { + CombatUtil.checkDeclareAttackers(game, c); + } + game.getStack().unfreezeStack(); this.bCombat = !game.getCombat().getAttackers().isEmpty(); - game.getStack().unfreezeStack(); this.nCombatsThisTurn++; break; diff --git a/src/main/java/forge/game/phase/PhaseUtil.java b/src/main/java/forge/game/phase/PhaseUtil.java index 7d0a495bceb..b81ca72cc6a 100644 --- a/src/main/java/forge/game/phase/PhaseUtil.java +++ b/src/main/java/forge/game/phase/PhaseUtil.java @@ -68,81 +68,6 @@ public class PhaseUtil { } - // ********* Declare Attackers *********** - - /** - *

- * handleDeclareAttackers. - *

- */ - public static void handleDeclareAttackers(final Game game) { - final Combat combat = game.getCombat(); - combat.verifyCreaturesInPlay(); - - // Handles removing cards like Mogg Flunkies from combat if group attack - // didn't occur - final List filterList = combat.getAttackers(); - for (Card c : filterList) { - if (c.hasKeyword("CARDNAME can't attack or block alone.") && c.isAttacking()) { - if (combat.getAttackers().size() < 2) { - combat.removeFromCombat(c); - } - } - } - - final List list = combat.getAttackers(); - - // TODO move propaganda to happen as the Attacker is Declared - // Remove illegal Propaganda attacks first only for attacking the Player - - - for (final Card c : list) { - boolean canAttack = CombatUtil.checkPropagandaEffects(game, c); - if ( canAttack ) { - if (!c.hasKeyword("Vigilance")) { c.tap(); } - } else { - game.getCombat().removeFromCombat(c); - } - } - PhaseUtil.handleAttackingTriggers(game); - } - - /** - *

- * handleAttackingTriggers. - *

- * @param game - */ - public static void handleAttackingTriggers(Game game) { - final List list = game.getCombat().getAttackers(); - game.getStack().freezeStack(); - // Then run other Attacker bonuses - // check for exalted: - if (list.size() == 1) { - final Player attackingPlayer = game.getCombat().getAttackingPlayer(); - final Card attacker = list.get(0); - for (Card card : attackingPlayer.getCardsIn(ZoneType.Battlefield)) { - int exaltedMagnitude = card.getKeywordAmount("Exalted"); - if (exaltedMagnitude > 0) { - CombatUtil.executeExaltedAbility(game, attacker, exaltedMagnitude, card); - // Make sure exalted effects get applied only once per combat - } - } - } - - game.getGameLog().addCombatAttackers(game.getCombat()); - - final HashMap runParams = new HashMap(); - runParams.put("Attackers", list); - runParams.put("AttackingPlayer", game.getCombat().getAttackingPlayer()); - game.getTriggerHandler().runTrigger(TriggerType.AttackersDeclared, runParams, false); - - for (final Card c : list) { - CombatUtil.checkDeclareAttackers(game, c); - } - game.getStack().unfreezeStack(); - } - /** *

* handleDeclareBlockers.