From 4cb64a18aa323a7612698f196d42a84b6038d882 Mon Sep 17 00:00:00 2001 From: drdev Date: Fri, 19 Sep 2014 21:45:24 +0000 Subject: [PATCH] Refactor dev mode cheat functions into separate class that through it's restricted access allows determining if a player as cheated during a game --- .gitattributes | 1 - .../main/java/forge/game/player/Player.java | 4 +- .../forge/game/player/PlayerController.java | 7 +- .../forge/screens/match/controllers/CDev.java | 28 +- .../screens/match/menus/DevModeMenu.java | 2 +- .../forge/screens/match/views/VDevMenu.java | 28 +- .../forge/player/PlayerControllerHuman.java | 532 ++++++++++++++++-- .../src/main/java/forge/util/DevModeUtil.java | 508 ----------------- .../src/main/java/forge/view/IGameView.java | 20 +- .../main/java/forge/view/WatchLocalGame.java | 56 +- 10 files changed, 522 insertions(+), 664 deletions(-) delete mode 100644 forge-gui/src/main/java/forge/util/DevModeUtil.java diff --git a/.gitattributes b/.gitattributes index 393aeec010a..1c75d38e82a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17080,7 +17080,6 @@ forge-gui/src/main/java/forge/sound/SoundEffectType.java -text forge-gui/src/main/java/forge/sound/SoundSystem.java -text forge-gui/src/main/java/forge/util/Base64Coder.java svneol=native#text/plain forge-gui/src/main/java/forge/util/Callback.java -text -forge-gui/src/main/java/forge/util/DevModeUtil.java -text forge-gui/src/main/java/forge/util/Evaluator.java -text forge-gui/src/main/java/forge/util/GuiDisplayUtil.java -text forge-gui/src/main/java/forge/util/HttpUtil.java svneol=native#text/plain diff --git a/forge-game/src/main/java/forge/game/player/Player.java b/forge-game/src/main/java/forge/game/player/Player.java index a7747d01475..e970d2471b7 100644 --- a/forge-game/src/main/java/forge/game/player/Player.java +++ b/forge-game/src/main/java/forge/game/player/Player.java @@ -185,8 +185,6 @@ public class Player extends GameEntity implements Comparable { private boolean isPlayingExtraTrun = false; - public boolean canCheatPlayUnlimitedLands = false; - private List lostOwnership = new ArrayList(); private List gainedOwnership = new ArrayList(); @@ -1923,7 +1921,7 @@ public class Player extends GameEntity implements Comparable { // **** Check for land play limit per turn **** // Dev Mode - if (this.canCheatPlayUnlimitedLands || this.hasKeyword("You may play any number of additional lands on each of your turns.")) { + if (this.getController().canPlayUnlimitedLands() || this.hasKeyword("You may play any number of additional lands on each of your turns.")) { return true; } diff --git a/forge-game/src/main/java/forge/game/player/PlayerController.java b/forge-game/src/main/java/forge/game/player/PlayerController.java index fe94ea6c60a..b8c37d9ee60 100644 --- a/forge-game/src/main/java/forge/game/player/PlayerController.java +++ b/forge-game/src/main/java/forge/game/player/PlayerController.java @@ -215,10 +215,11 @@ public abstract class PlayerController { public abstract List chooseSaToActivateFromOpeningHand(List usableFromOpeningHand); public abstract Mana chooseManaFromPool(List manaChoices); + public abstract String chooseSomeType(String kindOfType, SpellAbility sa, List validTypes, List invalidTypes, boolean isOptional); public final String chooseSomeType(String kindOfType, SpellAbility sa, List validTypes, List invalidTypes) { return chooseSomeType(kindOfType, sa, validTypes, invalidTypes, false); } - public abstract String chooseSomeType(String kindOfType, SpellAbility sa, List validTypes, List invalidTypes, boolean isOptional); + public abstract Object vote(SpellAbility sa, String prompt, List options, ArrayListMultimap votes); public abstract Pair chooseAndRemoveOrPutCounter(Card cardWithCounter); public abstract boolean confirmReplacementEffect(ReplacementEffect replacementEffect, SpellAbility effectSA, String question); @@ -286,4 +287,8 @@ public abstract class PlayerController { public boolean isGuiPlayer() { return false; } + + public boolean canPlayUnlimitedLands() { + return false; + } } \ No newline at end of file diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CDev.java b/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CDev.java index 6522b192643..cc208c6a947 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CDev.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/controllers/CDev.java @@ -27,7 +27,7 @@ public enum CDev implements ICDoc { public void togglePlayManyLandsPerTurn() { boolean newValue = !VDev.SINGLETON_INSTANCE.getLblUnlimitedLands().getToggled(); VDev.SINGLETON_INSTANCE.getLblUnlimitedLands().setToggled(newValue); - Singletons.getControl().getGameView().devSetUnlimitedLands(newValue); + Singletons.getControl().getGameView().cheat().setCanPlayUnlimitedLands(newValue); } private final MouseListener madMana = new MouseAdapter() { @@ -37,7 +37,7 @@ public enum CDev implements ICDoc { } }; public void generateMana() { - Singletons.getControl().getGameView().devGenerateMana(); + Singletons.getControl().getGameView().cheat().generateMana(); } private final MouseListener madSetup = new MouseAdapter() { @@ -47,7 +47,7 @@ public enum CDev implements ICDoc { } }; public void setupGameState() { - Singletons.getControl().getGameView().devSetupGameState(); + Singletons.getControl().getGameView().cheat().setupGameState(); } private final MouseListener madTutor = new MouseAdapter() { @@ -57,7 +57,7 @@ public enum CDev implements ICDoc { } }; public void tutorForCard() { - Singletons.getControl().getGameView().devTutorForCard(); + Singletons.getControl().getGameView().cheat().tutorForCard(); } private final MouseListener madCardToHand = new MouseAdapter() { @@ -67,7 +67,7 @@ public enum CDev implements ICDoc { } }; public void addCardToHand() { - Singletons.getControl().getGameView().devAddCardToHand(); + Singletons.getControl().getGameView().cheat().addCardToHand(); } private final MouseListener madCounter = new MouseAdapter() { @@ -77,7 +77,7 @@ public enum CDev implements ICDoc { } }; public void addCounterToPermanent() { - Singletons.getControl().getGameView().devAddCounterToPermanent(); + Singletons.getControl().getGameView().cheat().addCountersToPermanent(); } private final MouseListener madTap = new MouseAdapter() { @@ -87,7 +87,7 @@ public enum CDev implements ICDoc { } }; public void tapPermanent() { - Singletons.getControl().getGameView().devTapPermanent(); + Singletons.getControl().getGameView().cheat().tapPermanents(); } private final MouseListener madUntap = new MouseAdapter() { @@ -97,7 +97,7 @@ public enum CDev implements ICDoc { } }; public void untapPermanent() { - Singletons.getControl().getGameView().devUntapPermanent(); + Singletons.getControl().getGameView().cheat().untapPermanents(); } private final MouseListener madLife = new MouseAdapter() { @@ -107,7 +107,7 @@ public enum CDev implements ICDoc { } }; public void setPlayerLife() { - Singletons.getControl().getGameView().devSetPlayerLife(); + Singletons.getControl().getGameView().cheat().setPlayerLife(); } private final MouseListener madWinGame = new MouseAdapter() { @@ -117,7 +117,7 @@ public enum CDev implements ICDoc { } }; public void winGame() { - Singletons.getControl().getGameView().devWinGame(); + Singletons.getControl().getGameView().cheat().winGame(); } private final MouseListener madCardToBattlefield = new MouseAdapter() { @@ -127,7 +127,7 @@ public enum CDev implements ICDoc { } }; public void addCardToBattlefield() { - Singletons.getControl().getGameView().devAddCardToBattlefield(); + Singletons.getControl().getGameView().cheat().addCardToBattlefield(); } private final MouseListener madRiggedRoll = new MouseAdapter() { @@ -137,7 +137,7 @@ public enum CDev implements ICDoc { } }; public void riggedPlanerRoll() { - Singletons.getControl().getGameView().devRiggedPlanerRoll(); + Singletons.getControl().getGameView().cheat().riggedPlanarRoll(); } private final MouseListener madWalkToPlane = new MouseAdapter() { @@ -147,7 +147,7 @@ public enum CDev implements ICDoc { } }; public void planeswalkTo() { - Singletons.getControl().getGameView().devPlaneswalkTo(); + Singletons.getControl().getGameView().cheat().planeswalkTo(); } //========== End mouse listener inits @@ -186,6 +186,6 @@ public enum CDev implements ICDoc { */ @Override public void update() { - VDev.SINGLETON_INSTANCE.getLblUnlimitedLands().setToggled(Singletons.getControl().getGameView().devGetUnlimitedLands()); + VDev.SINGLETON_INSTANCE.getLblUnlimitedLands().setToggled(Singletons.getControl().getGameView().canPlayUnlimitedLands()); } } diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/menus/DevModeMenu.java b/forge-gui-desktop/src/main/java/forge/screens/match/menus/DevModeMenu.java index 76066e37ceb..661411c4f1b 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/menus/DevModeMenu.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/menus/DevModeMenu.java @@ -66,7 +66,7 @@ public class DevModeMenu implements ActionListener { menu.add(getMenuItem(DevMenuItem.WIN_GAME)); menu.addSeparator(); menu.add(getMenuItem(DevMenuItem.SETUP_GAME_STATE)); - menu.add(getCheckboxMenuItem(DevMenuItem.PLAY_UNLIMITED_LANDS, Singletons.getControl().getGameView().devGetUnlimitedLands())); + menu.add(getCheckboxMenuItem(DevMenuItem.PLAY_UNLIMITED_LANDS, Singletons.getControl().getGameView().canPlayUnlimitedLands())); menu.add(getMenuItem(DevMenuItem.ADD_COUNTER)); menu.addSeparator(); menu.add(getMenuItem(DevMenuItem.TAP_PERMANENT)); diff --git a/forge-gui-mobile/src/forge/screens/match/views/VDevMenu.java b/forge-gui-mobile/src/forge/screens/match/views/VDevMenu.java index 69b16c89879..96b817e7932 100644 --- a/forge-gui-mobile/src/forge/screens/match/views/VDevMenu.java +++ b/forge-gui-mobile/src/forge/screens/match/views/VDevMenu.java @@ -17,7 +17,7 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { //must invoke all these in game thread since they may require synchronous user input @Override public void run() { - FControl.getGameView().devGenerateMana(); + FControl.getGameView().cheat().generateMana(); } }); } @@ -28,7 +28,7 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - FControl.getGameView().devTutorForCard(); + FControl.getGameView().cheat().tutorForCard(); } }); } @@ -39,7 +39,7 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - FControl.getGameView().devAddCardToHand(); + FControl.getGameView().cheat().addCardToHand(); } }); } @@ -50,7 +50,7 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - FControl.getGameView().devAddCardToBattlefield(); + FControl.getGameView().cheat().addCardToBattlefield(); } }); } @@ -61,7 +61,7 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - FControl.getGameView().devSetPlayerLife(); + FControl.getGameView().cheat().setPlayerLife(); } }); } @@ -72,7 +72,7 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - FControl.getGameView().devWinGame(); + FControl.getGameView().cheat().winGame(); } }); } @@ -83,18 +83,18 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - FControl.getGameView().devSetupGameState(); + FControl.getGameView().cheat().setupGameState(); } }); } })); - final boolean unlimitedLands = FControl.getGameView().devGetUnlimitedLands(); + final boolean unlimitedLands = FControl.getGameView().canPlayUnlimitedLands(); addItem(new FCheckBoxMenuItem("Play Unlimited Lands", unlimitedLands, new FEventHandler() { @Override public void handleEvent(FEvent e) { - FControl.getGameView().devSetUnlimitedLands(!unlimitedLands); + FControl.getGameView().cheat().setCanPlayUnlimitedLands(!unlimitedLands); } })); addItem(new FMenuItem("Add Counters to Permanent", new FEventHandler() { @@ -103,7 +103,7 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - FControl.getGameView().devAddCounterToPermanent(); + FControl.getGameView().cheat().addCountersToPermanent(); } }); } @@ -114,7 +114,7 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - FControl.getGameView().devTapPermanent(); + FControl.getGameView().cheat().tapPermanents(); } }); } @@ -125,7 +125,7 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - FControl.getGameView().devUntapPermanent(); + FControl.getGameView().cheat().untapPermanents(); } }); } @@ -136,7 +136,7 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - FControl.getGameView().devRiggedPlanerRoll(); + FControl.getGameView().cheat().riggedPlanarRoll(); } }); } @@ -147,7 +147,7 @@ public class VDevMenu extends FDropDownMenu { ThreadUtil.invokeInGameThread(new Runnable() { @Override public void run() { - FControl.getGameView().devPlaneswalkTo(); + FControl.getGameView().cheat().planeswalkTo(); } }); } diff --git a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java index 5470bb519f1..8d76a16ac23 100644 --- a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java +++ b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java @@ -1,8 +1,15 @@ package forge.player; +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -16,6 +23,7 @@ import org.apache.commons.lang3.tuple.Pair; import com.google.common.base.Function; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -24,6 +32,7 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import forge.LobbyPlayer; +import forge.card.CardCharacteristicName; import forge.card.ColorSet; import forge.card.MagicColor; import forge.card.mana.ManaCost; @@ -39,8 +48,11 @@ import forge.game.GameLogEntryType; import forge.game.GameObject; import forge.game.GameOutcome; import forge.game.GameType; +import forge.game.PlanarDice; import forge.game.ability.effects.CharmEffect; import forge.game.card.Card; +import forge.game.card.CardLists; +import forge.game.card.CardPredicates; import forge.game.card.CardShields; import forge.game.card.CounterType; import forge.game.combat.Combat; @@ -54,16 +66,19 @@ import forge.game.player.Player; import forge.game.player.PlayerActionConfirmMode; import forge.game.player.PlayerController; import forge.game.replacement.ReplacementEffect; +import forge.game.spellability.AbilityManaPart; import forge.game.spellability.AbilitySub; import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbilityStackInstance; import forge.game.spellability.TargetChoices; import forge.game.trigger.Trigger; +import forge.game.trigger.TriggerType; import forge.game.trigger.WrappedAbility; import forge.game.zone.MagicStack; import forge.game.zone.Zone; import forge.game.zone.ZoneType; import forge.interfaces.IGuiBase; +import forge.item.IPaperCard; import forge.item.PaperCard; import forge.match.input.ButtonUtil; import forge.match.input.Input; @@ -80,8 +95,8 @@ import forge.match.input.InputSelectCardsForConvoke; import forge.match.input.InputSelectCardsFromList; import forge.match.input.InputSelectEntitiesFromList; import forge.model.FModel; +import forge.properties.ForgeConstants; import forge.properties.ForgePreferences.FPref; -import forge.util.DevModeUtil; import forge.util.ITriggerEvent; import forge.util.Lang; import forge.util.TextUtil; @@ -1318,16 +1333,14 @@ public class PlayerControllerHuman extends PlayerController { /* * What follows are the View methods. */ - private class GameView extends LocalGameView { - public GameView(Game game) { super(game); } @Override public GameOutcome.AnteResult getAnteResult() { - return this.getGame().getOutcome().anteResult.get(player); + return game.getOutcome().anteResult.get(player); } public void updateAchievements() { @@ -1449,64 +1462,6 @@ public class PlayerControllerHuman extends PlayerController { return card == null || !c.isFaceDown() || card.canCardFaceBeShownTo(player); } - // Dev mode functions - @Override - public boolean devGetUnlimitedLands() { - return player.canCheatPlayUnlimitedLands; - } - @Override - public void devSetUnlimitedLands(final boolean b) { - player.canCheatPlayUnlimitedLands = b; - } - @Override - public void devGenerateMana() { - DevModeUtil.devModeGenerateMana(game, PlayerControllerHuman.this); - } - @Override - public void devSetupGameState() { - DevModeUtil.devSetupGameState(game, PlayerControllerHuman.this); - } - @Override - public void devTutorForCard() { - DevModeUtil.devModeTutor(game, PlayerControllerHuman.this); - } - @Override - public void devAddCardToHand() { - DevModeUtil.devModeCardToHand(game, PlayerControllerHuman.this); - } - @Override - public void devAddCounterToPermanent() { - DevModeUtil.devModeAddCounter(game, PlayerControllerHuman.this); - } - @Override - public void devTapPermanent() { - DevModeUtil.devModeTapPerm(game, PlayerControllerHuman.this); - } - @Override - public void devUntapPermanent() { - DevModeUtil.devModeUntapPerm(game, PlayerControllerHuman.this); - } - @Override - public void devSetPlayerLife() { - DevModeUtil.devModeSetLife(game, PlayerControllerHuman.this); - } - @Override - public void devWinGame() { - DevModeUtil.devModeWinGame(game, PlayerControllerHuman.this); - } - @Override - public void devAddCardToBattlefield() { - DevModeUtil.devModeCardToBattlefield(game, PlayerControllerHuman.this); - } - @Override - public void devRiggedPlanerRoll() { - DevModeUtil.devModeRiggedPlanarRoll(game, PlayerControllerHuman.this); - } - @Override - public void devPlaneswalkTo() { - DevModeUtil.devModePlaneswalkTo(game, PlayerControllerHuman.this); - } - @Override public Iterable getAutoYields() { return PlayerControllerHuman.this.getAutoYields(); @@ -1564,6 +1519,16 @@ public class PlayerControllerHuman extends PlayerController { public void autoPassCancel() { PlayerControllerHuman.this.autoPassCancel(); } + + @Override + public boolean canPlayUnlimitedLands() { + return PlayerControllerHuman.this.canPlayUnlimitedLands(); + } + + @Override + public DevModeCheats cheat() { + return PlayerControllerHuman.this.cheat(); + } } /** @@ -1715,4 +1680,447 @@ public class PlayerControllerHuman extends PlayerController { // Not used by the human controller } + //Dev Mode cheat functions + private DevModeCheats cheats; + private boolean canPlayUnlimitedLands; + public DevModeCheats cheat() { + if (cheats == null) { + cheats = new DevModeCheats(); + //TODO: In Network game, inform other players that this player is cheating + } + return cheats; + } + public boolean hasCheated() { + return cheats != null; + } + @Override + public boolean canPlayUnlimitedLands() { + return canPlayUnlimitedLands; + } + public class DevModeCheats { + private DevModeCheats() { + } + + public void setCanPlayUnlimitedLands(boolean canPlayUnlimitedLands0) { + canPlayUnlimitedLands = canPlayUnlimitedLands0; + } + + public void generateMana() { + Player pPriority = game.getPhaseHandler().getPriorityPlayer(); + if (pPriority == null) { + SGuiDialog.message(getGui(), "No player has priority at the moment, so mana cannot be added to their pool."); + return; + } + + final Card dummy = new Card(-777777); + dummy.setOwner(pPriority); + Map produced = new HashMap(); + produced.put("Produced", "W W W W W W W U U U U U U U B B B B B B B G G G G G G G R R R R R R R 7"); + final AbilityManaPart abMana = new AbilityManaPart(dummy, produced); + game.getAction().invoke(new Runnable() { + @Override public void run() { abMana.produceMana(null); } + }); + } + + public void setupGameState() { + int humanLife = -1; + int computerLife = -1; + + final Map humanCardTexts = new EnumMap(ZoneType.class); + final Map aiCardTexts = new EnumMap(ZoneType.class); + + String tChangePlayer = "NONE"; + String tChangePhase = "NONE"; + + File gamesDir = new File(ForgeConstants.USER_GAMES_DIR); + if (!gamesDir.exists()) { // if the directory does not exist, try to create it + gamesDir.mkdir(); + } + + String filename = getGui().showFileDialog("Select Game State File", ForgeConstants.USER_GAMES_DIR); + if (filename == null) { + return; + } + + try { + final FileInputStream fstream = new FileInputStream(filename); + final DataInputStream in = new DataInputStream(fstream); + final BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + String temp = ""; + + while ((temp = br.readLine()) != null) { + + final String[] tempData = temp.split("="); + if (tempData.length < 2 || temp.charAt(0) == '#') { + continue; + } + + final String categoryName = tempData[0].toLowerCase(); + final String categoryValue = tempData[1]; + + if (categoryName.equals("humanlife")) humanLife = Integer.parseInt(categoryValue); + else if (categoryName.equals("ailife")) computerLife = Integer.parseInt(categoryValue); + + else if (categoryName.equals("activeplayer")) tChangePlayer = categoryValue.trim().toLowerCase(); + else if (categoryName.equals("activephase")) tChangePhase = categoryValue; + + else if (categoryName.equals("humancardsinplay")) humanCardTexts.put(ZoneType.Battlefield, categoryValue); + else if (categoryName.equals("aicardsinplay")) aiCardTexts.put(ZoneType.Battlefield, categoryValue); + else if (categoryName.equals("humancardsinhand")) humanCardTexts.put(ZoneType.Hand, categoryValue); + else if (categoryName.equals("aicardsinhand")) aiCardTexts.put(ZoneType.Hand, categoryValue); + else if (categoryName.equals("humancardsingraveyard")) humanCardTexts.put(ZoneType.Graveyard, categoryValue); + else if (categoryName.equals("aicardsingraveyard")) aiCardTexts.put(ZoneType.Graveyard, categoryValue); + else if (categoryName.equals("humancardsinlibrary")) humanCardTexts.put(ZoneType.Library, categoryValue); + else if (categoryName.equals("aicardsinlibrary")) aiCardTexts.put(ZoneType.Library, categoryValue); + else if (categoryName.equals("humancardsinexile")) humanCardTexts.put(ZoneType.Exile, categoryValue); + else if (categoryName.equals("aicardsinexile")) aiCardTexts.put(ZoneType.Exile, categoryValue); + } + + in.close(); + } + catch (final FileNotFoundException fnfe) { + SOptionPane.showErrorDialog(getGui(), "File not found: " + filename); + } + catch (final Exception e) { + SOptionPane.showErrorDialog(getGui(), "Error loading battle setup file!"); + return; + } + + setupGameState(humanLife, computerLife, humanCardTexts, aiCardTexts, tChangePlayer, tChangePhase); + } + + private void setupGameState(final int humanLife, final int computerLife, final Map humanCardTexts, + final Map aiCardTexts, final String tChangePlayer, final String tChangePhase) { + + Player pPriority = game.getPhaseHandler().getPriorityPlayer(); + if (pPriority == null) { + SGuiDialog.message(getGui(), "No player has priority at the moment, so game state cannot be setup."); + return; + } + game.getAction().invoke(new Runnable() { + @Override + public void run() { + final Player human = game.getPlayers().get(0); + final Player ai = game.getPlayers().get(1); + + Player newPlayerTurn = tChangePlayer.equals("human") ? newPlayerTurn = human : tChangePlayer.equals("ai") ? newPlayerTurn = ai : null; + PhaseType newPhase = tChangePhase.trim().equalsIgnoreCase("none") ? null : PhaseType.smartValueOf(tChangePhase); + + game.getPhaseHandler().devModeSet(newPhase, newPlayerTurn); + + game.getTriggerHandler().suppressMode(TriggerType.ChangesZone); + + setupPlayerState(humanLife, humanCardTexts, human); + setupPlayerState(computerLife, aiCardTexts, ai); + + game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone); + + game.getAction().checkStaticAbilities(true); + } + }); + } + + private void setupPlayerState(int life, Map cardTexts, final Player p) { + Map> humanCards = new EnumMap>(ZoneType.class); + for(Entry kv : cardTexts.entrySet()) { + humanCards.put(kv.getKey(), processCardsForZone(kv.getValue().split(";"), p)); + } + + if (life > 0) p.setLife(life, null); + for (Entry> kv : humanCards.entrySet()) { + if (kv.getKey() == ZoneType.Battlefield) { + for (final Card c : kv.getValue()) { + p.getZone(ZoneType.Hand).add(c); + p.getGame().getAction().moveToPlay(c); + c.setSickness(false); + } + } else { + p.getZone(kv.getKey()).setCards(kv.getValue()); + } + } + } + + /** + *

+ * processCardsForZone. + *

+ * + * @param data + * an array of {@link java.lang.String} objects. + * @param player + * a {@link forge.game.player.Player} object. + * @return a {@link forge.CardList} object. + */ + private List processCardsForZone(final String[] data, final Player player) { + final List cl = new ArrayList(); + for (final String element : data) { + final String[] cardinfo = element.trim().split("\\|"); + + final Card c = Card.fromPaperCard(FModel.getMagicDb().getCommonCards().getCard(cardinfo[0]), player); + + boolean hasSetCurSet = false; + for (final String info : cardinfo) { + if (info.startsWith("Set:")) { + c.setCurSetCode(info.substring(info.indexOf(':') + 1)); + hasSetCurSet = true; + } else if (info.equalsIgnoreCase("Tapped:True")) { + c.tap(); + } else if (info.startsWith("Counters:")) { + final String[] counterStrings = info.substring(info.indexOf(':') + 1).split(","); + for (final String counter : counterStrings) { + c.addCounter(CounterType.valueOf(counter), 1, true); + } + } else if (info.equalsIgnoreCase("SummonSick:True")) { + c.setSickness(true); + } else if (info.equalsIgnoreCase("FaceDown:True")) { + c.setState(CardCharacteristicName.FaceDown); + } + } + + if (!hasSetCurSet) { + c.setCurSetCode(c.getMostRecentSet()); + } + + cl.add(c); + } + return cl; + } + + /** + *

+ * Tutor. + *

+ * + * @since 1.0.15 + */ + public void tutorForCard() { + Player pPriority = game.getPhaseHandler().getPriorityPlayer(); + if (pPriority == null) { + SGuiDialog.message(getGui(), "No player has priority at the moment, so their deck can't be tutored from."); + return; + } + + final List lib = pPriority.getCardsIn(ZoneType.Library); + final List origin = new ArrayList(); + origin.add(ZoneType.Library); + SpellAbility sa = new SpellAbility.EmptySa(new Card(-1)); + final Card card = chooseSingleCardForZoneChange(ZoneType.Hand, origin, sa, lib, "Choose a card", true, pPriority); + if (card == null) { return; } + + game.getAction().invoke(new Runnable() { + @Override + public void run() { + game.getAction().moveToHand(card); + } + }); + } + + /** + *

+ * AddCounter. + *

+ * + * @since 1.0.15 + */ + public void addCountersToPermanent() { + final List cards = game.getCardsIn(ZoneType.Battlefield); + final CardView cardView = SGuiChoose.oneOrNone(getGui(), "Add counters to which card?", getCardViews(cards)); + final Card card = getCard(cardView); + if (card == null) { return; } + + final CounterType counter = SGuiChoose.oneOrNone(getGui(), "Which type of counter?", CounterType.values()); + if (counter == null) { return; } + + final Integer count = SGuiChoose.getInteger(getGui(), "How many counters?", 1, Integer.MAX_VALUE, 10); + if (count == null) { return; } + + card.addCounter(counter, count, false); + } + + public void tapPermanents() { + game.getAction().invoke(new Runnable() { + @Override + public void run() { + final List untapped = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), Predicates.not(CardPredicates.Presets.TAPPED)); + InputSelectCardsFromList inp = new InputSelectCardsFromList(PlayerControllerHuman.this, 0, Integer.MAX_VALUE, untapped); + inp.setCancelAllowed(true); + inp.setMessage("Choose permanents to tap"); + inp.showAndWait(); + if (!inp.hasCancelled()) { + for (Card c : inp.getSelected()) { + c.tap(); + } + } + } + }); + } + + public void untapPermanents() { + game.getAction().invoke(new Runnable() { + @Override + public void run() { + final List tapped = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.TAPPED); + InputSelectCardsFromList inp = new InputSelectCardsFromList(PlayerControllerHuman.this, 0, Integer.MAX_VALUE, tapped); + inp.setCancelAllowed(true); + inp.setMessage("Choose permanents to untap"); + inp.showAndWait(); + if( !inp.hasCancelled() ) + for(Card c : inp.getSelected()) + c.untap(); + } + }); + } + + public void setPlayerLife() { + final List players = game.getPlayers(); + final PlayerView playerView = SGuiChoose.oneOrNone(getGui(), "Set life for which player?", getPlayerViews(players)); + final Player player = getPlayer(playerView); + if (player == null) { return; } + + final Integer life = SGuiChoose.getInteger(getGui(), "Set life to what?", 0); + if (life == null) { return; } + + player.setLife(life, null); + } + + public void winGame() { + Input input = getGui().getInputQueue().getInput(); + if (!(input instanceof InputPassPriority)) { + SOptionPane.showMessageDialog(getGui(), "You must have priority to use this feature.", "Win Game", SOptionPane.INFORMATION_ICON); + return; + } + + //set life of all other players to 0 + final LobbyPlayer guiPlayer = getLobbyPlayer(); + final List players = game.getPlayers(); + for (Player player : players) { + if (player.getLobbyPlayer() != guiPlayer) { + player.setLife(0, null); + } + } + + //pass priority so that causes gui player to win + input.selectButtonOK(); + } + + public void addCardToHand() { + final List players = game.getPlayers(); + final PlayerView pView = SGuiChoose.oneOrNone(getGui(), "Put card in hand for which player?", getPlayerViews(players)); + final Player p = getPlayer(pView); + if (null == p) { + return; + } + + final List cards = Lists.newArrayList(FModel.getMagicDb().getCommonCards().getUniqueCards()); + Collections.sort(cards); + + // use standard forge's list selection dialog + final IPaperCard c = SGuiChoose.oneOrNone(getGui(), "Name the card", cards); + if (c == null) { + return; + } + + game.getAction().invoke(new Runnable() { @Override public void run() { + game.getAction().moveToHand(Card.fromPaperCard(c, p)); + }}); + } + + public void addCardToBattlefield() { + final List players = game.getPlayers(); + final PlayerView pView = SGuiChoose.oneOrNone(getGui(), "Put card in play for which player?", getPlayerViews(players)); + final Player p = getPlayer(pView); + if (null == p) { + return; + } + + final List cards = Lists.newArrayList(FModel.getMagicDb().getCommonCards().getUniqueCards()); + Collections.sort(cards); + + // use standard forge's list selection dialog + final IPaperCard c = SGuiChoose.oneOrNone(getGui(), "Name the card", cards); + if (c == null) { + return; + } + + game.getAction().invoke(new Runnable() { + @Override public void run() { + final Card forgeCard = Card.fromPaperCard(c, p); + + if (c.getRules().getType().isLand()) { + game.getAction().moveToPlay(forgeCard); + } else { + final List choices = forgeCard.getBasicSpells(); + if (choices.isEmpty()) { + return; // when would it happen? + } + + final SpellAbility sa; + if (choices.size() == 1) { + sa = choices.iterator().next(); + } else { + final SpellAbilityView saView = SGuiChoose.oneOrNone(getGui(), "Choose", getSpellAbilityViews(choices)); + sa = getSpellAbility(saView); + } + + if (sa == null) { + return; // happens if cancelled + } + + game.getAction().moveToHand(forgeCard); // this is really needed (for rollbacks at least) + // Human player is choosing targets for an ability controlled by chosen player. + sa.setActivatingPlayer(p); + HumanPlay.playSaWithoutPayingManaCost(PlayerControllerHuman.this, game, sa, true); + } + game.getStack().addAllTriggeredAbilitiesToStack(); // playSa could fire some triggers + } + }); + } + + public void riggedPlanarRoll() { + final List players = game.getPlayers(); + final PlayerView playerView = SGuiChoose.oneOrNone(getGui(), "Which player should roll?", getPlayerViews(players)); + final Player player = getPlayer(playerView); + if (player == null) { return; } + + final PlanarDice res = SGuiChoose.oneOrNone(getGui(), "Choose result", PlanarDice.values()); + if (res == null) { return; } + + System.out.println("Rigging planar dice roll: " + res.toString()); + + game.getAction().invoke(new Runnable() { + @Override + public void run() { + PlanarDice.roll(player, res); + } + }); + } + + public void planeswalkTo() { + if (!game.getRules().hasAppliedVariant(GameType.Planechase)) { return; } + final Player p = game.getPhaseHandler().getPlayerTurn(); + + final List allPlanars = new ArrayList(); + for (PaperCard c : FModel.getMagicDb().getVariantCards().getAllCards()) { + if (c.getRules().getType().isPlane() || c.getRules().getType().isPhenomenon()) { + allPlanars.add(c); + } + } + Collections.sort(allPlanars); + + // use standard forge's list selection dialog + final IPaperCard c = SGuiChoose.oneOrNone(getGui(), "Name the card", allPlanars); + if (c == null) { return; } + final Card forgeCard = Card.fromPaperCard(c, p); + + forgeCard.setOwner(p); + game.getAction().invoke(new Runnable() { + @Override + public void run() { + game.getAction().changeZone(null, p.getZone(ZoneType.PlanarDeck), forgeCard, 0); + PlanarDice.roll(p, PlanarDice.Planeswalk); + } + }); + } + } } diff --git a/forge-gui/src/main/java/forge/util/DevModeUtil.java b/forge-gui/src/main/java/forge/util/DevModeUtil.java deleted file mode 100644 index 5039a368cda..00000000000 --- a/forge-gui/src/main/java/forge/util/DevModeUtil.java +++ /dev/null @@ -1,508 +0,0 @@ -package forge.util; - -import java.io.BufferedReader; -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import com.google.common.base.Predicates; -import com.google.common.collect.Lists; - -import forge.LobbyPlayer; -import forge.card.CardCharacteristicName; -import forge.game.Game; -import forge.game.GameType; -import forge.game.PlanarDice; -import forge.game.card.Card; -import forge.game.card.CardLists; -import forge.game.card.CardPredicates; -import forge.game.card.CounterType; -import forge.game.phase.PhaseType; -import forge.game.player.Player; -import forge.game.spellability.AbilityManaPart; -import forge.game.spellability.SpellAbility; -import forge.game.trigger.TriggerType; -import forge.game.zone.ZoneType; -import forge.item.IPaperCard; -import forge.item.PaperCard; -import forge.match.input.Input; -import forge.match.input.InputPassPriority; -import forge.match.input.InputSelectCardsFromList; -import forge.model.FModel; -import forge.player.HumanPlay; -import forge.player.PlayerControllerHuman; -import forge.properties.ForgeConstants; -import forge.util.gui.SGuiChoose; -import forge.util.gui.SGuiDialog; -import forge.util.gui.SOptionPane; -import forge.view.CardView; -import forge.view.PlayerView; -import forge.view.SpellAbilityView; - -public final class DevModeUtil { - - private DevModeUtil() { - } - - public static void devModeGenerateMana(final Game game, final PlayerControllerHuman controller) { - Player pPriority = game.getPhaseHandler().getPriorityPlayer(); - if (pPriority == null) { - SGuiDialog.message(controller.getGui(), "No player has priority at the moment, so mana cannot be added to their pool."); - return; - } - - final Card dummy = new Card(-777777); - dummy.setOwner(pPriority); - Map produced = new HashMap(); - produced.put("Produced", "W W W W W W W U U U U U U U B B B B B B B G G G G G G G R R R R R R R 7"); - final AbilityManaPart abMana = new AbilityManaPart(dummy, produced); - game.getAction().invoke(new Runnable() { - @Override public void run() { abMana.produceMana(null); } - }); - } - - public static void devSetupGameState(final Game game, final PlayerControllerHuman controller) { - int humanLife = -1; - int computerLife = -1; - - final Map humanCardTexts = new EnumMap(ZoneType.class); - final Map aiCardTexts = new EnumMap(ZoneType.class); - - String tChangePlayer = "NONE"; - String tChangePhase = "NONE"; - - File gamesDir = new File(ForgeConstants.USER_GAMES_DIR); - if (!gamesDir.exists()) { // if the directory does not exist, try to create it - gamesDir.mkdir(); - } - - String filename = controller.getGui().showFileDialog("Select Game State File", ForgeConstants.USER_GAMES_DIR); - if (filename == null) { - return; - } - - try { - final FileInputStream fstream = new FileInputStream(filename); - final DataInputStream in = new DataInputStream(fstream); - final BufferedReader br = new BufferedReader(new InputStreamReader(in)); - - String temp = ""; - - while ((temp = br.readLine()) != null) { - - final String[] tempData = temp.split("="); - if (tempData.length < 2 || temp.charAt(0) == '#') { - continue; - } - - final String categoryName = tempData[0].toLowerCase(); - final String categoryValue = tempData[1]; - - if (categoryName.equals("humanlife")) humanLife = Integer.parseInt(categoryValue); - else if (categoryName.equals("ailife")) computerLife = Integer.parseInt(categoryValue); - - else if (categoryName.equals("activeplayer")) tChangePlayer = categoryValue.trim().toLowerCase(); - else if (categoryName.equals("activephase")) tChangePhase = categoryValue; - - else if (categoryName.equals("humancardsinplay")) humanCardTexts.put(ZoneType.Battlefield, categoryValue); - else if (categoryName.equals("aicardsinplay")) aiCardTexts.put(ZoneType.Battlefield, categoryValue); - else if (categoryName.equals("humancardsinhand")) humanCardTexts.put(ZoneType.Hand, categoryValue); - else if (categoryName.equals("aicardsinhand")) aiCardTexts.put(ZoneType.Hand, categoryValue); - else if (categoryName.equals("humancardsingraveyard")) humanCardTexts.put(ZoneType.Graveyard, categoryValue); - else if (categoryName.equals("aicardsingraveyard")) aiCardTexts.put(ZoneType.Graveyard, categoryValue); - else if (categoryName.equals("humancardsinlibrary")) humanCardTexts.put(ZoneType.Library, categoryValue); - else if (categoryName.equals("aicardsinlibrary")) aiCardTexts.put(ZoneType.Library, categoryValue); - else if (categoryName.equals("humancardsinexile")) humanCardTexts.put(ZoneType.Exile, categoryValue); - else if (categoryName.equals("aicardsinexile")) aiCardTexts.put(ZoneType.Exile, categoryValue); - } - - in.close(); - } - catch (final FileNotFoundException fnfe) { - SOptionPane.showErrorDialog(controller.getGui(), "File not found: " + filename); - } - catch (final Exception e) { - SOptionPane.showErrorDialog(controller.getGui(), "Error loading battle setup file!"); - return; - } - - setupGameState(game, humanLife, computerLife, humanCardTexts, aiCardTexts, tChangePlayer, tChangePhase, controller); - } - - private static void setupGameState(final Game game, final int humanLife, final int computerLife, final Map humanCardTexts, - final Map aiCardTexts, final String tChangePlayer, final String tChangePhase, final PlayerControllerHuman controller) { - - Player pPriority = game.getPhaseHandler().getPriorityPlayer(); - if (pPriority == null) { - SGuiDialog.message(controller.getGui(), "No player has priority at the moment, so game state cannot be setup."); - return; - } - game.getAction().invoke(new Runnable() { - @Override - public void run() { - final Player human = game.getPlayers().get(0); - final Player ai = game.getPlayers().get(1); - - Player newPlayerTurn = tChangePlayer.equals("human") ? newPlayerTurn = human : tChangePlayer.equals("ai") ? newPlayerTurn = ai : null; - PhaseType newPhase = tChangePhase.trim().equalsIgnoreCase("none") ? null : PhaseType.smartValueOf(tChangePhase); - - game.getPhaseHandler().devModeSet(newPhase, newPlayerTurn); - - game.getTriggerHandler().suppressMode(TriggerType.ChangesZone); - - devSetupPlayerState(humanLife, humanCardTexts, human); - devSetupPlayerState(computerLife, aiCardTexts, ai); - - game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone); - - game.getAction().checkStaticAbilities(true); - } - }); - } - - private static void devSetupPlayerState(int life, Map cardTexts, final Player p) { - Map> humanCards = new EnumMap>(ZoneType.class); - for(Entry kv : cardTexts.entrySet()) { - humanCards.put(kv.getKey(), devProcessCardsForZone(kv.getValue().split(";"), p)); - } - - if (life > 0) p.setLife(life, null); - for (Entry> kv : humanCards.entrySet()) { - if (kv.getKey() == ZoneType.Battlefield) { - for (final Card c : kv.getValue()) { - p.getZone(ZoneType.Hand).add(c); - p.getGame().getAction().moveToPlay(c); - c.setSickness(false); - } - } else { - p.getZone(kv.getKey()).setCards(kv.getValue()); - } - } - } - - /** - *

- * devProcessCardsForZone. - *

- * - * @param data - * an array of {@link java.lang.String} objects. - * @param player - * a {@link forge.game.player.Player} object. - * @return a {@link forge.CardList} object. - */ - private static List devProcessCardsForZone(final String[] data, final Player player) { - final List cl = new ArrayList(); - for (final String element : data) { - final String[] cardinfo = element.trim().split("\\|"); - - final Card c = Card.fromPaperCard(FModel.getMagicDb().getCommonCards().getCard(cardinfo[0]), player); - - boolean hasSetCurSet = false; - for (final String info : cardinfo) { - if (info.startsWith("Set:")) { - c.setCurSetCode(info.substring(info.indexOf(':') + 1)); - hasSetCurSet = true; - } else if (info.equalsIgnoreCase("Tapped:True")) { - c.tap(); - } else if (info.startsWith("Counters:")) { - final String[] counterStrings = info.substring(info.indexOf(':') + 1).split(","); - for (final String counter : counterStrings) { - c.addCounter(CounterType.valueOf(counter), 1, true); - } - } else if (info.equalsIgnoreCase("SummonSick:True")) { - c.setSickness(true); - } else if (info.equalsIgnoreCase("FaceDown:True")) { - c.setState(CardCharacteristicName.FaceDown); - } - } - - if (!hasSetCurSet) { - c.setCurSetCode(c.getMostRecentSet()); - } - - cl.add(c); - } - return cl; - } - - /** - *

- * devModeTutor. - *

- * - * @since 1.0.15 - */ - public static void devModeTutor(final Game game, final PlayerControllerHuman controller) { - Player pPriority = game.getPhaseHandler().getPriorityPlayer(); - if (pPriority == null) { - SGuiDialog.message(controller.getGui(), "No player has priority at the moment, so their deck can't be tutored from."); - return; - } - - final List lib = pPriority.getCardsIn(ZoneType.Library); - final List origin = new ArrayList(); - origin.add(ZoneType.Library); - SpellAbility sa = new SpellAbility.EmptySa(new Card(-1)); - final Card card = controller.chooseSingleCardForZoneChange(ZoneType.Hand, origin, sa, lib, "Choose a card", true, pPriority); - if (card == null) { return; } - - game.getAction().invoke(new Runnable() { - @Override - public void run() { - game.getAction().moveToHand(card); - } - }); - } - - /** - *

- * devModeAddCounter. - *

- * - * @since 1.0.15 - */ - public static void devModeAddCounter(final Game game, final PlayerControllerHuman controller) { - final List cards = game.getCardsIn(ZoneType.Battlefield); - final CardView cardView = SGuiChoose.oneOrNone(controller.getGui(), "Add counters to which card?", controller.getCardViews(cards)); - final Card card = controller.getCard(cardView); - if (card == null) { return; } - - final CounterType counter = SGuiChoose.oneOrNone(controller.getGui(), "Which type of counter?", CounterType.values()); - if (counter == null) { return; } - - final Integer count = SGuiChoose.getInteger(controller.getGui(), "How many counters?", 1, Integer.MAX_VALUE, 10); - if (count == null) { return; } - - card.addCounter(counter, count, false); - } - - /** - *

- * devModeTapPerm. - *

- * - * @since 1.0.15 - */ - public static void devModeTapPerm(final Game game, final PlayerControllerHuman controller) { - game.getAction().invoke(new Runnable() { - @Override - public void run() { - final List untapped = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), Predicates.not(CardPredicates.Presets.TAPPED)); - InputSelectCardsFromList inp = new InputSelectCardsFromList(controller, 0, Integer.MAX_VALUE, untapped); - inp.setCancelAllowed(true); - inp.setMessage("Choose permanents to tap"); - inp.showAndWait(); - if (!inp.hasCancelled()) { - for (Card c : inp.getSelected()) { - c.tap(); - } - } - } - }); - } - - /** - *

- * devModeUntapPerm. - *

- * - * @since 1.0.15 - */ - public static void devModeUntapPerm(final Game game, final PlayerControllerHuman controller) { - game.getAction().invoke(new Runnable() { - @Override - public void run() { - final List tapped = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.TAPPED); - InputSelectCardsFromList inp = new InputSelectCardsFromList(controller, 0, Integer.MAX_VALUE, tapped); - inp.setCancelAllowed(true); - inp.setMessage("Choose permanents to untap"); - inp.showAndWait(); - if( !inp.hasCancelled() ) - for(Card c : inp.getSelected()) - c.untap(); - } - }); - } - - /** - *

- * devModeSetLife. - *

- * - * @since 1.1.3 - */ - public static void devModeSetLife(final Game game, final PlayerControllerHuman controller) { - final List players = game.getPlayers(); - final PlayerView playerView = SGuiChoose.oneOrNone(controller.getGui(), "Set life for which player?", controller.getPlayerViews(players)); - final Player player = controller.getPlayer(playerView); - if (player == null) { return; } - - final Integer life = SGuiChoose.getInteger(controller.getGui(), "Set life to what?", 0); - if (life == null) { return; } - - player.setLife(life, null); - } - - /** - *

- * devModeWinGame. - *

- * - * @since 1.5.23 - */ - public static void devModeWinGame(final Game game, final PlayerControllerHuman controller) { - Input input = controller.getGui().getInputQueue().getInput(); - if (!(input instanceof InputPassPriority)) { - SOptionPane.showMessageDialog(controller.getGui(), "You must have priority to use this feature.", "Win Game", SOptionPane.INFORMATION_ICON); - return; - } - - //set life of all other players to 0 - final LobbyPlayer guiPlayer = controller.getLobbyPlayer(); - final List players = game.getPlayers(); - for (Player player : players) { - if (player.getLobbyPlayer() != guiPlayer) { - player.setLife(0, null); - } - } - - //pass priority so that causes gui player to win - input.selectButtonOK(); - } - - /** - *

- * devModeTutorAnyCard. - *

- * - * @since 1.2.7 - */ - public static void devModeCardToHand(final Game game, final PlayerControllerHuman controller) { - final List players = game.getPlayers(); - final PlayerView pView = SGuiChoose.oneOrNone(controller.getGui(), "Put card in hand for which player?", controller.getPlayerViews(players)); - final Player p = controller.getPlayer(pView); - if (null == p) { - return; - } - - final List cards = Lists.newArrayList(FModel.getMagicDb().getCommonCards().getUniqueCards()); - Collections.sort(cards); - - // use standard forge's list selection dialog - final IPaperCard c = SGuiChoose.oneOrNone(controller.getGui(), "Name the card", cards); - if (c == null) { - return; - } - - game.getAction().invoke(new Runnable() { @Override public void run() { - game.getAction().moveToHand(Card.fromPaperCard(c, p)); - }}); - } - - public static void devModeCardToBattlefield(final Game game, final PlayerControllerHuman controller) { - final List players = game.getPlayers(); - final PlayerView pView = SGuiChoose.oneOrNone(controller.getGui(), "Put card in play for which player?", controller.getPlayerViews(players)); - final Player p = controller.getPlayer(pView); - if (null == p) { - return; - } - - final List cards = Lists.newArrayList(FModel.getMagicDb().getCommonCards().getUniqueCards()); - Collections.sort(cards); - - // use standard forge's list selection dialog - final IPaperCard c = SGuiChoose.oneOrNone(controller.getGui(), "Name the card", cards); - if (c == null) { - return; - } - - game.getAction().invoke(new Runnable() { - @Override public void run() { - final Card forgeCard = Card.fromPaperCard(c, p); - - if (c.getRules().getType().isLand()) { - game.getAction().moveToPlay(forgeCard); - } else { - final List choices = forgeCard.getBasicSpells(); - if (choices.isEmpty()) { - return; // when would it happen? - } - - final SpellAbility sa; - if (choices.size() == 1) { - sa = choices.iterator().next(); - } else { - final SpellAbilityView saView = SGuiChoose.oneOrNone(controller.getGui(), "Choose", controller.getSpellAbilityViews(choices)); - sa = controller.getSpellAbility(saView); - } - - if (sa == null) { - return; // happens if cancelled - } - - game.getAction().moveToHand(forgeCard); // this is really needed (for rollbacks at least) - // Human player is choosing targets for an ability controlled by chosen player. - sa.setActivatingPlayer(p); - HumanPlay.playSaWithoutPayingManaCost(controller, game, sa, true); - } - game.getStack().addAllTriggeredAbilitiesToStack(); // playSa could fire some triggers - } - }); - } - - public static void devModeRiggedPlanarRoll(final Game game, final PlayerControllerHuman controller) { - final List players = game.getPlayers(); - final PlayerView playerView = SGuiChoose.oneOrNone(controller.getGui(), "Which player should roll?", controller.getPlayerViews(players)); - final Player player = controller.getPlayer(playerView); - if (player == null) { return; } - - final PlanarDice res = SGuiChoose.oneOrNone(controller.getGui(), "Choose result", PlanarDice.values()); - if (res == null) { return; } - - System.out.println("Rigging planar dice roll: " + res.toString()); - - game.getAction().invoke(new Runnable() { - @Override - public void run() { - PlanarDice.roll(player, res); - } - }); - } - - public static void devModePlaneswalkTo(final Game game, final PlayerControllerHuman controller) { - if (!game.getRules().hasAppliedVariant(GameType.Planechase)) { return; } - final Player p = game.getPhaseHandler().getPlayerTurn(); - - final List allPlanars = new ArrayList(); - for (PaperCard c : FModel.getMagicDb().getVariantCards().getAllCards()) { - if (c.getRules().getType().isPlane() || c.getRules().getType().isPhenomenon()) { - allPlanars.add(c); - } - } - Collections.sort(allPlanars); - - // use standard forge's list selection dialog - final IPaperCard c = SGuiChoose.oneOrNone(controller.getGui(), "Name the card", allPlanars); - if (c == null) { return; } - final Card forgeCard = Card.fromPaperCard(c, p); - - forgeCard.setOwner(p); - game.getAction().invoke(new Runnable() { - @Override - public void run() { - game.getAction().changeZone(null, p.getZone(ZoneType.PlanarDeck), forgeCard, 0); - PlanarDice.roll(p, PlanarDice.Planeswalk); - } - }); - } -} diff --git a/forge-gui/src/main/java/forge/view/IGameView.java b/forge-gui/src/main/java/forge/view/IGameView.java index 65c59d39fd1..63d67b3aa19 100644 --- a/forge-gui/src/main/java/forge/view/IGameView.java +++ b/forge-gui/src/main/java/forge/view/IGameView.java @@ -14,6 +14,7 @@ import forge.game.GameType; import forge.game.phase.PhaseType; import forge.match.input.Input; import forge.match.input.InputConfirm; +import forge.player.PlayerControllerHuman.DevModeCheats; import forge.util.ITriggerEvent; /** @@ -251,20 +252,9 @@ public interface IGameView { * automatically. */ public abstract void autoPassCancel(); + + public abstract boolean canPlayUnlimitedLands(); - public abstract boolean devGetUnlimitedLands(); - public abstract void devSetUnlimitedLands(boolean b); - public abstract void devGenerateMana(); - public abstract void devSetupGameState(); - public abstract void devTutorForCard(); - public abstract void devAddCardToHand(); - public abstract void devAddCounterToPermanent(); - public abstract void devTapPermanent(); - public abstract void devUntapPermanent(); - public abstract void devSetPlayerLife(); - public abstract void devWinGame(); - public abstract void devAddCardToBattlefield(); - public abstract void devRiggedPlanerRoll(); - public abstract void devPlaneswalkTo(); - + //method used to wrap all functions that cheat + public abstract DevModeCheats cheat(); } \ No newline at end of file diff --git a/forge-gui/src/main/java/forge/view/WatchLocalGame.java b/forge-gui/src/main/java/forge/view/WatchLocalGame.java index 8592ed74b74..219053c2a1b 100644 --- a/forge-gui/src/main/java/forge/view/WatchLocalGame.java +++ b/forge-gui/src/main/java/forge/view/WatchLocalGame.java @@ -7,6 +7,7 @@ import forge.game.Game; import forge.match.input.Input; import forge.match.input.InputPlaybackControl; import forge.match.input.InputQueue; +import forge.player.PlayerControllerHuman.DevModeCheats; import forge.util.ITriggerEvent; /** @@ -109,51 +110,6 @@ public class WatchLocalGame extends LocalGameView { return true; } - // Dev mode functions - @Override - public boolean devGetUnlimitedLands() { - return false; - } - @Override - public void devSetUnlimitedLands(final boolean b) { - } - @Override - public void devGenerateMana() { - } - @Override - public void devSetupGameState() { - } - @Override - public void devTutorForCard() { - } - @Override - public void devAddCardToHand() { - } - @Override - public void devAddCounterToPermanent() { - } - @Override - public void devTapPermanent() { - } - @Override - public void devUntapPermanent() { - } - @Override - public void devSetPlayerLife() { - } - @Override - public void devWinGame() { - } - @Override - public void devAddCardToBattlefield() { - } - @Override - public void devRiggedPlanerRoll() { - } - @Override - public void devPlaneswalkTo() { - } - @Override public Iterable getAutoYields() { return null; @@ -190,4 +146,14 @@ public class WatchLocalGame extends LocalGameView { public void autoPassCancel() { } + @Override + public boolean canPlayUnlimitedLands() { + return false; + } + + @Override + public DevModeCheats cheat() { + return null; + } + }