From 7f9ef96178b73393b3e2972292846a8c9c9a9a40 Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Sun, 12 Jan 2014 18:16:03 +0000 Subject: [PATCH] wipe gui calls from effects --- .../ability/effects/ChangeZoneEffect.java | 308 +++++++++--------- .../game/ability/effects/ManaEffect.java | 4 +- .../game/player/PlayerActionConfirmMode.java | 3 +- .../gui/player/PlayerControllerHuman.java | 2 +- 4 files changed, 154 insertions(+), 163 deletions(-) diff --git a/forge-gui/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java b/forge-gui/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java index 5b9677b7897..04795f3ad67 100644 --- a/forge-gui/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java +++ b/forge-gui/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java @@ -29,8 +29,6 @@ import forge.game.spellability.TargetRestrictions; import forge.game.trigger.TriggerType; import forge.game.zone.Zone; import forge.game.zone.ZoneType; -import forge.gui.GuiChoose; -import forge.gui.GuiDialog; import forge.util.Aggregates; import forge.util.Lang; @@ -663,9 +661,9 @@ public class ChangeZoneEffect extends SpellAbilityEffect { int changeNum = sa.hasParam("ChangeNum") ? AbilityUtils.calculateAmount(source, sa.getParam("ChangeNum"), sa) : 1; - if (optional && !GuiDialog.confirm(source, defined ? "Put that card from " + origin + "to " + destination : "Search " + origin + "?")) { + if( optional && !decider.getController().confirmAction(sa, PlayerActionConfirmMode.ChangeZoneGeneral, defined ? "Put that card from " + origin + "to " + destination : "Search " + origin + "?")) return; - } + List fetchList; boolean shuffleMandatory = true; @@ -735,7 +733,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect { source.clearImprinted(); } - for (int i = 0; i < changeNum; i++) { + for (int i = 0; i < changeNum && destination != null; i++) { if (sa.hasParam("DifferentNames")) { for (Card c : movedCards) { fetchList = CardLists.filter(fetchList, Predicates.not(CardPredicates.nameEquals(c.getName()))); @@ -746,171 +744,163 @@ public class ChangeZoneEffect extends SpellAbilityEffect { fetchList = CardLists.getValidCards(fetchList, "Card.cmcLE" + Integer.toString(totcmc), source.getController(), source); } } - if ((fetchList.size() == 0) || (destination == null)) { - break; - } - Card c; + Card c = null; if (sa.hasParam("AtRandom")) { c = Aggregates.random(fetchList); } else if (sa.hasParam("Defined")) { - c = fetchList.get(0); + c = Iterables.getFirst(fetchList, null); } else { - boolean mustChoose = sa.hasParam("Mandatory"); - // card has to be on battlefield or in own hand - if (mustChoose && fetchList.size() == 1) { - c = fetchList.get(0); - } else { - c = decider.getController().chooseSingleEntityForEffect(fetchList, sa, selectPrompt, !mustChoose); - } + c = decider.getController().chooseSingleEntityForEffect(fetchList, sa, selectPrompt, !sa.hasParam("Mandatory")); } - if (c != null) { - fetchList.remove(c); - Card movedCard = null; - - if (destination.equals(ZoneType.Library)) { - // do not shuffle the library once we have placed a fetched - // card on top. - if (origin.contains(ZoneType.Library) && (i < 1) && !"False".equals(sa.getParam("Shuffle"))) { - player.shuffle(sa); - } - movedCard = game.getAction().moveToLibrary(c, libraryPos); - } else if (destination.equals(ZoneType.Battlefield)) { - if (sa.hasParam("Tapped")) { - c.setTapped(true); - } - if (sa.hasParam("GainControl")) { - if (sa.hasParam("NewController")) { - final Player p = AbilityUtils.getDefinedPlayers(source, sa.getParam("NewController"), sa).get(0); - c.setController(p, game.getNextTimestamp()); - } else { - c.setController(sa.getActivatingPlayer(), game.getNextTimestamp()); - } - } - - if (sa.hasParam("AttachedTo")) { - List list = AbilityUtils.getDefinedCards(source, sa.getParam("AttachedTo"), sa); - if (list.isEmpty()) { - list = game.getCardsIn(ZoneType.Battlefield); - list = CardLists.getValidCards(list, sa.getParam("AttachedTo"), c.getController(), c); - } - if (!list.isEmpty()) { - Card attachedTo = null; - if (list.size() > 1) { - attachedTo = decider.getController().chooseSingleEntityForEffect(list, sa, c + " - Select a card to attach to."); - } else { - attachedTo = list.get(0); - } - if (c.isAura()) { - if (c.isEnchanting()) { - // If this Card is already Enchanting something, need - // to unenchant it, then clear out the commands - final GameEntity oldEnchanted = c.getEnchanting(); - c.removeEnchanting(oldEnchanted); - } - c.enchantEntity(attachedTo); - } else if (c.isEquipment()) { //Equipment - if (c.isEquipping()) { - final Card oldEquiped = c.getEquippingCard(); - if ( null != oldEquiped ) - c.unEquipCard(oldEquiped); - } - c.equipCard(attachedTo); - } else { - if (c.isFortifying()) { - final Card oldFortified = c.getFortifyingCard(); - if ( null != oldFortified ) - c.unFortifyCard(oldFortified); - } - c.fortifyCard(attachedTo); - } - } else { // When it should enter the battlefield attached to an illegal permanent it fails - continue; - } - } - - if (sa.hasParam("AttachedToPlayer")) { - List list = AbilityUtils.getDefinedPlayers(source, sa.getParam("AttachedToPlayer"), sa); - if (!list.isEmpty()) { - Player attachedTo = player.getController().chooseSingleEntityForEffect(list, sa, c + " - Select a player to attach to."); - if (c.isAura()) { - if (c.isEnchanting()) { - // If this Card is already Enchanting something, need - // to unenchant it, then clear out the commands - final GameEntity oldEnchanted = c.getEnchanting(); - c.removeEnchanting(oldEnchanted); - } - c.enchantEntity(attachedTo); - } - } else { // When it should enter the battlefield attached to an illegal permanent it fails - continue; - } - } - - if (sa.hasParam("Attacking")) { - final Combat combat = game.getCombat(); - if ( null != combat ) { - final List e = combat.getDefenders(); - final GameEntity defender = e.size() == 1 ? e.get(0) : GuiChoose.one("Declare " + c, e); - combat.addAttacker(c, defender); - } - } - if (sa.hasParam("Blocking")) { - final Combat combat = game.getCombat(); - if ( null != combat ) { - List attackers = AbilityUtils.getDefinedCards(source, sa.getParam("Blocking"), sa); - if (!attackers.isEmpty()) { - Card attacker = attackers.get(0); - if (combat.isAttacking(attacker)) { - combat.addBlocker(attacker, c); - combat.orderAttackersForDamageAssignment(c); - } - } - } - } - movedCard = game.getAction().moveTo(c.getController().getZone(destination), c); - if (sa.hasParam("Tapped")) { - movedCard.setTapped(true); - } - } else if (destination.equals(ZoneType.Exile)) { - movedCard = game.getAction().exile(c); - if (sa.hasParam("ExileFaceDown")) { - movedCard.setState(CardCharacteristicName.FaceDown); - } - } else { - movedCard = game.getAction().moveTo(destination, c); - } - movedCards.add(movedCard); - - if (champion) { - final HashMap runParams = new HashMap(); - runParams.put("Card", source); - runParams.put("Championed", c); - game.getTriggerHandler().runTrigger(TriggerType.Championed, runParams, false); - } - - if (remember) { - source.addRemembered(movedCard); - } - if (forget) { - source.removeRemembered(movedCard); - } - // for imprinted since this doesn't use Target - if (imprint) { - source.addImprinted(movedCard); - } - if (totalcmc != null) { - totcmc -= movedCard.getCMC(); - } - } else { - final StringBuilder sb = new StringBuilder(); + if (c == null) { final int num = Math.min(fetchList.size(), changeNum - i); - sb.append("Cancel Search? Up to ").append(num).append(" more cards can change zones."); + String message = String.format("Cancel Search? Up to %d more cards can change zones.", num); - if (((i + 1) == changeNum) || GuiDialog.confirm(source, sb.toString())) { + if (fetchList.isEmpty() || decider.getController().confirmAction(sa, PlayerActionConfirmMode.ChangeZoneGeneral, message)) { break; } + i--; + continue; + } + + fetchList.remove(c); + Card movedCard = null; + + if (destination.equals(ZoneType.Library)) { + // do not shuffle the library once we have placed a fetched + // card on top. + if (origin.contains(ZoneType.Library) && (i < 1) && !"False".equals(sa.getParam("Shuffle"))) { + player.shuffle(sa); + } + movedCard = game.getAction().moveToLibrary(c, libraryPos); + } else if (destination.equals(ZoneType.Battlefield)) { + if (sa.hasParam("Tapped")) { + c.setTapped(true); + } + if (sa.hasParam("GainControl")) { + if (sa.hasParam("NewController")) { + final Player p = AbilityUtils.getDefinedPlayers(source, sa.getParam("NewController"), sa).get(0); + c.setController(p, game.getNextTimestamp()); + } else { + c.setController(sa.getActivatingPlayer(), game.getNextTimestamp()); + } + } + + if (sa.hasParam("AttachedTo")) { + List list = AbilityUtils.getDefinedCards(source, sa.getParam("AttachedTo"), sa); + if (list.isEmpty()) { + list = game.getCardsIn(ZoneType.Battlefield); + list = CardLists.getValidCards(list, sa.getParam("AttachedTo"), c.getController(), c); + } + if (!list.isEmpty()) { + Card attachedTo = null; + if (list.size() > 1) { + attachedTo = decider.getController().chooseSingleEntityForEffect(list, sa, c + " - Select a card to attach to."); + } else { + attachedTo = list.get(0); + } + if (c.isAura()) { + if (c.isEnchanting()) { + // If this Card is already Enchanting something, need + // to unenchant it, then clear out the commands + final GameEntity oldEnchanted = c.getEnchanting(); + c.removeEnchanting(oldEnchanted); + } + c.enchantEntity(attachedTo); + } else if (c.isEquipment()) { //Equipment + if (c.isEquipping()) { + final Card oldEquiped = c.getEquippingCard(); + if ( null != oldEquiped ) + c.unEquipCard(oldEquiped); + } + c.equipCard(attachedTo); + } else { + if (c.isFortifying()) { + final Card oldFortified = c.getFortifyingCard(); + if ( null != oldFortified ) + c.unFortifyCard(oldFortified); + } + c.fortifyCard(attachedTo); + } + } else { // When it should enter the battlefield attached to an illegal permanent it fails + continue; + } + } + + if (sa.hasParam("AttachedToPlayer")) { + List list = AbilityUtils.getDefinedPlayers(source, sa.getParam("AttachedToPlayer"), sa); + if (!list.isEmpty()) { + Player attachedTo = player.getController().chooseSingleEntityForEffect(list, sa, c + " - Select a player to attach to."); + if (c.isAura()) { + if (c.isEnchanting()) { + // If this Card is already Enchanting something, need + // to unenchant it, then clear out the commands + final GameEntity oldEnchanted = c.getEnchanting(); + c.removeEnchanting(oldEnchanted); + } + c.enchantEntity(attachedTo); + } + } else { // When it should enter the battlefield attached to an illegal permanent it fails + continue; + } + } + + if (sa.hasParam("Attacking")) { + final Combat combat = game.getCombat(); + if ( null != combat ) { + final List e = combat.getDefenders(); + final GameEntity defender = player.getController().chooseSingleEntityForEffect(e, sa, "Declare " + c); + combat.addAttacker(c, defender); + } + } + if (sa.hasParam("Blocking")) { + final Combat combat = game.getCombat(); + if ( null != combat ) { + List attackers = AbilityUtils.getDefinedCards(source, sa.getParam("Blocking"), sa); + if (!attackers.isEmpty()) { + Card attacker = attackers.get(0); + if (combat.isAttacking(attacker)) { + combat.addBlocker(attacker, c); + combat.orderAttackersForDamageAssignment(c); + } + } + } + } + movedCard = game.getAction().moveTo(c.getController().getZone(destination), c); + if (sa.hasParam("Tapped")) { + movedCard.setTapped(true); + } + } else if (destination.equals(ZoneType.Exile)) { + movedCard = game.getAction().exile(c); + if (sa.hasParam("ExileFaceDown")) { + movedCard.setState(CardCharacteristicName.FaceDown); + } + } else { + movedCard = game.getAction().moveTo(destination, c); + } + movedCards.add(movedCard); + + if (champion) { + final HashMap runParams = new HashMap(); + runParams.put("Card", source); + runParams.put("Championed", c); + game.getTriggerHandler().runTrigger(TriggerType.Championed, runParams, false); + } + + if (remember) { + source.addRemembered(movedCard); + } + if (forget) { + source.removeRemembered(movedCard); + } + // for imprinted since this doesn't use Target + if (imprint) { + source.addImprinted(movedCard); + } + if (totalcmc != null) { + totcmc -= movedCard.getCMC(); } } if (sa.hasParam("Reveal") && !movedCards.isEmpty()) { diff --git a/forge-gui/src/main/java/forge/game/ability/effects/ManaEffect.java b/forge-gui/src/main/java/forge/game/ability/effects/ManaEffect.java index 5b6719bb5c7..a37e2039870 100644 --- a/forge-gui/src/main/java/forge/game/ability/effects/ManaEffect.java +++ b/forge-gui/src/main/java/forge/game/ability/effects/ManaEffect.java @@ -90,7 +90,7 @@ public class ManaEffect extends SpellAbilityEffect { if (chosen.equals("")) { chosen = MagicColor.Constant.BLACK; } - GuiChoose.reveal("Computer picked", chosen); + game.action.nofityOfValue(sa, card, "Computer picked" + chosen, activator); String manaString = ""; for (int i = 0; i < amount; i++) { manaString = manaString + MagicColor.toShortString(chosen) + " "; @@ -149,7 +149,7 @@ public class ManaEffect extends SpellAbilityEffect { if (chosen.equals("")) { chosen = MagicColor.Constant.GREEN; } - GuiChoose.reveal("Computer picked", chosen); + game.action.nofityOfValue(sa, card, "Computer picked " + chosen, act); abMana.setExpressChoice(MagicColor.toShortString(chosen)); } if (abMana.getExpressChoice().isEmpty()) { diff --git a/forge-gui/src/main/java/forge/game/player/PlayerActionConfirmMode.java b/forge-gui/src/main/java/forge/game/player/PlayerActionConfirmMode.java index 7c9add29850..64c42ea4f59 100644 --- a/forge-gui/src/main/java/forge/game/player/PlayerActionConfirmMode.java +++ b/forge-gui/src/main/java/forge/game/player/PlayerActionConfirmMode.java @@ -9,7 +9,8 @@ public enum PlayerActionConfirmMode { // BraidOfFire, FromOpeningHand, ChangeZoneToAltDestination, - ChangeZoneFromAltSource; + ChangeZoneFromAltSource, + ChangeZoneGeneral; // Ripple; diff --git a/forge-gui/src/main/java/forge/gui/player/PlayerControllerHuman.java b/forge-gui/src/main/java/forge/gui/player/PlayerControllerHuman.java index a8a8c90be6b..b604efd3149 100644 --- a/forge-gui/src/main/java/forge/gui/player/PlayerControllerHuman.java +++ b/forge-gui/src/main/java/forge/gui/player/PlayerControllerHuman.java @@ -1041,7 +1041,7 @@ public class PlayerControllerHuman extends PlayerController { @Override public void revealAnte(String message, Multimap removedAnteCards) { for (Player p : removedAnteCards.keySet()) { - GuiChoose.reveal(message + " from " + Lang.getPossesive(mayBeYou(p)) + " deck", removedAnteCards.get(p)); + GuiChoose.reveal(message + " from " + Lang.getPossessedObject(mayBeYou(p), "deck"), removedAnteCards.get(p)); } }