From c92faa2d875b1360b5bda0b866d16f11a21fa59a Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Fri, 19 Oct 2012 22:39:09 +0000 Subject: [PATCH] 1. MatchController contains inputControl, subscribes listeners to event by itself 2. most of AllZone methods static moved into instances, consider retrieving frequently used values into class fields or local variables --- .gitattributes | 1 - src/main/java/forge/AllZone.java | 21 -- src/main/java/forge/Card.java | 61 ++-- src/main/java/forge/CardUtil.java | 5 +- src/main/java/forge/CommandReturn.java | 37 --- src/main/java/forge/GameAction.java | 155 ++++----- src/main/java/forge/GameActionUtil.java | 55 ++-- src/main/java/forge/StaticEffects.java | 3 +- .../card/abilityfactory/AbilityFactory.java | 29 +- .../AbilityFactoryAlterLife.java | 3 +- .../abilityfactory/AbilityFactoryAnimate.java | 5 +- .../abilityfactory/AbilityFactoryAttach.java | 9 +- .../abilityfactory/AbilityFactoryBond.java | 4 +- .../AbilityFactoryChangeZone.java | 25 +- .../abilityfactory/AbilityFactoryChoose.java | 30 +- .../abilityfactory/AbilityFactoryCleanup.java | 3 +- .../abilityfactory/AbilityFactoryCopy.java | 7 +- .../AbilityFactoryCounters.java | 18 +- .../AbilityFactoryDealDamage.java | 17 +- .../abilityfactory/AbilityFactoryDebuff.java | 17 +- .../abilityfactory/AbilityFactoryDestroy.java | 9 +- .../abilityfactory/AbilityFactoryEffect.java | 9 +- .../AbilityFactoryGainControl.java | 13 +- .../abilityfactory/AbilityFactoryMana.java | 3 +- .../AbilityFactoryPermanentState.java | 24 +- .../abilityfactory/AbilityFactoryPlay.java | 5 +- .../AbilityFactoryPreventDamage.java | 9 +- .../AbilityFactoryProtection.java | 27 +- .../abilityfactory/AbilityFactoryPump.java | 40 +-- .../AbilityFactoryRegenerate.java | 11 +- .../abilityfactory/AbilityFactoryRepeat.java | 4 +- .../abilityfactory/AbilityFactoryReveal.java | 3 +- .../AbilityFactorySacrifice.java | 5 +- .../AbilityFactorySetState.java | 4 +- .../abilityfactory/AbilityFactoryToken.java | 5 +- .../cardfactory/CardFactoryArtifacts.java | 6 +- .../card/cardfactory/CardFactoryAuras.java | 21 +- .../cardfactory/CardFactoryCreatures.java | 25 +- .../cardfactory/CardFactoryEnchantments.java | 8 +- .../card/cardfactory/CardFactoryInstants.java | 13 +- .../card/cardfactory/CardFactoryLands.java | 10 +- .../cardfactory/CardFactorySorceries.java | 44 ++- .../card/cardfactory/CardFactoryUtil.java | 59 ++-- src/main/java/forge/card/cost/CostReturn.java | 5 +- .../java/forge/card/cost/CostSacrifice.java | 5 +- .../java/forge/card/cost/CostUntapType.java | 8 +- src/main/java/forge/card/cost/CostUtil.java | 4 +- src/main/java/forge/card/mana/ManaPool.java | 3 +- .../card/replacement/ReplacementEffect.java | 6 +- .../card/replacement/ReplacementHandler.java | 3 +- .../java/forge/card/spellability/Ability.java | 3 +- .../card/spellability/AbilityActivated.java | 5 +- .../forge/card/spellability/AbilityMana.java | 3 +- .../java/forge/card/spellability/Spell.java | 5 +- .../spellability/SpellAbilityCondition.java | 15 +- .../SpellAbilityRequirements.java | 3 +- .../spellability/SpellAbilityRestriction.java | 5 +- .../card/spellability/SpellPermanent.java | 29 +- .../java/forge/card/spellability/Target.java | 3 +- .../card/spellability/TargetSelection.java | 17 +- .../card/staticability/StaticAbility.java | 3 +- .../StaticAbilityCantBeCast.java | 4 +- .../StaticAbilityContinuous.java | 7 +- src/main/java/forge/card/trigger/Trigger.java | 5 +- .../forge/card/trigger/TriggerHandler.java | 21 +- src/main/java/forge/control/input/Input.java | 36 +-- .../java/forge/control/input/InputAttack.java | 3 +- .../forge/control/input/InputControl.java | 51 ++- .../forge/control/input/InputMulligan.java | 5 +- .../control/input/InputPassPriority.java | 5 +- .../forge/control/input/InputPayManaCost.java | 9 +- .../control/input/InputPayManaCostUtil.java | 9 +- src/main/java/forge/game/GameNew.java | 2 +- src/main/java/forge/game/GameState.java | 294 ++---------------- src/main/java/forge/game/MatchController.java | 35 ++- src/main/java/forge/game/phase/Combat.java | 3 +- .../java/forge/game/phase/CombatUtil.java | 72 +++-- src/main/java/forge/game/phase/EndOfTurn.java | 17 +- .../java/forge/game/phase/PhaseHandler.java | 19 +- src/main/java/forge/game/phase/PhaseUtil.java | 9 +- src/main/java/forge/game/phase/Untap.java | 36 +-- src/main/java/forge/game/phase/Upkeep.java | 45 ++- .../forge/game/player/ComputerAIGeneral.java | 3 +- .../java/forge/game/player/ComputerUtil.java | 11 +- .../forge/game/player/ComputerUtilAttack.java | 5 +- .../java/forge/game/player/HumanPlayer.java | 9 +- src/main/java/forge/game/player/Player.java | 84 ++++- src/main/java/forge/game/zone/MagicStack.java | 42 +-- src/main/java/forge/game/zone/PlayerZone.java | 5 +- .../game/zone/PlayerZoneBattlefield.java | 12 +- src/main/java/forge/gui/GuiDisplayUtil.java | 7 +- src/main/java/forge/gui/GuiInput.java | 23 +- .../forge/gui/match/controllers/CLog.java | 5 - .../forge/gui/match/controllers/CMessage.java | 5 - .../forge/gui/match/controllers/CStack.java | 5 - .../forge/gui/match/nonsingleton/CField.java | 12 +- src/main/java/forge/model/FModel.java | 10 +- .../java/forge/view/arcane/CardPanel.java | 3 +- 98 files changed, 780 insertions(+), 1135 deletions(-) delete mode 100644 src/main/java/forge/CommandReturn.java diff --git a/.gitattributes b/.gitattributes index 3cedae507e4..ff06272d192 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12386,7 +12386,6 @@ src/main/java/forge/Color.java svneol=native#text/plain src/main/java/forge/ColorChanger.java -text src/main/java/forge/Command.java svneol=native#text/plain src/main/java/forge/CommandList.java svneol=native#text/plain -src/main/java/forge/CommandReturn.java svneol=native#text/plain src/main/java/forge/Constant.java svneol=native#text/plain src/main/java/forge/Counters.java svneol=native#text/plain src/main/java/forge/GameAction.java svneol=native#text/plain diff --git a/src/main/java/forge/AllZone.java b/src/main/java/forge/AllZone.java index 9a9a8a19014..af2d1330ada 100644 --- a/src/main/java/forge/AllZone.java +++ b/src/main/java/forge/AllZone.java @@ -19,7 +19,6 @@ package forge; import forge.card.cardfactory.CardFactory; import forge.card.cardfactory.CardFactoryInterface; -import forge.control.input.InputControl; import forge.game.limited.GauntletMini; import forge.properties.ForgeProps; import forge.properties.NewConstants; @@ -54,9 +53,6 @@ public final class AllZone { /** Global cardFactory. */ private static CardFactoryInterface cardFactory = null; - /** Constant inputControl. */ - private static InputControl inputControl = null; - // initialized at Runtime since it has to be the last object constructed // shared between Input_Attack, Input_Block, Input_CombatDamage , @@ -103,23 +99,6 @@ public final class AllZone { AllZone.cardFactory = factory; } - /** - *

- * getInputControl. - *

- * - * @return a {@link forge.control.input.InputControl} object. - * @since 1.0.15 - */ - public static InputControl getInputControl() { - return AllZone.inputControl; - } - - /** @param i0   {@link forge.control.input.InputControl} */ - public static void setInputControl(InputControl i0) { - AllZone.inputControl = i0; - } - /** * Create and return the next timestamp. * diff --git a/src/main/java/forge/Card.java b/src/main/java/forge/Card.java index 8b7fc6c8946..051bbe80415 100644 --- a/src/main/java/forge/Card.java +++ b/src/main/java/forge/Card.java @@ -34,6 +34,7 @@ import java.util.TreeMap; import com.esotericsoftware.minlog.Log; import com.google.common.collect.Iterables; +import forge.CardPredicates.Presets; import forge.card.CardCharacteristics; import forge.card.CardManaCost; import forge.card.EditionInfo; @@ -53,7 +54,6 @@ import forge.card.staticability.StaticAbility; import forge.card.trigger.Trigger; import forge.card.trigger.TriggerType; import forge.card.trigger.ZCTrigger; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -1226,7 +1226,7 @@ public class Card extends GameEntity implements Comparable { return false; } if (this.isCreature() && counterName.equals(Counters.M1M1)) { - for (final Card c : GameState.getCreaturesInPlay(this.getController())) { // look + for (final Card c : this.getController().getCreaturesInPlay()) { // look // for // Melira, // Sylvok @@ -1287,7 +1287,7 @@ public class Card extends GameEntity implements Comparable { if (!this.canHaveCountersPlacedOnIt(counterName)) { return; } - final int multiplier = GameState.getCounterDoublersMagnitude(this.getController(),counterName); + final int multiplier = this.getController().getCounterDoublersMagnitude(counterName); if (this.counters.containsKey(counterName)) { final Integer aux = this.counters.get(counterName) + (multiplier * n); this.counters.put(counterName, aux); @@ -1335,11 +1335,11 @@ public class Card extends GameEntity implements Comparable { if (counterName.equals(Counters.TIME) && (aux == 0)) { final boolean hasVanish = CardFactoryUtil.hasKeyword(this, "Vanishing") != -1; - if (hasVanish && GameState.isCardInPlay(this)) { + if (hasVanish && this.isInPlay()) { Singletons.getModel().getGameAction().sacrifice(this, null); } - if (this.hasSuspend() && GameState.isCardExiled(this)) { + if (this.hasSuspend() && Singletons.getModel().getGameState().isCardExiled(this)) { final Card c = this; c.setSuspendCast(true); @@ -4753,7 +4753,7 @@ public class Card extends GameEntity implements Comparable { return 0; } - if (GameState.isCardInPlay("Doran, the Siege Tower")) { + if (Singletons.getModel().getGameState().isCardInPlay("Doran, the Siege Tower")) { return this.getNetDefense(); } return this.getNetAttack(); @@ -6491,7 +6491,7 @@ public class Card extends GameEntity implements Comparable { } } else if (property.startsWith("RememberedPlayerCtrl")) { if (source.getRemembered().isEmpty()) { - final Card newCard = GameState.getCardState(source); + final Card newCard = Singletons.getModel().getGameState().getCardState(source); for (final Object o : newCard.getRemembered()) { if (o instanceof Player) { if (!this.getController().equals((Player) o)) { @@ -6724,7 +6724,7 @@ public class Card extends GameEntity implements Comparable { } } else if (restriction.equals("MostProminentColor")) { for (final String color : CardUtil.getColors(this)) { - if (CardFactoryUtil.isMostProminentColor(GameState.getCardsIn(ZoneType.Battlefield), color)) { + if (CardFactoryUtil.isMostProminentColor(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), color)) { return true; } } @@ -6813,12 +6813,12 @@ public class Card extends GameEntity implements Comparable { return false; } } else if (restriction.equals(ZoneType.Battlefield.toString())) { - final List list = GameState.getCardsIn(ZoneType.Battlefield); + final List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); if (list.isEmpty()) { return false; } boolean shares = false; - for (final Card card : GameState.getCardsIn(ZoneType.Battlefield)) { + for (final Card card : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { if (this.getName().equals(card.getName())) { shares = true; } @@ -6986,28 +6986,28 @@ public class Card extends GameEntity implements Comparable { return false; } } else if (property.startsWith("greatestPower")) { - final List list = GameState.getCreaturesInPlay(); + final List list = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); for (final Card crd : list) { if (crd.getNetAttack() > this.getNetAttack()) { return false; } } } else if (property.startsWith("leastPower")) { - final List list = GameState.getCreaturesInPlay(); + final List list = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); for (final Card crd : list) { if (crd.getNetAttack() < this.getNetAttack()) { return false; } } } else if (property.startsWith("greatestCMC")) { - final List list = GameState.getCreaturesInPlay(); + final List list = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); for (final Card crd : list) { if (crd.getCMC() > this.getCMC()) { return false; } } } else if (property.startsWith("lowestCMC")) { - final List list = GameState.getCardsIn(ZoneType.Battlefield); + final List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card crd : list) { if (!crd.isLand() && !crd.isImmutable() && (crd.getCMC() < this.getCMC())) { return false; @@ -7052,7 +7052,7 @@ public class Card extends GameEntity implements Comparable { } } } else if (property.startsWith("suspended")) { - if (!this.hasSuspend() || !GameState.isCardExiled(this) + if (!this.hasSuspend() || !Singletons.getModel().getGameState().isCardExiled(this) || !(this.getCounters(Counters.getType("TIME")) >= 1)) { return false; } @@ -7273,7 +7273,7 @@ public class Card extends GameEntity implements Comparable { return false; } } else if (property.startsWith("OnBattlefield")) { - final List list = GameState.getCardsIn(ZoneType.Battlefield); + final List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); if (!list.contains(this)) { return false; } @@ -7952,7 +7952,7 @@ public class Card extends GameEntity implements Comparable { map.put(source, damageToAdd); } - if (GameState.isCardInPlay(this)) { + if (this.isInPlay()) { this.addDamage(map); } } @@ -8006,7 +8006,7 @@ public class Card extends GameEntity implements Comparable { public final int staticDamagePrevention(final int damage, final int possiblePrvenetion, final Card source, final boolean isCombat) { - if (GameState.isCardInPlay("Leyline of Punishment")) { + if (Singletons.getModel().getGameState().isCardInPlay("Leyline of Punishment")) { return damage; } @@ -8035,7 +8035,7 @@ public class Card extends GameEntity implements Comparable { @Override public final int staticDamagePrevention(final int damageIn, final Card source, final boolean isCombat) { - if (GameState.isCardInPlay("Leyline of Punishment")) { + if (Singletons.getModel().getGameState().isCardInPlay("Leyline of Punishment")) { return damageIn; } @@ -8098,7 +8098,7 @@ public class Card extends GameEntity implements Comparable { } // Prevent Damage static abilities - final List allp = GameState.getCardsIn(ZoneType.Battlefield); + final List allp = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card ca : allp) { final ArrayList staticAbilities = ca.getStaticAbilities(); for (final StaticAbility stAb : staticAbilities) { @@ -8112,7 +8112,7 @@ public class Card extends GameEntity implements Comparable { return 0; } - if ((source.isCreature() && GameState.isCardInPlay("Well-Laid Plans") && source.sharesColorWith(this))) { + if ((source.isCreature() && Singletons.getModel().getGameState().isCardInPlay("Well-Laid Plans") && source.sharesColorWith(this))) { return 0; } } // Creature end @@ -8140,7 +8140,7 @@ public class Card extends GameEntity implements Comparable { @Override public final int preventDamage(final int damage, final Card source, final boolean isCombat) { - if (GameState.isCardInPlay("Leyline of Punishment") + if (Singletons.getModel().getGameState().isCardInPlay("Leyline of Punishment") || source.hasKeyword("Damage that would be dealt by CARDNAME can't be prevented.")) { return damage; } @@ -8206,7 +8206,7 @@ public class Card extends GameEntity implements Comparable { public final int staticReplaceDamage(final int damage, final Card source, final boolean isCombat) { int restDamage = damage; - for (Card c : GameState.getCardsIn(ZoneType.Battlefield)) { + for (Card c : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { if (c.getName().equals("Sulfuric Vapors")) { if (source.isSpell() && source.isRed()) { restDamage += 1; @@ -8365,12 +8365,12 @@ public class Card extends GameEntity implements Comparable { GameActionUtil.executeDamageToCreatureEffects(source, this, damageToAdd); - if (GameState.isCardInPlay(this) && wither) { + if (this.isInPlay() && wither) { this.addCounter(Counters.M1M1, damageToAdd); } if (source.hasKeyword("Deathtouch") && this.isCreature()) { Singletons.getModel().getGameAction().destroy(this); - } else if (GameState.isCardInPlay(this) && !wither) { + } else if (this.isInPlay() && !wither) { this.damage += damageToAdd; } return true; @@ -8869,7 +8869,7 @@ public class Card extends GameEntity implements Comparable { * @return boolean */ public boolean isInZone(final ZoneType zone) { - return GameState.isCardInZone(this, zone); + return Singletons.getModel().getGameState().isCardInZone(this, zone); } /** @@ -8887,7 +8887,7 @@ public class Card extends GameEntity implements Comparable { } // CantTarget static abilities - final List allp = GameState.getCardsIn(ZoneType.Battlefield); + final List allp = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card ca : allp) { final ArrayList staticAbilities = ca.getStaticAbilities(); for (final StaticAbility stAb : staticAbilities) { @@ -9078,4 +9078,11 @@ public class Card extends GameEntity implements Comparable { this.startsGameInPlay = startsGameInPlay; } + public boolean isInPlay() { + if (getController() == null) { + return false; + } + return getController().getCardsIn(ZoneType.Battlefield).contains(this); + } + } // end Card class diff --git a/src/main/java/forge/CardUtil.java b/src/main/java/forge/CardUtil.java index d99acd8c3a4..8bffc5d8b3c 100644 --- a/src/main/java/forge/CardUtil.java +++ b/src/main/java/forge/CardUtil.java @@ -38,7 +38,6 @@ import forge.card.CardManaCost; import forge.card.EditionInfo; import forge.card.mana.ManaCost; import forge.control.input.InputPayManaCostUtil; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.gui.GuiDisplayUtil; @@ -212,7 +211,7 @@ public final class CardUtil { int xPaid = 0; // 2012-07-22 - If a card is on the stack, count the xManaCost in with it's CMC - if (GameState.getCardsIn(ZoneType.Stack).contains(c) && c.getManaCost() != null) { + if (Singletons.getModel().getGameState().getCardsIn(ZoneType.Stack).contains(c) && c.getManaCost() != null) { xPaid = c.getXManaCostPaid() * c.getManaCost().countX(); } return c.getManaCost().getCMC() + xPaid; @@ -829,7 +828,7 @@ public final class CardUtil { if (strCol.equalsIgnoreCase("Colorless")) { continue; } - for (final Card c : GameState.getColorInPlay(strCol)) { + for (final Card c : Singletons.getModel().getGameState().getColoredCardsInPlay(strCol)) { if (!res.contains(c) && c.isValid(valid, source.getController(), source) && !c.equals(origin)) { res.add(c); } diff --git a/src/main/java/forge/CommandReturn.java b/src/main/java/forge/CommandReturn.java deleted file mode 100644 index 8da20bc2585..00000000000 --- a/src/main/java/forge/CommandReturn.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge; - -/** - *

- * CommandReturn interface. - *

- * - * @author Forge - * @version $Id$ - */ -public interface CommandReturn { - /** - *

- * execute. - *

- * - * @return a {@link java.lang.Object} object. - */ - Object execute(); -} diff --git a/src/main/java/forge/GameAction.java b/src/main/java/forge/GameAction.java index fca7140b8e3..a3a04385a2c 100644 --- a/src/main/java/forge/GameAction.java +++ b/src/main/java/forge/GameAction.java @@ -76,8 +76,14 @@ public class GameAction { * resetActivationsPerTurn. *

*/ + + private final GameState game; + public GameAction(GameState game0) { + game = game0; + } + public final void resetActivationsPerTurn() { - final List all = GameState.getCardsInGame(); + final List all = game.getCardsInGame(); // Reset Activations per Turn for (final Card card : all) { @@ -101,7 +107,7 @@ public class GameAction { * @param position TODO * @return a {@link forge.Card} object. */ - public static Card changeZone(final PlayerZone zoneFrom, final PlayerZone zoneTo, final Card c, Integer position) { + public Card changeZone(final PlayerZone zoneFrom, final PlayerZone zoneTo, final Card c, Integer position) { if (c.isCopiedSpell()) { if ((zoneFrom != null)) { zoneFrom.remove(c); @@ -177,9 +183,9 @@ public class GameAction { repParams.put("Origin", zoneFrom != null ? zoneFrom.getZoneType() : null); repParams.put("Destination", zoneTo.getZoneType()); - ReplacementResult repres = Singletons.getModel().getGameState().getReplacementHandler().run(repParams); + ReplacementResult repres = game.getReplacementHandler().run(repParams); if (repres != ReplacementResult.NotReplaced) { - if (Singletons.getModel().getGameState().getStack().isResolving(c) && !zoneTo.is(ZoneType.Graveyard) && repres == ReplacementResult.Prevented) { + if (game.getStack().isResolving(c) && !zoneTo.is(ZoneType.Graveyard) && repres == ReplacementResult.Prevented) { return Singletons.getModel().getGameAction().moveToGraveyard(c); } return c; @@ -191,7 +197,7 @@ public class GameAction { } if (suppress) { - Singletons.getModel().getGameState().getTriggerHandler().suppressMode(TriggerType.ChangesZone); + game.getTriggerHandler().suppressMode(TriggerType.ChangesZone); } // "enter the battlefield as a copy" - apply code here @@ -210,7 +216,7 @@ public class GameAction { if (zoneFrom != null) { if (zoneFrom.is(ZoneType.Battlefield) && c.isCreature()) { - Singletons.getModel().getGameState().getCombat().removeFromCombat(c); + game.getCombat().removeFromCombat(c); } zoneFrom.remove(c); } @@ -228,11 +234,11 @@ public class GameAction { runParams.put("Origin", null); } runParams.put("Destination", zoneTo.getZoneType().name()); - Singletons.getModel().getGameState().getTriggerHandler().runTrigger(TriggerType.ChangesZone, runParams); + game.getTriggerHandler().runTrigger(TriggerType.ChangesZone, runParams); // AllZone.getStack().chooseOrderOfSimultaneousStackEntryAll(); if (suppress) { - Singletons.getModel().getGameState().getTriggerHandler().clearSuppression(TriggerType.ChangesZone); + game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone); } if (zoneFrom == null) { @@ -256,7 +262,7 @@ public class GameAction { if (copied.isEquipped()) { final List equipments = new ArrayList(copied.getEquippedBy()); for (final Card equipment : equipments) { - if (GameState.isCardInPlay(equipment)) { + if (equipment.isInPlay()) { equipment.unEquipCard(copied); } } @@ -265,7 +271,7 @@ public class GameAction { if (copied.isEquipped()) { final List equipments = new ArrayList(copied.getEquippedBy()); for (final Card equipment : equipments) { - if (GameState.isCardInPlay(equipment)) { + if (equipment.isInPlay()) { equipment.unEquipCard(copied); } } @@ -273,7 +279,7 @@ public class GameAction { // equipment moving off battlefield if (copied.isEquipping()) { final Card equippedCreature = copied.getEquipping().get(0); - if (GameState.isCardInPlay(equippedCreature)) { + if (equippedCreature.isInPlay()) { copied.unEquipCard(equippedCreature); } } @@ -342,7 +348,7 @@ public class GameAction { public final Card moveTo(final PlayerZone zoneTo, Card c, Integer position) { // Ideally move to should never be called without a prevZone // Remove card from Current Zone, if it has one - final PlayerZone zoneFrom = GameState.getZoneOf(c); + final PlayerZone zoneFrom = game.getZoneOf(c); // String prevName = prev != null ? prev.getZoneName() : ""; if (c.hasKeyword("If CARDNAME would leave the battlefield, exile it instead of putting it anywhere else.") @@ -355,7 +361,7 @@ public class GameAction { // Card lastKnownInfo = c; - c = GameAction.changeZone(zoneFrom, zoneTo, c, position); + c = changeZone(zoneFrom, zoneTo, c, position); if (zoneTo.is(ZoneType.Stack)) { c.setCastFrom(zoneFrom.getZoneType()); @@ -390,7 +396,7 @@ public class GameAction { final PlayerZone hand = c.getOwner().getZone(ZoneType.Hand); final PlayerZone play = c.getController().getZone(ZoneType.Battlefield); - c = GameAction.changeZone(hand, play, c, null); + c = Singletons.getModel().getGameAction().changeZone(hand, play, c, null); return c; } @@ -403,7 +409,7 @@ public class GameAction { */ public final void controllerChangeZoneCorrection(final Card c) { System.out.println("Correcting zone for " + c.toString()); - final PlayerZone oldBattlefield = GameState.getZoneOf(c); + final PlayerZone oldBattlefield = game.getZoneOf(c); if (oldBattlefield == null || oldBattlefield.getZoneType() == ZoneType.Stack) { return; } @@ -413,8 +419,8 @@ public class GameAction { return; } - Singletons.getModel().getGameState().getTriggerHandler().suppressMode(TriggerType.ChangesZone); - for (Player p: Singletons.getModel().getGameState().getPlayers()) { + game.getTriggerHandler().suppressMode(TriggerType.ChangesZone); + for (Player p: game.getPlayers()) { ((PlayerZoneBattlefield)p.getZone(ZoneType.Battlefield)).setTriggers(false); } @@ -426,16 +432,16 @@ public class GameAction { if (c.hasStartOfKeyword("Echo")) { c.addExtrinsicKeyword("(Echo unpaid)"); } - Singletons.getModel().getGameState().getCombat().removeFromCombat(c); + game.getCombat().removeFromCombat(c); c.setTurnInZone(tiz); final HashMap runParams = new HashMap(); runParams.put("Card", c); - Singletons.getModel().getGameState().getTriggerHandler().runTrigger(TriggerType.ChangesController, runParams); + game.getTriggerHandler().runTrigger(TriggerType.ChangesController, runParams); - Singletons.getModel().getGameState().getTriggerHandler().clearSuppression(TriggerType.ChangesZone); - for (Player p: Singletons.getModel().getGameState().getPlayers()) { + game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone); + for (Player p: game.getPlayers()) { ((PlayerZoneBattlefield)p.getZone(ZoneType.Battlefield)).setTriggers(true); } } @@ -450,7 +456,7 @@ public class GameAction { * @return a {@link forge.Card} object. */ public final Card moveToStack(final Card c) { - final PlayerZone stack = Singletons.getModel().getGameState().getStackZone(); + final PlayerZone stack = game.getStackZone(); return this.moveTo(stack, c); } @@ -464,7 +470,7 @@ public class GameAction { * @return a {@link forge.Card} object. */ public final Card moveToGraveyard(Card c) { - final PlayerZone origZone = GameState.getZoneOf(c); + final PlayerZone origZone = game.getZoneOf(c); final Player owner = c.getOwner(); final PlayerZone grave = owner.getZone(ZoneType.Graveyard); final PlayerZone exile = owner.getZone(ZoneType.Exile); @@ -561,7 +567,7 @@ public class GameAction { }; recoverAbility.setStackDescription(sb.toString()); - Singletons.getModel().getGameState().getStack().addSimultaneousStackEntry(recoverAbility); + game.getStack().addSimultaneousStackEntry(recoverAbility); } } } @@ -651,7 +657,7 @@ public class GameAction { * @return a {@link forge.Card} object. */ public final Card moveToLibrary(Card c, int libPosition) { - final PlayerZone p = GameState.getZoneOf(c); + final PlayerZone p = game.getZoneOf(c); final PlayerZone library = c.getOwner().getZone(ZoneType.Library); if (c.hasKeyword("If CARDNAME would leave the battlefield, exile it instead of putting it anywhere else.")) { @@ -695,7 +701,7 @@ public class GameAction { runParams.put("Origin", null); } runParams.put("Destination", ZoneType.Library.name()); - Singletons.getModel().getGameState().getTriggerHandler().runTrigger(TriggerType.ChangesZone, runParams); + game.getTriggerHandler().runTrigger(TriggerType.ChangesZone, runParams); if (p != null) { Player owner = p.getPlayer(); @@ -723,7 +729,7 @@ public class GameAction { * @return a {@link forge.Card} object. */ public final Card exile(final Card c) { - if (GameState.isCardExiled(c)) { + if (game.isCardExiled(c)) { return c; } @@ -824,7 +830,7 @@ public class GameAction { activate.setActivatingPlayer(card.getOwner()); activate.setTrigger(true); - Singletons.getModel().getGameState().getStack().add(activate); + game.getStack().add(activate); } /** @@ -888,7 +894,7 @@ public class GameAction { activate.setStackDescription(sbAct.toString()); activate.setActivatingPlayer(card.getOwner()); - Singletons.getModel().getGameState().getStack().add(activate); + game.getStack().add(activate); } /** @@ -940,10 +946,10 @@ public class GameAction { /** */ public final void checkStaticAbilities() { // remove old effects - Singletons.getModel().getGameState().getStaticEffects().clearStaticEffects(); + game.getStaticEffects().clearStaticEffects(); // search for cards with static abilities - final List allCards = GameState.getCardsInGame(); + final List allCards = game.getCardsInGame(); final ArrayList staticAbilities = new ArrayList(); for (final Card card : allCards) { for (StaticAbility sa : card.getStaticAbilities()) { @@ -977,7 +983,7 @@ public class GameAction { } // card state effects like Glorious Anthem - for (final String effect : Singletons.getModel().getGameState().getStaticEffects().getStateBasedMap().keySet()) { + for (final String effect : game.getStaticEffects().getStateBasedMap().keySet()) { final Command com = GameActionUtil.getCommands().get(effect); com.execute(); } @@ -994,12 +1000,12 @@ public class GameAction { // sol(10/29) added for Phase updates, state effects shouldn't be // checked during Spell Resolution (except when persist-returning - if (Singletons.getModel().getGameState().getStack().getResolving()) { + if (game.getStack().isResolving()) { return; } - final boolean refreeze = Singletons.getModel().getGameState().getStack().isFrozen(); - Singletons.getModel().getGameState().getStack().setFrozen(true); + final boolean refreeze = game.getStack().isFrozen(); + game.getStack().setFrozen(true); final JFrame frame = Singletons.getView().getFrame(); if (!frame.isDisplayable()) { @@ -1012,7 +1018,7 @@ public class GameAction { new ViewWinLose(match); match.getCurrentGame().getStack().clearSimultaneousStack(); if (!refreeze) { - Singletons.getModel().getGameState().getStack().unfreezeStack(); + game.getStack().unfreezeStack(); } return; } @@ -1026,14 +1032,14 @@ public class GameAction { this.checkStaticAbilities(); final HashMap runParams = new HashMap(); - Singletons.getModel().getGameState().getTriggerHandler().runTrigger(TriggerType.Always, runParams); + game.getTriggerHandler().runTrigger(TriggerType.Always, runParams); - for (Card c : GameState.getCardsIn(ZoneType.Battlefield)) { + for (Card c : game.getCardsIn(ZoneType.Battlefield)) { if (c.isEquipped()) { final List equipments = new ArrayList(c.getEquippedBy()); for (final Card equipment : equipments) { - if (!GameState.isCardInPlay(equipment)) { + if (!equipment.isInPlay()) { equipment.unEquipCard(c); checkAgain = true; } @@ -1042,7 +1048,7 @@ public class GameAction { if (c.isEquipping()) { final Card equippedCreature = c.getEquipping().get(0); - if (!equippedCreature.isCreature() || !GameState.isCardInPlay(equippedCreature)) { + if (!equippedCreature.isCreature() || !equippedCreature.isInPlay()) { c.unEquipCard(equippedCreature); checkAgain = true; } @@ -1066,7 +1072,7 @@ public class GameAction { if (entity instanceof Card) { final Card perm = (Card) entity; - if (!GameState.isCardInPlay(perm) || !perm.canBeEnchantedBy(c)) { + if (!perm.isInPlay() || !perm.canBeEnchantedBy(c)) { c.unEnchantEntity(perm); this.moveToGraveyard(c); checkAgain = true; @@ -1089,7 +1095,7 @@ public class GameAction { } } - if (GameState.isCardInPlay(c) && !c.isEnchanting()) { + if (c.isInPlay() && !c.isEnchanting()) { this.moveToGraveyard(c); checkAgain = true; } @@ -1105,13 +1111,13 @@ public class GameAction { this.destroy(c); // this is untested with instants and abilities but // required for First Strike combat phase - Singletons.getModel().getGameState().getCombat().removeFromCombat(c); + game.getCombat().removeFromCombat(c); checkAgain = true; } else if (c.getNetDefense() <= 0) { // TODO This shouldn't be a destroy, and should happen // before the damage check probably this.destroy(c); - Singletons.getModel().getGameState().getCombat().removeFromCombat(c); + game.getCombat().removeFromCombat(c); checkAgain = true; } // Soulbond unpairing @@ -1192,7 +1198,7 @@ public class GameAction { this.destroyPlaneswalkers(); if (!refreeze) { - Singletons.getModel().getGameState().getStack().unfreezeStack(); + game.getStack().unfreezeStack(); } } // checkStateEffects() @@ -1203,7 +1209,7 @@ public class GameAction { */ private void destroyPlaneswalkers() { // get all Planeswalkers - final List list = CardLists.filter(GameState.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.PLANEWALKERS); + final List list = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.PLANEWALKERS); Card c; for (int i = 0; i < list.size(); i++) { @@ -1236,13 +1242,13 @@ public class GameAction { *

*/ private void destroyLegendaryCreatures() { - final List a = CardLists.getType(GameState.getCardsIn(ZoneType.Battlefield), "Legendary"); - if (a.isEmpty() || GameState.isCardInPlay("Mirror Gallery")) { + final List a = CardLists.getType(game.getCardsIn(ZoneType.Battlefield), "Legendary"); + if (a.isEmpty() || game.isCardInPlay("Mirror Gallery")) { return; } while (!a.isEmpty()) { - List b = GameState.getCardsIn(ZoneType.Battlefield, a.get(0).getName()); + List b = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals(a.get(0).getName())); b = CardLists.getType(b, "Legendary"); b = CardLists.filter(b, new Predicate() { @Override @@ -1285,7 +1291,7 @@ public class GameAction { // Run triggers final HashMap runParams = new HashMap(); runParams.put("Card", c); - Singletons.getModel().getGameState().getTriggerHandler().runTrigger(TriggerType.Sacrificed, runParams); + game.getTriggerHandler().runTrigger(TriggerType.Sacrificed, runParams); return true; } @@ -1300,7 +1306,7 @@ public class GameAction { * @return a boolean. */ public final boolean destroyNoRegeneration(final Card c) { - if (!GameState.isCardInPlay(c) || c.hasKeyword("Indestructible")) { + if (!c.isInPlay() || c.hasKeyword("Indestructible")) { return false; } @@ -1340,7 +1346,7 @@ public class GameAction { sb.append(crd).append(" - Totem armor: destroy this aura."); ability.setStackDescription(sb.toString()); - Singletons.getModel().getGameState().getStack().add(ability); + game.getStack().add(ability); return false; } } // totem armor @@ -1365,7 +1371,7 @@ public class GameAction { @Override public void execute() { - if (GameState.isCardInPlay(c) && c.isCreature()) { + if (c.isInPlay() && c.isCreature()) { c.addExtrinsicKeyword("Haste"); } } // execute() @@ -1400,7 +1406,7 @@ public class GameAction { * @return a boolean. */ public final boolean sacrificeDestroy(final Card c) { - if (!GameState.isCardInPlay(c)) { + if (!c.isInPlay()) { return false; } @@ -1433,7 +1439,7 @@ public class GameAction { @Override public void resolve() { - if (GameState.getZoneOf(persistCard).is(ZoneType.Graveyard)) { + if (game.getZoneOf(persistCard).is(ZoneType.Graveyard)) { final PlayerZone ownerPlay = persistCard.getOwner().getZone(ZoneType.Battlefield); final Card card = GameAction.this.moveTo(ownerPlay, persistCard); card.addCounter(Counters.M1M1, 1); @@ -1444,7 +1450,7 @@ public class GameAction { persistAb.setDescription(newCard.getName() + " - Returning from Persist"); persistAb.setActivatingPlayer(c.getController()); - Singletons.getModel().getGameState().getStack().addSimultaneousStackEntry(persistAb); + game.getStack().addSimultaneousStackEntry(persistAb); } if (undying) { @@ -1453,7 +1459,7 @@ public class GameAction { @Override public void resolve() { - if (GameState.getZoneOf(undyingCard).is(ZoneType.Graveyard)) { + if (game.getZoneOf(undyingCard).is(ZoneType.Graveyard)) { final PlayerZone ownerPlay = undyingCard.getOwner().getZone(ZoneType.Battlefield); final Card card = GameAction.this.moveTo(ownerPlay, undyingCard); card.addCounter(Counters.P1P1, 1); @@ -1464,7 +1470,7 @@ public class GameAction { undyingAb.setDescription(newCard.getName() + " - Returning from Undying"); undyingAb.setActivatingPlayer(c.getController()); - Singletons.getModel().getGameState().getStack().addSimultaneousStackEntry(undyingAb); + game.getStack().addSimultaneousStackEntry(undyingAb); } return true; } // sacrificeDestroy() @@ -1479,7 +1485,7 @@ public class GameAction { * @return a boolean. */ public final boolean destroy(final Card c) { - if (!GameState.isCardInPlay(c) + if (!c.isInPlay() || (c.hasKeyword("Indestructible") && (!c.isCreature() || (c.getNetDefense() > 0)))) { return false; } @@ -1489,7 +1495,7 @@ public class GameAction { c.setDamage(0); c.tap(); c.addRegeneratedThisTurn(); - Singletons.getModel().getGameState().getCombat().removeFromCombat(c); + game.getCombat().removeFromCombat(c); return false; } @@ -1541,7 +1547,7 @@ public class GameAction { final ArrayList abilities = c.getSpellAbilities(); final ArrayList choices = new ArrayList(); final Player human = Singletons.getControl().getPlayer(); - final PlayerZone zone = GameState.getZoneOf(c); + final PlayerZone zone = game.getZoneOf(c); if (c.isLand() && human.canPlayLand()) { if (zone.is(ZoneType.Hand) || ((!zone.is(ZoneType.Battlefield)) && c.hasStartOfKeyword("May be played"))) { @@ -1647,11 +1653,10 @@ public class GameAction { } boolean x = sa.getSourceCard().getManaCost().getShardCount(ManaCostShard.X) > 0; - Singletons.getModel().getGameState().getStack().add(sa, x); + game.getStack().add(sa, x); } else { sa.setManaCost("0"); // Beached As - sa.getBeforePayMana().setFree(true); - AllZone.getInputControl().setInput(sa.getBeforePayMana()); + Singletons.getModel().getMatch().getInput().setInput(sa.getBeforePayMana()); } } @@ -1682,7 +1687,7 @@ public class GameAction { originalCard.setXManaCostPaid(0); } - if (Singletons.getModel().getGameState() != null || sa.isTrigger()) { + if (game != null || sa.isTrigger()) { return manaCost; } @@ -1835,11 +1840,11 @@ public class GameAction { // AND that you can't use mana tapabilities of convoked // creatures // to pay the convoked cost. - Singletons.getModel().getGameState().getTriggerHandler().suppressMode(TriggerType.Taps); + game.getTriggerHandler().suppressMode(TriggerType.Taps); for (final Card c : sa.getTappedForConvoke()) { c.tap(); } - Singletons.getModel().getGameState().getTriggerHandler().clearSuppression(TriggerType.Taps); + game.getTriggerHandler().clearSuppression(TriggerType.Taps); manaCost = newCost; } @@ -1848,7 +1853,7 @@ public class GameAction { } } // isSpell - List cardsOnBattlefield = GameState.getCardsIn(ZoneType.Battlefield); + List cardsOnBattlefield = game.getCardsIn(ZoneType.Battlefield); cardsOnBattlefield.add(originalCard); final ArrayList raiseAbilities = new ArrayList(); final ArrayList reduceAbilities = new ArrayList(); @@ -1973,7 +1978,7 @@ public class GameAction { sa.setSourceCard(Singletons.getModel().getGameAction().moveToStack(source)); } - Singletons.getModel().getGameState().getStack().add(sa); + game.getStack().add(sa); if (sa.isTapAbility() && !sa.wasCancelled()) { sa.getSourceCard().tap(); } @@ -1982,12 +1987,12 @@ public class GameAction { } return; } else { - AllZone.getInputControl().setInput(sa.getAfterPayMana()); + Singletons.getModel().getMatch().getInput().setInput(sa.getAfterPayMana()); } } else if (sa.getBeforePayMana() == null) { - AllZone.getInputControl().setInput(new InputPayManaCost(sa, manaCost)); + Singletons.getModel().getMatch().getInput().setInput(new InputPayManaCost(sa, manaCost)); } else { - AllZone.getInputControl().setInput(sa.getBeforePayMana()); + Singletons.getModel().getMatch().getInput().setInput(sa.getBeforePayMana()); } } } @@ -2034,12 +2039,12 @@ public class GameAction { } return; } else { - AllZone.getInputControl().setInput(sa.getAfterPayMana()); + Singletons.getModel().getMatch().getInput().setInput(sa.getAfterPayMana()); } } else if (sa.getBeforePayMana() == null) { - AllZone.getInputControl().setInput(new InputPayManaCost(sa, true)); + Singletons.getModel().getMatch().getInput().setInput(new InputPayManaCost(sa, true)); } else { - AllZone.getInputControl().setInput(sa.getBeforePayMana()); + Singletons.getModel().getMatch().getInput().setInput(sa.getBeforePayMana()); } } } diff --git a/src/main/java/forge/GameActionUtil.java b/src/main/java/forge/GameActionUtil.java index a9abefc86db..3b1d31cf90f 100644 --- a/src/main/java/forge/GameActionUtil.java +++ b/src/main/java/forge/GameActionUtil.java @@ -50,7 +50,6 @@ import forge.control.input.InputPayManaCostAbility; import forge.control.input.InputPayReturnCost; import forge.control.input.InputPaySacCost; import forge.game.GameLossReason; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -106,7 +105,7 @@ public final class GameActionUtil { public void execute() { if (!c.isCopiedSpell()) { - final List maelstromNexii = GameState.getCardsIn(ZoneType.Battlefield, "Maelstrom Nexus"); + final List maelstromNexii = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Maelstrom Nexus")); for (final Card nexus : maelstromNexii) { if (CardUtil.getThisTurnCast("Card.YouCtrl", nexus).size() == 1) { @@ -346,9 +345,9 @@ public final class GameActionUtil { final Command unpaid) { // temporarily disable the Resolve flag, so the user can payMana for the // resolving Ability - final boolean bResolving = Singletons.getModel().getGameState().getStack().getResolving(); + final boolean bResolving = Singletons.getModel().getGameState().getStack().isResolving(); Singletons.getModel().getGameState().getStack().setResolving(false); - AllZone.getInputControl().setInput(new InputPayManaCostAbility(message, manaCost, paid, unpaid)); + Singletons.getModel().getMatch().getInput().setInput(new InputPayManaCostAbility(message, manaCost, paid, unpaid)); Singletons.getModel().getGameState().getStack().setResolving(bResolving); } @@ -491,29 +490,29 @@ public final class GameActionUtil { //the following costs need inputs and can't be combined at the moment if (costPart instanceof CostSacrifice) { - final boolean bResolving = Singletons.getModel().getGameState().getStack().getResolving(); + final boolean bResolving = Singletons.getModel().getGameState().getStack().isResolving(); Singletons.getModel().getGameState().getStack().setResolving(false); - AllZone.getInputControl().setInput(new InputPaySacCost((CostSacrifice) costPart, ability, paid, unpaid)); + Singletons.getModel().getMatch().getInput().setInput(new InputPaySacCost((CostSacrifice) costPart, ability, paid, unpaid)); Singletons.getModel().getGameState().getStack().setResolving(bResolving); } else if (costPart instanceof CostReturn) { - final boolean bResolving = Singletons.getModel().getGameState().getStack().getResolving(); + final boolean bResolving = Singletons.getModel().getGameState().getStack().isResolving(); Singletons.getModel().getGameState().getStack().setResolving(false); - AllZone.getInputControl().setInput(new InputPayReturnCost((CostReturn) costPart, ability, paid, unpaid)); + Singletons.getModel().getMatch().getInput().setInput(new InputPayReturnCost((CostReturn) costPart, ability, paid, unpaid)); Singletons.getModel().getGameState().getStack().setResolving(bResolving); } else if (costPart instanceof CostDiscard) { - final boolean bResolving = Singletons.getModel().getGameState().getStack().getResolving(); + final boolean bResolving = Singletons.getModel().getGameState().getStack().isResolving(); Singletons.getModel().getGameState().getStack().setResolving(false); - AllZone.getInputControl().setInput(new InputPayDiscardCost((CostDiscard) costPart, ability, paid, unpaid)); + Singletons.getModel().getMatch().getInput().setInput(new InputPayDiscardCost((CostDiscard) costPart, ability, paid, unpaid)); Singletons.getModel().getGameState().getStack().setResolving(bResolving); } else if (costPart instanceof CostMana) { // temporarily disable the Resolve flag, so the user can payMana for the // resolving Ability - final boolean bResolving = Singletons.getModel().getGameState().getStack().getResolving(); + final boolean bResolving = Singletons.getModel().getGameState().getStack().isResolving(); Singletons.getModel().getGameState().getStack().setResolving(false); - AllZone.getInputControl().setInput(new InputPayManaCostAbility(source + "\r\n", ability.getManaCost(), paid, unpaid)); + Singletons.getModel().getMatch().getInput().setInput(new InputPayManaCostAbility(source + "\r\n", ability.getManaCost(), paid, unpaid)); Singletons.getModel().getGameState().getStack().setResolving(bResolving); } } @@ -698,7 +697,7 @@ public final class GameActionUtil { public static void executeVampiricEffects(final Card c) { final ArrayList a = c.getKeyword(); for (int i = 0; i < a.size(); i++) { - if (GameState.isCardInPlay(c) + if (c.isInPlay() && a.get(i) .toString() .startsWith( @@ -713,7 +712,7 @@ public final class GameActionUtil { if (kw.contains("+2/+2")) { counter = Counters.P2P2; } - if (GameState.isCardInPlay(thisCard)) { + if (thisCard.isInPlay()) { thisCard.addCounter(counter, 1); } } @@ -984,7 +983,7 @@ public final class GameActionUtil { produces.put("Plains", "W"); produces.put("Swamp", "B"); - List lands = GameState.getCardsInGame(); + List lands = Singletons.getModel().getGameState().getCardsInGame(); lands = CardLists.filter(lands, Presets.LANDS); // remove all abilities granted by this Command @@ -1055,8 +1054,8 @@ public final class GameActionUtil { } // add +1/+1 to cards list.clear(); - final int num = GameState.getCardsIn(ZoneType.Battlefield, "Coat of Arms").size(); - final List creatures = CardLists.filter(GameState.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.CREATURES); + final int num = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Coat of Arms")).size(); + final List creatures = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.CREATURES); for (Card c : creatures) { for (Card c2 : creatures) { @@ -1080,9 +1079,9 @@ public final class GameActionUtil { @Override public void execute() { - final List alphaStatuses = GameState.getCardsIn(ZoneType.Battlefield, "Alpha Status"); + final List alphaStatuses = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Alpha Status")); - final List allCreatures = GameState.getCreaturesInPlay(); + final List allCreatures = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); for (int i = 0; i < this.previouslyPumped.size(); i++) { this.previouslyPumped.get(i).addSemiPermanentAttackBoost(0 - this.previouslyPumpedValue.get(i)); @@ -1117,7 +1116,7 @@ public final class GameActionUtil { @Override public void execute() { // get all creatures - final List cards = GameState.getCardsIn(ZoneType.Battlefield, "Umbra Stalker"); + final List cards = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Umbra Stalker")); for (final Card c : cards) { final Player player = c.getController(); final List grave = player.getCardsIn(ZoneType.Graveyard); @@ -1134,7 +1133,7 @@ public final class GameActionUtil { @Override public void execute() { - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.filter(list, new Predicate() { @Override @@ -1157,7 +1156,7 @@ public final class GameActionUtil { @Override public void execute() { - final List list = GameState.getCardsIn(ZoneType.Battlefield, "Old Man of the Sea"); + final List list = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Old Man of the Sea")); for (final Card oldman : list) { if (!oldman.getGainControlTargets().isEmpty()) { if (oldman.getNetAttack() < oldman.getGainControlTargets().get(0).getNetAttack()) { @@ -1178,7 +1177,7 @@ public final class GameActionUtil { @Override public void execute() { - final List list = GameState.getCardsIn(ZoneType.Battlefield, "Liu Bei, Lord of Shu"); + final List list = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Liu Bei, Lord of Shu")); if (list.size() > 0) { for (int i = 0; i < list.size(); i++) { @@ -1217,7 +1216,7 @@ public final class GameActionUtil { @Override public void execute() { - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.filter(list, new Predicate() { @Override public boolean apply(final Card c) { @@ -1235,7 +1234,7 @@ public final class GameActionUtil { } private int countSoundTheCalls() { - List list = GameState.getCardsIn(ZoneType.Graveyard, "Sound the Call"); + List list = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Graveyard), CardPredicates.nameEquals("Sound the Call")); return list.size(); } @@ -1248,7 +1247,7 @@ public final class GameActionUtil { @Override public void execute() { // get all creatures - final List list = GameState.getCardsIn(ZoneType.Battlefield, "Tarmogoyf"); + final List list = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Tarmogoyf")); for (int i = 0; i < list.size(); i++) { final Card c = list.get(i); @@ -1259,7 +1258,7 @@ public final class GameActionUtil { } // execute() private int countDiffTypes() { - final List list = GameState.getCardsIn(ZoneType.Graveyard); + final List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Graveyard); int count = 0; for (int q = 0; q < list.size(); q++) { @@ -1347,7 +1346,7 @@ public final class GameActionUtil { */ public static void doPowerSink(final Player p) { // get all lands with mana abilities - List lands = GameState.getPlayerLandsInPlay(p); + List lands = p.getLandsInPlay(); lands = CardLists.filter(lands, new Predicate() { @Override public boolean apply(final Card c) { diff --git a/src/main/java/forge/StaticEffects.java b/src/main/java/forge/StaticEffects.java index 2a08569adbd..71d97bad192 100644 --- a/src/main/java/forge/StaticEffects.java +++ b/src/main/java/forge/StaticEffects.java @@ -27,7 +27,6 @@ import com.esotericsoftware.minlog.Log; import forge.card.replacement.ReplacementEffect; import forge.card.spellability.SpellAbility; import forge.card.staticability.StaticAbility; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -326,7 +325,7 @@ public class StaticEffects { public final void rePopulateStateBasedList() { this.reset(); - final List cards = GameState.getCardsIn(ZoneType.Battlefield); + final List cards = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); Log.debug("== Start add state effects =="); for (int i = 0; i < cards.size(); i++) { diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactory.java b/src/main/java/forge/card/abilityfactory/AbilityFactory.java index 498d631d5f6..3e509068de8 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactory.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactory.java @@ -39,7 +39,6 @@ import forge.card.spellability.SpellAbilityCondition; import forge.card.spellability.SpellAbilityRestriction; import forge.card.spellability.SpellPermanent; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; import forge.game.player.Player; @@ -1631,10 +1630,10 @@ public class AbilityFactory { // Add whole Remembered list to handlePaid final List list = new ArrayList(); if (card.getRemembered().isEmpty()) { - final Card newCard = GameState.getCardState(card); + final Card newCard = Singletons.getModel().getGameState().getCardState(card); for (final Object o : newCard.getRemembered()) { if (o instanceof Card) { - list.add(GameState.getCardState((Card) o)); + list.add(Singletons.getModel().getGameState().getCardState((Card) o)); } } } @@ -1648,7 +1647,7 @@ public class AbilityFactory { } else { for (final Object o : card.getRemembered()) { if (o instanceof Card) { - list.add(GameState.getCardState((Card) o)); + list.add(Singletons.getModel().getGameState().getCardState((Card) o)); } } } @@ -1658,7 +1657,7 @@ public class AbilityFactory { // Add whole Imprinted list to handlePaid final List list = new ArrayList(); for (final Card c : card.getImprinted()) { - list.add(GameState.getCardState(c)); + list.add(Singletons.getModel().getGameState().getCardState(c)); } return CardFactoryUtil.handlePaid(list, calcX[1], card) * multiplier; @@ -1668,7 +1667,7 @@ public class AbilityFactory { if (card.isEnchanting()) { Object o = card.getEnchanting(); if (o instanceof Card) { - list.add(GameState.getCardState((Card) o)); + list.add(Singletons.getModel().getGameState().getCardState((Card) o)); } } return CardFactoryUtil.handlePaid(list, calcX[1], card) * multiplier; @@ -1928,7 +1927,7 @@ public class AbilityFactory { else { final Object crd = root.getTriggeringObject(defined.substring(9)); if (crd instanceof Card) { - c = GameState.getCardState((Card) crd); + c = Singletons.getModel().getGameState().getCardState((Card) crd); c = (Card) crd; } else if (crd instanceof List) { for (final Card cardItem : (List) crd) { @@ -1940,7 +1939,7 @@ public class AbilityFactory { final SpellAbility root = sa.getRootSpellAbility(); final Object crd = root.getReplacingObject(defined.substring(8)); if (crd instanceof Card) { - c = GameState.getCardState((Card) crd); + c = Singletons.getModel().getGameState().getCardState((Card) crd); } else if (crd instanceof List) { for (final Card cardItem : (List) crd) { cards.add(cardItem); @@ -1948,26 +1947,26 @@ public class AbilityFactory { } } else if (defined.equals("Remembered")) { if (hostCard.getRemembered().isEmpty()) { - final Card newCard = GameState.getCardState(hostCard); + final Card newCard = Singletons.getModel().getGameState().getCardState(hostCard); for (final Object o : newCard.getRemembered()) { if (o instanceof Card) { - cards.add(GameState.getCardState((Card) o)); + cards.add(Singletons.getModel().getGameState().getCardState((Card) o)); } } } for (final Object o : hostCard.getRemembered()) { if (o instanceof Card) { - cards.add(GameState.getCardState((Card) o)); + cards.add(Singletons.getModel().getGameState().getCardState((Card) o)); } } } else if (defined.equals("Clones")) { for (final Card clone : hostCard.getClones()) { - cards.add(GameState.getCardState(clone)); + cards.add(Singletons.getModel().getGameState().getCardState(clone)); } } else if (defined.equals("Imprinted")) { for (final Card imprint : hostCard.getImprinted()) { - cards.add(GameState.getCardState(imprint)); + cards.add(Singletons.getModel().getGameState().getCardState(imprint)); } } else if (defined.startsWith("ThisTurnEntered")) { final String[] workingCopy = defined.split("_"); @@ -2263,7 +2262,7 @@ public class AbilityFactory { for (final Object o : card.getRemembered()) { if (o instanceof Card) { final Card rem = (Card) o; - sas.addAll(GameState.getCardState(rem).getSpellAbilities()); + sas.addAll(Singletons.getModel().getGameState().getCardState(rem).getSpellAbilities()); } } } else if (defined.equals("Imprinted")) { @@ -2284,7 +2283,7 @@ public class AbilityFactory { final SpellAbility root = sa.getRootSpellAbility(); final Object crd = root.getTriggeringObject("Card"); if (crd instanceof Card) { - triggeredCard = GameState.getCardState((Card) crd); + triggeredCard = Singletons.getModel().getGameState().getCardState((Card) crd); } //find the imprinted card that does not share a name with the triggered card for (final SpellAbility spell : imprintedCards) { if (!spell.getSourceCard().getName().equals(triggeredCard.getName())) { diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryAlterLife.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryAlterLife.java index 13aea5ae93a..d1967deea23 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryAlterLife.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryAlterLife.java @@ -33,7 +33,6 @@ import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.CombatUtil; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; @@ -1616,7 +1615,7 @@ public class AbilityFactoryAlterLife { } if (source.getName().equals("Eternity Vessel") - && (GameState.isCardInPlay("Vampire Hexmage", opponent) || (source + && (opponent.isCardInPlay("Vampire Hexmage") || (source .getCounters(Counters.CHARGE) == 0))) { return false; } diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryAnimate.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryAnimate.java index 202c5a26b1d..bafb18c5d3a 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryAnimate.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryAnimate.java @@ -44,7 +44,6 @@ import forge.card.cost.Cost; import forge.card.staticability.StaticAbility; import forge.card.trigger.Trigger; import forge.card.trigger.TriggerHandler; -import forge.game.GameState; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; import forge.game.player.Player; @@ -538,7 +537,7 @@ public final class AbilityFactoryAnimate { //if host is not on the battlefield don't apply if (params.containsKey("UntilHostLeavesPlay") - && !GameState.isCardInPlay(sa.getSourceCard())) { + && !sa.getSourceCard().isInPlay()) { return; } @@ -1296,7 +1295,7 @@ public final class AbilityFactoryAnimate { } if ((tgtPlayers == null) || tgtPlayers.isEmpty()) { - list = GameState.getCardsIn(ZoneType.Battlefield); + list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); } else { list = tgtPlayers.get(0).getCardsIn(ZoneType.Battlefield); } diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java index 1101a2f160b..2feb08fdef9 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java @@ -46,7 +46,6 @@ import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellPermanent; import forge.card.spellability.Target; import forge.card.staticability.StaticAbility; -import forge.game.GameState; import forge.game.phase.CombatUtil; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; @@ -347,7 +346,7 @@ public class AbilityFactoryAttach { return null; } - List list = GameState.getCardsIn(tgt.getZone()); + List list = Singletons.getModel().getGameState().getCardsIn(tgt.getZone()); list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), attachSource); if (params.containsKey("AITgts")) { list = CardLists.getValidCards(list, params.get("AITgts"), sa.getActivatingPlayer(), attachSource); @@ -1313,7 +1312,7 @@ public class AbilityFactoryAttach { return; } - if (GameState.isCardInPlay(crd)) { + if (crd.isInPlay()) { crd.removeController(card); } @@ -1417,7 +1416,7 @@ public class AbilityFactoryAttach { return true; } } else { - List list = GameState.getCardsIn(tgt.getZone()); + List list = Singletons.getModel().getGameState().getCardsIn(tgt.getZone()); list = CardLists.getValidCards(list, tgt.getValidTgts(), aura.getActivatingPlayer(), source); final Object o = GuiChoose.one(source + " - Select a card to attach to.", list); @@ -1711,7 +1710,7 @@ public class AbilityFactoryAttach { // If Cast Targets will be checked on the Stack for (final Object o : targets) { String valid = params.get("UnattachValid"); - List unattachList = GameState.getCardsIn(ZoneType.Battlefield); + List unattachList = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); unattachList = CardLists.getValidCards(unattachList, valid.split(","), source.getController(), source); for (final Card c : unattachList) { AbilityFactoryAttach.handleUnattachment(o, c, af); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryBond.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryBond.java index 19c6895d31a..2c82501b7cc 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryBond.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryBond.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.List; import forge.Card; +import forge.Singletons; import forge.card.spellability.AbilityActivated; import forge.card.spellability.AbilitySub; @@ -29,7 +30,6 @@ import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; import forge.card.cardfactory.CardFactoryUtil; import forge.card.cost.Cost; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -325,7 +325,7 @@ public final class AbilityFactoryBond { } // find list of valid cards to pair with - List cards = GameState.getCardsIn(ZoneType.Battlefield); + List cards = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); cards = AbilityFactory.filterListByType(cards, params.get("ValidCards"), sa); if (cards.isEmpty()) { return; diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java index 6faf91e722f..056c795eaae 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java @@ -49,7 +49,6 @@ import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbilityStackInstance; import forge.card.spellability.SpellPermanent; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.Combat; import forge.game.phase.CombatUtil; import forge.game.phase.PhaseType; @@ -512,7 +511,7 @@ public final class AbilityFactoryChangeZone { //Ninjutsu if (params.containsKey("Ninjutsu")) { - if (source.isType("Legendary") && !GameState.isCardInPlay("Mirror Gallery")) { + if (source.isType("Legendary") && !Singletons.getModel().getGameState().isCardInPlay("Mirror Gallery")) { final List list = ai.getCardsIn(ZoneType.Battlefield); if (Iterables.any(list, CardPredicates.nameEquals(source.getName()))) { return false; @@ -975,7 +974,7 @@ public final class AbilityFactoryChangeZone { } } else if (!origin.contains(ZoneType.Library) && !origin.contains(ZoneType.Hand) && !params.containsKey("DefinedPlayer")) { - fetchList = GameState.getCardsIn(origin); + fetchList = Singletons.getModel().getGameState().getCardsIn(origin); } else { fetchList = player.getCardsIn(origin); } @@ -1161,7 +1160,7 @@ public final class AbilityFactoryChangeZone { } } else if (!origin.contains(ZoneType.Library) && !origin.contains(ZoneType.Hand) && !params.containsKey("DefinedPlayer")) { - fetchList = GameState.getCardsIn(origin); + fetchList = Singletons.getModel().getGameState().getCardsIn(origin); fetchList = AbilityFactory.filterListByType(fetchList, type, sa); } else { fetchList = player.getCardsIn(origin); @@ -1461,11 +1460,11 @@ public final class AbilityFactoryChangeZone { Card card = null; Combat combat = new Combat(); combat.initiatePossibleDefenders(ai); - List attackers = GameState.getCreaturesInPlay(ai.getOpponent()); + List attackers = ai.getOpponent().getCreaturesInPlay(); for (Card att : attackers) { combat.addAttacker(att); } - combat = ComputerUtilBlock.getBlockers(ai, combat, GameState.getCreaturesInPlay(ai)); + combat = ComputerUtilBlock.getBlockers(ai, combat, ai.getCreaturesInPlay()); if (CombatUtil.lifeInDanger(ai, combat)) { // need something AI can cast now @@ -1665,7 +1664,7 @@ public final class AbilityFactoryChangeZone { tgt.resetTargets(); } - List list = GameState.getCardsIn(origin); + List list = Singletons.getModel().getGameState().getCardsIn(origin); list = CardLists.getValidCards(list, tgt.getValidTgts(), ai, source); if (params.containsKey("AITgts")) { list = CardLists.getValidCards(list, params.get("AITgts"), sa.getActivatingPlayer(), source); @@ -1775,7 +1774,7 @@ public final class AbilityFactoryChangeZone { if (!sa.isTrigger() && sa.getPayCosts() != null && Singletons.getModel().getGameState().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) && Singletons.getModel().getGameState().getPhaseHandler().isPlayerTurn(ai) - && GameState.getCreaturesInPlay(ai).isEmpty()) { + && ai.getCreaturesInPlay().isEmpty()) { return false; } list = CardLists.filterControlledBy(list, ai.getOpponent()); @@ -1900,7 +1899,7 @@ public final class AbilityFactoryChangeZone { final ZoneType destination = ZoneType.smartValueOf(params.get("Destination")); final Target tgt = sa.getTarget(); - List list = GameState.getCardsIn(origin); + List list = Singletons.getModel().getGameState().getCardsIn(origin); list = CardLists.getValidCards(list, tgt.getValidTgts(), ai, source); // Narrow down the list: @@ -2235,7 +2234,7 @@ public final class AbilityFactoryChangeZone { && !GameActionUtil.showYesNoDialog(hostCard, sb.toString())) { continue; } - final PlayerZone originZone = GameState.getZoneOf(tgtC); + final PlayerZone originZone = Singletons.getModel().getGameState().getZoneOf(tgtC); // if Target isn't in the expected Zone, continue @@ -2348,7 +2347,7 @@ public final class AbilityFactoryChangeZone { final ArrayList list = AbilityFactory.getDefinedCards(sa.getSourceCard(), defined, sa); for (final Card c : list) { - final Card actualCard = GameState.getCardState(c); + final Card actualCard = Singletons.getModel().getGameState().getCardState(c); ret.add(actualCard); } return ret; @@ -2926,7 +2925,7 @@ public final class AbilityFactoryChangeZone { } if ((tgtPlayers == null) || tgtPlayers.isEmpty()) { - cards = GameState.getCardsIn(origin); + cards = Singletons.getModel().getGameState().getCardsIn(origin); } else { cards = tgtPlayers.get(0).getCardsIn(origin); } @@ -2971,7 +2970,7 @@ public final class AbilityFactoryChangeZone { } if (remember != null) { - GameState.getCardState(sa.getSourceCard()).addRemembered(c); + Singletons.getModel().getGameState().getCardState(sa.getSourceCard()).addRemembered(c); } } diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java index a5d57d1f287..608c3772d93 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java @@ -46,7 +46,6 @@ import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; import forge.card.cost.Cost; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -382,8 +381,7 @@ public final class AbilityFactoryChoose { if (params.containsKey("AILogic")) { final String logic = params.get("AILogic"); if (logic.equals("MostProminentOnBattlefield")) { - chosen = CardFactoryUtil.getMostProminentCreatureType(GameState - .getCardsIn(ZoneType.Battlefield)); + chosen = CardFactoryUtil.getMostProminentCreatureType(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)); } if (logic.equals("MostProminentComputerControls")) { chosen = CardFactoryUtil.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Battlefield)); @@ -391,11 +389,11 @@ public final class AbilityFactoryChoose { if (logic.equals("MostProminentHumanControls")) { chosen = CardFactoryUtil.getMostProminentCreatureType(opp.getCardsIn(ZoneType.Battlefield)); if (!CardUtil.isACreatureType(chosen) || invalidTypes.contains(chosen)) { - chosen = CardFactoryUtil.getMostProminentCreatureType(CardLists.filterControlledBy(GameState.getCardsInGame(), opp)); + chosen = CardFactoryUtil.getMostProminentCreatureType(CardLists.filterControlledBy(Singletons.getModel().getGameState().getCardsInGame(), opp)); } } if (logic.equals("MostProminentInComputerDeck")) { - chosen = CardFactoryUtil.getMostProminentCreatureType(CardLists.filterControlledBy(GameState.getCardsInGame(), ai)); + chosen = CardFactoryUtil.getMostProminentCreatureType(CardLists.filterControlledBy(Singletons.getModel().getGameState().getCardsInGame(), ai)); } if (logic.equals("MostProminentInComputerGraveyard")) { chosen = CardFactoryUtil.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Graveyard)); @@ -730,21 +728,21 @@ public final class AbilityFactoryChoose { if (params.containsKey("AILogic")) { final String logic = params.get("AILogic"); if (logic.equals("MostProminentInHumanDeck")) { - chosen.add(CardFactoryUtil.getMostProminentColor(CardLists.filterControlledBy(GameState.getCardsInGame(), opp))); + chosen.add(CardFactoryUtil.getMostProminentColor(CardLists.filterControlledBy(Singletons.getModel().getGameState().getCardsInGame(), opp))); } else if (logic.equals("MostProminentInComputerDeck")) { - chosen.add(CardFactoryUtil.getMostProminentColor(CardLists.filterControlledBy(GameState.getCardsInGame(), ai))); + chosen.add(CardFactoryUtil.getMostProminentColor(CardLists.filterControlledBy(Singletons.getModel().getGameState().getCardsInGame(), ai))); } else if (logic.equals("MostProminentDualInComputerDeck")) { - List prominence = CardFactoryUtil.getColorByProminence(CardLists.filterControlledBy(GameState.getCardsInGame(), ai)); + List prominence = CardFactoryUtil.getColorByProminence(CardLists.filterControlledBy(Singletons.getModel().getGameState().getCardsInGame(), ai)); chosen.add(prominence.get(0)); chosen.add(prominence.get(1)); } else if (logic.equals("MostProminentInGame")) { - chosen.add(CardFactoryUtil.getMostProminentColor(GameState.getCardsInGame())); + chosen.add(CardFactoryUtil.getMostProminentColor(Singletons.getModel().getGameState().getCardsInGame())); } else if (logic.equals("MostProminentHumanCreatures")) { - List list = GameState.getCreaturesInPlay(opp); + List list = opp.getCreaturesInPlay(); if (list.isEmpty()) { - list = CardLists.filter(CardLists.filterControlledBy(GameState.getCardsInGame(), opp), CardPredicates.Presets.CREATURES); + list = CardLists.filter(CardLists.filterControlledBy(Singletons.getModel().getGameState().getCardsInGame(), opp), CardPredicates.Presets.CREATURES); } chosen.add(CardFactoryUtil.getMostProminentColor(list)); } @@ -752,7 +750,7 @@ public final class AbilityFactoryChoose { chosen.add(CardFactoryUtil.getMostProminentColor(ai.getCardsIn(ZoneType.Battlefield))); } else if (logic.equals("MostProminentPermanent")) { - final List list = GameState.getCardsIn(ZoneType.Battlefield); + final List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); chosen.add(CardFactoryUtil.getMostProminentColor(list)); } else if (logic.equals("MostProminentAttackers")) { @@ -1646,7 +1644,7 @@ public final class AbilityFactoryChoose { chosen = CardFactoryUtil.getMostProminentCardName(p.getOpponent().getCardsIn(ZoneType.Library)); } } else { - List list = CardLists.filterControlledBy(GameState.getCardsInGame(), p.getOpponent()); + List list = CardLists.filterControlledBy(Singletons.getModel().getGameState().getCardsInGame(), p.getOpponent()); list = CardLists.filter(list, Predicates.not(Presets.LANDS)); if (!list.isEmpty()) { chosen = list.get(0).getName(); @@ -1872,7 +1870,7 @@ public final class AbilityFactoryChoose { if (params.containsKey("ChoiceZone")) { choiceZone = ZoneType.smartValueOf(params.get("ChoiceZone")); } - List choices = GameState.getCardsIn(choiceZone); + List choices = Singletons.getModel().getGameState().getCardsIn(choiceZone); if (params.containsKey("Choices")) { choices = CardLists.getValidCards(choices, params.get("Choices"), host.getController(), host); } @@ -1941,7 +1939,7 @@ public final class AbilityFactoryChoose { if (params.containsKey("ChoiceZone")) { choiceZone = ZoneType.smartValueOf(params.get("ChoiceZone")); } - List choices = GameState.getCardsIn(choiceZone); + List choices = Singletons.getModel().getGameState().getCardsIn(choiceZone); if (params.containsKey("Choices")) { choices = CardLists.getValidCards(choices, params.get("Choices"), host.getController(), host); } @@ -1954,7 +1952,7 @@ public final class AbilityFactoryChoose { ? CardFactoryUtil.xCount(host, host.getSVar(params.get("Amount"))) : Integer.parseInt(numericAmount); if (params.containsKey("SunderingTitan")) { - final List land = GameState.getLandsInPlay(); + final List land = Singletons.getModel().getGameState().getLandsInPlay(); final ArrayList basic = CardUtil.getBasicTypes(); for (final String type : basic) { diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryCleanup.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryCleanup.java index b98ad6d4363..93096043d81 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryCleanup.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryCleanup.java @@ -25,7 +25,6 @@ import forge.card.cardfactory.CardFactoryUtil; import forge.card.spellability.AbilitySub; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; // Cleanup is not the same as other AFs, it is only used as a Drawback, and only used to Cleanup particular card states // That need to be reset. I'm creating this to clear Remembered Cards at the @@ -106,7 +105,7 @@ public final class AbilityFactoryCleanup { if (params.containsKey("ClearRemembered")) { source.clearRemembered(); - GameState.getCardState(source).clearRemembered(); + Singletons.getModel().getGameState().getCardState(source).clearRemembered(); } if (params.containsKey("ClearImprinted")) { source.clearImprinted(); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryCopy.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryCopy.java index b5ebe47bfd4..9b30d2c8f55 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryCopy.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryCopy.java @@ -40,7 +40,6 @@ import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; import forge.game.player.Player; @@ -307,7 +306,7 @@ public final class AbilityFactoryCopy { final Target abTgt = sa.getTarget(); if (abTgt != null) { - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.getValidCards(list, abTgt.getValidTgts(), source.getController(), source); list = CardLists.getTargetableCards(list, sa); abTgt.resetTargets(); @@ -402,7 +401,7 @@ public final class AbilityFactoryCopy { } // start copied Kiki code - int multiplier = GameState.getTokenDoublersMagnitude(hostCard.getController()); + int multiplier = hostCard.getController().getTokenDoublersMagnitude(); multiplier *= numCopies; final Card[] crds = new Card[multiplier]; @@ -487,7 +486,7 @@ public final class AbilityFactoryCopy { public void resolve() { // technically your opponent could steal the token // and the token shouldn't be sacrificed - if (GameState.isCardInPlay(target[index])) { + if (target[index].isInPlay()) { if (params.get("AtEOT").equals("Sacrifice")) { // maybe do a setSacrificeAtEOT, but // probably not. diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java index 366ca11d931..7be804cf2ef 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryCounters.java @@ -27,7 +27,6 @@ import java.util.Random; import com.google.common.base.Predicate; -import forge.AllZone; import forge.Card; import forge.CardLists; @@ -42,7 +41,6 @@ import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; import forge.control.input.Input; -import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; @@ -756,7 +754,7 @@ public class AbilityFactoryCounters { if (max != -1) { counterAmount = max - tgtCard.getCounters(Counters.valueOf(type)); } - final PlayerZone zone = GameState.getZoneOf(tgtCard); + final PlayerZone zone = Singletons.getModel().getGameState().getZoneOf(tgtCard); if (zone == null) { // Do nothing, token disappeared } else if (zone.is(ZoneType.Battlefield)) { @@ -1177,7 +1175,7 @@ public class AbilityFactoryCounters { } for (final Card tgtCard : tgtCards) { if ((tgt == null) || tgtCard.canBeTargetedBy(sa)) { - final PlayerZone zone = GameState.getZoneOf(tgtCard); + final PlayerZone zone = Singletons.getModel().getGameState().getZoneOf(tgtCard); if (params.get("CounterNum").equals("All")) { counterAmount = tgtCard.getCounters(Counters.valueOf(type)); } @@ -1526,8 +1524,8 @@ public class AbilityFactoryCounters { } private static void proliferateResolveHuman(final AbilityFactory af, final SpellAbility sa) { - final List unchosen = GameState.getCardsIn(ZoneType.Battlefield); - AllZone.getInputControl().setInput(new Input() { + final List unchosen = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); + Singletons.getModel().getMatch().getInput().setInput(new Input() { private static final long serialVersionUID = -1779224307654698954L; @Override @@ -1599,7 +1597,7 @@ public class AbilityFactoryCounters { } }; - List cardsToProliferate = CardLists.filter(GameState.getCardsIn(ZoneType.Battlefield), predProliferate); + List cardsToProliferate = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), predProliferate); List playersToPoison = new ArrayList(); for( Player e : enemies ) { if ( e.getPoisonCounters() > 0 ) @@ -1990,7 +1988,7 @@ public class AbilityFactoryCounters { final String valid = params.get("ValidCards"); final ZoneType zone = params.containsKey("ValidZone") ? ZoneType.smartValueOf(params.get("ValidZone")) : ZoneType.Battlefield; - List cards = GameState.getCardsIn(zone); + List cards = Singletons.getModel().getGameState().getCardsIn(zone); cards = CardLists.getValidCards(cards, valid, sa.getSourceCard().getController(), sa.getSourceCard()); final Target tgt = sa.getTarget(); @@ -2000,7 +1998,7 @@ public class AbilityFactoryCounters { } for (final Card tgtCard : cards) { - if (GameState.getZoneOf(tgtCard).is(ZoneType.Battlefield)) { + if (Singletons.getModel().getGameState().getZoneOf(tgtCard).is(ZoneType.Battlefield)) { tgtCard.addCounter(Counters.valueOf(type), counterAmount); } else { // adding counters to something like re-suspend cards @@ -2245,7 +2243,7 @@ public class AbilityFactoryCounters { final String valid = params.get("ValidCards"); final ZoneType zone = params.containsKey("ValidZone") ? ZoneType.smartValueOf(params.get("ValidZone")) : ZoneType.Battlefield; - List cards = GameState.getCardsIn(zone); + List cards = Singletons.getModel().getGameState().getCardsIn(zone); cards = CardLists.getValidCards(cards, valid, sa.getSourceCard().getController(), sa.getSourceCard()); final Target tgt = sa.getTarget(); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java index 949a458d2f0..7e4160d7e0e 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java @@ -40,7 +40,6 @@ import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; import forge.card.spellability.TargetSelection; -import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; @@ -907,7 +906,7 @@ public class AbilityFactoryDealDamage { for (final Object o : tgts) { if (o instanceof Card) { final Card c = (Card) o; - if (GameState.isCardInPlay(c) && (!targeted || c.canBeTargetedBy(saMe))) { + if (c.isInPlay() && (!targeted || c.canBeTargetedBy(saMe))) { if (noPrevention) { c.addDamageWithoutPrevention(dmg, source); } else if (combatDmg) { @@ -1383,7 +1382,7 @@ public class AbilityFactoryDealDamage { } if (params.containsKey("ValidCards")) { - list = GameState.getCardsIn(ZoneType.Battlefield); + list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); } if (targetPlayer != null) { @@ -1647,7 +1646,7 @@ public class AbilityFactoryDealDamage { final HashMap params = af.getMapParams(); final Card card = sa.getSourceCard(); - List sources = GameState.getCardsIn(ZoneType.Battlefield); + List sources = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); if (params.containsKey("ValidCards")) { sources = CardLists.getValidCards(sources, params.get("ValidCards"), card.getController(), card); } @@ -1667,7 +1666,7 @@ public class AbilityFactoryDealDamage { // System.out.println(source+" deals "+dmg+" damage to "+o.toString()); if (o instanceof Card) { final Card c = (Card) o; - if (GameState.isCardInPlay(c) && (!targeted || c.canBeTargetedBy(sa))) { + if (c.isInPlay() && (!targeted || c.canBeTargetedBy(sa))) { c.addDamage(dmg, source); } @@ -1907,7 +1906,7 @@ public class AbilityFactoryDealDamage { Target tgt = sa.getTarget(); tgt.resetTargets(); - List aiCreatures = GameState.getCreaturesInPlay(ai); + List aiCreatures = ai.getCreaturesInPlay(); aiCreatures = CardLists.getTargetableCards(aiCreatures, sa); aiCreatures = CardLists.filter(aiCreatures, new Predicate() { @Override @@ -1916,7 +1915,7 @@ public class AbilityFactoryDealDamage { } }); - List humCreatures = GameState.getCreaturesInPlay(ai.getOpponent()); + List humCreatures = ai.getOpponent().getCreaturesInPlay(); humCreatures = CardLists.getTargetableCards(humCreatures, sa); final Random r = MyRandom.getRandom(); @@ -2000,8 +1999,8 @@ public class AbilityFactoryDealDamage { fighter2 = tgts.get(1); } - if (fighter1 == null || fighter2 == null || !GameState.isCardInPlay(fighter1) - || !GameState.isCardInPlay(fighter2)) { + if (fighter1 == null || fighter2 == null || !fighter1.isInPlay() + || !fighter2.isInPlay()) { return; } diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java index a5166f169b0..51df55ddbf0 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java @@ -40,7 +40,6 @@ import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbilityRestriction; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.CombatUtil; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; @@ -297,7 +296,7 @@ public final class AbilityFactoryDebuff { private static boolean debuffCanPlayAI(final Player ai, final AbilityFactory af, final SpellAbility sa) { // if there is no target and host card isn't in play, don't activate final Card source = sa.getSourceCard(); - if ((sa.getTarget() == null) && !GameState.isCardInPlay(source)) { + if ((sa.getTarget() == null) && !source.isInPlay()) { return false; } @@ -466,7 +465,7 @@ public final class AbilityFactoryDebuff { private static List getCurseCreatures(final Player ai, final AbilityFactory af, final SpellAbility sa, final ArrayList kws) { final Player opp = ai.getOpponent(); - List list = GameState.getCreaturesInPlay(opp); + List list = opp.getCreaturesInPlay(); list = CardLists.getTargetableCards(list, sa); if (!list.isEmpty()) { @@ -496,7 +495,7 @@ public final class AbilityFactoryDebuff { * @return a boolean. */ private static boolean debuffMandatoryTarget(final Player ai, final AbilityFactory af, final SpellAbility sa, final boolean mandatory) { - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); final Target tgt = sa.getTarget(); list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard()); @@ -617,7 +616,7 @@ public final class AbilityFactoryDebuff { for (final Card tgtC : tgtCards) { final ArrayList hadIntrinsic = new ArrayList(); - if (GameState.isCardInPlay(tgtC) && tgtC.canBeTargetedBy(sa)) { + if (tgtC.isInPlay() && tgtC.canBeTargetedBy(sa)) { for (final String kw : kws) { if (tgtC.getIntrinsicKeyword().contains(kw)) { hadIntrinsic.add(kw); @@ -632,7 +631,7 @@ public final class AbilityFactoryDebuff { @Override public void execute() { - if (GameState.isCardInPlay(tgtC)) { + if (tgtC.isInPlay()) { for (final String kw : hadIntrinsic) { tgtC.addIntrinsicKeyword(kw); } @@ -858,12 +857,12 @@ public final class AbilityFactoryDebuff { valid = params.get("ValidCards"); } - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.getValidCards(list, valid.split(","), hostCard.getController(), hostCard); for (final Card tgtC : list) { final ArrayList hadIntrinsic = new ArrayList(); - if (GameState.isCardInPlay(tgtC) && tgtC.canBeTargetedBy(sa)) { + if (tgtC.isInPlay() && tgtC.canBeTargetedBy(sa)) { for (final String kw : kws) { if (tgtC.getIntrinsicKeyword().contains(kw)) { hadIntrinsic.add(kw); @@ -878,7 +877,7 @@ public final class AbilityFactoryDebuff { @Override public void execute() { - if (GameState.isCardInPlay(tgtC)) { + if (tgtC.isInPlay()) { for (final String kw : hadIntrinsic) { tgtC.addIntrinsicKeyword(kw); } diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java index 17989c1125b..f0e99e7f76d 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java @@ -39,7 +39,6 @@ import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -376,7 +375,7 @@ public class AbilityFactoryDestroy { final Player opp = ai.getOpponent(); if (tgt != null) { List list; - list = GameState.getCardsIn(ZoneType.Battlefield); + list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.getTargetableCards(list, sa); list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source); @@ -591,7 +590,7 @@ public class AbilityFactoryDestroy { } for (final Card tgtC : tgtCards) { - if (GameState.isCardInPlay(tgtC) && ((tgt == null) || tgtC.canBeTargetedBy(sa))) { + if (tgtC.isInPlay() && ((tgt == null) || tgtC.canBeTargetedBy(sa))) { boolean destroyed = false; if (sac) { destroyed = Singletons.getModel().getGameAction().sacrifice(tgtC, sa); @@ -606,7 +605,7 @@ public class AbilityFactoryDestroy { } for (final Card unTgtC : untargetedCards) { - if (GameState.isCardInPlay(unTgtC)) { + if (unTgtC.isInPlay()) { boolean destroyed = false; if (sac) { destroyed = Singletons.getModel().getGameAction().sacrifice(unTgtC, sa); @@ -1037,7 +1036,7 @@ public class AbilityFactoryDestroy { valid = valid.replace("X", Integer.toString(AbilityFactory.calculateAmount(card, "X", sa))); } - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); if (targetPlayer != null) { list = CardLists.filterControlledBy(list, targetPlayer); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryEffect.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryEffect.java index d404891e1f5..f80744b1cd1 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryEffect.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryEffect.java @@ -41,7 +41,6 @@ import forge.card.spellability.Target; import forge.card.trigger.Trigger; import forge.card.trigger.TriggerHandler; import forge.card.trigger.TriggerType; -import forge.game.GameState; import forge.game.phase.CombatUtil; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; @@ -298,8 +297,8 @@ public class AbilityFactoryEffect { } else if (logic.equals("Always")) { randomReturn = true; } else if (logic.equals("Evasion")) { - List comp = GameState.getCreaturesInPlay(ai); - List human = GameState.getCreaturesInPlay(ai.getOpponent()); + List comp = ai.getCreaturesInPlay(); + List human = ai.getOpponent().getCreaturesInPlay(); // only count creatures that can attack or block comp = CardLists.filter(comp, new Predicate() { @@ -447,7 +446,7 @@ public class AbilityFactoryEffect { } // Unique Effects shouldn't be duplicated - if (params.containsKey("Unique") && GameState.isCardInPlay(name)) { + if (params.containsKey("Unique") && Singletons.getModel().getGameState().isCardInPlay(name)) { return; } @@ -553,7 +552,7 @@ public class AbilityFactoryEffect { // Remember created effect if (params.containsKey("RememberEffect")) { - GameState.getCardState(card).addRemembered(eff); + Singletons.getModel().getGameState().getCardState(card).addRemembered(eff); } // Duration diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryGainControl.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryGainControl.java index 4a00caa380b..278b0a4ac73 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryGainControl.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryGainControl.java @@ -39,7 +39,6 @@ import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; import forge.card.cost.Cost; -import forge.game.GameState; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; import forge.game.player.Player; @@ -424,7 +423,7 @@ public class AbilityFactoryGainControl { final Target tgt = sa.getTarget(); if (this.params.containsKey("AllValid")) { - tgtCards = GameState.getCardsIn(ZoneType.Battlefield); + tgtCards = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); tgtCards = AbilityFactory.filterListByType(tgtCards, this.params.get("AllValid"), sa); } else if ((tgt != null) && !this.params.containsKey("Defined")) { tgtCards.addAll(tgt.getTargetCards()); @@ -468,7 +467,7 @@ public class AbilityFactoryGainControl { sa.getSourceCard().addGainControlTarget(tgtC); } - if (GameState.isCardInPlay(tgtC)) { + if (tgtC.isInPlay()) { if (!tgtC.equals(newController)) { tgtC.addController(newController); @@ -561,7 +560,7 @@ public class AbilityFactoryGainControl { private boolean gainControlDrawbackAI(final Player ai, final SpellAbility sa) { if ((sa.getTarget() == null) || !sa.getTarget().doesTarget()) { if (this.params.containsKey("AllValid")) { - List tgtCards = CardLists.filterControlledBy(GameState.getCardsIn(ZoneType.Battlefield), ai.getOpponent()); + List tgtCards = CardLists.filterControlledBy(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), ai.getOpponent()); tgtCards = AbilityFactory.filterListByType(tgtCards, this.params.get("AllValid"), sa); if (tgtCards.isEmpty()) { return false; @@ -650,7 +649,7 @@ public class AbilityFactoryGainControl { if (null == c) { return; } - if (GameState.isCardInPlay(c)) { + if (c.isInPlay()) { c.removeController(newController); // Singletons.getModel().getGameAction().changeController(new ArrayList(c), // c.getController(), originalController); @@ -908,8 +907,8 @@ public class AbilityFactoryGainControl { object2 = tgts.get(1); } - if (object1 == null || object2 == null || !GameState.isCardInPlay(object1) - || !GameState.isCardInPlay(object2)) { + if (object1 == null || object2 == null || !object1.isInPlay() + || !object2.isInPlay()) { return; } diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryMana.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryMana.java index 1f76b13cb77..8b21e629d62 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryMana.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryMana.java @@ -41,7 +41,6 @@ import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; import forge.control.input.InputPayManaCostUtil; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -772,7 +771,7 @@ public class AbilityFactoryMana { cards.add(c); } } else { - cards = CardLists.getValidCards(GameState.getCardsIn(ZoneType.Battlefield), validCard, abMana.getActivatingPlayer(), card); + cards = CardLists.getValidCards(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), validCard, abMana.getActivatingPlayer(), card); } // remove anything cards that is already in parents diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java index 27efc6be2ea..adc0c77ef15 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java @@ -26,7 +26,6 @@ import java.util.Random; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; -import forge.AllZone; import forge.Card; import forge.CardLists; @@ -41,7 +40,6 @@ import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; @@ -476,7 +474,7 @@ public class AbilityFactoryPermanentState { final Card source = sa.getSourceCard(); final Target tgt = sa.getTarget(); - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source); list = CardLists.getTargetableCards(list, sa); @@ -606,7 +604,7 @@ public class AbilityFactoryPermanentState { } for (final Card tgtC : tgtCards) { - if (GameState.isCardInPlay(tgtC) && ((tgt == null) || tgtC.canBeTargetedBy(sa))) { + if (tgtC.isInPlay() && ((tgt == null) || tgtC.canBeTargetedBy(sa))) { tgtC.untap(); } } @@ -635,7 +633,7 @@ public class AbilityFactoryPermanentState { for (final Player p : definedPlayers) { if (p.isHuman()) { - AllZone.getInputControl().setInput(CardFactoryUtil.inputUntapUpToNType(num, valid)); + Singletons.getModel().getMatch().getInput().setInput(CardFactoryUtil.inputUntapUpToNType(num, valid)); } else { List list = p.getCardsIn(ZoneType.Battlefield); list = CardLists.getType(list, valid); @@ -1101,7 +1099,7 @@ public class AbilityFactoryPermanentState { final Card source = sa.getSourceCard(); final Target tgt = sa.getTarget(); - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source); list = CardLists.getTargetableCards(list, sa); @@ -1230,7 +1228,7 @@ public class AbilityFactoryPermanentState { } for (final Card tgtC : tgtCards) { - if ((GameState.isCardInPlay(tgtC) || params.containsKey("ETB")) && ((tgt == null) || tgtC.canBeTargetedBy(sa))) { + if ((tgtC.isInPlay() || params.containsKey("ETB")) && ((tgt == null) || tgtC.canBeTargetedBy(sa))) { if (tgtC.isUntapped() && (remTapped)) { card.addRemembered(tgtC); } @@ -1421,7 +1419,7 @@ public class AbilityFactoryPermanentState { } if ((tgtPlayers == null) || tgtPlayers.isEmpty()) { - list = GameState.getCardsIn(ZoneType.Battlefield); + list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); } else { list = tgtPlayers.get(0).getCardsIn(ZoneType.Battlefield); } @@ -1679,7 +1677,7 @@ public class AbilityFactoryPermanentState { } if ((tgtPlayers == null) || tgtPlayers.isEmpty()) { - cards = GameState.getCardsIn(ZoneType.Battlefield); + cards = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); } else { cards = tgtPlayers.get(0).getCardsIn(ZoneType.Battlefield); } @@ -1723,7 +1721,7 @@ public class AbilityFactoryPermanentState { valid = params.get("ValidCards"); } - List validTappables = GameState.getCardsIn(ZoneType.Battlefield); + List validTappables = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); final Target tgt = sa.getTarget(); @@ -1774,7 +1772,7 @@ public class AbilityFactoryPermanentState { * @return a {@link forge.CardList} object. */ private static List getTapAllTargets(final String valid, final Card source) { - List tmpList = GameState.getCardsIn(ZoneType.Battlefield); + List tmpList = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); tmpList = CardLists.getValidCards(tmpList, valid, source.getController(), source); tmpList = CardLists.filter(tmpList, Presets.UNTAPPED); return tmpList; @@ -2227,7 +2225,7 @@ public class AbilityFactoryPermanentState { } for (final Card tgtC : tgtCards) { - if (GameState.isCardInPlay(tgtC) && ((tgt == null) || tgtC.canBeTargetedBy(sa))) { + if (tgtC.isInPlay() && ((tgt == null) || tgtC.canBeTargetedBy(sa))) { if (sa.getActivatingPlayer().isHuman()) { final String[] tapOrUntap = new String[] { "Tap", "Untap" }; final Object z = GuiChoose.oneOrNone("Tap or Untap " + tgtC + "?", tapOrUntap); @@ -2602,7 +2600,7 @@ public class AbilityFactoryPermanentState { final Card source = sa.getSourceCard(); final Target tgt = sa.getTarget(); - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.getTargetableCards(CardLists.getValidCards(list, tgt.getValidTgts(), source.getController(), source), sa); return false; diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java index 14cdd241d9e..37d41962d66 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryPlay.java @@ -43,7 +43,6 @@ import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbilityRestriction; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -304,7 +303,7 @@ public final class AbilityFactoryPlay { final Target tgt = sa.getTarget(); if (tgt != null) { ZoneType zone = tgt.getZone().get(0); - cards = GameState.getCardsIn(zone); + cards = Singletons.getModel().getGameState().getCardsIn(zone); cards = CardLists.getValidCards(cards, tgt.getValidTgts(), ai, source); if (cards.isEmpty()) { return false; @@ -376,7 +375,7 @@ public final class AbilityFactoryPlay { if (params.containsKey("ValidZone")) { zone = ZoneType.smartValueOf(params.get("ValidZone")); } - tgtCards = GameState.getCardsIn(zone); + tgtCards = Singletons.getModel().getGameState().getCardsIn(zone); tgtCards = AbilityFactory.filterListByType(tgtCards, params.get("Valid"), sa); } else if (params.containsKey("Defined")) { tgtCards = new ArrayList(AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("Defined"), sa)); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryPreventDamage.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryPreventDamage.java index 77d3c28ea92..fab7ecb8036 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryPreventDamage.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryPreventDamage.java @@ -35,7 +35,6 @@ import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.CombatUtil; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; @@ -457,7 +456,7 @@ public class AbilityFactoryPreventDamage { final Target tgt = sa.getTarget(); tgt.resetTargets(); // filter AIs battlefield by what I can target - List targetables = GameState.getCardsIn(ZoneType.Battlefield); + List targetables = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); targetables = CardLists.getValidCards(targetables, tgt.getValidTgts(), ai, hostCard); final List compTargetables = CardLists.filterControlledBy(targetables, ai); @@ -535,7 +534,7 @@ public class AbilityFactoryPreventDamage { for (final Object o : tgts) { if (o instanceof Card) { final Card c = (Card) o; - if (GameState.isCardInPlay(c) && (!targeted || c.canBeTargetedBy(sa))) { + if (c.isInPlay() && (!targeted || c.canBeTargetedBy(sa))) { c.addPreventNextDamage(numDam); } @@ -548,7 +547,7 @@ public class AbilityFactoryPreventDamage { } for (final Card c : untargetedCards) { - if (GameState.isCardInPlay(c)) { + if (c.isInPlay()) { c.addPreventNextDamage(numDam); } } @@ -787,7 +786,7 @@ public class AbilityFactoryPreventDamage { } if (params.containsKey("ValidCards")) { - list = GameState.getCardsIn(ZoneType.Battlefield); + list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); } list = AbilityFactory.filterListByType(list, params.get("ValidCards"), sa); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java index 149148ea5cf..350b7d33d46 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java @@ -42,7 +42,6 @@ import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.CombatUtil; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; @@ -248,7 +247,7 @@ public final class AbilityFactoryProtection { final Card hostCard = af.getHostCard(); final ArrayList gains = AbilityFactoryProtection.getProtectionList(hostCard, af.getMapParams()); - List list = GameState.getCreaturesInPlay(ai); + List list = ai.getCreaturesInPlay(); list = CardLists.filter(list, new Predicate() { @Override public boolean apply(final Card c) { @@ -303,7 +302,7 @@ public final class AbilityFactoryProtection { final HashMap params = af.getMapParams(); final Card hostCard = af.getHostCard(); // if there is no target and host card isn't in play, don't activate - if ((sa.getTarget() == null) && !GameState.isCardInPlay(hostCard)) { + if ((sa.getTarget() == null) && !hostCard.isInPlay()) { return false; } @@ -469,7 +468,7 @@ public final class AbilityFactoryProtection { final HashMap params = af.getMapParams(); final Card host = af.getHostCard(); - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); final Target tgt = sa.getTarget(); list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard()); @@ -744,9 +743,9 @@ public final class AbilityFactoryProtection { if (params.containsKey("AILogic")) { final String logic = params.get("AILogic"); if (logic.equals("MostProminentHumanCreatures")) { - List list = GameState.getCreaturesInPlay(ai.getOpponent()); + List list = ai.getOpponent().getCreaturesInPlay(); if (list.isEmpty()) { - list = CardLists.filterControlledBy(GameState.getCardsInGame(), ai.getOpponent()); + list = CardLists.filterControlledBy(Singletons.getModel().getGameState().getCardsInGame(), ai.getOpponent()); } if (!list.isEmpty()) { choice = CardFactoryUtil.getMostProminentColor(list); @@ -787,7 +786,7 @@ public final class AbilityFactoryProtection { final Card tgtC = tgtCards.get(j); // only pump things in play - if (!GameState.isCardInPlay(tgtC)) { + if (!tgtC.isInPlay()) { continue; } @@ -807,7 +806,7 @@ public final class AbilityFactoryProtection { @Override public void execute() { - if (GameState.isCardInPlay(tgtC)) { + if (tgtC.isInPlay()) { for (final String gain : gains) { tgtC.removeExtrinsicKeyword("Protection from " + gain); } @@ -824,7 +823,7 @@ public final class AbilityFactoryProtection { for (final Card unTgtC : untargetedCards) { // only pump things in play - if (!GameState.isCardInPlay(unTgtC)) { + if (!unTgtC.isInPlay()) { continue; } @@ -839,7 +838,7 @@ public final class AbilityFactoryProtection { @Override public void execute() { - if (GameState.isCardInPlay(unTgtC)) { + if (unTgtC.isInPlay()) { for (final String gain : gains) { unTgtC.removeExtrinsicKeyword("Protection from " + gain); } @@ -1031,7 +1030,7 @@ public final class AbilityFactoryProtection { private static boolean protectAllCanPlayAI(final Player ai, final AbilityFactory af, final SpellAbility sa) { final Card hostCard = af.getHostCard(); // if there is no target and host card isn't in play, don't activate - if ((sa.getTarget() == null) && !GameState.isCardInPlay(hostCard)) { + if ((sa.getTarget() == null) && !hostCard.isInPlay()) { return false; } @@ -1191,11 +1190,11 @@ public final class AbilityFactoryProtection { valid = params.get("ValidCards"); } if (!valid.equals("")) { - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.getValidCards(list, valid, sa.getActivatingPlayer(), host); for (final Card tgtC : list) { - if (GameState.isCardInPlay(tgtC)) { + if (tgtC.isInPlay()) { for (final String gain : gains) { tgtC.addExtrinsicKeyword("Protection from " + gain); } @@ -1207,7 +1206,7 @@ public final class AbilityFactoryProtection { @Override public void execute() { - if (GameState.isCardInPlay(tgtC)) { + if (tgtC.isInPlay()) { for (final String gain : gains) { tgtC.removeExtrinsicKeyword("Protection from " + gain); } diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java index 5b8e7d106c2..9013e32d368 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java @@ -30,6 +30,7 @@ import forge.Card; import forge.CardLists; import forge.CardPredicates; +import forge.CardPredicates.Presets; import forge.CardUtil; import forge.Command; import forge.GameActionUtil; @@ -44,7 +45,6 @@ import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbilityRestriction; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.Combat; import forge.game.phase.CombatUtil; import forge.game.phase.PhaseHandler; @@ -371,7 +371,7 @@ public class AbilityFactoryPump { || card.getNetCombatDamage() <= 0 || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY) || ph.getPhase().isBefore(PhaseType.MAIN1) - || CardLists.getNotKeyword(GameState.getCreaturesInPlay(ai), "Defender").isEmpty())) { + || CardLists.getNotKeyword(ai.getCreaturesInPlay(), "Defender").isEmpty())) { return false; } if (ph.isPlayerTurn(human) && (!card.isAttacking() @@ -413,7 +413,7 @@ public class AbilityFactoryPump { } Predicate opBlockers = CardPredicates.possibleBlockers(card); - List cardsCanBlock = CardLists.filter(GameState.getCreaturesInPlay(opp), opBlockers); + List cardsCanBlock = CardLists.filter(opp.getCreaturesInPlay(), opBlockers); final boolean evasive = (keyword.endsWith("Unblockable") || keyword.endsWith("Fear") || keyword.endsWith("Intimidate") || keyword.endsWith("Shadow")); @@ -478,7 +478,7 @@ public class AbilityFactoryPump { } } else if (ph.isPlayerTurn(ai) && ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS) && CombatUtil.canAttack(card)) { - List blockers = GameState.getCreaturesInPlay(opp); + List blockers = opp.getCreaturesInPlay(); for (Card blocker : blockers) { if (CombatUtil.canBlock(card, blocker, combat) && !CombatUtil.canDestroyBlocker(blocker, card, combat, false)) { @@ -490,7 +490,7 @@ public class AbilityFactoryPump { } else if (combatRelevant) { if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY) - || (GameState.getCreaturesInPlay(opp).size() < 1) + || (opp.getCreaturesInPlay().size() < 1) || cardsCanBlock.isEmpty()) { return false; } @@ -553,7 +553,7 @@ public class AbilityFactoryPump { } else if (keyword.equals("Vigilance")) { if (ph.isPlayerTurn(opp) || !CombatUtil.canAttack(card) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS) - || CardLists.getNotKeyword(GameState.getCreaturesInPlay(opp), "Defender").size() < 1) { + || CardLists.getNotKeyword(opp.getCreaturesInPlay(), "Defender").size() < 1) { return false; } } else if (keyword.equals("Reach")) { @@ -590,7 +590,7 @@ public class AbilityFactoryPump { if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || card.getNetCombatDamage() <= 0 - || CardLists.getType(GameState.getPlayerLandsInPlay(opp), "Island").isEmpty() + || CardLists.getType(opp.getLandsInPlay(), "Island").isEmpty() || cardsCanBlock.isEmpty()) { return false; } @@ -598,7 +598,7 @@ public class AbilityFactoryPump { if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || card.getNetCombatDamage() <= 0 - || CardLists.getType(GameState.getPlayerLandsInPlay(opp), "Swamp").isEmpty() + || CardLists.getType(opp.getLandsInPlay(), "Swamp").isEmpty() || cardsCanBlock.isEmpty()) { return false; } @@ -606,7 +606,7 @@ public class AbilityFactoryPump { if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || card.getNetCombatDamage() <= 0 - || CardLists.getType(GameState.getPlayerLandsInPlay(opp), "Mountain").isEmpty() + || CardLists.getType(opp.getLandsInPlay(), "Mountain").isEmpty() || cardsCanBlock.isEmpty()) { return false; } @@ -614,7 +614,7 @@ public class AbilityFactoryPump { if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || card.getNetCombatDamage() <= 0 - || CardLists.getType(GameState.getPlayerLandsInPlay(opp), "Forest").isEmpty() + || CardLists.getType(opp.getLandsInPlay(), "Forest").isEmpty() || cardsCanBlock.isEmpty()) { return false; } @@ -704,7 +704,7 @@ public class AbilityFactoryPump { */ private List getPumpCreatures(final Player ai, final SpellAbility sa) { - List list = GameState.getCreaturesInPlay(ai); + List list = ai.getCreaturesInPlay(); list = CardLists.filter(list, new Predicate() { @Override public boolean apply(final Card c) { @@ -728,7 +728,7 @@ public class AbilityFactoryPump { * @return a {@link forge.CardList} object. */ private List getCurseCreatures(final Player ai, final SpellAbility sa, final int defense, final int attack) { - List list = GameState.getCreaturesInPlay(ai.getOpponent()); + List list = ai.getOpponent().getCreaturesInPlay(); list = CardLists.getTargetableCards(list, sa); if ((defense < 0) && !list.isEmpty()) { // with spells that give -X/-X, // compi will try to destroy a @@ -981,7 +981,7 @@ public class AbilityFactoryPump { List list = new ArrayList(); if (this.abilityFactory.getMapParams().containsKey("AILogic")) { if (this.abilityFactory.getMapParams().get("AILogic").equals("HighestPower")) { - list = CardLists.getValidCards(GameState.getCreaturesInPlay(), tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard()); + list = CardLists.getValidCards(CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.CREATURES), tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard()); list = CardLists.getTargetableCards(list, sa); CardLists.sortAttack(list); if (!list.isEmpty()) { @@ -1000,7 +1000,7 @@ public class AbilityFactoryPump { } else { if (!tgt.canTgtCreature()) { ZoneType zone = tgt.getZone().get(0); - list = GameState.getCardsIn(zone); + list = Singletons.getModel().getGameState().getCardsIn(zone); } else { list = this.getPumpCreatures(ai, sa); } @@ -1080,7 +1080,7 @@ public class AbilityFactoryPump { * @return a boolean. */ private boolean pumpMandatoryTarget(final Player ai, final AbilityFactory af, final SpellAbility sa, final boolean mandatory) { - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); final Target tgt = sa.getTarget(); final Player opp = ai.getOpponent(); list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard()); @@ -1444,7 +1444,7 @@ public class AbilityFactoryPump { final Card tgtC = tgtCards.get(j); // only pump things in PumpZone - if (!GameState.getCardsIn(pumpZone).contains(tgtC)) { + if (!Singletons.getModel().getGameState().getCardsIn(pumpZone).contains(tgtC)) { continue; } @@ -1459,7 +1459,7 @@ public class AbilityFactoryPump { for (int i = 0; i < untargetedCards.size(); i++) { final Card tgtC = untargetedCards.get(i); // only pump things in PumpZone - if (!GameState.getCardsIn(pumpZone).contains(tgtC)) { + if (!Singletons.getModel().getGameState().getCardsIn(pumpZone).contains(tgtC)) { continue; } @@ -1479,7 +1479,7 @@ public class AbilityFactoryPump { //if host is not on the battlefield don't apply if (this.params.containsKey("UntilLoseControlOfHost") - && !GameState.isCardInPlay(sa.getSourceCard())) { + && !sa.getSourceCard().isInPlay()) { return; } final int a = this.getNumAttack(sa); @@ -1858,7 +1858,7 @@ public class AbilityFactoryPump { list = new ArrayList(); if ((tgtPlayers == null) || tgtPlayers.isEmpty()) { for (final ZoneType zone : affectedZones) { - list.addAll(GameState.getCardsIn(zone)); + list.addAll(Singletons.getModel().getGameState().getCardsIn(zone)); } } else { @@ -1906,7 +1906,7 @@ public class AbilityFactoryPump { @Override public void execute() { - if (GameState.isCardInPlay(tgtC)) { + if (tgtC.isInPlay()) { tgtC.addTempAttackBoost(-1 * a); tgtC.addTempDefenseBoost(-1 * d); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryRegenerate.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryRegenerate.java index ad4b7118a32..9f97d9d44ba 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryRegenerate.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryRegenerate.java @@ -36,7 +36,6 @@ import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.CombatUtil; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; @@ -424,7 +423,7 @@ public class AbilityFactoryRegenerate { final Target tgt = sa.getTarget(); tgt.resetTargets(); // filter AIs battlefield by what I can target - List targetables = GameState.getCardsIn(ZoneType.Battlefield); + List targetables = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); targetables = CardLists.getValidCards(targetables, tgt.getValidTgts(), ai, hostCard); targetables = CardLists.getTargetableCards(targetables, sa); final List compTargetables = CardLists.filterControlledBy(targetables, ai); @@ -511,7 +510,7 @@ public class AbilityFactoryRegenerate { } }; - if (GameState.isCardInPlay(tgtC) && ((tgt == null) || tgtC.canBeTargetedBy(sa))) { + if (tgtC.isInPlay() && ((tgt == null) || tgtC.canBeTargetedBy(sa))) { tgtC.addShield(); Singletons.getModel().getGameState().getEndOfTurn().addUntil(untilEOT); } @@ -739,7 +738,7 @@ public class AbilityFactoryRegenerate { valid = params.get("ValidCards"); } - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.getValidCards(list, valid.split(","), hostCard.getController(), hostCard); list = CardLists.filter(list, CardPredicates.isController(ai)); @@ -828,7 +827,7 @@ public class AbilityFactoryRegenerate { valid = params.get("ValidCards"); } - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.getValidCards(list, valid.split(","), hostCard.getController(), hostCard); for (final Card c : list) { @@ -841,7 +840,7 @@ public class AbilityFactoryRegenerate { } }; - if (GameState.isCardInPlay(c)) { + if (c.isInPlay()) { c.addShield(); Singletons.getModel().getGameState().getEndOfTurn().addUntil(untilEOT); } diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryRepeat.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryRepeat.java index 7a7d439c25f..3733129cdb5 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryRepeat.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryRepeat.java @@ -23,6 +23,7 @@ import java.util.List; import forge.Card; import forge.CardLists; +import forge.Singletons; import forge.card.cost.Cost; import forge.GameActionUtil; @@ -32,7 +33,6 @@ import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.util.Expressions; @@ -279,7 +279,7 @@ public final class AbilityFactoryRepeat { if (params.containsKey("RepeatDefined")) { list.addAll(AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("RepeatDefined"), sa)); } else { - list = GameState.getCardsIn(ZoneType.Battlefield); + list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); } list = CardLists.getValidCards(list, repeatPresent.split(","), sa.getActivatingPlayer(), sa.getSourceCard()); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryReveal.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryReveal.java index 655ea192d52..d090b0adc9f 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryReveal.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryReveal.java @@ -42,7 +42,6 @@ import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; import forge.game.player.Player; @@ -669,7 +668,7 @@ public final class AbilityFactoryReveal { */ private static List sharesNameWithCardOnBattlefield(final List list) { final List toReturn = new ArrayList(); - final List play = GameState.getCardsIn(ZoneType.Battlefield); + final List play = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card c : list) { for (final Card p : play) { if (p.getName().equals(c.getName()) && !toReturn.contains(c)) { diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactorySacrifice.java b/src/main/java/forge/card/abilityfactory/AbilityFactorySacrifice.java index 1aba2e396df..30536ac5a48 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactorySacrifice.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactorySacrifice.java @@ -35,7 +35,6 @@ import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -495,7 +494,7 @@ public class AbilityFactorySacrifice { final boolean remSacrificed = params.containsKey("RememberSacrificed"); if (valid.equals("Self")) { - if (GameState.getZoneOf(card).is(ZoneType.Battlefield)) { + if (Singletons.getModel().getGameState().getZoneOf(card).is(ZoneType.Battlefield)) { if (Singletons.getModel().getGameAction().sacrifice(card, sa) && remSacrificed) { card.addRemembered(card); } @@ -934,7 +933,7 @@ public class AbilityFactorySacrifice { if (params.containsKey("Defined")) { list = new ArrayList(AbilityFactory.getDefinedCards(af.getHostCard(), params.get("Defined"), sa)); } else { - list = GameState.getCardsIn(ZoneType.Battlefield); + list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); } final boolean remSacrificed = params.containsKey("RememberSacrificed"); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactorySetState.java b/src/main/java/forge/card/abilityfactory/AbilityFactorySetState.java index 984f0a2cc1f..4dbae8291f5 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactorySetState.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactorySetState.java @@ -25,6 +25,7 @@ import java.util.Map; import forge.Card; import forge.CardCharacteristicName; +import forge.Singletons; import forge.CardLists; import forge.card.spellability.AbilityActivated; @@ -34,7 +35,6 @@ import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; import forge.card.cardfactory.CardFactoryUtil; import forge.card.cost.Cost; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -471,7 +471,7 @@ public class AbilityFactorySetState { valid = valid.replace("X", Integer.toString(AbilityFactory.calculateAmount(card, "X", sa))); } - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); if (targetPlayer != null) { list = CardLists.filterControlledBy(list, targetPlayer); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryToken.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryToken.java index e2cce2d437e..c8316c8900e 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryToken.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryToken.java @@ -35,7 +35,6 @@ import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; import forge.card.trigger.Trigger; import forge.card.trigger.TriggerHandler; -import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; @@ -640,10 +639,10 @@ public class AbilityFactoryToken extends AbilityFactory { Singletons.getModel().getGameState().getCombat().addAttacker(c); } if (remember != null) { - GameState.getCardState(sa.getSourceCard()).addRemembered(c); + Singletons.getModel().getGameState().getCardState(sa.getSourceCard()).addRemembered(c); } if (this.abilityFactory.getMapParams().get("RememberSource") != null) { - GameState.getCardState(c).addRemembered(host); + Singletons.getModel().getGameState().getCardState(c).addRemembered(host); } } } diff --git a/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java b/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java index 57540f77bc7..3dc776e6364 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryArtifacts.java @@ -5,7 +5,6 @@ import java.util.List; import javax.swing.JOptionPane; -import forge.AllZone; import forge.Card; import forge.Command; @@ -17,7 +16,6 @@ import forge.card.spellability.AbilityActivated; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; import forge.control.input.Input; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.PlayerZone; @@ -212,7 +210,7 @@ class CardFactoryArtifacts { } if (this.getTargetCard() != null) { - if (GameState.isCardInPlay(this.getTargetCard()) + if (this.getTargetCard().isInPlay() && this.getTargetCard().canBeTargetedBy(this)) { this.getTargetCard().addDamage(damage, card); } @@ -370,7 +368,7 @@ class CardFactoryArtifacts { public void resolve() { // not implemented for compy if (card.getController().isHuman()) { - AllZone.getInputControl().setInput(new Input() { + Singletons.getModel().getMatch().getInput().setInput(new Input() { private static final long serialVersionUID = -2305549394512889450L; private final List exiled = new ArrayList(); diff --git a/src/main/java/forge/card/cardfactory/CardFactoryAuras.java b/src/main/java/forge/card/cardfactory/CardFactoryAuras.java index ee2eccb42fe..d733439cbe8 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryAuras.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryAuras.java @@ -40,7 +40,6 @@ import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellPermanent; import forge.card.spellability.Target; import forge.control.input.Input; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; @@ -87,7 +86,7 @@ class CardFactoryAuras { final Player opp = getActivatingPlayer().getOpponent(); final String[] landTypes = new String[] { "Plains", "Island", "Swamp", "Mountain", "Forest" }; final HashMap humanLandCount = new HashMap(); - final List humanlands = GameState.getPlayerLandsInPlay(opp); + final List humanlands = opp.getLandsInPlay(); for (final String landType : landTypes) { humanLandCount.put(landType, 0); @@ -115,7 +114,7 @@ class CardFactoryAuras { } newType[0] = landTypes[minAt]; - List list = GameState.getPlayerLandsInPlay(opp); + List list = opp.getLandsInPlay(); list = CardLists.getNotType(list, newType[0]); // Don't enchant lands // that already have the // type @@ -136,7 +135,7 @@ class CardFactoryAuras { final Card c = this.getTargetCard(); - if (GameState.isCardInPlay(c) && c.canBeTargetedBy(this)) { + if (c.isInPlay() && c.canBeTargetedBy(this)) { card.enchantEntity(c); } @@ -250,7 +249,7 @@ class CardFactoryAuras { @Override public void showMessage() { - final List land = GameState.getLandsInPlay(); + final List land = Singletons.getModel().getGameState().getLandsInPlay(); this.stopSetNext(CardFactoryUtil .inputTargetSpecific(spell, land, "Select target land", true, false)); } @@ -268,7 +267,7 @@ class CardFactoryAuras { @Override public boolean canPlayAI() { - List list = GameState.getCreaturesInPlay(getActivatingPlayer().getOpponent()); + List list = getActivatingPlayer().getOpponent().getCreaturesInPlay(); list = CardLists.getKeyword(list, "Flying"); if (list.isEmpty()) { return false; @@ -300,7 +299,7 @@ class CardFactoryAuras { final Card c = this.getTargetCard(); - if (GameState.isCardInPlay(c) && c.canBeTargetedBy(this)) { + if (c.isInPlay() && c.canBeTargetedBy(this)) { card.enchantEntity(c); Log.debug("Enchanted: " + this.getTargetCard()); } @@ -378,7 +377,7 @@ class CardFactoryAuras { this.setTargetCard(stuffy.get(0)); return true; } else { - final List list = GameState.getCreaturesInPlay(getActivatingPlayer().getOpponent()); + final List list = getActivatingPlayer().getOpponent().getCreaturesInPlay(); if (list.isEmpty()) { return false; @@ -407,7 +406,7 @@ class CardFactoryAuras { final Card c = this.getTargetCard(); - if (GameState.isCardInPlay(c) && c.canBeTargetedBy(this)) { + if (c.isInPlay() && c.canBeTargetedBy(this)) { aura.enchantEntity(c); } } // resolve() @@ -427,7 +426,7 @@ class CardFactoryAuras { // This includes creatures Animate Dead can't enchant once // in play. // The human may try to Animate them, the AI will not. - return CardLists.filter(GameState.getCardsIn(ZoneType.Graveyard), Presets.CREATURES); + return CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Graveyard), Presets.CREATURES); } @Override @@ -481,7 +480,7 @@ class CardFactoryAuras { } final Card animated = targetC[0]; - final PlayerZone grave = GameState.getZoneOf(animated); + final PlayerZone grave = Singletons.getModel().getGameState().getZoneOf(animated); if (!grave.is(ZoneType.Graveyard)) { // Animated Creature got removed before ability resolved diff --git a/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java b/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java index 9f2af4f6e53..b9bbcfe9ba4 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java @@ -52,7 +52,6 @@ import forge.card.spellability.Target; import forge.card.trigger.Trigger; import forge.card.trigger.TriggerHandler; import forge.control.input.Input; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; @@ -103,7 +102,7 @@ public class CardFactoryCreatures { if (c.sumAllCounters() == 0) { return; - } else if (GameState.isCardInPlay(c) && c.canBeTargetedBy(this)) { + } else if (c.isInPlay() && c.canBeTargetedBy(this)) { // zerker clean up: for (final Counters c1 : Counters.values()) { if (c.getCounters(c1) > 0) { @@ -199,7 +198,7 @@ public class CardFactoryCreatures { @Override public boolean canPlayAI() { return Iterables.any(getActivatingPlayer().getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.ARTIFACTS) - && GameState.getZoneOf(this.getSourceCard()).is(ZoneType.Hand); + && Singletons.getModel().getGameState().getZoneOf(this.getSourceCard()).is(ZoneType.Hand); } }); card.addComesIntoPlayCommand(intoPlay); @@ -276,7 +275,7 @@ public class CardFactoryCreatures { @Override public void execute() { - if (GameState.isCardInPlay(card)) { + if (card.isInPlay()) { Singletons.getModel().getGameAction().sacrifice(card, null); } } @@ -304,7 +303,7 @@ public class CardFactoryCreatures { @Override public void execute() { - final List list = GameState.getCardsIn(ZoneType.Battlefield, "Stangg Twin"); + final List list = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Stangg Twin")); if (list.size() == 1) { Singletons.getModel().getGameAction().exile(list.get(0)); @@ -330,7 +329,7 @@ public class CardFactoryCreatures { @Override public void resolve() { - List allTokens = GameState.getCreaturesInPlay(card.getController()); + List allTokens = card.getController().getCreaturesInPlay(); allTokens = CardLists.filter(allTokens, Presets.TOKEN); CardFactoryUtil.copyTokens(allTokens); @@ -338,7 +337,7 @@ public class CardFactoryCreatures { @Override public boolean canPlayAI() { - List allTokens = GameState.getCreaturesInPlay(getActivatingPlayer()); + List allTokens = getActivatingPlayer().getCreaturesInPlay(); allTokens = CardLists.filter(allTokens, Presets.TOKEN); return allTokens.size() >= 2; @@ -451,7 +450,7 @@ public class CardFactoryCreatures { return; } - if (!(target.canBeTargetedBy(this) && GameState.isCardInPlay(target))) { + if (!(target.canBeTargetedBy(this) && target.isInPlay())) { return; } @@ -463,7 +462,7 @@ public class CardFactoryCreatures { if (target.getController().isHuman()) { // Human choose // spread damage for (int x = 0; x < target.getNetAttack(); x++) { - AllZone.getInputControl().setInput( + Singletons.getModel().getMatch().getInput().setInput( CardFactoryUtil.masterOfTheWildHuntInputTargetCreature(this, wolves, new Command() { private static final long serialVersionUID = -328305150127775L; @@ -890,7 +889,7 @@ public class CardFactoryCreatures { if (p.canBeTargetedBy(this)) { p.setSkipNextUntap(true); for (final Card c : targetPerms) { - if (GameState.isCardInPlay(c) && c.canBeTargetedBy(this)) { + if (c.isInPlay() && c.canBeTargetedBy(this)) { c.tap(); } } @@ -978,9 +977,9 @@ public class CardFactoryCreatures { final Player player = card.getController(); if (player.isHuman()) { - AllZone.getInputControl().setInput(playerInput); + Singletons.getModel().getMatch().getInput().setInput(playerInput); } else { - List list = GameState.getCreaturesInPlay(player.getOpponent()); + List list = player.getOpponent().getCreaturesInPlay(); list = CardLists.getTargetableCards(list, ability); if ( !list.isEmpty() ) { @@ -1046,7 +1045,7 @@ public class CardFactoryCreatures { this.stop(); } }; // Input - AllZone.getInputControl().setInput(target); + Singletons.getModel().getMatch().getInput().setInput(target); } } // end resolve diff --git a/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java b/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java index 91cd66c5352..a21130d6dac 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java @@ -4,7 +4,6 @@ import java.util.List; import com.google.common.collect.Iterables; -import forge.AllZone; import forge.Card; import forge.CardLists; @@ -18,7 +17,6 @@ import forge.card.trigger.Trigger; import forge.card.trigger.TriggerHandler; import forge.control.input.Input; import forge.game.GameLossReason; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; @@ -160,8 +158,8 @@ class CardFactoryEnchantments { @Override public boolean canPlayAI() { - final List compCreats = GameState.getCreaturesInPlay(getActivatingPlayer()); - final List humCreats = GameState.getCreaturesInPlay(getActivatingPlayer().getOpponent()); + final List compCreats = getActivatingPlayer().getCreaturesInPlay(); + final List humCreats = getActivatingPlayer().getOpponent().getCreaturesInPlay(); // only play standstill if comp controls more creatures than // human @@ -247,7 +245,7 @@ class CardFactoryEnchantments { sb.append(card).append(" - Select a card drawn this turn: ").append(numPutBack - i) .append(" of " + numPutBack); final String prompt = sb.toString(); - AllZone.getInputControl().setInput(new Input() { + Singletons.getModel().getMatch().getInput().setInput(new Input() { private static final long serialVersionUID = -3389565833121544797L; @Override diff --git a/src/main/java/forge/card/cardfactory/CardFactoryInstants.java b/src/main/java/forge/card/cardfactory/CardFactoryInstants.java index 874125dbfc2..05f5a971fe6 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryInstants.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryInstants.java @@ -36,7 +36,6 @@ import forge.card.spellability.AbilitySub; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; -import forge.game.GameState; import forge.game.phase.PhaseUtil; import forge.game.player.ComputerUtil; import forge.game.player.Player; @@ -91,7 +90,7 @@ public class CardFactoryInstants { @Override public void resolve() { Player player = getTargetPlayer(); - List artifacts = GameState.getCardsIn(ZoneType.Battlefield); + List artifacts = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); artifacts = CardLists.filter(artifacts, CardPredicates.Presets.ARTIFACTS); for (int i = 0; i < artifacts.size(); i++) { @@ -303,7 +302,7 @@ public class CardFactoryInstants { // the siren flag final Player player = card.getController(); final Player opponent = player.getOpponent(); - final List creatures = GameState.getCreaturesInPlay(opponent); + final List creatures = opponent.getCreaturesInPlay(); for (final Card creature : creatures) { // skip walls, skip creatures with summoning sickness // also skip creatures with haste if they came onto the @@ -319,7 +318,7 @@ public class CardFactoryInstants { public void resolve() { final Player player = card.getController(); final Player opponent = player.getOpponent(); - final List creatures = GameState.getCreaturesInPlay(opponent); + final List creatures = opponent.getCreaturesInPlay(); for (final Card creature : creatures) { // System.out.println("Siren's Call - EOT - "+creature.getName() @@ -327,7 +326,7 @@ public class CardFactoryInstants { // System.out.println("Siren's Call - EOT - "+creature.getName() // +" attacked?: "+creature.getCreatureAttackedThisCombat()); if (creature.getSirenAttackOrDestroy() && !creature.getDamageHistory().getCreatureAttackedThisTurn()) { - if (GameState.isCardInPlay(creature)) { + if (creature.isInPlay()) { // System.out.println("Siren's Call - destroying "+creature.getName()); // this should probably go on the stack Singletons.getModel().getGameAction().destroy(creature); @@ -416,7 +415,7 @@ public class CardFactoryInstants { @Override public void resolve() { final Player you = card.getController(); - final List ens = CardLists.filter(GameState.getCardsIn(ZoneType.Battlefield), Presets.ENCHANTMENTS); + final List ens = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.ENCHANTMENTS); final List toReturn = CardLists.filter(ens, new Predicate() { @Override public boolean apply(final Card c) { @@ -520,7 +519,7 @@ public class CardFactoryInstants { public void resolve() { final Card myc = this.getParent().getTargetCard(); final Card tgt = this.getTargetCard(); - if (GameState.isCardInPlay(myc) && GameState.isCardInPlay(tgt)) { + if (myc.isInPlay() && tgt.isInPlay()) { if (myc.canBeTargetedBy(this) && tgt.canBeTargetedBy(this)) { tgt.addDamage(myc.getNetAttack(), myc); } diff --git a/src/main/java/forge/card/cardfactory/CardFactoryLands.java b/src/main/java/forge/card/cardfactory/CardFactoryLands.java index cb992011d7b..9605a37a74d 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryLands.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryLands.java @@ -24,7 +24,6 @@ import javax.swing.JOptionPane; import com.google.common.base.Predicate; -import forge.AllZone; import forge.Card; import forge.CardLists; @@ -36,7 +35,6 @@ import forge.card.cost.Cost; import forge.card.spellability.AbilityActivated; import forge.card.spellability.Target; import forge.control.input.Input; -import forge.game.GameState; import forge.game.phase.PhaseType; import forge.game.player.Player; import forge.game.zone.PlayerZone; @@ -97,7 +95,7 @@ class CardFactoryLands { boolean needsTheMana = false; final Player ai = card.getController(); if (ai.getLife() > 3) { - final int landsize = GameState.getPlayerLandsInPlay(ai).size(); + final int landsize = ai.getLandsInPlay().size(); for (Card c : ai.getCardsIn(ZoneType.Hand)) { if (landsize == c.getCMC()) { needsTheMana = true; @@ -145,7 +143,7 @@ class CardFactoryLands { @Override public boolean apply(final Card c) { - return GameState.isCardInPlay(c) && c.isCreature() + return c.isInPlay() && c.isCreature() && (c.getTurnInZone() == Singletons.getModel().getGameState().getPhaseHandler().getTurn()); } }; @@ -181,7 +179,7 @@ class CardFactoryLands { @Override public void resolve() { this.inPlay.clear(); - this.inPlay.addAll(GameState.getCardsIn(ZoneType.Battlefield)); + this.inPlay.addAll(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)); for (final Card targ : CardLists.filter(this.inPlay, targets)) { targ.addCounter(Counters.P1P1, 1); } @@ -291,7 +289,7 @@ class CardFactoryLands { } public void humanExecute() { - AllZone.getInputControl().setInput(new Input() { + Singletons.getModel().getMatch().getInput().setInput(new Input() { private static final long serialVersionUID = -2774066137824255680L; @Override diff --git a/src/main/java/forge/card/cardfactory/CardFactorySorceries.java b/src/main/java/forge/card/cardfactory/CardFactorySorceries.java index 7a187637085..e5b1b43f85d 100644 --- a/src/main/java/forge/card/cardfactory/CardFactorySorceries.java +++ b/src/main/java/forge/card/cardfactory/CardFactorySorceries.java @@ -31,7 +31,6 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Iterables; -import forge.AllZone; import forge.Card; import forge.CardLists; @@ -49,7 +48,6 @@ import forge.card.spellability.Target; import forge.control.input.Input; import forge.control.input.InputPayManaCost; import forge.control.input.InputPayManaCostAbility; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.player.PlayerUtil; @@ -262,15 +260,15 @@ public class CardFactorySorceries { public boolean canPlayAI() { final Player ai = getActivatingPlayer(); final Player opp = ai.getOpponent(); - List humTokenCreats = CardLists.filter(GameState.getCreaturesInPlay(opp), Presets.TOKEN); - List compTokenCreats = CardLists.filter(GameState.getCreaturesInPlay(ai), Presets.TOKEN); + List humTokenCreats = CardLists.filter(opp.getCreaturesInPlay(), Presets.TOKEN); + List compTokenCreats = CardLists.filter(ai.getCreaturesInPlay(), Presets.TOKEN); return compTokenCreats.size() > humTokenCreats.size(); } // canPlayAI() @Override public void resolve() { - List tokens = GameState.getCreaturesInPlay(); + List tokens = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); tokens = CardLists.filter(tokens, Presets.TOKEN); CardFactoryUtil.copyTokens(tokens); @@ -318,7 +316,7 @@ public class CardFactorySorceries { // Vector computerBasic = new Vector(); // figure out which basic land types the computer has - List land = GameState.getPlayerLandsInPlay(Singletons.getControl().getPlayer().getOpponent()); + List land = Singletons.getControl().getPlayer().getOpponent().getLandsInPlay(); for (final String element : Constant.Color.BASIC_LANDS) { final List cl = CardLists.getType(land, element); @@ -353,7 +351,7 @@ public class CardFactorySorceries { // when this spell resolves all basic lands which were not // selected are sacrificed. for (int i = 0; i < target.size(); i++) { - if (GameState.isCardInPlay(target.get(i)) && !saveList.contains(target.get(i))) { + if (target.get(i).isInPlay() && !saveList.contains(target.get(i))) { Singletons.getModel().getGameAction().sacrifice(target.get(i), this); } } @@ -402,7 +400,7 @@ public class CardFactorySorceries { /* && !saveList.contains(c) */) { // get all other basic[count] lands human player // controls and add them to target - List land = GameState.getPlayerLandsInPlay(c.getController()); + List land = c.getController().getLandsInPlay(); List cl = CardLists.getType(land, humanBasic.get(this.count)); cl = CardLists.filter(cl, new Predicate() { @Override @@ -576,7 +574,7 @@ public class CardFactorySorceries { List> lands = new ArrayList>(); for (Player p : Singletons.getModel().getGameState().getPlayers()) { - lands.add(GameState.getPlayerLandsInPlay(p)); + lands.add(p.getLandsInPlay()); } int min = Integer.MAX_VALUE; @@ -596,7 +594,7 @@ public class CardFactorySorceries { Singletons.getModel().getGameAction().sacrifice(l.get(i), card); } } else { - AllZone.getInputControl().setInput(PlayerUtil.inputSacrificePermanents(sac, "Land")); + Singletons.getModel().getMatch().getInput().setInput(PlayerUtil.inputSacrificePermanents(sac, "Land")); } } } @@ -626,7 +624,7 @@ public class CardFactorySorceries { List> creats = new ArrayList>(); for (Player p : Singletons.getModel().getGameState().getPlayers()) { - creats.add(GameState.getCreaturesInPlay(p)); + creats.add(p.getCreaturesInPlay()); } int min = Integer.MAX_VALUE; for(List h : creats) { @@ -647,7 +645,7 @@ public class CardFactorySorceries { Singletons.getModel().getGameAction().sacrifice(c.get(i), card); } } else { - AllZone.getInputControl().setInput(PlayerUtil.inputSacrificePermanents(sac, "Creature")); + Singletons.getModel().getMatch().getInput().setInput(PlayerUtil.inputSacrificePermanents(sac, "Creature")); } } } @@ -668,12 +666,12 @@ public class CardFactorySorceries { int diff = 0; final Player ai = getActivatingPlayer(); final Player opp = ai.getOpponent(); - final List humLand = GameState.getPlayerLandsInPlay(opp); - final List compLand = GameState.getPlayerLandsInPlay(ai); + final List humLand = opp.getLandsInPlay(); + final List compLand = ai.getLandsInPlay(); diff += humLand.size() - compLand.size(); - final List humCreats = GameState.getCreaturesInPlay(opp); - List compCreats = GameState.getCreaturesInPlay(ai); + final List humCreats = opp.getCreaturesInPlay(); + List compCreats = ai.getCreaturesInPlay(); compCreats = CardLists.filter(compCreats, CardPredicates.Presets.CREATURES); diff += 1.5 * (humCreats.size() - compCreats.size()); @@ -826,7 +824,7 @@ public class CardFactorySorceries { } } - List bidded = CardLists.filter(GameState.getCardsIn(ZoneType.Graveyard), CardPredicates.Presets.CREATURES); + List bidded = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Graveyard), CardPredicates.Presets.CREATURES); for (final Card c : bidded) { for(int i = 0; i < types.size(); i++) { if (c.isType(types.get(i))) { @@ -988,7 +986,7 @@ public class CardFactorySorceries { if (card.getChoice(i).equals(cardChoice[2])) { final Card c = ab2card[0]; if (c != null) { - if (GameState.isCardInPlay(c) && c.canBeTargetedBy(this)) { + if (c.isInPlay() && c.canBeTargetedBy(this)) { final int boost = x[0] * -1; c.addTempAttackBoost(boost); c.addTempDefenseBoost(boost); @@ -997,7 +995,7 @@ public class CardFactorySorceries { @Override public void execute() { - if (GameState.isCardInPlay(c)) { + if (c.isInPlay()) { c.addTempAttackBoost(-1 * boost); c.addTempDefenseBoost(-1 * boost); @@ -1015,14 +1013,14 @@ public class CardFactorySorceries { final ArrayList cs = new ArrayList(); cs.addAll(ab3cards); for (final Card c : cs) { - if (GameState.isCardInPlay(c) && c.canBeTargetedBy(this)) { + if (c.isInPlay() && c.canBeTargetedBy(this)) { c.addExtrinsicKeyword("Fear"); final Command untilEOT = new Command() { private static final long serialVersionUID = 986259855862338866L; @Override public void execute() { - if (GameState.isCardInPlay(c)) { + if (c.isInPlay()) { c.removeExtrinsicKeyword("Fear"); } } @@ -1302,7 +1300,7 @@ public class CardFactorySorceries { final ArrayList display = new ArrayList(); // get all - final List creatures = GameState.getCreaturesInPlay(); + final List creatures = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); List grave = card.getController().getCardsIn(ZoneType.Graveyard); grave = CardLists.filter(grave, Presets.CREATURES); @@ -1415,7 +1413,7 @@ public class CardFactorySorceries { Singletons.getModel().getGameAction().moveToPlay(newArtifact[0]); } else { final String diffCost = String.valueOf(newCMC - baseCMC); - AllZone.getInputControl().setInput(new InputPayManaCostAbility(diffCost, new Command() { + Singletons.getModel().getMatch().getInput().setInput(new InputPayManaCostAbility(diffCost, new Command() { private static final long serialVersionUID = -8729850321341068049L; @Override diff --git a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java index 91c2064aaa7..a2660e6122e 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java @@ -31,7 +31,6 @@ import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import forge.AllZone; import forge.Card; import forge.CardCharacteristicName; @@ -68,7 +67,6 @@ import forge.card.trigger.TriggerType; import forge.control.input.Input; import forge.control.input.InputPayManaCost; import forge.control.input.InputPayManaCostUtil; -import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; @@ -864,7 +862,7 @@ public class CardFactoryUtil { public boolean canPlay() { //Lands do not have SpellPermanents. if (sourceCard.isLand()) { - return (GameState.getZoneOf(sourceCard).is(ZoneType.Hand) || sourceCard.hasKeyword("May be played")) + return (Singletons.getModel().getGameState().getZoneOf(sourceCard).is(ZoneType.Hand) || sourceCard.hasKeyword("May be played")) && PhaseHandler.canCastSorcery(sourceCard.getController()); } else { @@ -917,7 +915,7 @@ public class CardFactoryUtil { @Override public boolean canPlay() { return sourceCard.getController().equals(this.getActivatingPlayer()) && sourceCard.isFaceDown() - && GameState.isCardInPlay(sourceCard); + && sourceCard.isInPlay(); } }; // morph_up @@ -1271,7 +1269,6 @@ public class CardFactoryUtil { } else if (choices.contains(card)) { spell.setTargetCard(card); if (spell.getManaCost().equals("0") || free) { - this.setFree(false); Singletons.getModel().getGameState().getStack().add(spell); this.stop(); } else { @@ -1571,7 +1568,7 @@ public class CardFactoryUtil { */ public static boolean isTargetStillValid(final SpellAbility ability, final Card target) { - if (GameState.getZoneOf(target) == null) { + if (Singletons.getModel().getGameState().getZoneOf(target) == null) { return false; // for tokens that disappeared } @@ -1587,7 +1584,7 @@ public class CardFactoryUtil { // Check if the target is in the zone it needs to be in to be // targeted - if (!GameState.getZoneOf(target).is(tgt.getZone())) { + if (!Singletons.getModel().getGameState().getZoneOf(target).is(tgt.getZone())) { return false; } } else { @@ -1849,7 +1846,7 @@ public class CardFactoryUtil { if (l[0].contains("Valid")) { final String restrictions = l[0].replace("Valid ", ""); final String[] rest = restrictions.split(","); - List cardsonbattlefield = GameState.getCardsIn(ZoneType.Battlefield); + List cardsonbattlefield = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); cardsonbattlefield = CardLists.getValidCards(cardsonbattlefield, rest, players.get(0), source); n = cardsonbattlefield.size(); @@ -1899,7 +1896,7 @@ public class CardFactoryUtil { if (sq[0].contains("CreaturesInPlay")) { if (players.size() > 0) { - return CardFactoryUtil.doXMath(GameState.getCreaturesInPlay(players.get(0)).size(), m, source); + return CardFactoryUtil.doXMath(players.get(0).getCreaturesInPlay().size(), m, source); } } @@ -2057,7 +2054,7 @@ public class CardFactoryUtil { String restrictions = l[0].replace("ValidGrave ", ""); restrictions = restrictions.replace("Count$", ""); final String[] rest = restrictions.split(","); - List cards = GameState.getCardsIn(ZoneType.Graveyard); + List cards = Singletons.getModel().getGameState().getCardsIn(ZoneType.Graveyard); cards = CardLists.getValidCards(cards, rest, cardController, c); n = cards.size(); @@ -2069,7 +2066,7 @@ public class CardFactoryUtil { String restrictions = l[0].replace("Valid ", ""); restrictions = restrictions.replace("Count$", ""); final String[] rest = restrictions.split(","); - List cardsonbattlefield = GameState.getCardsIn(ZoneType.Battlefield); + List cardsonbattlefield = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); cardsonbattlefield = CardLists.getValidCards(cardsonbattlefield, rest, cardController, c); n = cardsonbattlefield.size(); @@ -2096,7 +2093,7 @@ public class CardFactoryUtil { } if (l[0].contains("GreatestPowerYouControl")) { - final List list = GameState.getCreaturesInPlay(c.getController()); + final List list = c.getController().getCreaturesInPlay(); int highest = 0; for (final Card crd : list) { if (crd.getNetAttack() > highest) { @@ -2107,7 +2104,7 @@ public class CardFactoryUtil { } if (l[0].contains("GreatestPowerYouDontControl")) { - final List list = GameState.getCreaturesInPlay(c.getController().getOpponent()); + final List list = c.getController().getOpponent().getCreaturesInPlay(); int highest = 0; for (final Card crd : list) { if (crd.getNetAttack() > highest) { @@ -2122,7 +2119,7 @@ public class CardFactoryUtil { int highest = 0; for (final Object o : c.getRemembered()) { if (o instanceof Card) { - list.add(GameState.getCardState((Card) o)); + list.add(Singletons.getModel().getGameState().getCardState((Card) o)); } } for (final Card crd : list) { @@ -2137,7 +2134,7 @@ public class CardFactoryUtil { final List list = new ArrayList(); for (final Object o : c.getRemembered()) { if (o instanceof Card) { - list.add(GameState.getCardState((Card) o)); + list.add(Singletons.getModel().getGameState().getCardState((Card) o)); } } return Aggregates.sum(Iterables.filter(list, CardPredicates.Presets.hasSecondStrike), CardPredicates.Accessors.fnGetAttack); @@ -2450,7 +2447,7 @@ public class CardFactoryUtil { if (sq[0].contains("SumPower")) { final String[] restrictions = l[0].split("_"); final String[] rest = restrictions[1].split(","); - List cardsonbattlefield = GameState.getCardsIn(ZoneType.Battlefield); + List cardsonbattlefield = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); List filteredCards = CardLists.getValidCards(cardsonbattlefield, rest, cardController, c); int sumPower = 0; for (int i = 0; i < filteredCards.size(); i++) { @@ -2470,7 +2467,7 @@ public class CardFactoryUtil { if (sq[0].contains("SumCMC")) { final String[] restrictions = l[0].split("_"); final String[] rest = restrictions[1].split(","); - List cardsonbattlefield = GameState.getCardsIn(ZoneType.Battlefield); + List cardsonbattlefield = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); List filteredCards = CardLists.getValidCards(cardsonbattlefield, rest, cardController, c); return CardLists.sumCMC(filteredCards); } @@ -2491,7 +2488,7 @@ public class CardFactoryUtil { final String[] restrictions = l[0].split("_"); final Counters cType = Counters.getType(restrictions[1]); final String[] validFilter = restrictions[2].split(","); - List validCards = GameState.getCardsIn(ZoneType.Battlefield); + List validCards = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); validCards = CardLists.getValidCards(validCards, validFilter, cardController, c); int cCount = 0; for (final Card card : validCards) { @@ -2520,9 +2517,9 @@ public class CardFactoryUtil { // Count$M12Empires.. if (sq[0].contains("AllM12Empires")) { - boolean has = GameState.isCardInPlay("Crown of Empires", c.getController()); - has &= GameState.isCardInPlay("Scepter of Empires", c.getController()); - has &= GameState.isCardInPlay("Throne of Empires", c.getController()); + boolean has = c.getController().isCardInPlay("Crown of Empires"); + has &= c.getController().isCardInPlay("Scepter of Empires"); + has &= c.getController().isCardInPlay("Throne of Empires"); if (has) { return CardFactoryUtil.doXMath(Integer.parseInt(sq[1]), m, c); } else { @@ -2664,7 +2661,7 @@ public class CardFactoryUtil { } if (sq[0].contains("SpellsOnStack")) { - someCards.addAll(GameState.getCardsIn(ZoneType.Stack)); + someCards.addAll(Singletons.getModel().getGameState().getCardsIn(ZoneType.Stack)); } if (sq[0].contains("InAllHands")) { @@ -3248,7 +3245,7 @@ public class CardFactoryUtil { c.setBaseAttack(baseAttack); c.setBaseDefense(baseDefense); - final int multiplier = GameState.getTokenDoublersMagnitude(controller); + final int multiplier = controller.getTokenDoublersMagnitude(); for (int i = 0; i < multiplier; i++) { Card temp = CardFactoryUtil.copyStats(c); @@ -3336,7 +3333,7 @@ public class CardFactoryUtil { @Override public void execute() { - if (GameState.isCardInPlay(crd)) { + if (crd.isInPlay()) { crd.addTempAttackBoost(-1 * magnitude); crd.addTempDefenseBoost(-1 * magnitude); } @@ -3400,7 +3397,7 @@ public class CardFactoryUtil { * @return the worst land found based on the description above */ public static Card getWorstLand(final Player player) { - final List lands = GameState.getPlayerLandsInPlay(player); + final List lands = player.getLandsInPlay(); return CardFactoryUtil.getWorstLand(lands); } // end getWorstLand @@ -4020,7 +4017,7 @@ public class CardFactoryUtil { final Ability haunterDiesSetup = new Ability(card, "0") { @Override public void resolve() { - final List creats = GameState.getCreaturesInPlay(); + final List creats = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); for (int i = 0; i < creats.size(); i++) { if (!creats.get(i).canBeTargetedBy(this)) { creats.remove(i); @@ -4034,7 +4031,7 @@ public class CardFactoryUtil { // need to do it this way because I don't know quite how to // make TriggerHandler respect BeforePayMana. if (card.getController().isHuman()) { - AllZone.getInputControl().setInput(target); + Singletons.getModel().getMatch().getInput().setInput(target); } else { // AI choosing what to haunt final List oppCreats = CardLists.filterControlledBy(creats, card.getController().getOpponent()); @@ -4475,7 +4472,7 @@ public class CardFactoryUtil { @Override public void execute() { - final List lands = GameState.getPlayerLandsInPlay(card.getController()); + final List lands = card.getController().getLandsInPlay(); lands.remove(card); if (!(lands.size() <= 2)) { // it enters the battlefield this way, and should not @@ -4560,7 +4557,7 @@ public class CardFactoryUtil { @Override public void execute() { - final List cardsInPlay = CardLists.getType(GameState.getCardsIn(ZoneType.Battlefield), "World"); + final List cardsInPlay = CardLists.getType(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), "World"); cardsInPlay.remove(card); for (int i = 0; i < cardsInPlay.size(); i++) { Singletons.getModel().getGameAction().sacrificeDestroy(cardsInPlay.get(i)); @@ -4647,7 +4644,7 @@ public class CardFactoryUtil { @Override public void execute() { - final List creats = GameState.getCreaturesInPlay(card.getController()); + final List creats = card.getController().getCreaturesInPlay(); creats.remove(card); // System.out.println("Creats size: " + creats.size()); @@ -4732,7 +4729,7 @@ public class CardFactoryUtil { } } } else { - AllZone.getInputControl().setInput(CardFactoryUtil.modularInput(ability, card)); + Singletons.getModel().getMatch().getInput().setInput(CardFactoryUtil.modularInput(ability, card)); } } }); diff --git a/src/main/java/forge/card/cost/CostReturn.java b/src/main/java/forge/card/cost/CostReturn.java index 05018855d49..45f91adbb50 100644 --- a/src/main/java/forge/card/cost/CostReturn.java +++ b/src/main/java/forge/card/cost/CostReturn.java @@ -28,7 +28,6 @@ import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.spellability.SpellAbility; import forge.control.input.Input; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.PlayerZone; @@ -116,7 +115,7 @@ public class CostReturn extends CostPartWithList { if ((amount != null) && (typeList.size() < amount)) { return false; } - } else if (!GameState.isCardInPlay(source)) { + } else if (!source.isInPlay()) { return false; } @@ -297,7 +296,7 @@ public class CostReturn extends CostPartWithList { @Override public void showMessage() { final Card card = sa.getSourceCard(); - if (card.getController().isHuman() && GameState.isCardInPlay(card)) { + if (card.getController().isHuman() && card.isInPlay()) { final StringBuilder sb = new StringBuilder(); sb.append(card.getName()); sb.append(" - Return to Hand?"); diff --git a/src/main/java/forge/card/cost/CostSacrifice.java b/src/main/java/forge/card/cost/CostSacrifice.java index 28ed381d6c3..0817dab0cc4 100644 --- a/src/main/java/forge/card/cost/CostSacrifice.java +++ b/src/main/java/forge/card/cost/CostSacrifice.java @@ -28,7 +28,6 @@ import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.spellability.SpellAbility; import forge.control.input.Input; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.PlayerZone; @@ -120,7 +119,7 @@ public class CostSacrifice extends CostPartWithList { // choice, it can be Paid even if it's 0 } else { - if (!GameState.isCardInPlay(source)) { + if (!source.isInPlay()) { return false; } else if (source.isCreature() && activator.hasKeyword("You can't sacrifice creatures to cast spells or activate abilities.")) { @@ -357,7 +356,7 @@ public class CostSacrifice extends CostPartWithList { @Override public void showMessage() { final Card card = sa.getSourceCard(); - if (card.getController().isHuman() && GameState.isCardInPlay(card)) { + if (card.getController().isHuman() && card.isInPlay()) { final StringBuilder sb = new StringBuilder(); sb.append(card.getName()); sb.append(" - Sacrifice?"); diff --git a/src/main/java/forge/card/cost/CostUntapType.java b/src/main/java/forge/card/cost/CostUntapType.java index 761fa21b452..a349059b49a 100644 --- a/src/main/java/forge/card/cost/CostUntapType.java +++ b/src/main/java/forge/card/cost/CostUntapType.java @@ -23,10 +23,10 @@ import forge.Card; import forge.CardLists; import forge.CardPredicates.Presets; +import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.spellability.SpellAbility; import forge.control.input.Input; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.PlayerZone; @@ -120,7 +120,7 @@ public class CostUntapType extends CostPartWithList { */ @Override public final boolean canPay(final SpellAbility ability, final Card source, final Player activator, final Cost cost) { - List typeList = GameState.getCardsIn(ZoneType.Battlefield); + List typeList = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); typeList = CardLists.getValidCards(typeList, this.getType().split(";"), activator, source); @@ -160,7 +160,7 @@ public class CostUntapType extends CostPartWithList { @Override public final boolean payHuman(final SpellAbility ability, final Card source, final CostPayment payment) { final boolean untap = payment.getCost().getUntap(); - List typeList = GameState.getCardsIn(ZoneType.Battlefield); + List typeList = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); typeList = CardLists.getValidCards(typeList, this.getType().split(";"), ability.getActivatingPlayer(), ability.getSourceCard()); typeList = CardLists.filter(typeList, Presets.TAPPED); if (untap) { @@ -197,7 +197,7 @@ public class CostUntapType extends CostPartWithList { if (c == null) { final String sVar = ability.getSVar(amount); if (sVar.equals("XChoice")) { - List typeList = GameState.getCardsIn(ZoneType.Battlefield); + List typeList = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); typeList = CardLists.getValidCards(typeList, this.getType().split(";"), ai, ability.getSourceCard()); if (untap) { typeList.remove(source); diff --git a/src/main/java/forge/card/cost/CostUtil.java b/src/main/java/forge/card/cost/CostUtil.java index 12ea8937d34..66d936f5895 100644 --- a/src/main/java/forge/card/cost/CostUtil.java +++ b/src/main/java/forge/card/cost/CostUtil.java @@ -21,8 +21,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -import forge.AllZone; import forge.Card; +import forge.Singletons; import forge.CardLists; import forge.Counters; @@ -463,7 +463,7 @@ public class CostUtil { */ public static void setInput(final Input in) { // Just a shortcut.. - AllZone.getInputControl().setInput(in, true); + Singletons.getModel().getMatch().getInput().setInput(in, true); } public static Cost combineCosts(Cost cost1, Cost cost2) { diff --git a/src/main/java/forge/card/mana/ManaPool.java b/src/main/java/forge/card/mana/ManaPool.java index 85003e4f535..052cc880892 100644 --- a/src/main/java/forge/card/mana/ManaPool.java +++ b/src/main/java/forge/card/mana/ManaPool.java @@ -26,7 +26,6 @@ import forge.Singletons; import forge.card.spellability.AbilityMana; import forge.card.spellability.SpellAbility; import forge.control.input.InputPayManaCostUtil; -import forge.game.GameState; import forge.game.player.Player; import forge.gui.GuiChoose; @@ -185,7 +184,7 @@ public class ManaPool { return numRemoved; } - if (GameState.isCardInPlay("Omnath, Locus of Mana", this.owner)) { + if (this.owner.isCardInPlay("Omnath, Locus of Mana")) { // Omnath in play, clear all non-green mana int i = 0; while (i < this.floatingMana.size()) { diff --git a/src/main/java/forge/card/replacement/ReplacementEffect.java b/src/main/java/forge/card/replacement/ReplacementEffect.java index 587b14233c4..c5f99d0dc7f 100644 --- a/src/main/java/forge/card/replacement/ReplacementEffect.java +++ b/src/main/java/forge/card/replacement/ReplacementEffect.java @@ -25,11 +25,11 @@ import forge.Card; import forge.CardLists; import forge.CardUtil; +import forge.Singletons; import forge.card.TriggerReplacementBase; import forge.card.abilityfactory.AbilityFactory; import forge.card.cardfactory.CardFactoryUtil; import forge.card.spellability.SpellAbility; -import forge.game.GameState; import forge.game.zone.ZoneType; import forge.util.Expressions; @@ -321,7 +321,7 @@ public abstract class ReplacementEffect extends TriggerReplacementBase { } if (this.getMapParams().containsKey("CheckSVar")) { - final int sVar = AbilityFactory.calculateAmount(GameState.getCardState(this.getHostCard()), this + final int sVar = AbilityFactory.calculateAmount(Singletons.getModel().getGameState().getCardState(this.getHostCard()), this .getMapParams().get("CheckSVar"), null); String comparator = "GE1"; if (this.getMapParams().containsKey("SVarCompare")) { @@ -329,7 +329,7 @@ public abstract class ReplacementEffect extends TriggerReplacementBase { } final String svarOperator = comparator.substring(0, 2); final String svarOperand = comparator.substring(2); - final int operandValue = AbilityFactory.calculateAmount(GameState.getCardState(this.getHostCard()), + final int operandValue = AbilityFactory.calculateAmount(Singletons.getModel().getGameState().getCardState(this.getHostCard()), svarOperand, null); if (!Expressions.compare(sVar, svarOperator, operandValue)) { return false; diff --git a/src/main/java/forge/card/replacement/ReplacementHandler.java b/src/main/java/forge/card/replacement/ReplacementHandler.java index b5cabe9b9c2..bbb511b1a47 100644 --- a/src/main/java/forge/card/replacement/ReplacementHandler.java +++ b/src/main/java/forge/card/replacement/ReplacementHandler.java @@ -27,7 +27,6 @@ import forge.GameActionUtil; import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.spellability.SpellAbility; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -111,7 +110,7 @@ public class ReplacementHandler { && replacementEffect.requirementsCheck() && replacementEffect.canReplace(runParams) && !possibleReplacers.contains(replacementEffect) - && replacementEffect.zonesCheck(GameState.getZoneOf(crd))) { + && replacementEffect.zonesCheck(Singletons.getModel().getGameState().getZoneOf(crd))) { possibleReplacers.add(replacementEffect); } } diff --git a/src/main/java/forge/card/spellability/Ability.java b/src/main/java/forge/card/spellability/Ability.java index 4a97573b320..64bf0f11d30 100644 --- a/src/main/java/forge/card/spellability/Ability.java +++ b/src/main/java/forge/card/spellability/Ability.java @@ -21,7 +21,6 @@ import com.esotericsoftware.minlog.Log; import forge.Card; import forge.Singletons; -import forge.game.GameState; /** *

@@ -73,6 +72,6 @@ public abstract class Ability extends SpellAbility { return false; } - return GameState.isCardInPlay(this.getSourceCard()) && !this.getSourceCard().isFaceDown(); + return this.getSourceCard().isInPlay() && !this.getSourceCard().isFaceDown(); } } diff --git a/src/main/java/forge/card/spellability/AbilityActivated.java b/src/main/java/forge/card/spellability/AbilityActivated.java index 7432c2affe0..e68fa4c95d2 100644 --- a/src/main/java/forge/card/spellability/AbilityActivated.java +++ b/src/main/java/forge/card/spellability/AbilityActivated.java @@ -26,7 +26,6 @@ import forge.Singletons; import forge.card.cost.Cost; import forge.card.cost.CostPayment; import forge.card.staticability.StaticAbility; -import forge.game.GameState; import forge.game.zone.ZoneType; /** @@ -94,7 +93,7 @@ public abstract class AbilityActivated extends SpellAbility implements java.io.S } // CantBeActivated static abilities - final List allp = GameState.getCardsIn(ZoneType.Battlefield); + final List allp = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card ca : allp) { final ArrayList staticAbilities = ca.getStaticAbilities(); for (final StaticAbility stAb : staticAbilities) { @@ -108,7 +107,7 @@ public abstract class AbilityActivated extends SpellAbility implements java.io.S return false; } - if (this.isCycling() && GameState.isCardInPlay("Stabilizer")) { + if (this.isCycling() && Singletons.getModel().getGameState().isCardInPlay("Stabilizer")) { return false; } diff --git a/src/main/java/forge/card/spellability/AbilityMana.java b/src/main/java/forge/card/spellability/AbilityMana.java index 4485f2f2c1e..7625898d47e 100644 --- a/src/main/java/forge/card/spellability/AbilityMana.java +++ b/src/main/java/forge/card/spellability/AbilityMana.java @@ -29,7 +29,6 @@ import forge.card.mana.Mana; import forge.card.mana.ManaPool; import forge.card.trigger.TriggerType; import forge.control.input.InputPayManaCostUtil; -import forge.game.GameState; import forge.game.player.Player; /** @@ -539,7 +538,7 @@ public class AbilityMana extends AbilityActivated implements java.io.Serializabl * @return a boolean. */ public final boolean isUndoable() { - return this.undoable && this.getPayCosts().isUndoable() && GameState.isCardInPlay(this.getSourceCard()); + return this.undoable && this.getPayCosts().isUndoable() && this.getSourceCard().isInPlay(); } /** diff --git a/src/main/java/forge/card/spellability/Spell.java b/src/main/java/forge/card/spellability/Spell.java index cd7febf92d7..d9fa925c789 100644 --- a/src/main/java/forge/card/spellability/Spell.java +++ b/src/main/java/forge/card/spellability/Spell.java @@ -29,7 +29,6 @@ import forge.card.cost.Cost; import forge.card.cost.CostPayment; import forge.card.staticability.StaticAbility; import forge.error.ErrorViewer; -import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -125,7 +124,7 @@ public abstract class Spell extends SpellAbility implements java.io.Serializable } // CantBeCast static abilities - final List allp = GameState.getCardsIn(ZoneType.Battlefield); + final List allp = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); allp.add(card); for (final Card ca : allp) { final ArrayList staticAbilities = ca.getStaticAbilities(); @@ -145,7 +144,7 @@ public abstract class Spell extends SpellAbility implements java.io.Serializable final Card card = this.getSourceCard(); if (card.getSVar("NeedsToPlay").length() > 0) { final String needsToPlay = card.getSVar("NeedsToPlay"); - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.getValidCards(list, needsToPlay.split(","), card.getController(), card); if (list.isEmpty()) { diff --git a/src/main/java/forge/card/spellability/SpellAbilityCondition.java b/src/main/java/forge/card/spellability/SpellAbilityCondition.java index 4a9c31f690a..7de52f7e5e8 100644 --- a/src/main/java/forge/card/spellability/SpellAbilityCondition.java +++ b/src/main/java/forge/card/spellability/SpellAbilityCondition.java @@ -27,7 +27,6 @@ import forge.CardLists; import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.cardfactory.CardFactoryUtil; -import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.Player; @@ -228,18 +227,18 @@ public class SpellAbilityCondition extends SpellAbilityVariables { if (this.isAllM12Empires()) { final Player p = sa.getSourceCard().getController(); - boolean has = GameState.isCardInPlay("Crown of Empires", p); - has &= GameState.isCardInPlay("Scepter of Empires", p); - has &= GameState.isCardInPlay("Throne of Empires", p); + boolean has = p.isCardInPlay("Crown of Empires"); + has &= p.isCardInPlay("Scepter of Empires"); + has &= p.isCardInPlay("Throne of Empires"); if (!has) { return false; } } if (this.isNotAllM12Empires()) { final Player p = sa.getSourceCard().getController(); - boolean has = GameState.isCardInPlay("Crown of Empires", p); - has &= GameState.isCardInPlay("Scepter of Empires", p); - has &= GameState.isCardInPlay("Throne of Empires", p); + boolean has = p.isCardInPlay("Crown of Empires"); + has &= p.isCardInPlay("Scepter of Empires"); + has &= p.isCardInPlay("Throne of Empires"); if (has) { return false; } @@ -257,7 +256,7 @@ public class SpellAbilityCondition extends SpellAbilityVariables { if (this.getPresentDefined() != null) { list.addAll(AbilityFactory.getDefinedCards(sa.getSourceCard(), this.getPresentDefined(), sa)); } else { - list = GameState.getCardsIn(ZoneType.Battlefield); + list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); } list = CardLists.getValidCards(list, this.getIsPresent().split(","), sa.getActivatingPlayer(), sa.getSourceCard()); diff --git a/src/main/java/forge/card/spellability/SpellAbilityRequirements.java b/src/main/java/forge/card/spellability/SpellAbilityRequirements.java index 20176da0683..4a20613bcd8 100644 --- a/src/main/java/forge/card/spellability/SpellAbilityRequirements.java +++ b/src/main/java/forge/card/spellability/SpellAbilityRequirements.java @@ -23,7 +23,6 @@ import forge.Card; import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.cost.CostPayment; -import forge.game.GameState; import forge.game.zone.PlayerZone; /** @@ -111,7 +110,7 @@ public class SpellAbilityRequirements { if (!this.ability.getSourceCard().isCopiedSpell()) { final Card c = this.ability.getSourceCard(); - this.fromZone = GameState.getZoneOf(c); + this.fromZone = Singletons.getModel().getGameState().getZoneOf(c); this.zonePosition = this.fromZone.getPosition(c); this.ability.setSourceCard(Singletons.getModel().getGameAction().moveToStack(c)); } diff --git a/src/main/java/forge/card/spellability/SpellAbilityRestriction.java b/src/main/java/forge/card/spellability/SpellAbilityRestriction.java index 4017f8ed237..aa4c8ca8d11 100644 --- a/src/main/java/forge/card/spellability/SpellAbilityRestriction.java +++ b/src/main/java/forge/card/spellability/SpellAbilityRestriction.java @@ -27,7 +27,6 @@ import forge.CardLists; import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.cardfactory.CardFactoryUtil; -import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.Player; @@ -187,7 +186,7 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { if (this.getZone() == null) { return true; } - PlayerZone cardZone = GameState.getZoneOf(c); + PlayerZone cardZone = Singletons.getModel().getGameState().getZoneOf(c); Player activator = sa.getActivatingPlayer(); if (cardZone == null || !cardZone.is(this.getZone())) { // If Card is not in the default activating zone, do some additional checks @@ -356,7 +355,7 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { } } if (this.getIsPresent() != null) { - List list = GameState.getCardsIn(this.getPresentZone()); + List list = Singletons.getModel().getGameState().getCardsIn(this.getPresentZone()); list = CardLists.getValidCards(list, this.getIsPresent().split(","), activator, c); diff --git a/src/main/java/forge/card/spellability/SpellPermanent.java b/src/main/java/forge/card/spellability/SpellPermanent.java index 6b5aaa3f423..915242986d4 100644 --- a/src/main/java/forge/card/spellability/SpellPermanent.java +++ b/src/main/java/forge/card/spellability/SpellPermanent.java @@ -21,15 +21,14 @@ import java.security.InvalidParameterException; import java.util.HashMap; import java.util.List; +import com.google.common.base.Supplier; import com.google.common.collect.Iterables; -import forge.AllZone; import forge.Card; import forge.CardLists; import forge.CardPredicates; import forge.Command; -import forge.CommandReturn; import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.cardfactory.CardFactoryUtil; @@ -40,7 +39,6 @@ import forge.card.replacement.ReplacementEffect; import forge.card.trigger.Trigger; import forge.card.trigger.TriggerType; import forge.control.input.Input; -import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.ComputerAIGeneral; @@ -71,8 +69,7 @@ public class SpellPermanent extends Spell { @Override public void showMessage() { - @SuppressWarnings("unchecked") - final List choice = (List) SpellPermanent.this.championGetCreature.execute(); + final List choice = SpellPermanent.this.championGetCreature.get(); this.stopSetNext(CardFactoryUtil.inputTargetChampionSac(SpellPermanent.this.getSourceCard(), SpellPermanent.this.championAbilityComes, choice, "Select another " @@ -82,9 +79,9 @@ public class SpellPermanent extends Spell { } }; - private final CommandReturn championGetCreature = new CommandReturn() { + private final Supplier> championGetCreature = new Supplier>() { @Override - public Object execute() { + public List get() { final List cards = SpellPermanent.this.getSourceCard().getController().getCardsIn(ZoneType.Battlefield); return CardLists.getValidCards(cards, SpellPermanent.this.championValid, SpellPermanent.this.getSourceCard() .getController(), SpellPermanent.this.getSourceCard()); @@ -99,13 +96,12 @@ public class SpellPermanent extends Spell { final Card source = this.getSourceCard(); final Player controller = source.getController(); - @SuppressWarnings("unchecked") - final List creature = (List) SpellPermanent.this.championGetCreature.execute(); + final List creature = SpellPermanent.this.championGetCreature.get(); if (creature.size() == 0) { Singletons.getModel().getGameAction().sacrifice(source, null); return; } else if (controller.isHuman()) { - AllZone.getInputControl().setInput(SpellPermanent.this.championInputComes); + Singletons.getModel().getMatch().getInput().setInput(SpellPermanent.this.championInputComes); } else { // Computer List computer = controller.getCardsIn(ZoneType.Battlefield); computer = CardLists.getValidCards(computer, SpellPermanent.this.championValid, controller, source); @@ -115,7 +111,7 @@ public class SpellPermanent extends Spell { if (computer.size() != 0) { final Card c = computer.get(0); source.setChampionedCard(c); - if (GameState.isCardInPlay(c)) { + if (c.isInPlay()) { Singletons.getModel().getGameAction().exile(c); } @@ -158,7 +154,7 @@ public class SpellPermanent extends Spell { @Override public void resolve() { final Card c = this.getSourceCard().getChampionedCard(); - if ((c != null) && !c.isToken() && GameState.isCardExiled(c)) { + if ((c != null) && !c.isToken() && Singletons.getModel().getGameState().isCardExiled(c)) { Singletons.getModel().getGameAction().moveToPlay(c); } } // resolve() @@ -353,7 +349,7 @@ public class SpellPermanent extends Spell { } // check on legendary - if (card.isType("Legendary") && !GameState.isCardInPlay("Mirror Gallery")) { + if (card.isType("Legendary") && !Singletons.getModel().getGameState().isCardInPlay("Mirror Gallery")) { final List list = ai.getCardsIn(ZoneType.Battlefield); if (Iterables.any(list, CardPredicates.nameEquals(card.getName()))) { return false; @@ -388,13 +384,12 @@ public class SpellPermanent extends Spell { } if (this.willChampion) { - final Object o = this.championGetCreature.execute(); + final Object o = this.championGetCreature.get(); if (o == null) { return false; } - @SuppressWarnings("unchecked") - final List cl = (List) this.championGetCreature.execute(); + final List cl = (List) this.championGetCreature.get(); if ((o == null) || !(cl.size() > 0) || !this.getSourceCard().isInZone(ZoneType.Hand)) { return false; } @@ -415,7 +410,7 @@ public class SpellPermanent extends Spell { private static boolean checkETBEffects(final Card card, final SpellAbility sa, final String api, final Player ai) { - if (card.isCreature() && GameState.isCardInPlay("Torpor Orb")) { + if (card.isCreature() && Singletons.getModel().getGameState().isCardInPlay("Torpor Orb")) { return true; } diff --git a/src/main/java/forge/card/spellability/Target.java b/src/main/java/forge/card/spellability/Target.java index bca598ff4fe..e3918c98c4c 100644 --- a/src/main/java/forge/card/spellability/Target.java +++ b/src/main/java/forge/card/spellability/Target.java @@ -25,7 +25,6 @@ import forge.Card; import forge.CardUtil; import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -714,7 +713,7 @@ public class Target { if (this.tgtZone.contains(ZoneType.Stack)) { return true; } else { - for (final Card c : GameState.getCardsIn(this.tgtZone)) { + for (final Card c : Singletons.getModel().getGameState().getCardsIn(this.tgtZone)) { if (c.isValid(this.validTgts, this.srcCard.getController(), this.srcCard) && (!isTargeted || c.canBeTargetedBy(sa)) && !this.getTargetCards().contains(c)) { diff --git a/src/main/java/forge/card/spellability/TargetSelection.java b/src/main/java/forge/card/spellability/TargetSelection.java index cd5da768025..21324e07b9f 100644 --- a/src/main/java/forge/card/spellability/TargetSelection.java +++ b/src/main/java/forge/card/spellability/TargetSelection.java @@ -23,14 +23,12 @@ import java.util.List; import com.google.common.base.Predicate; -import forge.AllZone; import forge.Card; import forge.Singletons; import forge.CardLists; import forge.card.abilityfactory.AbilityFactory; import forge.control.input.Input; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; @@ -270,8 +268,7 @@ public class TargetSelection { return; } - List choices = CardLists.getTargetableCards(CardLists.getValidCards(GameState - .getCardsIn(zone), this.target.getValidTgts(), this.ability.getActivatingPlayer(), this.ability.getSourceCard()), this.ability); + List choices = CardLists.getTargetableCards(CardLists.getValidCards(Singletons.getModel().getGameState().getCardsIn(zone), this.target.getValidTgts(), this.ability.getActivatingPlayer(), this.ability.getSourceCard()), this.ability); ArrayList objects = new ArrayList(); if (tgt.isUniqueTargets()) { @@ -321,7 +318,7 @@ public class TargetSelection { } if (zone.contains(ZoneType.Battlefield) && zone.size() == 1) { - AllZone.getInputControl().setInput(this.inputTargetSpecific(choices, true, mandatory, objects)); + Singletons.getModel().getMatch().getInput().setInput(this.inputTargetSpecific(choices, true, mandatory, objects)); } else { this.chooseCardFromList(choices, true, mandatory); } @@ -462,15 +459,15 @@ public class TargetSelection { final List crdsLibrary = new ArrayList(); final List crdsStack = new ArrayList(); for (final Card inZone : choicesZoneUnfiltered) { - if (GameState.getCardsIn(ZoneType.Battlefield).contains(inZone)) { + if (Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield).contains(inZone)) { crdsBattle.add(inZone); - } else if (GameState.getCardsIn(ZoneType.Exile).contains(inZone)) { + } else if (Singletons.getModel().getGameState().getCardsIn(ZoneType.Exile).contains(inZone)) { crdsExile.add(inZone); - } else if (GameState.getCardsIn(ZoneType.Graveyard).contains(inZone)) { + } else if (Singletons.getModel().getGameState().getCardsIn(ZoneType.Graveyard).contains(inZone)) { crdsGrave.add(inZone); - } else if (GameState.getCardsIn(ZoneType.Library).contains(inZone)) { + } else if (Singletons.getModel().getGameState().getCardsIn(ZoneType.Library).contains(inZone)) { crdsLibrary.add(inZone); - } else if (GameState.getCardsIn(ZoneType.Stack).contains(inZone)) { + } else if (Singletons.getModel().getGameState().getCardsIn(ZoneType.Stack).contains(inZone)) { crdsStack.add(inZone); } } diff --git a/src/main/java/forge/card/staticability/StaticAbility.java b/src/main/java/forge/card/staticability/StaticAbility.java index 3ef7888a998..661223ae19a 100644 --- a/src/main/java/forge/card/staticability/StaticAbility.java +++ b/src/main/java/forge/card/staticability/StaticAbility.java @@ -28,7 +28,6 @@ import forge.card.abilityfactory.AbilityFactory; import forge.card.cost.Cost; import forge.card.mana.ManaCost; import forge.card.spellability.SpellAbility; -import forge.game.GameState; import forge.game.phase.PhaseType; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -457,7 +456,7 @@ public class StaticAbility { if (this.mapParams.containsKey("EffectZone")) { if (!this.mapParams.get("EffectZone").equals("All") && !ZoneType.listValueOf(this.mapParams.get("EffectZone")) - .contains(GameState.getZoneOf(this.hostCard).getZoneType())) { + .contains(Singletons.getModel().getGameState().getZoneOf(this.hostCard).getZoneType())) { return false; } } else { diff --git a/src/main/java/forge/card/staticability/StaticAbilityCantBeCast.java b/src/main/java/forge/card/staticability/StaticAbilityCantBeCast.java index 44727c5404f..29d138db04e 100644 --- a/src/main/java/forge/card/staticability/StaticAbilityCantBeCast.java +++ b/src/main/java/forge/card/staticability/StaticAbilityCantBeCast.java @@ -21,9 +21,9 @@ import java.util.HashMap; import java.util.List; import forge.Card; +import forge.Singletons; import forge.card.spellability.AbilityMana; import forge.card.spellability.SpellAbility; -import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -64,7 +64,7 @@ public class StaticAbilityCantBeCast { if (params.containsKey("Origin")) { List src = ZoneType.listValueOf(params.get("Origin")); - if (!src.contains(GameState.getZoneOf(card).getZoneType())) { + if (!src.contains(Singletons.getModel().getGameState().getZoneOf(card).getZoneType())) { return false; } } diff --git a/src/main/java/forge/card/staticability/StaticAbilityContinuous.java b/src/main/java/forge/card/staticability/StaticAbilityContinuous.java index 2fda583c62b..76a7cdda3e2 100644 --- a/src/main/java/forge/card/staticability/StaticAbilityContinuous.java +++ b/src/main/java/forge/card/staticability/StaticAbilityContinuous.java @@ -35,7 +35,6 @@ import forge.card.spellability.AbilityActivated; import forge.card.spellability.SpellAbility; import forge.card.trigger.Trigger; import forge.card.trigger.TriggerHandler; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -232,7 +231,7 @@ public class StaticAbilityContinuous { } } - List cardsIGainedAbilitiesFrom = GameState.getCardsIn(validZones); + List cardsIGainedAbilitiesFrom = Singletons.getModel().getGameState().getCardsIn(validZones); cardsIGainedAbilitiesFrom = CardLists.getValidCards(cardsIGainedAbilitiesFrom, valids, hostCard.getController(), hostCard); if (cardsIGainedAbilitiesFrom.size() > 0) { @@ -430,9 +429,9 @@ public class StaticAbilityContinuous { List affectedCards = new ArrayList(); if (params.containsKey("AffectedZone")) { - affectedCards.addAll(GameState.getCardsIn(ZoneType.listValueOf(params.get("AffectedZone")))); + affectedCards.addAll(Singletons.getModel().getGameState().getCardsIn(ZoneType.listValueOf(params.get("AffectedZone")))); } else { - affectedCards = GameState.getCardsIn(ZoneType.Battlefield); + affectedCards = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); } if (params.containsKey("Affected") && !params.get("Affected").contains(",")) { diff --git a/src/main/java/forge/card/trigger/Trigger.java b/src/main/java/forge/card/trigger/Trigger.java index 69c29b6194e..60e16043f81 100644 --- a/src/main/java/forge/card/trigger/Trigger.java +++ b/src/main/java/forge/card/trigger/Trigger.java @@ -32,7 +32,6 @@ import forge.card.abilityfactory.AbilityFactory; import forge.card.cardfactory.CardFactoryUtil; import forge.card.spellability.Ability; import forge.card.spellability.SpellAbility; -import forge.game.GameState; import forge.game.phase.PhaseType; import forge.game.zone.ZoneType; import forge.util.Expressions; @@ -411,7 +410,7 @@ public abstract class Trigger extends TriggerReplacementBase { } if (this.getMapParams().containsKey("CheckSVar")) { - final int sVar = AbilityFactory.calculateAmount(GameState.getCardState(this.getHostCard()), this + final int sVar = AbilityFactory.calculateAmount(Singletons.getModel().getGameState().getCardState(this.getHostCard()), this .getMapParams().get("CheckSVar"), null); String comparator = "GE1"; if (this.getMapParams().containsKey("SVarCompare")) { @@ -419,7 +418,7 @@ public abstract class Trigger extends TriggerReplacementBase { } final String svarOperator = comparator.substring(0, 2); final String svarOperand = comparator.substring(2); - final int operandValue = AbilityFactory.calculateAmount(GameState.getCardState(this.getHostCard()), + final int operandValue = AbilityFactory.calculateAmount(Singletons.getModel().getGameState().getCardState(this.getHostCard()), svarOperand, null); if (!Expressions.compare(sVar, svarOperator, operandValue)) { return false; diff --git a/src/main/java/forge/card/trigger/TriggerHandler.java b/src/main/java/forge/card/trigger/TriggerHandler.java index b5702cfdc6c..2c35a9b2039 100644 --- a/src/main/java/forge/card/trigger/TriggerHandler.java +++ b/src/main/java/forge/card/trigger/TriggerHandler.java @@ -39,7 +39,6 @@ import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbilityRestriction; import forge.card.spellability.Target; import forge.control.input.Input; -import forge.game.GameState; import forge.game.phase.PhaseType; //import forge.util.TextUtil; import forge.game.player.ComputerUtil; @@ -64,7 +63,7 @@ public class TriggerHandler { * Clean up temporary triggers. */ public final void cleanUpTemporaryTriggers() { - final List absolutelyAllCards = GameState.getCardsInGame(); + final List absolutelyAllCards = Singletons.getModel().getGameState().getCardsInGame(); for (final Card c : absolutelyAllCards) { for (int i = 0; i < c.getTriggers().size(); i++) { if (c.getTriggers().get(i).isTemporary()) { @@ -286,8 +285,8 @@ public class TriggerHandler { // This is done to allow the list of triggers to be modified while // triggers are running. final ArrayList delayedTriggersWorkingCopy = new ArrayList(this.delayedTriggers); - List allCards = GameState.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES); - allCards.addAll(GameState.getCardsIn(ZoneType.Stack)); + List allCards = Singletons.getModel().getGameState().getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES); + allCards.addAll(Singletons.getModel().getGameState().getCardsIn(ZoneType.Stack)); boolean checkStatics = false; // Static triggers @@ -313,12 +312,12 @@ public class TriggerHandler { // AP allCards = playerAP.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES); - allCards.addAll(CardLists.filterControlledBy(GameState.getCardsIn(ZoneType.Stack), playerAP)); + allCards.addAll(CardLists.filterControlledBy(Singletons.getModel().getGameState().getCardsIn(ZoneType.Stack), playerAP)); // add cards that move to hidden zones if (runParams.containsKey("Destination") && runParams.containsKey("Card")) { Card card = (Card) runParams.get("Card"); if (playerAP.equals(card.getController()) && !allCards.contains(card) - && (GameState.getZoneOf(card) == null || GameState.getZoneOf(card).getZoneType().isHidden())) { + && (Singletons.getModel().getGameState().getZoneOf(card) == null || Singletons.getModel().getGameState().getZoneOf(card).getZoneType().isHidden())) { allCards.add(card); } } @@ -339,12 +338,12 @@ public class TriggerHandler { // NAP allCards = playerAP.getOpponent().getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES); - allCards.addAll(CardLists.filterControlledBy(GameState.getCardsIn(ZoneType.Stack), playerAP.getOpponent())); + allCards.addAll(CardLists.filterControlledBy(Singletons.getModel().getGameState().getCardsIn(ZoneType.Stack), playerAP.getOpponent())); // add cards that move to hidden zones if (runParams.containsKey("Destination") && runParams.containsKey("Card")) { Card card = (Card) runParams.get("Card"); if (!playerAP.equals(card.getController()) && !allCards.contains(card) - && (GameState.getZoneOf(card) == null || GameState.getZoneOf(card).getZoneType().isHidden())) { + && (Singletons.getModel().getGameState().getZoneOf(card) == null || Singletons.getModel().getGameState().getZoneOf(card).getZoneType().isHidden())) { allCards.add(card); } } @@ -410,7 +409,7 @@ public class TriggerHandler { if (regtrig.isSuppressed()) { return false; // Trigger removed by effect } - if (!regtrig.zonesCheck(GameState.getZoneOf(regtrig.getHostCard()))) { + if (!regtrig.zonesCheck(Singletons.getModel().getGameState().getZoneOf(regtrig.getHostCard()))) { return false; // Host card isn't where it needs to be. } @@ -420,7 +419,7 @@ public class TriggerHandler { String dest = (String) runParams.get("Destination"); if (dest.equals("Battlefield") && runParams.get("Card") instanceof Card) { Card card = (Card) runParams.get("Card"); - if (card.isCreature() && GameState.isCardInPlay("Torpor Orb")) { + if (card.isCreature() && Singletons.getModel().getGameState().isCardInPlay("Torpor Orb")) { return false; } } @@ -447,7 +446,7 @@ public class TriggerHandler { final AbilityFactory abilityFactory = new AbilityFactory(); final SpellAbility[] sa = new SpellAbility[1]; - Card host = GameState.getCardState(regtrig.getHostCard()); + Card host = Singletons.getModel().getGameState().getCardState(regtrig.getHostCard()); if (host == null) { host = regtrig.getHostCard(); diff --git a/src/main/java/forge/control/input/Input.java b/src/main/java/forge/control/input/Input.java index 63ef44abca9..809eecf7f91 100644 --- a/src/main/java/forge/control/input/Input.java +++ b/src/main/java/forge/control/input/Input.java @@ -17,9 +17,9 @@ */ package forge.control.input; -import forge.AllZone; import forge.Card; import forge.Singletons; +import forge.game.phase.PhaseHandler; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.gui.match.CMatchUI; @@ -36,8 +36,6 @@ public abstract class Input implements java.io.Serializable { /** Constant serialVersionUID=-6539552513871194081L. */ private static final long serialVersionUID = -6539552513871194081L; - private boolean isFree = false; - // showMessage() is always the first method called /** *

@@ -99,12 +97,13 @@ public abstract class Input implements java.io.Serializable { */ public final void stop() { // clears a "temp" Input like Input_PayManaCost if there is one - AllZone.getInputControl().resetInput(); + Singletons.getModel().getMatch().getInput().resetInput(); - if (Singletons.getModel().getGameState().getPhaseHandler().isNeedToNextPhase()) { + PhaseHandler ph = Singletons.getModel().getGameState().getPhaseHandler(); + if (ph.isNeedToNextPhase()) { // mulligan needs this to move onto next phase - Singletons.getModel().getGameState().getPhaseHandler().setNeedToNextPhase(false); - Singletons.getModel().getGameState().getPhaseHandler().nextPhase(); + ph.setNeedToNextPhase(false); + ph.nextPhase(); } } @@ -119,7 +118,7 @@ public abstract class Input implements java.io.Serializable { */ public final void stopSetNext(final Input in) { this.stop(); - AllZone.getInputControl().setInput(in); + Singletons.getModel().getMatch().getInput().setInput(in); } /** {@inheritDoc} */ @@ -128,26 +127,5 @@ public abstract class Input implements java.io.Serializable { return "blank"; } // returns the Input name like "EmptyStack" - /** - *

- * setFree. - *

- * - * @param isFree - * a boolean. - */ - public void setFree(final boolean isFree) { - this.isFree = isFree; - } - /** - *

- * isFree. - *

- * - * @return a boolean. - */ - public boolean isFree() { - return this.isFree; - } } diff --git a/src/main/java/forge/control/input/InputAttack.java b/src/main/java/forge/control/input/InputAttack.java index 225551d79b8..85c180929c9 100644 --- a/src/main/java/forge/control/input/InputAttack.java +++ b/src/main/java/forge/control/input/InputAttack.java @@ -21,7 +21,6 @@ import java.util.List; import com.google.common.collect.Iterables; -import forge.AllZone; import forge.Card; import forge.CardPredicates; @@ -89,7 +88,7 @@ public class InputAttack extends Input { } Singletons.getModel().getGameState().getPhaseHandler().setNeedToNextPhase(true); - AllZone.getInputControl().resetInput(); + Singletons.getModel().getMatch().getInput().resetInput(); } /** {@inheritDoc} */ diff --git a/src/main/java/forge/control/input/InputControl.java b/src/main/java/forge/control/input/InputControl.java index 85234da528b..67fedff61b9 100644 --- a/src/main/java/forge/control/input/InputControl.java +++ b/src/main/java/forge/control/input/InputControl.java @@ -20,13 +20,13 @@ package forge.control.input; import java.util.LinkedList; import java.util.Stack; -import forge.Singletons; +import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.ComputerAIInput; import forge.game.player.Player; +import forge.game.zone.MagicStack; import forge.gui.match.CMatchUI; -import forge.model.FModel; import forge.util.MyObservable; /** @@ -47,7 +47,7 @@ public class InputControl extends MyObservable implements java.io.Serializable { private final Stack resolvingStack = new Stack(); private final LinkedList resolvingQueue = new LinkedList(); - private final FModel model; + private final GameState game; private ComputerAIInput aiInput; // initialized at runtime to be the latest // object created @@ -57,8 +57,8 @@ public class InputControl extends MyObservable implements java.io.Serializable { * @param fModel * the f model */ - public InputControl(final FModel fModel) { - this.model = fModel; + public InputControl(final GameState game0) { + this.game = game0; } /** @@ -70,8 +70,10 @@ public class InputControl extends MyObservable implements java.io.Serializable { * a {@link forge.control.input.Input} object. */ public final void setInput(final Input in) { - if (this.model.getGameState().getStack().getResolving() - || !((this.input == null) || (this.input instanceof InputPassPriority))) { + MagicStack stack = this.game.getStack(); + boolean isInputEmpty = this.input == null || this.input instanceof InputPassPriority; + + if (stack.isResolving() || !isInputEmpty) { this.inputStack.add(in); } else { this.input = in; @@ -136,15 +138,6 @@ public class InputControl extends MyObservable implements java.io.Serializable { this.inputStack.clear(); } - /** - *

- * resetInput. - *

- */ - public final void resetInput() { - this.input = null; - this.updateObservers(); - } /** *

@@ -154,6 +147,7 @@ public class InputControl extends MyObservable implements java.io.Serializable { * @param update * a boolean. */ + public final void resetInput() { resetInput(true); } public final void resetInput(final boolean update) { this.input = null; if (update) { @@ -169,10 +163,11 @@ public class InputControl extends MyObservable implements java.io.Serializable { * @return a {@link forge.control.input.Input} object. */ public final Input updateInput() { - final PhaseHandler handler = this.model.getGameState().getPhaseHandler(); + final PhaseHandler handler = game.getPhaseHandler(); final PhaseType phase = handler.getPhase(); final Player playerTurn = handler.getPlayerTurn(); final Player priority = handler.getPriorityPlayer(); + final MagicStack stack = game.getStack(); // TODO this resolving portion needs more work, but fixes Death Cloud // issues @@ -187,18 +182,20 @@ public class InputControl extends MyObservable implements java.io.Serializable { return this.input; } - if (this.model.getGameState().getStack().getResolving()) { + if (stack.isResolving()) { return null; } if (this.input != null) { return this.input; - } else if (this.inputStack.size() > 0) { // incoming input to Control + } + + if (!this.inputStack.isEmpty()) { // incoming input to Control this.changeInput(this.inputStack.pop()); return this.input; } - if (Singletons.getModel().getGameState() != null && handler.doPhaseEffects()) { + if (handler.doPhaseEffects()) { // Handle begin phase stuff, then start back from the top handler.handleBeginPhase(); return this.updateInput(); @@ -212,19 +209,19 @@ public class InputControl extends MyObservable implements java.io.Serializable { // Special Inputs needed for the following phases: if (phase == PhaseType.COMBAT_DECLARE_ATTACKERS) { - this.model.getGameState().getStack().freezeStack(); + stack.freezeStack(); if (playerTurn.isHuman() && !handler.getAutoPass()) { - Singletons.getModel().getGameState().getCombat().initiatePossibleDefenders(playerTurn.getOpponent()); + game.getCombat().initiatePossibleDefenders(playerTurn.getOpponent()); return new InputAttack(); } } else if (phase == PhaseType.COMBAT_DECLARE_BLOCKERS) { - this.model.getGameState().getStack().freezeStack(); + stack.freezeStack(); if (playerTurn.isHuman()) { this.aiInput.getComputer().declareBlockers(); return null; } else { - if (this.model.getGameState().getCombat().getAttackers().isEmpty()) { + if (game.getCombat().getAttackers().isEmpty()) { // no active attackers, skip the Blocking phase handler.setNeedToNextPhase(true); return null; @@ -235,7 +232,7 @@ public class InputControl extends MyObservable implements java.io.Serializable { } } else if (phase == PhaseType.CLEANUP) { // discard - if (this.model.getGameState().getStack().size() == 0) { + if (stack.isEmpty()) { // resolve things // like Madness return new InputCleanup(); @@ -263,13 +260,13 @@ public class InputControl extends MyObservable implements java.io.Serializable { } // getInput() private boolean autoSkipHumanPriority(Player turn, PhaseType phase) { - PhaseHandler handler = this.model.getGameState().getPhaseHandler(); + PhaseHandler handler = game.getPhaseHandler(); // Handler tells me if I should skip, and I reset the flag final boolean skip = handler.doSkipPhase(); handler.setSkipPhase(false); // If the stack isn't empty, and skip is disallowed, stop auto passing - if (!skip || !this.model.getGameState().getStack().isEmpty()) { + if (!skip || !this.game.getStack().isEmpty()) { handler.setAutoPass(false); return false; } diff --git a/src/main/java/forge/control/input/InputMulligan.java b/src/main/java/forge/control/input/InputMulligan.java index 908e787e372..d9a0872a1a9 100644 --- a/src/main/java/forge/control/input/InputMulligan.java +++ b/src/main/java/forge/control/input/InputMulligan.java @@ -23,12 +23,12 @@ import java.util.List; import forge.Card; import forge.CardLists; +import forge.CardPredicates; import forge.GameAction; import forge.GameActionUtil; import forge.Singletons; import forge.card.abilityfactory.AbilityFactory; import forge.card.spellability.SpellAbility; -import forge.game.GameState; import forge.game.phase.PhaseUtil; import forge.game.player.ComputerUtil; import forge.game.player.Player; @@ -159,8 +159,7 @@ public class InputMulligan extends Input { } } if (c.getName().startsWith("Leyline") - && !(c.getName().startsWith("Leyline of Singularity") && (GameState.getCardsIn(ZoneType.Battlefield, - "Leyline of Singularity").size() > 0))) { + && !(c.getName().startsWith("Leyline of Singularity") && (CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Leyline of Singularity")).size() > 0))) { ga.moveToPlay(c); //ga.checkStateEffects(); } diff --git a/src/main/java/forge/control/input/InputPassPriority.java b/src/main/java/forge/control/input/InputPassPriority.java index 5456a4830f8..14197403972 100644 --- a/src/main/java/forge/control/input/InputPassPriority.java +++ b/src/main/java/forge/control/input/InputPassPriority.java @@ -17,7 +17,6 @@ */ package forge.control.input; -import forge.AllZone; import forge.Card; import forge.Singletons; import forge.game.phase.PhaseType; @@ -75,9 +74,9 @@ public class InputPassPriority extends Input implements java.io.Serializable { public final void selectButtonOK() { Singletons.getModel().getGameState().getPhaseHandler().passPriority(); //GuiDisplayUtil.updateGUI(); - final Input in = AllZone.getInputControl().getInput(); + final Input in = Singletons.getModel().getMatch().getInput().getInput(); if ((in == this) || (in == null)) { - AllZone.getInputControl().resetInput(); + Singletons.getModel().getMatch().getInput().resetInput(); // Clear out PassPriority after clicking button } } diff --git a/src/main/java/forge/control/input/InputPayManaCost.java b/src/main/java/forge/control/input/InputPayManaCost.java index ed61f55ac00..ddbc6df6168 100644 --- a/src/main/java/forge/control/input/InputPayManaCost.java +++ b/src/main/java/forge/control/input/InputPayManaCost.java @@ -17,7 +17,6 @@ */ package forge.control.input; -import forge.AllZone; import forge.Card; import forge.Singletons; import forge.card.mana.ManaCost; @@ -163,7 +162,7 @@ public class InputPayManaCost extends InputMana { this.manaCost = InputPayManaCostUtil.activateManaAbility(this.spell, card, this.manaCost); // only show message if this is the active input - if (AllZone.getInputControl().getInput() == this) { + if (Singletons.getModel().getMatch().getInput().getInput() == this) { this.showMessage(); } @@ -200,7 +199,7 @@ public class InputPayManaCost extends InputMana { if (this.spell.getAfterPayMana() != null) { this.stopSetNext(this.spell.getAfterPayMana()); } else { - AllZone.getInputControl().resetInput(); + Singletons.getModel().getMatch().getInput().resetInput(); } } else { Singletons.getControl().getPlayer().getManaPool().clearManaPaid(this.spell, false); @@ -228,7 +227,7 @@ public class InputPayManaCost extends InputMana { } else { Singletons.getModel().getGameState().getStack().add(this.spell); } - AllZone.getInputControl().resetInput(); + Singletons.getModel().getMatch().getInput().resetInput(); } // If this is a spell with convoke, re-tap all creatures used for @@ -304,7 +303,7 @@ public class InputPayManaCost extends InputMana { this.manaCost = InputPayManaCostUtil.activateManaAbility(color, this.spell, this.manaCost); // only show message if this is the active input - if (AllZone.getInputControl().getInput() == this) { + if (Singletons.getModel().getMatch().getInput().getInput() == this) { this.showMessage(); } diff --git a/src/main/java/forge/control/input/InputPayManaCostUtil.java b/src/main/java/forge/control/input/InputPayManaCostUtil.java index 88e6b7b51c8..bfc40419052 100644 --- a/src/main/java/forge/control/input/InputPayManaCostUtil.java +++ b/src/main/java/forge/control/input/InputPayManaCostUtil.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import forge.AllZone; import forge.Card; import forge.CardUtil; import forge.Constant; @@ -408,7 +407,7 @@ public class InputPayManaCostUtil { this.xPaid++; } - if (AllZone.getInputControl().getInput() == this) { + if (Singletons.getModel().getMatch().getInput().getInput() == this) { this.showMessage(); } } @@ -440,7 +439,7 @@ public class InputPayManaCostUtil { this.xPaid++; } - if (AllZone.getInputControl().getInput() == this) { + if (Singletons.getModel().getMatch().getInput().getInput() == this) { this.showMessage(); } } @@ -503,7 +502,7 @@ public class InputPayManaCostUtil { if (this.mana.isPaid()) { this.done(); - } else if (AllZone.getInputControl().getInput() == this) { + } else if (Singletons.getModel().getMatch().getInput().getInput() == this) { this.showMessage(); } } @@ -605,7 +604,7 @@ public class InputPayManaCostUtil { if (this.mana.isPaid()) { this.done(); - } else if (AllZone.getInputControl().getInput() == this) { + } else if (Singletons.getModel().getMatch().getInput().getInput() == this) { this.showMessage(); } } diff --git a/src/main/java/forge/game/GameNew.java b/src/main/java/forge/game/GameNew.java index 22f8573cb3a..b26cbac13da 100644 --- a/src/main/java/forge/game/GameNew.java +++ b/src/main/java/forge/game/GameNew.java @@ -97,7 +97,7 @@ public class GameNew { * their decks and other special starting conditions. */ public static void newGame(final Map playersConditions, GameType gameType) { - AllZone.getInputControl().clearInput(); + Singletons.getModel().getMatch().getInput().clearInput(); AllZone.getColorChanger().reset(); Card.resetUniqueNumber(); diff --git a/src/main/java/forge/game/GameState.java b/src/main/java/forge/game/GameState.java index 5337945c4e6..ee31961077b 100644 --- a/src/main/java/forge/game/GameState.java +++ b/src/main/java/forge/game/GameState.java @@ -21,17 +21,11 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; import forge.Card; import forge.CardLists; -import forge.CardPredicates; import forge.CardPredicates.Presets; -import forge.CardUtil; -import forge.Counters; import forge.GameLog; -import forge.Singletons; import forge.StaticEffects; import forge.card.replacement.ReplacementHandler; import forge.card.trigger.TriggerHandler; @@ -53,13 +47,6 @@ import forge.game.zone.ZoneType; * "cleaned up" at each new game. */ public class GameState { - - /** The Constant HUMAN_PLAYER_NAME. */ - public static final String HUMAN_PLAYER_NAME = "Human"; - - /** The Constant AI_PLAYER_NAME. */ - public static final String AI_PLAYER_NAME = "Computer"; - private final List roPlayers; private final Cleanup cleanup = new Cleanup(); private final EndOfTurn endOfTurn = new EndOfTurn(); @@ -292,26 +279,12 @@ public class GameState { // THESE WERE MOVED HERE FROM AllZoneUtil // They must once become non-static members of this class - /** - *

- * getZone. - *

- * - * @param c - * a {@link forge.Card} object. - * @return a {@link forge.game.zone.PlayerZone} object. - */ - public static PlayerZone getZoneOf(final Card c) { - final GameState gameState = Singletons.getModel().getGameState(); - if (gameState == null) { - return null; + public PlayerZone getZoneOf(final Card c) { + if (getStackZone().contains(c)) { + return getStackZone(); } - if (gameState.getStackZone().contains(c)) { - return gameState.getStackZone(); - } - - for (final Player p : gameState.getPlayers()) { + for (final Player p : getPlayers()) { for (final ZoneType z : Player.ALL_ZONES) { final PlayerZone pz = p.getZone(z); if (pz.contains(c)) { @@ -323,28 +296,13 @@ public class GameState { return null; } - /** - * - * isCardInZone. - * - * @param c - * Card - * @param zone - * Constant.Zone - * @return boolean - */ - public static boolean isCardInZone(final Card c, final ZoneType zone) { - final GameState gameState = Singletons.getModel().getGameState(); - if (gameState == null) { - return false; - } - - if (zone.equals(ZoneType.Stack)) { - if (gameState.getStackZone().contains(c)) { + public boolean isCardInZone(final Card c, final ZoneType zone) { + if (zone.equals(ZoneType.Stack)) { + if (getStackZone().contains(c)) { return true; } } else { - for (final Player p : gameState.getPlayers()) { + for (final Player p : getPlayers()) { if (p.getZone(zone).contains(c)) { return true; } @@ -354,37 +312,12 @@ public class GameState { return false; } - /** - *

- * resetZoneMoveTracking. - *

- */ - public static void resetZoneMoveTracking() { - final GameState gameState = Singletons.getModel().getGameState(); - if (gameState == null) { - return; - } - for (final Player p : gameState.getPlayers()) { - for (final ZoneType z : Player.ALL_ZONES) { - p.getZone(z).resetCardsAddedThisTurn(); - } - } - } - - /** - * gets a list of all cards owned by both players that have are currently in - * the given zone. - * - * @param zone - * Constant.Zone - * @return a List with all cards currently in a graveyard - */ - public static List getCardsIn(final ZoneType zone) { + public List getCardsIn(final ZoneType zone) { if (zone == ZoneType.Stack) { - return Singletons.getModel().getGameState().getStackZone().getCards(); + return getStackZone().getCards(); } else { List cards = null; - for (final Player p : Singletons.getModel().getGameState().getPlayers()) { + for (final Player p : getPlayers()) { if ( cards == null ) cards = p.getZone(zone).getCards(); else @@ -394,7 +327,7 @@ public class GameState { } } - public static List getCardsIn(final Iterable zones) { + public List getCardsIn(final Iterable zones) { final List cards = new ArrayList(); for (final ZoneType z : zones) { cards.addAll(getCardsIn(z)); @@ -402,168 +335,33 @@ public class GameState { return cards; } - /** - * gets a list of all cards owned by both players that have are currently in - * the given zone. - * - * @param zone - * a Constant.Zone - * @param cardName - * a String - * @return a List with all cards currently in a graveyard - */ - public static List getCardsIn(final ZoneType zone, final String cardName) { - return CardLists.filter(GameState.getCardsIn(zone), CardPredicates.nameEquals(cardName)); + public List getLandsInPlay() { + return CardLists.filter(getCardsIn(ZoneType.Battlefield), Presets.LANDS); } - /** - * use to get a List of all creatures on the battlefield for both. - * players - * - * @return a List of all creatures on the battlefield on both sides - */ - public static List getCreaturesInPlay() { - final List creats = GameState.getCardsIn(ZoneType.Battlefield); - return CardLists.filter(creats, Presets.CREATURES); + public boolean isCardExiled(final Card c) { + return getCardsIn(ZoneType.Exile).contains(c); } - /** - * use to get a list of creatures in play for a given player. - * - * @param player - * the player to get creatures for - * @return a List containing all creatures a given player has in play - */ - public static List getCreaturesInPlay(final Player player) { - final List creats = player.getCardsIn(ZoneType.Battlefield); - return CardLists.filter(creats, Presets.CREATURES); - } - - /** - * use to get a list of all lands a given player has on the battlefield. - * - * @param player - * the player whose lands we want to get - * @return a List containing all lands the given player has in play - */ - public static List getPlayerLandsInPlay(final Player player) { - return CardLists.filter(player.getCardsIn(ZoneType.Battlefield), Presets.LANDS); - } - - /** - * gets a list of all lands in play. - * - * @return a List of all lands on the battlefield - */ - public static List getLandsInPlay() { - return CardLists.filter(GameState.getCardsIn(ZoneType.Battlefield), Presets.LANDS); - } - - /** - * answers the question "is the given card in any exile zone?". - * - * @param c - * the card to look for in Exile - * @return true is the card is in Human or Computer's Exile zone - */ - public static boolean isCardExiled(final Card c) { - return GameState.getCardsIn(ZoneType.Exile).contains(c); - } - - // /Check if a certain card is in play - /** - *

- * isCardInPlay. - *

- * - * @param card - * a {@link forge.Card} object. - * @return a boolean. - */ - public static boolean isCardInPlay(final Card card) { - if (card.getController() == null) { - return false; - } - return card.getController().getCardsIn(ZoneType.Battlefield).contains(card); - } - - /** - * Answers the question: "Is in play?". - * - * @param cardName - * the name of the card to look for - * @return true is the card is in play, false otherwise - */ - public static boolean isCardInPlay(final String cardName) { - for (final Player p : Singletons.getModel().getGameState().getPlayers()) { - if (isCardInPlay(cardName, p)) + + public boolean isCardInPlay(final String cardName) { + for (final Player p : getPlayers()) { + if (p.isCardInPlay(cardName)) return true; } return false; } - /** - * Answers the question: "Does have in play?". - * - * @param cardName - * the name of the card to look for - * @param player - * the player whose battlefield we want to check - * @return true if that player has that card in play, false otherwise - */ - public static boolean isCardInPlay(final String cardName, final Player player) { - return Iterables.any(player.getZone(ZoneType.Battlefield), CardPredicates.nameEquals(cardName)); - } - - /** - * gets a list of all Cards of a given color on the battlefield. - * - * @param color - * the color of cards to get - * @return a List of all cards in play of a given color - */ - public static List getColorInPlay(final String color) { + public List getColoredCardsInPlay(final String color) { final List cards = new ArrayList(); - for(Player p : Singletons.getModel().getGameState().getPlayers()) { - cards.addAll(getPlayerColorInPlay(p, color)); + for(Player p : getPlayers()) { + cards.addAll(p.getColoredCardsInPlay(color)); } return cards; } - /** - * gets a list of all Cards of a given color a given player has on the - * battlefield. - * - * @param player - * the player's cards to get - * @param color - * the color of cards to get - * @return a List of all cards in play of a given color - */ - public static List getPlayerColorInPlay(final Player player, final String color) { - List cards = player.getCardsIn(ZoneType.Battlefield); - cards = CardLists.filter(cards, new Predicate() { - @Override - public boolean apply(final Card c) { - final List colorList = CardUtil.getColors(c); - return colorList.contains(color); - } - }); - return cards; - } - - /** - *

- * getCardState. - *

- * - * @param card - * a {@link forge.Card} object. - * @return a {@link forge.Card} object. - */ - public static Card getCardState(final Card card) { - - for (final Card c : GameState.getCardsInGame()) { + public Card getCardState(final Card card) { + for (final Card c : getCardsInGame()) { if (card.equals(c)) { return c; } @@ -610,45 +408,19 @@ public class GameState { return (playerList.size() - opponentList.size()); } - /** - * a CardListFilter to get all cards that are a part of this game. - * - * @return a {@link forge.CardList} with all cards in all Battlefields, - * Hands, Graveyards, Libraries, and Exiles. - */ - public static List getCardsInGame() { + public List getCardsInGame() { final List all = new ArrayList(); - for (final Player player : Singletons.getModel().getGameState().getPlayers()) { + for (final Player player : getPlayers()) { all.addAll(player.getZone(ZoneType.Graveyard).getCards()); all.addAll(player.getZone(ZoneType.Hand).getCards()); all.addAll(player.getZone(ZoneType.Library).getCards()); all.addAll(player.getZone(ZoneType.Battlefield).getCards(false)); all.addAll(player.getZone(ZoneType.Exile).getCards()); } - all.addAll(Singletons.getModel().getGameState().getStackZone().getCards()); + all.addAll(getStackZone().getCards()); return all; } - - /** - *

- * getDoublingSeasonMagnitude. - *

- * - * @param player - * the {@link forge.game.player.Player} player to determine if is affected by - * Doubling Season - * @return a int. - */ - public static int getCounterDoublersMagnitude(final Player player, Counters type) { - int counterDoublers = player.getCardsIn(ZoneType.Battlefield, "Doubling Season").size(); - if(type == Counters.P1P1) { - counterDoublers += player.getCardsIn(ZoneType.Battlefield, "Corpsejack Menace").size(); - } - return (int) Math.pow(2, counterDoublers); // pow(a,0) = 1; pow(a,1) = a - // ... no worries about size - // = 0 - } - + /** *

* getTokenDoublersMagnitude. @@ -659,11 +431,5 @@ public class GameState { * Doubling Season * @return a int. */ - public static int getTokenDoublersMagnitude(final Player player) { - final int tokenDoublers = player.getCardsIn(ZoneType.Battlefield, "Parallel Lives").size() - + player.getCardsIn(ZoneType.Battlefield, "Doubling Season").size(); - return (int) Math.pow(2, tokenDoublers); // pow(a,0) = 1; pow(a,1) = a - // ... no worries about size = - // 0 - } + } diff --git a/src/main/java/forge/game/MatchController.java b/src/main/java/forge/game/MatchController.java index 0067b0d2165..7452eb66e1b 100644 --- a/src/main/java/forge/game/MatchController.java +++ b/src/main/java/forge/game/MatchController.java @@ -6,10 +6,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import forge.AllZone; import forge.Singletons; import forge.Constant.Preferences; import forge.control.FControl; +import forge.control.input.InputControl; import forge.control.input.InputMulligan; import forge.deck.Deck; import forge.error.ErrorViewer; @@ -19,6 +19,7 @@ import forge.game.player.LobbyPlayer; import forge.game.player.Player; import forge.game.player.PlayerType; import forge.game.zone.ZoneType; +import forge.gui.GuiInput; import forge.gui.framework.EDocID; import forge.gui.framework.SDisplayUtil; import forge.gui.match.CMatchUI; @@ -49,6 +50,8 @@ public class MatchController { private final List gamesPlayed = new ArrayList(); private final List gamesPlayedRo; + private InputControl input; + public MatchController() { gamesPlayedRo = Collections.unmodifiableList(gamesPlayed); } @@ -95,6 +98,10 @@ public class MatchController { // Will this lose all the ordering? currentGame = Singletons.getModel().newGame(players.keySet()); + // Instantiate AI + input = new InputControl(currentGame); + + Map startConditions = new HashMap(); for (Player p : currentGame.getPlayers()) startConditions.put(p, players.get(p.getLobbyPlayer())); @@ -106,15 +113,19 @@ public class MatchController { SDisplayUtil.showTab(EDocID.REPORT_LOG.getDoc()); // set all observers - CMessage.SINGLETON_INSTANCE.subscribe(currentGame); - CLog.SINGLETON_INSTANCE.subscribe(currentGame); - CStack.SINGLETON_INSTANCE.subscribe(currentGame); + GuiInput inputControl = CMessage.SINGLETON_INSTANCE.getInputControl(); + input.addObserver(inputControl); + currentGame.getStack().addObserver(inputControl); + currentGame.getPhaseHandler().addObserver(inputControl); + currentGame.getGameLog().addObserver(CLog.SINGLETON_INSTANCE); + currentGame.getStack().addObserver(CStack.SINGLETON_INSTANCE); + // some observers are set in CMatchUI.initMatch GameNew.newGame(startConditions, gameType); Player computerPlayer = Aggregates.firstFieldEquals(currentGame.getPlayers(), Player.Accessors.FN_GET_TYPE, PlayerType.COMPUTER); - AllZone.getInputControl().setComputer(new ComputerAIInput(new ComputerAIGeneral(computerPlayer))); + input.setComputer(new ComputerAIInput(new ComputerAIGeneral(computerPlayer))); if (this.getPlayedGames().isEmpty()) { @@ -127,16 +138,16 @@ public class MatchController { } VAntes.SINGLETON_INSTANCE.clearAnteCards(); - AllZone.getInputControl().resetInput(); + Singletons.getModel().getMatch().getInput().resetInput(); } // per player observers were set in CMatchUI.SINGLETON_INSTANCE.initMatch CMessage.SINGLETON_INSTANCE.updateGameInfo(this); // Update observers - Singletons.getModel().getGameState().getStack().updateObservers(); - AllZone.getInputControl().updateObservers(); - Singletons.getModel().getGameState().getGameLog().updateObservers(); + currentGame.getStack().updateObservers(); + input.updateObservers(); + currentGame.getGameLog().updateObservers(); for( Player p : currentGame.getPlayers() ) { @@ -145,7 +156,7 @@ public class MatchController { } CMatchUI.SINGLETON_INSTANCE.setCard(Singletons.getControl().getPlayer().getCardsIn(ZoneType.Hand).get(0)); - AllZone.getInputControl().setInput(new InputMulligan()); + input.setInput(new InputMulligan()); } catch (Exception e) { ErrorViewer.showError(e); @@ -257,4 +268,8 @@ public class MatchController { PlayerStartConditions cond = players.get(lobbyPlayer); return cond == null ? null : cond.getDeck(); } + + public final InputControl getInput() { + return input; + } } diff --git a/src/main/java/forge/game/phase/Combat.java b/src/main/java/forge/game/phase/Combat.java index 56757a42575..540af7b9a84 100644 --- a/src/main/java/forge/game/phase/Combat.java +++ b/src/main/java/forge/game/phase/Combat.java @@ -34,7 +34,6 @@ import forge.GameActionUtil; import forge.GameEntity; import forge.Singletons; import forge.card.trigger.TriggerType; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.gui.match.CMatchUI; @@ -625,7 +624,7 @@ public class Combat { all.addAll(this.getAllBlockers()); for (int i = 0; i < all.size(); i++) { - if (!GameState.isCardInPlay(all.get(i))) { + if (!all.get(i).isInPlay()) { this.removeFromCombat(all.get(i)); } } diff --git a/src/main/java/forge/game/phase/CombatUtil.java b/src/main/java/forge/game/phase/CombatUtil.java index 131402f7e24..7b2effff493 100644 --- a/src/main/java/forge/game/phase/CombatUtil.java +++ b/src/main/java/forge/game/phase/CombatUtil.java @@ -35,7 +35,6 @@ import forge.CardPredicates; import forge.Command; import forge.Constant; import forge.Counters; -import forge.GameAction; import forge.GameActionUtil; import forge.GameEntity; import forge.Singletons; @@ -53,7 +52,6 @@ import forge.card.staticability.StaticAbility; import forge.card.trigger.Trigger; import forge.card.trigger.TriggerHandler; import forge.card.trigger.TriggerType; -import forge.game.GameState; import forge.game.player.ComputerUtil; import forge.game.player.ComputerUtilBlock; import forge.game.player.Player; @@ -100,7 +98,7 @@ public class CombatUtil { return false; } - for (final Card c : GameState.getCardsIn(ZoneType.Battlefield)) { + for (final Card c : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { for (final String keyword : c.getKeyword()) { if (keyword.equals("No more than one creature can block each combat.") && (combat.getAllBlockers().size() > 0)) { @@ -113,7 +111,7 @@ public class CombatUtil { } } - if (combat.getAllBlockers().size() > 0 && GameState.isCardInPlay("Dueling Grounds")) { + if (combat.getAllBlockers().size() > 0 && Singletons.getModel().getGameState().isCardInPlay("Dueling Grounds")) { return false; } @@ -159,7 +157,7 @@ public class CombatUtil { return false; } - final List list = GameState.getCreaturesInPlay(blocker.getController()); + final List list = blocker.getController().getCreaturesInPlay(); if (list.size() < 2 && blocker.hasKeyword("CARDNAME can't attack or block alone.")) { return false; } @@ -381,7 +379,7 @@ public class CombatUtil { */ public static boolean finishedMandatoryBlocks(final Combat combat) { - final List blockers = GameState.getCreaturesInPlay(Singletons.getControl().getPlayer()); + final List blockers = Singletons.getControl().getPlayer().getCreaturesInPlay(); final List attackers = combat.getAttackerList(); // if a creature does not block but should, return false @@ -760,7 +758,7 @@ public class CombatUtil { return false; } - if (GameState.isCardInPlay("Shifting Sliver")) { + if (Singletons.getModel().getGameState().isCardInPlay("Shifting Sliver")) { if (attacker.isType("Sliver") && !blocker.isType("Sliver")) { return false; } @@ -784,7 +782,7 @@ public class CombatUtil { public static boolean canAttack(final Card c, final Combat combat) { int cntAttackers = combat.getAttackers().size(); - for (final Card card : GameState.getCardsIn(ZoneType.Battlefield)) { + for (final Card card : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { for (final String keyword : card.getKeyword()) { if (keyword.equals("No more than one creature can attack each combat.") && cntAttackers > 0) { return false; @@ -802,7 +800,7 @@ public class CombatUtil { } } - final List list = GameState.getCreaturesInPlay(c.getController()); + final List list = c.getController().getCreaturesInPlay(); if (list.size() < 2 && c.hasKeyword("CARDNAME can't attack or block alone.")) { return false; } @@ -811,7 +809,7 @@ public class CombatUtil { return false; } - if (cntAttackers > 0 && GameState.isCardInPlay("Dueling Grounds")) { + if (cntAttackers > 0 && Singletons.getModel().getGameState().isCardInPlay("Dueling Grounds")) { return false; } @@ -879,7 +877,7 @@ public class CombatUtil { if (asSeparateWords[12].matches("[0-9][0-9]?")) { powerLimit[0] = Integer.parseInt((asSeparateWords[12]).trim()); - List list = GameState.getCreaturesInPlay(c.getController().getOpponent()); + List list = c.getController().getOpponent().getCreaturesInPlay(); list = CardLists.filter(list, new Predicate() { @Override public boolean apply(final Card ct) { @@ -958,7 +956,7 @@ public class CombatUtil { public static int getTotalFirstStrikeBlockPower(final Card attacker, final Player player) { final Card att = attacker; - List list = GameState.getCreaturesInPlay(player); + List list = player.getCreaturesInPlay(); list = CardLists.filter(list, new Predicate() { @Override public boolean apply(final Card c) { @@ -1321,7 +1319,7 @@ public class CombatUtil { } int defenderDamage = defender.getNetAttack() + CombatUtil.predictPowerBonusOfBlocker(attacker, defender, true); - if (GameState.isCardInPlay("Doran, the Siege Tower")) { + if (Singletons.getModel().getGameState().isCardInPlay("Doran, the Siege Tower")) { defenderDamage = defender.getNetDefense() + CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, true); } @@ -1465,7 +1463,7 @@ public class CombatUtil { combat = Singletons.getModel().getGameState().getCombat(); } - if (!trigger.zonesCheck(GameState.getZoneOf(trigger.getHostCard()))) { + if (!trigger.zonesCheck(Singletons.getModel().getGameState().getZoneOf(trigger.getHostCard()))) { return false; } if (!trigger.requirementsCheck()) { @@ -1581,7 +1579,7 @@ public class CombatUtil { // look out for continuous static abilities that only care for blocking // creatures - final List cardList = GameState.getCardsIn(ZoneType.Battlefield); + final List cardList = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card card : cardList) { for (final StaticAbility stAb : card.getStaticAbilities()) { final HashMap params = stAb.getMapParams(); @@ -1608,7 +1606,7 @@ public class CombatUtil { } final ArrayList theTriggers = new ArrayList(); - for (Card card : GameState.getCardsIn(ZoneType.Battlefield)) { + for (Card card : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { theTriggers.addAll(card.getTriggers()); } theTriggers.addAll(attacker.getTriggers()); @@ -1707,7 +1705,7 @@ public class CombatUtil { toughness += defender.getKeywordMagnitude("Bushido"); final ArrayList theTriggers = new ArrayList(); - for (Card card : GameState.getCardsIn(ZoneType.Battlefield)) { + for (Card card : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { theTriggers.addAll(card.getTriggers()); } theTriggers.addAll(attacker.getTriggers()); @@ -1829,7 +1827,7 @@ public class CombatUtil { } final ArrayList theTriggers = new ArrayList(); - for (Card card : GameState.getCardsIn(ZoneType.Battlefield)) { + for (Card card : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { theTriggers.addAll(card.getTriggers()); } // if the defender has first strike and wither the attacker will deal @@ -1846,7 +1844,7 @@ public class CombatUtil { // look out for continuous static abilities that only care for attacking // creatures - final List cardList = GameState.getCardsIn(ZoneType.Battlefield); + final List cardList = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card card : cardList) { for (final StaticAbility stAb : card.getStaticAbilities()) { final HashMap params = stAb.getMapParams(); @@ -1961,7 +1959,7 @@ public class CombatUtil { } final ArrayList theTriggers = new ArrayList(); - for (Card card : GameState.getCardsIn(ZoneType.Battlefield)) { + for (Card card : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { theTriggers.addAll(card.getTriggers()); } if (defender != null) { @@ -1971,7 +1969,7 @@ public class CombatUtil { // look out for continuous static abilities that only care for attacking // creatures - final List cardList = GameState.getCardsIn(ZoneType.Battlefield); + final List cardList = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card card : cardList) { for (final StaticAbility stAb : card.getStaticAbilities()) { final HashMap params = stAb.getMapParams(); @@ -2092,7 +2090,7 @@ public class CombatUtil { */ public static boolean checkDestroyBlockerTrigger(final Card attacker, final Card defender) { final ArrayList theTriggers = new ArrayList(); - for (Card card : GameState.getCardsIn(ZoneType.Battlefield)) { + for (Card card : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { theTriggers.addAll(card.getTriggers()); } for (Trigger trigger : theTriggers) { @@ -2147,7 +2145,7 @@ public class CombatUtil { */ public static boolean checkDestroyAttackerTrigger(final Card attacker, final Card defender) { final ArrayList theTriggers = new ArrayList(); - for (Card card : GameState.getCardsIn(ZoneType.Battlefield)) { + for (Card card : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { theTriggers.addAll(card.getTriggers()); } for (Trigger trigger : theTriggers) { @@ -2241,7 +2239,7 @@ public class CombatUtil { + CombatUtil.predictPowerBonusOfBlocker(attacker, defender, withoutAbilities); int attackerDamage = attacker.getNetAttack() + CombatUtil.predictPowerBonusOfAttacker(attacker, defender, combat); - if (GameState.isCardInPlay("Doran, the Siege Tower")) { + if (Singletons.getModel().getGameState().isCardInPlay("Doran, the Siege Tower")) { defenderDamage = defender.getNetDefense() + CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities); attackerDamage = attacker.getNetDefense() @@ -2389,7 +2387,7 @@ public class CombatUtil { + CombatUtil.predictPowerBonusOfBlocker(attacker, defender, withoutAbilities); int attackerDamage = attacker.getNetAttack() + CombatUtil.predictPowerBonusOfAttacker(attacker, defender, combat); - if (GameState.isCardInPlay("Doran, the Siege Tower")) { + if (Singletons.getModel().getGameState().isCardInPlay("Doran, the Siege Tower")) { defenderDamage = defender.getNetDefense() + CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities); attackerDamage = attacker.getNetDefense() @@ -2478,7 +2476,7 @@ public class CombatUtil { *

*/ public static void removeAllDamage() { - final List cl = GameState.getCardsIn(ZoneType.Battlefield); + final List cl = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card c : cl) { c.setDamage(0); } @@ -2644,7 +2642,7 @@ public class CombatUtil { public static void checkPropagandaEffects(final Card c, final boolean bLast) { Cost attackCost = new Cost(c, "0", true); // Sort abilities to apply them in proper order - for (Card card : GameState.getCardsIn(ZoneType.Battlefield)) { + for (Card card : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { final ArrayList staticAbilities = card.getStaticAbilities(); for (final StaticAbility stAb : staticAbilities) { Cost additionalCost = stAb.getCostAbility("CantAttackUnless", c, Singletons.getModel().getGameState().getCombat().getDefenderByAttacker(c)); @@ -2800,13 +2798,13 @@ public class CombatUtil { @Override public void execute() { - if (GameState.isCardInPlay(charger)) { + if (charger.isInPlay()) { charger.removeIntrinsicKeyword("Trample"); } } }; // Command - if (GameState.isCardInPlay(charger)) { + if (charger.isInPlay()) { charger.addIntrinsicKeyword("Trample"); Singletons.getModel().getGameState().getEndOfTurn().addUntil(untilEOT); @@ -2952,14 +2950,14 @@ public class CombatUtil { @Override public void execute() { - if (GameState.isCardInPlay(blocker)) { + if (blocker.isInPlay()) { blocker.addTempAttackBoost(mag); blocker.addTempDefenseBoost(mag); } } }; // Command - if (GameState.isCardInPlay(blocker)) { + if (blocker.isInPlay()) { blocker.addTempAttackBoost(-mag); blocker.addTempDefenseBoost(-mag); @@ -3008,14 +3006,14 @@ public class CombatUtil { @Override public void execute() { - if (GameState.isCardInPlay(crd)) { + if (crd.isInPlay()) { crd.addTempAttackBoost(-1); crd.addTempDefenseBoost(-1); } } }; // Command - if (GameState.isCardInPlay(crd)) { + if (crd.isInPlay()) { crd.addTempAttackBoost(1); crd.addTempDefenseBoost(1); @@ -3105,8 +3103,8 @@ public class CombatUtil { } else { enchantment = CardFactoryUtil.getBestEnchantmentAI(enchantments, this, false); } - if ((enchantment != null) && GameState.isCardInPlay(attacker)) { - GameAction.changeZone(GameState.getZoneOf(enchantment), + if ((enchantment != null) && attacker.isInPlay()) { + Singletons.getModel().getGameAction().changeZone(Singletons.getModel().getGameState().getZoneOf(enchantment), enchantment.getOwner().getZone(ZoneType.Battlefield), enchantment, null); enchantment.enchantEntity(attacker); } @@ -3152,14 +3150,14 @@ public class CombatUtil { @Override public void execute() { - if (GameState.isCardInPlay(crd)) { + if (crd.isInPlay()) { crd.addTempAttackBoost(-pump); crd.addTempDefenseBoost(-pump); } } }; // Command - if (GameState.isCardInPlay(crd)) { + if (crd.isInPlay()) { crd.addTempAttackBoost(pump); crd.addTempDefenseBoost(pump); diff --git a/src/main/java/forge/game/phase/EndOfTurn.java b/src/main/java/forge/game/phase/EndOfTurn.java index 5821a03b83c..d7dfd367086 100644 --- a/src/main/java/forge/game/phase/EndOfTurn.java +++ b/src/main/java/forge/game/phase/EndOfTurn.java @@ -29,7 +29,6 @@ import forge.Singletons; import forge.card.spellability.Ability; import forge.card.spellability.SpellAbility; import forge.game.GameLossReason; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -56,7 +55,7 @@ public class EndOfTurn extends Phase implements java.io.Serializable { // TODO - should this freeze the Stack? - final List all = GameState.getCardsIn(ZoneType.Battlefield); + final List all = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); //EndOfTurn.endOfTurnWallOfReverence(); EndOfTurn.endOfTurnLighthouseChronologist(); @@ -72,7 +71,7 @@ public class EndOfTurn extends Phase implements java.io.Serializable { final SpellAbility sac = new Ability(card, "0") { @Override public void resolve() { - if (GameState.isCardInPlay(card)) { + if (card.isInPlay()) { Singletons.getModel().getGameAction().sacrifice(card, null); } } @@ -90,7 +89,7 @@ public class EndOfTurn extends Phase implements java.io.Serializable { final SpellAbility exile = new Ability(card, "0") { @Override public void resolve() { - if (GameState.isCardInPlay(card)) { + if (card.isInPlay()) { Singletons.getModel().getGameAction().exile(card); } } @@ -108,7 +107,7 @@ public class EndOfTurn extends Phase implements java.io.Serializable { final SpellAbility destroy = new Ability(card, "0") { @Override public void resolve() { - if (GameState.isCardInPlay(card)) { + if (card.isInPlay()) { Singletons.getModel().getGameAction().destroy(card); } } @@ -128,7 +127,7 @@ public class EndOfTurn extends Phase implements java.io.Serializable { final SpellAbility sac = new Ability(card, "0") { @Override public void resolve() { - if (GameState.isCardInPlay(card)) { + if (card.isInPlay()) { Singletons.getModel().getGameAction().destroy(card); } } @@ -150,7 +149,7 @@ public class EndOfTurn extends Phase implements java.io.Serializable { final SpellAbility change = new Ability(vale, "0") { @Override public void resolve() { - if (GameState.isCardInPlay(vale)) { + if (vale.isInPlay()) { vale.addController(vale.getController().getOpponent()); // Singletons.getModel().getGameAction().changeController( // new ArrayList(vale), vale.getController(), @@ -175,7 +174,7 @@ public class EndOfTurn extends Phase implements java.io.Serializable { final SpellAbility change = new Ability(raider, "0") { @Override public void resolve() { - if (GameState.isCardInPlay(raider)) { + if (raider.isInPlay()) { raider.getController().addDamage(2, raider); } } @@ -194,7 +193,7 @@ public class EndOfTurn extends Phase implements java.io.Serializable { final SpellAbility change = new Ability(source, "0") { @Override public void resolve() { - if (GameState.isCardInPlay(source)) { + if (source.isInPlay()) { Singletons.getModel().getGameAction().moveToHand(source); } } diff --git a/src/main/java/forge/game/phase/PhaseHandler.java b/src/main/java/forge/game/phase/PhaseHandler.java index 435c3c2ec56..f0bfbf823b4 100644 --- a/src/main/java/forge/game/phase/PhaseHandler.java +++ b/src/main/java/forge/game/phase/PhaseHandler.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.Stack; import com.esotericsoftware.minlog.Log; -import forge.AllZone; import forge.Card; import forge.CardLists; @@ -31,7 +30,6 @@ import forge.GameActionUtil; import forge.Singletons; import forge.card.spellability.SpellAbility; import forge.card.trigger.TriggerType; -import forge.game.GameState; import forge.game.player.Player; import forge.game.player.PlayerType; import forge.game.zone.ZoneType; @@ -394,7 +392,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable { case CLEANUP: // Reset Damage received map - final List list = GameState.getCardsIn(ZoneType.Battlefield); + final List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card c : list) { c.resetPreventNextDamage(); c.resetReceivedDamageFromThisTurn(); @@ -474,7 +472,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable { return; } this.bPhaseEffects = true; - if (!GameState.isCardInPlay("Upwelling")) { + if (!Singletons.getModel().getGameState().isCardInPlay("Upwelling")) { for (Player p : Singletons.getModel().getGameState().getPlayers()) { int burn = p.getManaPool().clearPool(); if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_MANABURN)) { @@ -563,7 +561,12 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable { Singletons.getModel().getGameState().getStack().setCardsCastLastTurn(); Singletons.getModel().getGameState().getStack().clearCardsCastThisTurn(); - GameState.resetZoneMoveTracking(); + + for (final Player p1 : Singletons.getModel().getGameState().getPlayers()) { + for (final ZoneType z : Player.ALL_ZONES) { + p1.getZone(z).resetCardsAddedThisTurn(); + } + } for( Player p : Singletons.getModel().getGameState().getPlayers() ) { p.resetProwl(); @@ -822,7 +825,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable { if (firstAction.equals(actingPlayer)) { // pass the priority to other player this.setPriorityPlayer(actingPlayer.getOpponent()); - AllZone.getInputControl().resetInput(); + Singletons.getModel().getMatch().getInput().resetInput(); Singletons.getModel().getGameState().getStack().chooseOrderOfSimultaneousStackEntryAll(); } else { if (Singletons.getModel().getGameState().getStack().size() == 0) { @@ -865,7 +868,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable { if (this.getPriorityPlayer().isHuman()) { // TODO This doesn't work quite 100% but pretty close this.passPriority(); - AllZone.getInputControl().resetInput(); + Singletons.getModel().getMatch().getInput().resetInput(); } } @@ -938,7 +941,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable { final Card source = sa.getRootSpellAbility().getSourceCard(); boolean onlyThis = true; if (Singletons.getModel().getGameState().getStack().size() != 0) { - for (final Card card : GameState.getCardsIn(ZoneType.Stack)) { + for (final Card card : Singletons.getModel().getGameState().getCardsIn(ZoneType.Stack)) { if (card != source) { onlyThis = false; //System.out.println("StackCard: " + card + " vs SourceCard: " + source); diff --git a/src/main/java/forge/game/phase/PhaseUtil.java b/src/main/java/forge/game/phase/PhaseUtil.java index 12d6998e9b5..46c25c93e60 100644 --- a/src/main/java/forge/game/phase/PhaseUtil.java +++ b/src/main/java/forge/game/phase/PhaseUtil.java @@ -28,7 +28,6 @@ import forge.CardLists; import forge.CardPredicates.Presets; import forge.Singletons; import forge.card.trigger.TriggerType; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.ZoneType; import forge.gui.match.CMatchUI; @@ -65,7 +64,7 @@ public class PhaseUtil { return true; } - if (GameState.isCardInPlay("Sands of Time") || GameState.isCardInPlay("Stasis")) { + if (Singletons.getModel().getGameState().isCardInPlay("Sands of Time") || Singletons.getModel().getGameState().isCardInPlay("Stasis")) { return true; } @@ -104,7 +103,7 @@ public class PhaseUtil { Singletons.getModel().getGameAction().resetActivationsPerTurn(); - final List lands = CardLists.filter(GameState.getPlayerLandsInPlay(turn), Presets.UNTAPPED); + final List lands = CardLists.filter(turn.getLandsInPlay(), Presets.UNTAPPED); turn.setNumPowerSurgeLands(lands.size()); // anything before this point happens regardless of whether the Untap @@ -154,13 +153,13 @@ public class PhaseUtil { * @return a boolean. */ public static boolean skipUpkeep() { - if (GameState.isCardInPlay("Eon Hub")) { + if (Singletons.getModel().getGameState().isCardInPlay("Eon Hub")) { return true; } final Player turn = Singletons.getModel().getGameState().getPhaseHandler().getPlayerTurn(); - if ((turn.getCardsIn(ZoneType.Hand).size() == 0) && GameState.isCardInPlay("Gibbering Descent", turn)) { + if ((turn.getCardsIn(ZoneType.Hand).size() == 0) && turn.isCardInPlay("Gibbering Descent")) { return true; } diff --git a/src/main/java/forge/game/phase/Untap.java b/src/main/java/forge/game/phase/Untap.java index e6c89da137c..8cbb82a66a7 100644 --- a/src/main/java/forge/game/phase/Untap.java +++ b/src/main/java/forge/game/phase/Untap.java @@ -22,10 +22,10 @@ import java.util.List; import com.google.common.base.Predicate; import com.google.common.base.Predicates; -import forge.AllZone; import forge.Card; import forge.CardLists; +import forge.CardPredicates; import forge.CardPredicates.Presets; import forge.Counters; import forge.GameActionUtil; @@ -33,7 +33,6 @@ import forge.GameEntity; import forge.Singletons; import forge.card.cardfactory.CardFactoryUtil; import forge.control.input.Input; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; @@ -87,7 +86,7 @@ public class Untap extends Phase implements java.io.Serializable { return false; } - final List allp = GameState.getCardsIn(ZoneType.Battlefield); + final List allp = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card ca : allp) { if (ca.hasStartOfKeyword("Permanents don't untap during their controllers' untap steps")) { final int keywordPosition = ca @@ -131,12 +130,11 @@ public class Untap extends Phase implements java.io.Serializable { if (Untap.canOnlyUntapOneLand() && c.isLand()) { return false; } - if ((GameState.isCardInPlay("Damping Field") || GameState.isCardInPlay("Imi Statue")) + if ((Singletons.getModel().getGameState().isCardInPlay("Damping Field") || Singletons.getModel().getGameState().isCardInPlay("Imi Statue")) && c.isArtifact()) { return false; } - if ((GameState.isCardInPlay("Smoke") || GameState.isCardInPlay("Stoic Angel") || GameState - .isCardInPlay("Intruder Alarm")) && c.isCreature()) { + if ((Singletons.getModel().getGameState().isCardInPlay("Smoke") || Singletons.getModel().getGameState().isCardInPlay("Stoic Angel") || Singletons.getModel().getGameState().isCardInPlay("Intruder Alarm")) && c.isCreature()) { return false; } return true; @@ -154,7 +152,7 @@ public class Untap extends Phase implements java.io.Serializable { prompt += "\r\n" + c + " is controlling: "; for (final Card target : targets) { prompt += target; - if (GameState.isCardInPlay(target)) { + if (target.isInPlay()) { defaultChoice = false; } } @@ -170,7 +168,7 @@ public class Untap extends Phase implements java.io.Serializable { final ArrayList targets = c.getGainControlTargets(); boolean untap = true; for (final Card target : targets) { - if (GameState.isCardInPlay(target)) { + if (target.isInPlay()) { untap |= true; } } @@ -180,7 +178,7 @@ public class Untap extends Phase implements java.io.Serializable { } } } - } else if ((c.getCounters(Counters.WIND) > 0) && GameState.isCardInPlay("Freyalise's Winds")) { + } else if ((c.getCounters(Counters.WIND) > 0) && Singletons.getModel().getGameState().isCardInPlay("Freyalise's Winds")) { // remove a WIND counter instead of untapping c.subtractCounter(Counters.WIND, 1); } else { @@ -200,7 +198,7 @@ public class Untap extends Phase implements java.io.Serializable { if (Untap.canOnlyUntapOneLand()) { if (player.isComputer()) { // search for lands the computer has and only untap 1 - List landList = GameState.getPlayerLandsInPlay(player); + List landList = player.getLandsInPlay(); landList = CardLists.filter(landList, tappedCanUntap); if (landList.size() > 0) { @@ -229,14 +227,14 @@ public class Untap extends Phase implements java.io.Serializable { } } // selectCard() }; // Input - List landList = GameState.getPlayerLandsInPlay(player); + List landList = player.getLandsInPlay(); landList = CardLists.filter(landList, tappedCanUntap); if (landList.size() > 0) { - AllZone.getInputControl().setInput(target); + Singletons.getModel().getMatch().getInput().setInput(target); } } } - if (GameState.isCardInPlay("Damping Field") || GameState.isCardInPlay("Imi Statue")) { + if (Singletons.getModel().getGameState().isCardInPlay("Damping Field") || Singletons.getModel().getGameState().isCardInPlay("Imi Statue")) { final Player turnOwner = Singletons.getModel().getGameState().getPhaseHandler().getPlayerTurn(); if (turnOwner.isComputer()) { List artList = turnOwner.getCardsIn(ZoneType.Battlefield); @@ -273,13 +271,13 @@ public class Untap extends Phase implements java.io.Serializable { artList = CardLists.filter(artList, Presets.ARTIFACTS); artList = CardLists.filter(artList, tappedCanUntap); if (artList.size() > 0) { - AllZone.getInputControl().setInput(target); + Singletons.getModel().getMatch().getInput().setInput(target); } } } - if ((GameState.isCardInPlay("Smoke") || GameState.isCardInPlay("Stoic Angel"))) { + if ((Singletons.getModel().getGameState().isCardInPlay("Smoke") || Singletons.getModel().getGameState().isCardInPlay("Stoic Angel"))) { if (player.isComputer()) { - List creatures = GameState.getCreaturesInPlay(player); + List creatures = player.getCreaturesInPlay(); creatures = CardLists.filter(creatures, tappedCanUntap); if (creatures.size() > 0) { creatures.get(0).untap(); @@ -308,10 +306,10 @@ public class Untap extends Phase implements java.io.Serializable { } } // selectCard() }; // Input - List creatures = GameState.getCreaturesInPlay(player); + List creatures = player.getCreaturesInPlay(); creatures = CardLists.filter(creatures, tappedCanUntap); if (creatures.size() > 0) { - AllZone.getInputControl().setInput(target); + Singletons.getModel().getMatch().getInput().setInput(target); } } } @@ -331,7 +329,7 @@ public class Untap extends Phase implements java.io.Serializable { private static boolean canOnlyUntapOneLand() { // Winter Orb was given errata so it no longer matters if it's tapped or // not - if (GameState.getCardsIn(ZoneType.Battlefield, "Winter Orb").size() > 0) { + if (CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Winter Orb")).size() > 0) { return true; } diff --git a/src/main/java/forge/game/phase/Upkeep.java b/src/main/java/forge/game/phase/Upkeep.java index 893c732c188..32366a5176c 100644 --- a/src/main/java/forge/game/phase/Upkeep.java +++ b/src/main/java/forge/game/phase/Upkeep.java @@ -23,7 +23,6 @@ import java.util.List; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; -import forge.AllZone; import forge.Card; import forge.CardLists; @@ -31,7 +30,6 @@ import forge.CardPredicates; import forge.CardPredicates.Presets; import forge.Command; import forge.Counters; -import forge.GameAction; import forge.GameActionUtil; import forge.Singletons; import forge.card.cardfactory.CardFactoryUtil; @@ -476,8 +474,8 @@ public class Upkeep extends Phase implements java.io.Serializable { * regenerated. */ final Player player = Singletons.getModel().getGameState().getPhaseHandler().getPlayerTurn(); - final List the = GameState.getCardsIn(ZoneType.Battlefield, "The Abyss"); - final List magus = GameState.getCardsIn(ZoneType.Battlefield, "Magus of the Abyss"); + final List the = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("The Abyss")); + final List magus = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Magus of the Abyss")); final List cards = new ArrayList(); cards.addAll(the); @@ -486,7 +484,7 @@ public class Upkeep extends Phase implements java.io.Serializable { for (final Card c : cards) { final Card abyss = c; - final List abyssGetTargets = CardLists.filter(GameState.getCreaturesInPlay(player), Presets.NON_ARTIFACTS); + final List abyssGetTargets = CardLists.filter(player.getCreaturesInPlay(), Presets.NON_ARTIFACTS); final Ability sacrificeCreature = new Ability(abyss, "") { @Override @@ -494,7 +492,7 @@ public class Upkeep extends Phase implements java.io.Serializable { final List targets = CardLists.getTargetableCards(abyssGetTargets, this); if (player.isHuman()) { if (targets.size() > 0) { - AllZone.getInputControl().setInput(new Input() { + Singletons.getModel().getMatch().getInput().setInput(new Input() { private static final long serialVersionUID = 4820011040853968644L; @Override @@ -562,12 +560,12 @@ public class Upkeep extends Phase implements java.io.Serializable { final Ability ability = new Ability(c, "") { @Override public void resolve() { - final List creatures = GameState.getCreaturesInPlay(); + final List creatures = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); if (creatures.size() > 0) { CardLists.sortAttackLowFirst(creatures); final int power = creatures.get(0).getNetAttack(); if (player.isHuman()) { - AllZone.getInputControl().setInput( + Singletons.getModel().getMatch().getInput().setInput( CardFactoryUtil.inputDestroyNoRegeneration(this.getLowestPowerList(creatures), "Select creature with power: " + power + " to sacrifice.")); } else { // computer @@ -637,12 +635,12 @@ public class Upkeep extends Phase implements java.io.Serializable { final Ability noPay = new Ability(c, "B B B") { @Override public void resolve() { - final List playerLand = GameState.getPlayerLandsInPlay(player); + final List playerLand = player.getLandsInPlay(); c.tap(); if (c.getController().isComputer()) { if (playerLand.size() > 0) { - AllZone.getInputControl().setInput( + Singletons.getModel().getMatch().getInput().setInput( PlayerUtil.inputSacrificePermanent(playerLand, c.getName() + " - Select a land to sacrifice.")); } @@ -661,7 +659,7 @@ public class Upkeep extends Phase implements java.io.Serializable { final Ability pay = new Ability(c, "0") { @Override public void resolve() { - if (GameState.getZoneOf(c).is(ZoneType.Battlefield)) { + if (Singletons.getModel().getGameState().getZoneOf(c).is(ZoneType.Battlefield)) { final StringBuilder cost = new StringBuilder(); cost.append("Pay cost for ").append(c).append("\r\n"); GameActionUtil.payManaDuringAbilityResolve(cost.toString(), noPay.getManaCost(), @@ -1235,11 +1233,11 @@ public class Upkeep extends Phase implements java.io.Serializable { } // player isComputer() else { - List humanCreatures = GameState.getCreaturesInPlay(player.getOpponent()); + List humanCreatures = player.getOpponent().getCreaturesInPlay(); humanCreatures = CardLists.getValidCards(humanCreatures, smallCreatures, k.getController(), k); humanCreatures = CardLists.getNotKeyword(humanCreatures, "Indestructible"); - List computerCreatures = GameState.getCreaturesInPlay(player); + List computerCreatures = player.getCreaturesInPlay(); computerCreatures = CardLists.getValidCards(computerCreatures, smallCreatures, k.getController(), k); computerCreatures = CardLists.getNotKeyword(computerCreatures, "Indestructible"); @@ -1256,7 +1254,7 @@ public class Upkeep extends Phase implements java.io.Serializable { } if (wantDamageCreatures) { - final List allCreatures = GameState.getCreaturesInPlay(); + final List allCreatures = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); for (final Card crd : allCreatures) { crd.addDamage(2, k); } @@ -1607,7 +1605,7 @@ public class Upkeep extends Phase implements java.io.Serializable { } if (wantMerfolkBuff) { - final List creatures = GameState.getCreaturesInPlay(player); + final List creatures = player.getCreaturesInPlay(); for (int i = 0; i < creatures.size(); i++) { if (!creatures.get(i).hasKeyword("Flying")) { creatures.get(i).addExtrinsicKeyword("Flying"); @@ -1618,7 +1616,7 @@ public class Upkeep extends Phase implements java.io.Serializable { @Override public void execute() { - final List creatures = GameState.getCreaturesInPlay(player); + final List creatures = player.getCreaturesInPlay(); for (int i = 0; i < creatures.size(); i++) { if (creatures.get(i).hasKeyword("Flying")) { creatures.get(i).removeExtrinsicKeyword("Flying"); @@ -1937,7 +1935,7 @@ public class Upkeep extends Phase implements java.io.Serializable { *

*/ private static void upkeepOathOfDruids() { - final List oathList = GameState.getCardsIn(ZoneType.Battlefield, "Oath of Druids"); + final List oathList = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Oath of Druids")); if (oathList.isEmpty()) { return; } @@ -2018,7 +2016,7 @@ public class Upkeep extends Phase implements java.io.Serializable { *

*/ private static void upkeepOathOfGhouls() { - final List oathList = GameState.getCardsIn(ZoneType.Battlefield, "Oath of Ghouls"); + final List oathList = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Oath of Ghouls")); if (oathList.isEmpty()) { return; } @@ -2068,7 +2066,7 @@ public class Upkeep extends Phase implements java.io.Serializable { */ private static void upkeepKarma() { final Player player = Singletons.getModel().getGameState().getPhaseHandler().getPlayerTurn(); - final List karmas = GameState.getCardsIn(ZoneType.Battlefield, "Karma"); + final List karmas = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Karma")); final List swamps = CardLists.getType(player.getCardsIn(ZoneType.Battlefield), "Swamp"); // determine how much damage to deal the current player @@ -2113,7 +2111,7 @@ public class Upkeep extends Phase implements java.io.Serializable { * controlled at the beginning of this turn. */ final Player player = Singletons.getModel().getGameState().getPhaseHandler().getPlayerTurn(); - final List list = GameState.getCardsIn(ZoneType.Battlefield, "Power Surge"); + final List list = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Power Surge")); final int damage = player.getNumPowerSurgeLands(); for (final Card surge : list) { @@ -2143,7 +2141,7 @@ public class Upkeep extends Phase implements java.io.Serializable { */ private static void upkeepTangleWire() { final Player player = Singletons.getModel().getGameState().getPhaseHandler().getPlayerTurn(); - final List wires = GameState.getCardsIn(ZoneType.Battlefield, "Tangle Wire"); + final List wires = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Tangle Wire")); for (final Card source : wires) { final SpellAbility ability = new Ability(source, "0") { @@ -2185,7 +2183,7 @@ public class Upkeep extends Phase implements java.io.Serializable { list.remove(toTap); } } else { - AllZone.getInputControl().setInput(new Input() { + Singletons.getModel().getMatch().getInput().setInput(new Input() { private static final long serialVersionUID = 5313424586016061612L; @Override @@ -2304,7 +2302,8 @@ public class Upkeep extends Phase implements java.io.Serializable { enchantment = CardFactoryUtil.getBestEnchantmentAI(enchantmentsInLibrary, this, false); } if (enchantment != null) { - GameAction.changeZone(GameState.getZoneOf(enchantment), + Singletons.getModel().getGameAction().changeZone( + Singletons.getModel().getGameState().getZoneOf(enchantment), enchantment.getOwner().getZone(ZoneType.Battlefield), enchantment, null); enchantment.enchantEntity(source.getEnchantingPlayer()); } diff --git a/src/main/java/forge/game/player/ComputerAIGeneral.java b/src/main/java/forge/game/player/ComputerAIGeneral.java index 1f29366fb75..51ae8c9ce9c 100644 --- a/src/main/java/forge/game/player/ComputerAIGeneral.java +++ b/src/main/java/forge/game/player/ComputerAIGeneral.java @@ -34,7 +34,6 @@ import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellPermanent; import forge.card.trigger.Trigger; import forge.card.trigger.TriggerType; -import forge.game.GameState; import forge.game.phase.CombatUtil; import forge.game.zone.ZoneType; @@ -311,7 +310,7 @@ public class ComputerAIGeneral implements Computer { */ @Override public final void declareBlockers() { - final List blockers = GameState.getCreaturesInPlay(player); + final List blockers = player.getCreaturesInPlay(); Singletons.getModel().getGameState().setCombat(ComputerUtilBlock.getBlockers(player, Singletons.getModel().getGameState().getCombat(), blockers)); diff --git a/src/main/java/forge/game/player/ComputerUtil.java b/src/main/java/forge/game/player/ComputerUtil.java index 8ca999d55c1..1d3d7f67451 100644 --- a/src/main/java/forge/game/player/ComputerUtil.java +++ b/src/main/java/forge/game/player/ComputerUtil.java @@ -52,7 +52,6 @@ import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; import forge.control.input.InputPayManaCostUtil; import forge.error.ErrorViewer; -import forge.game.GameState; import forge.game.phase.Combat; import forge.game.phase.CombatUtil; import forge.game.phase.PhaseType; @@ -1279,7 +1278,7 @@ public class ComputerUtil { public boolean apply(final Card c) { if (c.getSVar("NeedsToPlay").length() > 0) { final String needsToPlay = c.getSVar("NeedsToPlay"); - List list = GameState.getCardsIn(ZoneType.Battlefield); + List list = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); list = CardLists.getValidCards(list, needsToPlay.split(","), c.getController(), c); if (list.isEmpty()) { @@ -1963,7 +1962,7 @@ public class ComputerUtil { final Target tgt = sa.getTarget(); if (tgt != null) { - if (CardLists.getValidCards(GameState.getCardsIn(ZoneType.Battlefield), tgt.getValidTgts(), controller, sa.getSourceCard()).contains(card)) { + if (CardLists.getValidCards(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), tgt.getValidTgts(), controller, sa.getSourceCard()).contains(card)) { return true; } } else if (AbilityFactory.getDefinedCards(sa.getSourceCard(), mapParams.get("Defined"), sa) @@ -2012,7 +2011,7 @@ public class ComputerUtil { } final Target tgt = sa.getTarget(); if (tgt != null) { - if (CardLists.getValidCards(GameState.getCardsIn(ZoneType.Battlefield), tgt.getValidTgts(), controller, af.getHostCard()).contains(card)) { + if (CardLists.getValidCards(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), tgt.getValidTgts(), controller, af.getHostCard()).contains(card)) { prevented += AbilityFactory.calculateAmount(af.getHostCard(), mapParams.get("Amount"), sa); } @@ -2112,13 +2111,13 @@ public class ComputerUtil { // Otherwise, if life is possibly in danger, then this is fine. Combat combat = new Combat(); combat.initiatePossibleDefenders(ai); - List attackers = GameState.getCreaturesInPlay(ai.getOpponent()); + List attackers = ai.getOpponent().getCreaturesInPlay(); for (Card att : attackers) { if (CombatUtil.canAttackNextTurn(att)) { combat.addAttacker(att); } } - combat = ComputerUtilBlock.getBlockers(ai, combat, GameState.getCreaturesInPlay(ai)); + combat = ComputerUtilBlock.getBlockers(ai, combat, ai.getCreaturesInPlay()); if (!CombatUtil.lifeInDanger(ai, combat)) { // Otherwise, return false. Do not play now. ret = false; diff --git a/src/main/java/forge/game/player/ComputerUtilAttack.java b/src/main/java/forge/game/player/ComputerUtilAttack.java index dd510566cbb..992c5bb8e8f 100644 --- a/src/main/java/forge/game/player/ComputerUtilAttack.java +++ b/src/main/java/forge/game/player/ComputerUtilAttack.java @@ -33,7 +33,6 @@ import forge.Singletons; import forge.card.cardfactory.CardFactoryUtil; import forge.card.trigger.Trigger; import forge.card.trigger.TriggerType; -import forge.game.GameState; import forge.game.phase.Combat; import forge.game.phase.CombatUtil; import forge.game.zone.ZoneType; @@ -313,7 +312,7 @@ public class ComputerUtilAttack { // bonus TWICE humanBaseAttack = humanBaseAttack + humanExaltedBonus; } - final int totalExaltedAttack = GameState.isCardInPlay("Rafiq of the Many", opp) ? 2 * humanBaseAttack + final int totalExaltedAttack = opp.isCardInPlay("Rafiq of the Many") ? 2 * humanBaseAttack : humanBaseAttack; if (ai.getLife() - 3 <= totalExaltedAttack) { // We will lose if there is an Exalted attack -- keep one @@ -381,7 +380,7 @@ public class ComputerUtilAttack { */ private boolean doAssault(final Player ai) { // Beastmaster Ascension - if (GameState.isCardInPlay("Beastmaster Ascension", ai) + if (ai.isCardInPlay("Beastmaster Ascension") && (this.attackers.size() > 1)) { final List beastions = ai.getCardsIn(ZoneType.Battlefield, "Beastmaster Ascension"); int minCreatures = 7; diff --git a/src/main/java/forge/game/player/HumanPlayer.java b/src/main/java/forge/game/player/HumanPlayer.java index 94e594e914a..9b552eb95f5 100644 --- a/src/main/java/forge/game/player/HumanPlayer.java +++ b/src/main/java/forge/game/player/HumanPlayer.java @@ -20,7 +20,6 @@ package forge.game.player; import java.util.ArrayList; import java.util.List; -import forge.AllZone; import forge.Card; import forge.Singletons; @@ -126,7 +125,7 @@ public class HumanPlayer extends Player { /** {@inheritDoc} */ @Override public final List discard(final int num, final SpellAbility sa, final boolean duringResolution) { - AllZone.getInputControl().setInput(PlayerUtil.inputDiscard(num, sa), duringResolution); + Singletons.getModel().getMatch().getInput().setInput(PlayerUtil.inputDiscard(num, sa), duringResolution); // why is List returned? return new ArrayList(); @@ -136,7 +135,7 @@ public class HumanPlayer extends Player { @Override public final void discardUnless(final int num, final String uType, final SpellAbility sa) { if (this.getCardsIn(ZoneType.Hand).size() > 0) { - AllZone.getInputControl().setInput(PlayerUtil.inputDiscardNumUnless(num, uType, sa)); + Singletons.getModel().getMatch().getInput().setInput(PlayerUtil.inputDiscardNumUnless(num, uType, sa)); } } @@ -150,7 +149,7 @@ public class HumanPlayer extends Player { */ @Override protected final void discardChainsOfMephistopheles() { - AllZone.getInputControl().setInput(PlayerUtil.inputChainsDiscard(), true); + Singletons.getModel().getMatch().getInput().setInput(PlayerUtil.inputChainsDiscard(), true); } /** {@inheritDoc} */ @@ -182,7 +181,7 @@ public class HumanPlayer extends Player { @Override public final void sacrificePermanent(final String prompt, final List choices) { final Input in = PlayerUtil.inputSacrificePermanent(choices, prompt); - AllZone.getInputControl().setInput(in); + Singletons.getModel().getMatch().getInput().setInput(in); } /** {@inheritDoc} */ diff --git a/src/main/java/forge/game/player/Player.java b/src/main/java/forge/game/player/Player.java index a0a28a36518..bdf70f4f232 100644 --- a/src/main/java/forge/game/player/Player.java +++ b/src/main/java/forge/game/player/Player.java @@ -37,9 +37,11 @@ import forge.Card; import forge.CardLists; import forge.CardPredicates; +import forge.CardPredicates.Presets; import forge.CardUtil; import forge.Constant; import forge.Constant.Preferences; +import forge.Counters; import forge.GameActionUtil; import forge.GameEntity; import forge.Singletons; @@ -50,7 +52,6 @@ import forge.card.spellability.SpellAbility; import forge.card.staticability.StaticAbility; import forge.card.trigger.TriggerType; import forge.game.GameLossReason; -import forge.game.GameState; import forge.game.phase.PhaseHandler; import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZoneBattlefield; @@ -583,7 +584,7 @@ public abstract class Player extends GameEntity implements Comparable { @Override public final int staticDamagePrevention(final int damage, final Card source, final boolean isCombat) { - if (GameState.isCardInPlay("Leyline of Punishment")) { + if (Singletons.getModel().getGameState().isCardInPlay("Leyline of Punishment")) { return damage; } @@ -615,7 +616,7 @@ public abstract class Player extends GameEntity implements Comparable { } // Prevent Damage static abilities - final List allp = GameState.getCardsIn(ZoneType.Battlefield); + final List allp = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card ca : allp) { final ArrayList staticAbilities = ca.getStaticAbilities(); for (final StaticAbility stAb : staticAbilities) { @@ -624,12 +625,12 @@ public abstract class Player extends GameEntity implements Comparable { } // specific cards - if (GameState.isCardInPlay("Spirit of Resistance", this)) { - if ((GameState.getPlayerColorInPlay(this, Constant.Color.BLACK).size() > 0) - && (GameState.getPlayerColorInPlay(this, Constant.Color.BLUE).size() > 0) - && (GameState.getPlayerColorInPlay(this, Constant.Color.GREEN).size() > 0) - && (GameState.getPlayerColorInPlay(this, Constant.Color.RED).size() > 0) - && (GameState.getPlayerColorInPlay(this, Constant.Color.WHITE).size() > 0)) { + if (this.isCardInPlay("Spirit of Resistance")) { + if ((this.getColoredCardsInPlay(Constant.Color.BLACK).size() > 0) + && (this.getColoredCardsInPlay(Constant.Color.BLUE).size() > 0) + && (this.getColoredCardsInPlay(Constant.Color.GREEN).size() > 0) + && (this.getColoredCardsInPlay(Constant.Color.RED).size() > 0) + && (this.getColoredCardsInPlay(Constant.Color.WHITE).size() > 0)) { return 0; } } @@ -662,7 +663,7 @@ public abstract class Player extends GameEntity implements Comparable { int restDamage = damage; - for (Card c : GameState.getCardsIn(ZoneType.Battlefield)) { + for (Card c : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { if (c.getName().equals("Sulfuric Vapors")) { if (source.isSpell() && source.isRed()) { restDamage += 1; @@ -750,7 +751,7 @@ public abstract class Player extends GameEntity implements Comparable { return 0; } - if (GameState.isCardInPlay("Crumbling Sanctuary")) { + if (Singletons.getModel().getGameState().isCardInPlay("Crumbling Sanctuary")) { for (int i = 0; i < damage; i++) { final List lib = this.getCardsIn(ZoneType.Library); if (lib.size() > 0) { @@ -781,7 +782,7 @@ public abstract class Player extends GameEntity implements Comparable { @Override public final int preventDamage(final int damage, final Card source, final boolean isCombat) { - if (GameState.isCardInPlay("Leyline of Punishment") + if (Singletons.getModel().getGameState().isCardInPlay("Leyline of Punishment") || source.hasKeyword("Damage that would be dealt by CARDNAME can't be prevented.")) { return damage; } @@ -1194,7 +1195,7 @@ public abstract class Player extends GameEntity implements Comparable { } } - if (!firstFromDraw && GameState.isCardInPlay("Chains of Mephistopheles")) { + if (!firstFromDraw && Singletons.getModel().getGameState().isCardInPlay("Chains of Mephistopheles")) { if (!this.getZone(ZoneType.Hand).isEmpty()) { if (this.isHuman()) { this.discardChainsOfMephistopheles(); @@ -1827,7 +1828,7 @@ public abstract class Player extends GameEntity implements Comparable { } // CantBeCast static abilities - final List allp = GameState.getCardsIn(ZoneType.Battlefield); + final List allp = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card ca : allp) { final ArrayList staticAbilities = ca.getStaticAbilities(); for (final StaticAbility stAb : staticAbilities) { @@ -2724,4 +2725,59 @@ public abstract class Player extends GameEntity implements Comparable { if ( null == stats.getOutcome() ) // not lost? setOutcome(PlayerOutcome.win()); // then won! } + + /** + * use to get a list of creatures in play for a given player. + * + * @param player + * the player to get creatures for + * @return a List containing all creatures a given player has in play + */ + public List getCreaturesInPlay() { + return CardLists.filter(getCardsIn(ZoneType.Battlefield), Presets.CREATURES); + } + + /** + * use to get a list of all lands a given player has on the battlefield. + * + * @param player + * the player whose lands we want to get + * @return a List containing all lands the given player has in play + */ + public List getLandsInPlay() { + return CardLists.filter(getCardsIn(ZoneType.Battlefield), Presets.LANDS); + } + public boolean isCardInPlay(final String cardName) { + return Iterables.any(getZone(ZoneType.Battlefield), CardPredicates.nameEquals(cardName)); + } + + + public List getColoredCardsInPlay(final String color) { + return CardLists.filter(getCardsIn(ZoneType.Battlefield), new Predicate() { + @Override + public boolean apply(final Card c) { + final List colorList = CardUtil.getColors(c); + return colorList.contains(color); + } + }); + } + + public int getCounterDoublersMagnitude(final Counters type) { + int counterDoublers = getCardsIn(ZoneType.Battlefield, "Doubling Season").size(); + if(type == Counters.P1P1) { + counterDoublers += getCardsIn(ZoneType.Battlefield, "Corpsejack Menace").size(); + } + return (int) Math.pow(2, counterDoublers); // pow(a,0) = 1; pow(a,1) = a + // ... no worries about size + // = 0 + } + + public int getTokenDoublersMagnitude() { + final int tokenDoublers = getCardsIn(ZoneType.Battlefield, "Parallel Lives").size() + + getCardsIn(ZoneType.Battlefield, "Doubling Season").size(); + return (int) Math.pow(2, tokenDoublers); // pow(a,0) = 1; pow(a,1) = a + // ... no worries about size = + // 0 + } + } diff --git a/src/main/java/forge/game/zone/MagicStack.java b/src/main/java/forge/game/zone/MagicStack.java index 34fb93ec926..5274a98fc3f 100644 --- a/src/main/java/forge/game/zone/MagicStack.java +++ b/src/main/java/forge/game/zone/MagicStack.java @@ -28,6 +28,7 @@ import forge.AllZone; import forge.Card; import forge.CardLists; +import forge.CardPredicates; import forge.CardPredicates.Presets; import forge.Command; import forge.GameActionUtil; @@ -49,7 +50,6 @@ import forge.card.trigger.Trigger; import forge.card.trigger.TriggerType; import forge.control.input.Input; import forge.control.input.InputPayManaCostAbility; -import forge.game.GameState; import forge.game.phase.PhaseType; import forge.game.player.ComputerUtil; import forge.game.player.Player; @@ -276,7 +276,7 @@ public class MagicStack extends MyObservable { * * @return a boolean. */ - public final boolean getResolving() { + public final boolean isResolving() { return this.bResolving; } @@ -514,7 +514,7 @@ public class MagicStack extends MyObservable { public void execute() { ability.resolve(); final Card crd = sa.getSourceCard(); - AllZone.getInputControl().setInput( + Singletons.getModel().getMatch().getInput().setInput( new InputPayManaCostAbility("Pay X cost for " + crd.getName() + " (X=" + crd.getXManaCostPaid() + ")\r\n", ability.getManaCost(), this, unpaidCommand, true)); @@ -524,7 +524,7 @@ public class MagicStack extends MyObservable { final Card crd = sa.getSourceCard(); Player player = sp.getSourceCard().getController(); if (player.isHuman()) { - AllZone.getInputControl().setInput( + Singletons.getModel().getMatch().getInput().setInput( new InputPayManaCostAbility("Pay X cost for " + sp.getSourceCard().getName() + " (X=" + crd.getXManaCostPaid() + ")\r\n", ability.getManaCost(), paidCommand, unpaidCommand, true)); @@ -573,12 +573,12 @@ public class MagicStack extends MyObservable { && Singletons.getModel().getGameAction().getCostCuttingGetMultiKickerManaCostPaidColored() .equals("")) { - AllZone.getInputControl().setInput( + Singletons.getModel().getMatch().getInput().setInput( new InputPayManaCostAbility("Multikicker for " + sa.getSourceCard() + "\r\n" + "Times Kicked: " + sa.getSourceCard().getMultiKickerMagnitude() + "\r\n", manaCost.toString(), this, unpaidCommand)); } else { - AllZone.getInputControl() + Singletons.getModel().getMatch().getInput() .setInput( new InputPayManaCostAbility( "Multikicker for " @@ -609,12 +609,12 @@ public class MagicStack extends MyObservable { } else { if ((Singletons.getModel().getGameAction().getCostCuttingGetMultiKickerManaCostPaid() == 0) && Singletons.getModel().getGameAction().getCostCuttingGetMultiKickerManaCostPaidColored().equals("")) { - AllZone.getInputControl().setInput( + Singletons.getModel().getMatch().getInput().setInput( new InputPayManaCostAbility("Multikicker for " + sa.getSourceCard() + "\r\n" + "Times Kicked: " + sa.getSourceCard().getMultiKickerMagnitude() + "\r\n", manaCost.toString(), paidCommand, unpaidCommand)); } else { - AllZone.getInputControl().setInput( + Singletons.getModel().getMatch().getInput().setInput( new InputPayManaCostAbility( "Multikicker for " + sa.getSourceCard() @@ -675,7 +675,7 @@ public class MagicStack extends MyObservable { this.execute(); } else { - AllZone.getInputControl().setInput( + Singletons.getModel().getMatch().getInput().setInput( new InputPayManaCostAbility("Replicate for " + sa.getSourceCard() + "\r\n" + "Times Replicated: " + sa.getSourceCard().getReplicateMagnitude() + "\r\n", manaCost.toString(), this, unpaidCommand)); @@ -690,7 +690,7 @@ public class MagicStack extends MyObservable { if (manaCost.isPaid()) { paidCommand.execute(); } else { - AllZone.getInputControl().setInput( + Singletons.getModel().getMatch().getInput().setInput( new InputPayManaCostAbility("Replicate for " + sa.getSourceCard() + "\r\n" + "Times Replicated: " + sa.getSourceCard().getReplicateMagnitude() + "\r\n", manaCost.toString(), paidCommand, unpaidCommand)); @@ -775,11 +775,11 @@ public class MagicStack extends MyObservable { * name is in a graveyard or a nontoken permanent with the same name is * on the battlefield. */ - if (sp.isSpell() && GameState.isCardInPlay("Bazaar of Wonders")) { + if (sp.isSpell() && Singletons.getModel().getGameState().isCardInPlay("Bazaar of Wonders")) { boolean found = false; - List all = GameState.getCardsIn(ZoneType.Battlefield); + List all = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); all = CardLists.filter(all, Presets.NON_TOKEN); - final List graves = GameState.getCardsIn(ZoneType.Graveyard); + final List graves = Singletons.getModel().getGameState().getCardsIn(ZoneType.Graveyard); all.addAll(graves); for (final Card c : all) { @@ -789,7 +789,7 @@ public class MagicStack extends MyObservable { } if (found) { - final List bazaars = GameState.getCardsIn(ZoneType.Battlefield, "Bazaar of Wonders"); // should + final List bazaars = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Bazaar of Wonders")); // should // only // be // 1... @@ -911,8 +911,8 @@ public class MagicStack extends MyObservable { sa.getSourceCard().setXManaCostPaid(0); if (source.hasStartOfKeyword("Haunt") && !source.isCreature() - && GameState.getZoneOf(source).is(ZoneType.Graveyard)) { - final List creats = GameState.getCreaturesInPlay(); + && Singletons.getModel().getGameState().getZoneOf(source).is(ZoneType.Graveyard)) { + final List creats = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); final Ability haunterDiesWork = new Ability(source, "0") { @Override public void resolve() { @@ -954,7 +954,7 @@ public class MagicStack extends MyObservable { }; if (source.getController().isHuman()) { - AllZone.getInputControl().setInput(target); + Singletons.getModel().getMatch().getInput().setInput(target); } else { // AI choosing what to haunt final List oppCreats = CardLists.filterControlledBy(creats, source.getController().getOpponent()); @@ -994,7 +994,7 @@ public class MagicStack extends MyObservable { sa.setFlashBackAbility(false); } else if (source.hasKeyword("Rebound") && source.getCastFrom() == ZoneType.Hand - && GameState.getZoneOf(source).is(ZoneType.Stack) + && Singletons.getModel().getGameState().getZoneOf(source).is(ZoneType.Stack) && source.getOwner().equals(source.getController())) //"If you cast this spell from your hand" { @@ -1058,7 +1058,7 @@ public class MagicStack extends MyObservable { final Card tmp = sa.getSourceCard(); tmp.setCanCounter(true); // reset mana pumped counter magic flag if (tmp.getClones().size() > 0) { - for (final Card c : GameState.getCardsIn(ZoneType.Battlefield)) { + for (final Card c : Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)) { if (c.equals(tmp)) { c.setClones(tmp.getClones()); } @@ -1106,7 +1106,7 @@ public class MagicStack extends MyObservable { } else if (o instanceof Card) { final Card card = (Card) o; - Card current = GameState.getCardState(card); + Card current = Singletons.getModel().getGameState().getCardState(card); invalidTarget = current.getTimestamp() != card.getTimestamp(); @@ -1471,7 +1471,7 @@ public class MagicStack extends MyObservable { * @return true, if is resolving */ public final boolean isResolving(Card c) { - if (!this.getResolving() || this.curResolvingCard == null) { + if (!this.isResolving() || this.curResolvingCard == null) { return false; } diff --git a/src/main/java/forge/game/zone/PlayerZone.java b/src/main/java/forge/game/zone/PlayerZone.java index c8734559f4b..c0ed2290751 100644 --- a/src/main/java/forge/game/zone/PlayerZone.java +++ b/src/main/java/forge/game/zone/PlayerZone.java @@ -29,7 +29,6 @@ import forge.Card; import forge.Singletons; import forge.card.trigger.TriggerType; -import forge.game.GameState; import forge.game.player.Player; import forge.util.MyObservable; @@ -83,7 +82,7 @@ public class PlayerZone extends MyObservable implements IPlayerZone, Observer, j // don't want to log those. if (!c.isImmutable()) { this.cardsAddedThisTurn.add(c); - final PlayerZone zone = GameState.getZoneOf(c); + final PlayerZone zone = Singletons.getModel().getGameState().getZoneOf(c); if (zone != null) { this.cardsAddedThisTurnSource.add(zone.getZoneType()); } else { @@ -163,7 +162,7 @@ public class PlayerZone extends MyObservable implements IPlayerZone, Observer, j // don't want to log those. if (!c.isImmutable()) { this.cardsAddedThisTurn.add(c); - final PlayerZone zone = GameState.getZoneOf(c); + final PlayerZone zone = Singletons.getModel().getGameState().getZoneOf(c); if (zone != null) { this.cardsAddedThisTurnSource.add(zone.getZoneType()); } else { diff --git a/src/main/java/forge/game/zone/PlayerZoneBattlefield.java b/src/main/java/forge/game/zone/PlayerZoneBattlefield.java index 753b80f3dd4..2b69c4e4d4b 100644 --- a/src/main/java/forge/game/zone/PlayerZoneBattlefield.java +++ b/src/main/java/forge/game/zone/PlayerZoneBattlefield.java @@ -27,6 +27,7 @@ import com.google.common.collect.Lists; import forge.Card; import forge.CardLists; +import forge.CardPredicates; import forge.CardPredicates.Presets; import forge.Command; import forge.GameActionUtil; @@ -34,7 +35,6 @@ import forge.Singletons; import forge.card.spellability.Ability; import forge.card.spellability.SpellAbility; import forge.card.staticability.StaticAbility; -import forge.game.GameState; import forge.game.player.Player; /** @@ -84,7 +84,7 @@ public class PlayerZoneBattlefield extends PlayerZone { c.setTapped(true); } else { // ETBTapped static abilities - final List allp = GameState.getCardsIn(ZoneType.Battlefield); + final List allp = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); for (final Card ca : allp) { final ArrayList staticAbilities = ca.getStaticAbilities(); for (final StaticAbility stAb : staticAbilities) { @@ -123,7 +123,7 @@ public class PlayerZoneBattlefield extends PlayerZone { if (c.isLand()) { // Tectonic Instability - final List tis = GameState.getCardsIn(ZoneType.Battlefield, "Tectonic Instability"); + final List tis = CardLists.filter(Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Tectonic Instability")); final Card tisLand = c; for (final Card ti : tis) { final Card source = ti; @@ -152,7 +152,7 @@ public class PlayerZoneBattlefield extends PlayerZone { final SpellAbility ability = new Ability(source, "") { @Override public void resolve() { - final List lands = GameState.getPlayerLandsInPlay(lesLand.getOwner()); + final List lands = lesLand.getOwner().getLandsInPlay(); lesLand.getOwner().sacrificePermanent(source.getName() + " - Select a land to sacrifice", lands); } @@ -161,8 +161,8 @@ public class PlayerZoneBattlefield extends PlayerZone { sb.append(source).append(" - "); sb.append(tisLand.getController()).append(" sacrifices a land."); ability.setStackDescription(sb.toString()); - final List pLands = GameState.getPlayerLandsInPlay(lesLand.getOwner()); - final List oLands = GameState.getPlayerLandsInPlay(lesLand.getOwner().getOpponent()); + final List pLands = lesLand.getOwner().getLandsInPlay(); + final List oLands = lesLand.getOwner().getOpponent().getLandsInPlay(); // (pLands - 1) because this land is in play, and the // ability is before it is in play if (oLands.size() <= (pLands.size() - 1)) { diff --git a/src/main/java/forge/gui/GuiDisplayUtil.java b/src/main/java/forge/gui/GuiDisplayUtil.java index 213856061ba..19de79caea7 100644 --- a/src/main/java/forge/gui/GuiDisplayUtil.java +++ b/src/main/java/forge/gui/GuiDisplayUtil.java @@ -42,7 +42,6 @@ import forge.Counters; import forge.Singletons; import forge.card.spellability.AbilityMana; import forge.card.trigger.TriggerType; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.game.zone.ZoneType; @@ -681,7 +680,7 @@ public final class GuiDisplayUtil { * @since 1.0.15 */ public static void devModeAddCounter() { - final Card o = GuiChoose.oneOrNone("Add counters to which card?", GameState.getCardsIn(ZoneType.Battlefield)); + final Card o = GuiChoose.oneOrNone("Add counters to which card?", Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield)); if (null == o) { return; } else { @@ -712,7 +711,7 @@ public final class GuiDisplayUtil { * @since 1.0.15 */ public static void devModeTapPerm() { - final List play = GameState.getCardsIn(ZoneType.Battlefield); + final List play = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); final Object o = GuiChoose.oneOrNone("Choose a permanent", play); if (null == o) { return; @@ -730,7 +729,7 @@ public final class GuiDisplayUtil { * @since 1.0.15 */ public static void devModeUntapPerm() { - final List play = GameState.getCardsIn(ZoneType.Battlefield); + final List play = Singletons.getModel().getGameState().getCardsIn(ZoneType.Battlefield); final Object o = GuiChoose.oneOrNone("Choose a permanent", play); if (null == o) { return; diff --git a/src/main/java/forge/gui/GuiInput.java b/src/main/java/forge/gui/GuiInput.java index 3a629c936eb..432874c1e73 100644 --- a/src/main/java/forge/gui/GuiInput.java +++ b/src/main/java/forge/gui/GuiInput.java @@ -20,10 +20,9 @@ package forge.gui; import java.util.Observable; import java.util.Observer; -import forge.AllZone; import forge.Card; +import forge.Singletons; import forge.control.input.Input; -import forge.game.GameState; import forge.game.player.Player; import forge.game.zone.PlayerZone; import forge.util.MyObservable; @@ -45,7 +44,7 @@ public class GuiInput extends MyObservable implements Observer { /** {@inheritDoc} */ @Override public final void update(final Observable observable, final Object obj) { - final Input tmp = AllZone.getInputControl().updateInput(); + final Input tmp = Singletons.getModel().getMatch().getInput().updateInput(); if (tmp != null) { this.setInput(tmp); } @@ -64,15 +63,6 @@ public class GuiInput extends MyObservable implements Observer { this.input.showMessage(); } - /** - *

- * showMessage. - *

- */ - public final void showMessage() { - this.getInput().showMessage(); - } - /** *

* selectButtonOK. @@ -128,12 +118,5 @@ public class GuiInput extends MyObservable implements Observer { return this.input; } - /** - * TODO: Write javadoc for this method. - */ - public void subscribe(GameState game) { - AllZone.getInputControl().addObserver(this); - game.getStack().addObserver(this); - game.getPhaseHandler().addObserver(this); - } + } diff --git a/src/main/java/forge/gui/match/controllers/CLog.java b/src/main/java/forge/gui/match/controllers/CLog.java index 679adfb746e..57f972099ad 100644 --- a/src/main/java/forge/gui/match/controllers/CLog.java +++ b/src/main/java/forge/gui/match/controllers/CLog.java @@ -4,7 +4,6 @@ import java.util.Observable; import java.util.Observer; import forge.Command; -import forge.game.GameState; import forge.gui.framework.ICDoc; import forge.gui.match.views.VLog; @@ -34,10 +33,6 @@ public enum CLog implements ICDoc, Observer { } - public void subscribe(GameState currentGame) { - currentGame.getGameLog().addObserver(this); - } - /* (non-Javadoc) * @see forge.gui.framework.ICDoc#update() */ diff --git a/src/main/java/forge/gui/match/controllers/CMessage.java b/src/main/java/forge/gui/match/controllers/CMessage.java index caede133f39..8bf944c853d 100644 --- a/src/main/java/forge/gui/match/controllers/CMessage.java +++ b/src/main/java/forge/gui/match/controllers/CMessage.java @@ -22,7 +22,6 @@ import java.awt.event.ActionListener; import forge.Command; import forge.Singletons; -import forge.game.GameState; import forge.game.MatchController; import forge.gui.GuiInput; import forge.gui.framework.ICDoc; @@ -61,10 +60,6 @@ public enum CMessage implements ICDoc { } }; - public void subscribe(GameState game) { - inputControl.subscribe(game); - } - @Override public void initialize() { VMessage.SINGLETON_INSTANCE.getBtnCancel().removeActionListener(actCancel); diff --git a/src/main/java/forge/gui/match/controllers/CStack.java b/src/main/java/forge/gui/match/controllers/CStack.java index e437d775059..80696a8a2d0 100644 --- a/src/main/java/forge/gui/match/controllers/CStack.java +++ b/src/main/java/forge/gui/match/controllers/CStack.java @@ -4,7 +4,6 @@ import java.util.Observable; import java.util.Observer; import forge.Command; -import forge.game.GameState; import forge.gui.framework.EDocID; import forge.gui.framework.ICDoc; import forge.gui.framework.SDisplayUtil; @@ -35,10 +34,6 @@ public enum CStack implements ICDoc, Observer { public void initialize() { } - public void subscribe(GameState currentGame) { - currentGame.getStack().addObserver(this); - } - /* (non-Javadoc) * @see forge.gui.framework.ICDoc#update() */ diff --git a/src/main/java/forge/gui/match/nonsingleton/CField.java b/src/main/java/forge/gui/match/nonsingleton/CField.java index 0bde0bfad68..7a3d48098ee 100644 --- a/src/main/java/forge/gui/match/nonsingleton/CField.java +++ b/src/main/java/forge/gui/match/nonsingleton/CField.java @@ -485,7 +485,7 @@ public class CField implements ICDoc { System.out.println("Stop trying to spend the AI's mana"); // TODO: Mindslaver might need to add changes here } else { - final Input in = AllZone.getInputControl().getInput(); + final Input in = Singletons.getModel().getMatch().getInput().getInput(); if (in instanceof InputMana) { // Do something ((InputMana) in).selectManaPool(Constant.Color.BLACK); @@ -499,7 +499,7 @@ public class CField implements ICDoc { System.out.println("Stop trying to spend the AI's mana"); // TODO: Mindslaver might need to add changes here } else { - final Input in = AllZone.getInputControl().getInput(); + final Input in = Singletons.getModel().getMatch().getInput().getInput(); if (in instanceof InputMana) { // Do something ((InputMana) in).selectManaPool(Constant.Color.BLUE); @@ -513,7 +513,7 @@ public class CField implements ICDoc { System.out.println("Stop trying to spend the AI's mana"); // TODO: Mindslaver might need to add changes here } else { - final Input in = AllZone.getInputControl().getInput(); + final Input in = Singletons.getModel().getMatch().getInput().getInput(); if (in instanceof InputMana) { // Do something ((InputMana) in).selectManaPool(Constant.Color.GREEN); @@ -527,7 +527,7 @@ public class CField implements ICDoc { System.out.println("Stop trying to spend the AI's mana"); // TODO: Mindslaver might need to add changes here } else { - final Input in = AllZone.getInputControl().getInput(); + final Input in = Singletons.getModel().getMatch().getInput().getInput(); if (in instanceof InputMana) { // Do something ((InputMana) in).selectManaPool(Constant.Color.RED); @@ -541,7 +541,7 @@ public class CField implements ICDoc { System.out.println("Stop trying to spend the AI's mana"); // TODO: Mindslaver might need to add changes here } else { - final Input in = AllZone.getInputControl().getInput(); + final Input in = Singletons.getModel().getMatch().getInput().getInput(); if (in instanceof InputMana) { // Do something ((InputMana) in).selectManaPool(Constant.Color.WHITE); @@ -555,7 +555,7 @@ public class CField implements ICDoc { System.out.println("Stop trying to spend the AI's mana"); // TODO: Mindslaver might need to add changes here } else { - final Input in = AllZone.getInputControl().getInput(); + final Input in = Singletons.getModel().getMatch().getInput().getInput(); if (in instanceof InputMana) { // Do something ((InputMana) in).selectManaPool(Constant.Color.COLORLESS); diff --git a/src/main/java/forge/model/FModel.java b/src/main/java/forge/model/FModel.java index 913a31d2dc9..15107abbf11 100644 --- a/src/main/java/forge/model/FModel.java +++ b/src/main/java/forge/model/FModel.java @@ -25,7 +25,6 @@ import java.io.OutputStream; import java.io.PrintStream; import java.util.List; -import forge.AllZone; import forge.Constant; import forge.Constant.Preferences; import forge.GameAction; @@ -34,7 +33,6 @@ import forge.card.CardBlock; import forge.card.EditionCollection; import forge.card.FatPackData; import forge.card.FormatCollection; -import forge.control.input.InputControl; import forge.deck.CardCollections; import forge.error.ExceptionHandler; import forge.game.GameState; @@ -73,10 +71,11 @@ public enum FModel { private BuildInfo buildInfo; private OutputStream logFileStream; - private final GameAction gameAction; + private final QuestPreferences questPreferences; private final ForgePreferences preferences; private GameState gameState; + private GameAction gameAction; private GauntletData gauntletData; private QuestController quest = null; @@ -128,7 +127,6 @@ public enum FModel { throw new RuntimeException(exn); } - this.gameAction = new GameAction(); this.questPreferences = new QuestPreferences(); this.gauntletData = new GauntletData(); @@ -144,9 +142,6 @@ public enum FModel { // TODO - there's got to be a better place for this...oblivion? Preferences.DEV_MODE = this.preferences.getPrefBoolean(FPref.DEV_MODE_ENABLED); - // Instantiate AI - AllZone.setInputControl(new InputControl(FModel.this)); - /// Wrong direction here. It is computer that lives inside player, not a player in computer testNetworkConnection(); @@ -429,6 +424,7 @@ public enum FModel { */ public GameState newGame(Iterable players) { gameState = new GameState(players); + gameAction = new GameAction(gameState); return gameState; } } diff --git a/src/main/java/forge/view/arcane/CardPanel.java b/src/main/java/forge/view/arcane/CardPanel.java index e6920352300..7ffd0bdf861 100644 --- a/src/main/java/forge/view/arcane/CardPanel.java +++ b/src/main/java/forge/view/arcane/CardPanel.java @@ -40,7 +40,6 @@ import forge.Card; import forge.Counters; import forge.ImageCache; import forge.Singletons; -import forge.game.GameState; import forge.gui.CardContainer; import forge.gui.toolbox.CardFaceSymbols; import forge.properties.ForgePreferences.FPref; @@ -414,7 +413,7 @@ public class CardPanel extends JPanel implements CardContainer { (this.cardYOffset + this.cardHeight) - (this.cardHeight / 8) - 16); } - if (this.getCard().isSick() && GameState.isCardInPlay(this.getCard())) { + if (this.getCard().isSick() && this.getCard().isInPlay()) { CardFaceSymbols.drawSymbol("summonsick", g, (this.cardXOffset + (this.cardWidth / 2)) - 16, (this.cardYOffset + this.cardHeight) - (this.cardHeight / 8) - 16); }