mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
More GUI code refactoring. Fixes all errors in forge-gui-desktop!
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -16829,6 +16829,7 @@ 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
|
||||
|
||||
@@ -536,7 +536,7 @@ public enum FControl implements KeyEventDispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
CDock.SINGLETON_INSTANCE.setModel(game0, humanLobbyPlayer);
|
||||
CDock.SINGLETON_INSTANCE.setModel(game0);
|
||||
CStack.SINGLETON_INSTANCE.setModel(game0, localPlayer);
|
||||
CPlayers.SINGLETON_INSTANCE.setModel(game0);
|
||||
CLog.SINGLETON_INSTANCE.setModel(game0.getGameLog());
|
||||
|
||||
@@ -1101,7 +1101,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
if (paperCard.isFoil()) {
|
||||
final CardView card = CardView.getCardForUi(paperCard);
|
||||
if (card.getFoilIndex() == 0) { //if foil finish not yet established, assign a random one
|
||||
card.setRandomFoil();
|
||||
card.card.setRandomFoil();
|
||||
}
|
||||
CardPanel.drawFoilEffect(g, card, bounds.x, bounds.y, bounds.width, bounds.height, borderSize);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,15 @@
|
||||
*/
|
||||
package forge.screens.match;
|
||||
|
||||
import forge.game.card.Card;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractListModel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.gui.CardDetailPanel;
|
||||
import forge.gui.CardPicturePanel;
|
||||
import forge.item.PaperCard;
|
||||
@@ -27,14 +35,7 @@ import forge.toolbox.FList;
|
||||
import forge.toolbox.FPanel;
|
||||
import forge.toolbox.FScrollPane;
|
||||
import forge.toolbox.FSkin;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import forge.view.CardView;
|
||||
|
||||
/**
|
||||
* A simple JPanel that shows three columns: card list, pic, and description..
|
||||
@@ -111,7 +112,7 @@ public class QuestWinLoseCardViewer extends FPanel {
|
||||
// (String) jList.getSelectedValue();
|
||||
if ((row >= 0) && (row < QuestWinLoseCardViewer.this.list.size())) {
|
||||
final PaperCard cp = QuestWinLoseCardViewer.this.list.get(row);
|
||||
QuestWinLoseCardViewer.this.detail.setCard(Card.getCardForUi(cp));
|
||||
QuestWinLoseCardViewer.this.detail.setCard(CardView.getCardForUi(cp), false);
|
||||
QuestWinLoseCardViewer.this.picture.setCard(cp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package forge.screens.match.controllers;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.UiCommand;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.game.player.Player;
|
||||
import forge.UiCommand;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.screens.match.views.VDev;
|
||||
import forge.util.GuiDisplayUtil;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
/**
|
||||
* Controls the combat panel in the match UI.
|
||||
@@ -44,13 +41,8 @@ public enum CDev implements ICDoc {
|
||||
VDev.SINGLETON_INSTANCE.getLblUnlimitedLands().toggleEnabled();
|
||||
boolean newValue = VDev.SINGLETON_INSTANCE.getLblUnlimitedLands().getEnabled();
|
||||
FModel.getPreferences().setPref(FPref.DEV_UNLIMITED_LAND, String.valueOf(newValue));
|
||||
|
||||
for(Player p : Singletons.getControl().getObservedGame().getPlayers()) {
|
||||
if( p.getLobbyPlayer() == GuiBase.getInterface().getGuiPlayer() )
|
||||
p.canCheatPlayUnlimitedLands = newValue;
|
||||
}
|
||||
Singletons.getControl().getGameView().devTogglePlayManyLands(newValue);
|
||||
// probably will need to call a synchronized method to have the game thread see changed value of the variable
|
||||
|
||||
FModel.getPreferences().save();
|
||||
}
|
||||
|
||||
@@ -59,7 +51,7 @@ public enum CDev implements ICDoc {
|
||||
generateMana(); }
|
||||
};
|
||||
public void generateMana() {
|
||||
GuiDisplayUtil.devModeGenerateMana();
|
||||
Singletons.getControl().getGameView().devGenerateMana();
|
||||
}
|
||||
|
||||
private final MouseListener madSetup = new MouseAdapter() { @Override
|
||||
@@ -67,7 +59,7 @@ public enum CDev implements ICDoc {
|
||||
setupGameState(); }
|
||||
};
|
||||
public void setupGameState() {
|
||||
GuiDisplayUtil.devSetupGameState();
|
||||
Singletons.getControl().getGameView().devSetupGameState();
|
||||
}
|
||||
|
||||
private final MouseListener madTutor = new MouseAdapter() { @Override
|
||||
@@ -75,7 +67,7 @@ public enum CDev implements ICDoc {
|
||||
tutorForCard(); }
|
||||
};
|
||||
public void tutorForCard() {
|
||||
GuiDisplayUtil.devModeTutor();
|
||||
Singletons.getControl().getGameView().devTutorForCard();
|
||||
}
|
||||
|
||||
private final MouseListener madCardToHand = new MouseAdapter() { @Override
|
||||
@@ -83,7 +75,7 @@ public enum CDev implements ICDoc {
|
||||
addCardToHand(); }
|
||||
};
|
||||
public void addCardToHand() {
|
||||
GuiDisplayUtil.devModeCardToHand();
|
||||
Singletons.getControl().getGameView().devAddCardToHand();
|
||||
}
|
||||
|
||||
private final MouseListener madCounter = new MouseAdapter() { @Override
|
||||
@@ -91,7 +83,7 @@ public enum CDev implements ICDoc {
|
||||
addCounterToPermanent(); }
|
||||
};
|
||||
public void addCounterToPermanent() {
|
||||
GuiDisplayUtil.devModeAddCounter();
|
||||
Singletons.getControl().getGameView().devAddCounterToPermanent();
|
||||
}
|
||||
|
||||
private final MouseListener madTap = new MouseAdapter() { @Override
|
||||
@@ -99,7 +91,7 @@ public enum CDev implements ICDoc {
|
||||
tapPermanent(); }
|
||||
};
|
||||
public void tapPermanent() {
|
||||
GuiDisplayUtil.devModeTapPerm();
|
||||
Singletons.getControl().getGameView().devTapPermanent();
|
||||
}
|
||||
|
||||
private final MouseListener madUntap = new MouseAdapter() { @Override
|
||||
@@ -107,7 +99,7 @@ public enum CDev implements ICDoc {
|
||||
untapPermanent(); }
|
||||
};
|
||||
public void untapPermanent() {
|
||||
GuiDisplayUtil.devModeUntapPerm();
|
||||
Singletons.getControl().getGameView().devUntapPermanent();
|
||||
}
|
||||
|
||||
private final MouseListener madLife = new MouseAdapter() { @Override
|
||||
@@ -115,7 +107,7 @@ public enum CDev implements ICDoc {
|
||||
setPlayerLife(); }
|
||||
};
|
||||
public void setPlayerLife() {
|
||||
GuiDisplayUtil.devModeSetLife();
|
||||
Singletons.getControl().getGameView().devSetPlayerLife();
|
||||
}
|
||||
|
||||
private final MouseListener madWinGame = new MouseAdapter() { @Override
|
||||
@@ -123,15 +115,15 @@ public enum CDev implements ICDoc {
|
||||
winGame(); }
|
||||
};
|
||||
public void winGame() {
|
||||
GuiDisplayUtil.devModeWinGame();
|
||||
Singletons.getControl().getGameView().devWinGame();
|
||||
}
|
||||
|
||||
private final MouseListener madCardToBattlefield = new MouseAdapter() { @Override
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
addCardToPlay(); }
|
||||
addCardToBattlefield(); }
|
||||
};
|
||||
public void addCardToPlay() {
|
||||
GuiDisplayUtil.devModeCardToBattlefield();
|
||||
public void addCardToBattlefield() {
|
||||
Singletons.getControl().getGameView().devAddCardToBattlefield();
|
||||
}
|
||||
|
||||
private final MouseListener madRiggedRoll = new MouseAdapter() { @Override
|
||||
@@ -139,7 +131,7 @@ public enum CDev implements ICDoc {
|
||||
riggedPlanerRoll(); }
|
||||
};
|
||||
public void riggedPlanerRoll() {
|
||||
GuiDisplayUtil.devModeRiggedPlanarRoll();
|
||||
Singletons.getControl().getGameView().devRiggedPlanerRoll();
|
||||
}
|
||||
|
||||
private final MouseListener madWalkToPlane = new MouseAdapter() { @Override
|
||||
@@ -147,7 +139,7 @@ public enum CDev implements ICDoc {
|
||||
planeswalkTo(); }
|
||||
};
|
||||
public void planeswalkTo() {
|
||||
GuiDisplayUtil.devModePlaneswalkTo();
|
||||
Singletons.getControl().getGameView().devPlaneswalkTo();
|
||||
}
|
||||
|
||||
//========== End mouse listener inits
|
||||
|
||||
@@ -17,22 +17,16 @@
|
||||
*/
|
||||
package forge.screens.match.controllers;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.GuiBase;
|
||||
import forge.LobbyPlayer;
|
||||
import forge.UiCommand;
|
||||
import forge.FThreads;
|
||||
import forge.Singletons;
|
||||
import forge.UiCommand;
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.deckchooser.FDeckViewer;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.CardPredicates.Presets;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.combat.CombatUtil;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.SOverlayUtils;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.gui.framework.SLayoutIO;
|
||||
@@ -47,9 +41,6 @@ import forge.toolbox.SaveOpenDialog.Filetypes;
|
||||
import forge.view.FView;
|
||||
import forge.view.IGameView;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controls the dock panel in the match UI.
|
||||
*
|
||||
@@ -62,25 +53,17 @@ public enum CDock implements ICDoc {
|
||||
private int arcState;
|
||||
private IGameView game;
|
||||
|
||||
public void setModel(IGameView game0, LobbyPlayer player0) {
|
||||
public void setModel(final IGameView game0) {
|
||||
game = game0;
|
||||
}
|
||||
|
||||
public Player findAffectedPlayer() {
|
||||
return Singletons.getControl().getCurrentPlayer();
|
||||
}
|
||||
|
||||
/**
|
||||
* End turn.
|
||||
*/
|
||||
public void endTurn() {
|
||||
Player p = findAffectedPlayer();
|
||||
|
||||
if (p != null) {
|
||||
p.getController().autoPassUntil(PhaseType.CLEANUP);
|
||||
game.autoPassUntilEndOfTurn();
|
||||
if (!CPrompt.SINGLETON_INSTANCE.getInputControl().passPriority()) {
|
||||
p.getController().autoPassCancel();
|
||||
}
|
||||
game.autoPassCancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,8 +161,9 @@ public enum CDock implements ICDoc {
|
||||
|
||||
/** Attack with everyone. */
|
||||
public void alphaStrike() {
|
||||
/* TODO: rewrite this!
|
||||
final Player p = this.findAffectedPlayer();
|
||||
final Combat combat = game.getCombat();
|
||||
final Combat combat = FControl.instance.getObservedGame().getCombat();
|
||||
if (this.game.isCombatDeclareAttackers()) {
|
||||
List<Player> defenders = p.getOpponents();
|
||||
|
||||
@@ -198,6 +182,7 @@ public enum CDock implements ICDoc {
|
||||
// TODO Is this redrawing immediately?
|
||||
FView.SINGLETON_INSTANCE.getFrame().repaint();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/** Toggle targeting overlay painting. */
|
||||
|
||||
@@ -31,7 +31,6 @@ public class DevModeMenu implements ActionListener {
|
||||
ADD_CARD_TO_PLAY("Add card to play"),
|
||||
RIGGED_PLANAR_ROLL("Rigged planar roll"),
|
||||
PLANESWALK_TO("Planeswalk to"),
|
||||
// LOSS_BY_MILLING("Loss by Milling"),
|
||||
PLAY_MANY_LANDS("Play many lands per Turn"),
|
||||
SETUP_GAME_STATE("Setup Game State"),
|
||||
ADD_COUNTER("Add Counter to Permanent"),
|
||||
@@ -68,7 +67,6 @@ public class DevModeMenu implements ActionListener {
|
||||
menu.add(getMenuItem(DevMenuItem.RIGGED_PLANAR_ROLL));
|
||||
menu.add(getMenuItem(DevMenuItem.PLANESWALK_TO));
|
||||
menu.addSeparator();
|
||||
// menu.add(getCheckboxMenuItem(DevMenuItem.LOSS_BY_MILLING, prefs.getPrefBoolean(FPref.DEV_MILLING_LOSS)));
|
||||
menu.add(getCheckboxMenuItem(DevMenuItem.PLAY_MANY_LANDS, prefs.getPrefBoolean(FPref.DEV_UNLIMITED_LAND)));
|
||||
menu.add(getMenuItem(DevMenuItem.SETUP_GAME_STATE));
|
||||
menu.add(getMenuItem(DevMenuItem.ADD_COUNTER));
|
||||
@@ -104,10 +102,9 @@ public class DevModeMenu implements ActionListener {
|
||||
case GENERATE_MANA: { controller.generateMana(); break; }
|
||||
case TUTOR_FOR_CARD: { controller.tutorForCard(); break; }
|
||||
case ADD_CARD_TO_HAND: { controller.addCardToHand(); break; }
|
||||
case ADD_CARD_TO_PLAY: { controller.addCardToPlay(); break; }
|
||||
case ADD_CARD_TO_PLAY: { controller.addCardToBattlefield(); break; }
|
||||
case RIGGED_PLANAR_ROLL:{ controller.riggedPlanerRoll(); break; }
|
||||
case PLANESWALK_TO: { controller.planeswalkTo(); break; }
|
||||
// case LOSS_BY_MILLING: { controller.toggleLossByMilling(); break; }
|
||||
case PLAY_MANY_LANDS: { controller.togglePlayManyLandsPerTurn(); break; }
|
||||
case SETUP_GAME_STATE: { controller.setupGameState(); break; }
|
||||
case ADD_COUNTER: { controller.addCounterToPermanent(); break; }
|
||||
|
||||
@@ -17,18 +17,20 @@
|
||||
*/
|
||||
package forge.toolbox.special;
|
||||
|
||||
import forge.game.card.Card;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractListModel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import forge.gui.CardDetailPanel;
|
||||
import forge.gui.CardPicturePanel;
|
||||
import forge.item.PaperCard;
|
||||
import forge.toolbox.FScrollPane;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import forge.view.CardView;
|
||||
|
||||
/**
|
||||
* A simple JPanel that shows three columns: card list, pic, and description..
|
||||
@@ -91,7 +93,7 @@ public class CardViewer extends JPanel {
|
||||
// (String) jList.getSelectedValue();
|
||||
if ((row >= 0) && (row < CardViewer.this.list.size())) {
|
||||
final PaperCard cp = CardViewer.this.list.get(row);
|
||||
CardViewer.this.detail.setCard(Card.getCardForUi(cp));
|
||||
CardViewer.this.detail.setCard(CardView.getCardForUi(cp), false);
|
||||
CardViewer.this.picture.setCard(cp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package forge.match.input;
|
||||
import forge.GuiBase;
|
||||
import forge.game.Game;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.match.MatchUtil;
|
||||
@@ -83,7 +82,7 @@ public class InputPassPriority extends InputSyncronizedBase {
|
||||
passPriority(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.getController().autoPassUntil(PhaseType.CLEANUP);
|
||||
player.getController().autoPassUntilEndOfTurn();
|
||||
stop();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -81,6 +81,7 @@ import forge.match.input.InputSelectCardsFromList;
|
||||
import forge.match.input.InputSelectEntitiesFromList;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.util.DevModeUtil;
|
||||
import forge.util.ITriggerEvent;
|
||||
import forge.util.Lang;
|
||||
import forge.util.TextUtil;
|
||||
@@ -95,7 +96,6 @@ import forge.view.PlayerView;
|
||||
import forge.view.StackItemView;
|
||||
import forge.view.ViewUtil;
|
||||
|
||||
|
||||
/**
|
||||
* A prototype for player controller class
|
||||
*
|
||||
@@ -718,8 +718,8 @@ public class PlayerControllerHuman extends PlayerController implements IGameView
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoPassUntil(PhaseType phase) {
|
||||
super.autoPassUntil(phase);
|
||||
public void autoPassUntilEndOfTurn() {
|
||||
super.autoPassUntilEndOfTurn();
|
||||
updateAutoPassPrompt();
|
||||
}
|
||||
|
||||
@@ -1569,4 +1569,58 @@ public class PlayerControllerHuman extends PlayerController implements IGameView
|
||||
public void setDisableAutoYields(final boolean b) {
|
||||
this.game.setDisableAutoYields(b);
|
||||
}
|
||||
|
||||
// Dev mode functions
|
||||
@Override
|
||||
public void devTogglePlayManyLands(final boolean b) {
|
||||
player.canCheatPlayUnlimitedLands = b;
|
||||
}
|
||||
@Override
|
||||
public void devGenerateMana() {
|
||||
DevModeUtil.devModeGenerateMana(game);
|
||||
}
|
||||
@Override
|
||||
public void devSetupGameState() {
|
||||
DevModeUtil.devSetupGameState(game);
|
||||
}
|
||||
@Override
|
||||
public void devTutorForCard() {
|
||||
DevModeUtil.devModeTutor(game);
|
||||
}
|
||||
@Override
|
||||
public void devAddCardToHand() {
|
||||
DevModeUtil.devModeCardToHand(game);
|
||||
}
|
||||
@Override
|
||||
public void devAddCounterToPermanent() {
|
||||
DevModeUtil.devModeAddCounter(game);
|
||||
}
|
||||
@Override
|
||||
public void devTapPermanent() {
|
||||
DevModeUtil.devModeTapPerm(game);
|
||||
}
|
||||
@Override
|
||||
public void devUntapPermanent() {
|
||||
DevModeUtil.devModeUntapPerm(game);
|
||||
}
|
||||
@Override
|
||||
public void devSetPlayerLife() {
|
||||
DevModeUtil.devModeSetLife(game);
|
||||
}
|
||||
@Override
|
||||
public void devWinGame() {
|
||||
DevModeUtil.devModeWinGame(game, player.getLobbyPlayer());
|
||||
}
|
||||
@Override
|
||||
public void devAddCardToBattlefield() {
|
||||
DevModeUtil.devModeCardToBattlefield(game);
|
||||
}
|
||||
@Override
|
||||
public void devRiggedPlanerRoll() {
|
||||
DevModeUtil.devModeRiggedPlanarRoll(game);
|
||||
}
|
||||
@Override
|
||||
public void devPlaneswalkTo() {
|
||||
DevModeUtil.devModeRiggedPlanarRoll(game);
|
||||
}
|
||||
}
|
||||
|
||||
494
forge-gui/src/main/java/forge/util/DevModeUtil.java
Normal file
494
forge-gui/src/main/java/forge/util/DevModeUtil.java
Normal file
@@ -0,0 +1,494 @@
|
||||
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.GuiBase;
|
||||
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.properties.ForgeConstants;
|
||||
import forge.util.gui.SGuiChoose;
|
||||
import forge.util.gui.SGuiDialog;
|
||||
import forge.util.gui.SOptionPane;
|
||||
|
||||
public final class DevModeUtil {
|
||||
|
||||
private DevModeUtil() {
|
||||
}
|
||||
|
||||
public static void devModeGenerateMana(final Game game) {
|
||||
Player pPriority = game.getPhaseHandler().getPriorityPlayer();
|
||||
if (pPriority == null) {
|
||||
SGuiDialog.message("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<String, String> produced = new HashMap<String, String>();
|
||||
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) {
|
||||
int humanLife = -1;
|
||||
int computerLife = -1;
|
||||
|
||||
final Map<ZoneType, String> humanCardTexts = new EnumMap<ZoneType, String>(ZoneType.class);
|
||||
final Map<ZoneType, String> aiCardTexts = new EnumMap<ZoneType, String>(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 = GuiBase.getInterface().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("File not found: " + filename);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
SOptionPane.showErrorDialog("Error loading battle setup file!");
|
||||
return;
|
||||
}
|
||||
|
||||
setupGameState(game, humanLife, computerLife, humanCardTexts, aiCardTexts, tChangePlayer, tChangePhase);
|
||||
}
|
||||
|
||||
private static void setupGameState(final Game game, final int humanLife, final int computerLife, final Map<ZoneType, String> humanCardTexts,
|
||||
final Map<ZoneType, String> aiCardTexts, final String tChangePlayer, final String tChangePhase) {
|
||||
|
||||
Player pPriority = game.getPhaseHandler().getPriorityPlayer();
|
||||
if (pPriority == null) {
|
||||
SGuiDialog.message("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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void devSetupPlayerState(int life, Map<ZoneType, String> cardTexts, final Player p) {
|
||||
Map<ZoneType, List<Card>> humanCards = new EnumMap<ZoneType, List<Card>>(ZoneType.class);
|
||||
for(Entry<ZoneType, String> kv : cardTexts.entrySet()) {
|
||||
humanCards.put(kv.getKey(), devProcessCardsForZone(kv.getValue().split(";"), p));
|
||||
}
|
||||
|
||||
if (life > 0) p.setLife(life, null);
|
||||
for (Entry<ZoneType, List<Card>> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devProcessCardsForZone.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> devProcessCardsForZone(final String[] data, final Player player) {
|
||||
final List<Card> cl = new ArrayList<Card>();
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeTutor.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static void devModeTutor(final Game game) {
|
||||
Player pPriority = game.getPhaseHandler().getPriorityPlayer();
|
||||
if (pPriority == null) {
|
||||
SGuiDialog.message("No player has priority at the moment, so their deck can't be tutored from.");
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Card> lib = pPriority.getCardsIn(ZoneType.Library);
|
||||
final Card card = SGuiChoose.oneOrNone("Choose a card", lib);
|
||||
if (card == null) { return; }
|
||||
|
||||
game.getAction().invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
game.getAction().moveToHand(card);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeAddCounter.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static void devModeAddCounter(final Game game) {
|
||||
final Card card = SGuiChoose.oneOrNone("Add counters to which card?", game.getCardsIn(ZoneType.Battlefield));
|
||||
if (card == null) { return; }
|
||||
|
||||
final CounterType counter = SGuiChoose.oneOrNone("Which type of counter?", CounterType.values());
|
||||
if (counter == null) { return; }
|
||||
|
||||
final Integer count = SGuiChoose.getInteger("How many counters?", 1, Integer.MAX_VALUE, 10);
|
||||
if (count == null) { return; }
|
||||
|
||||
card.addCounter(counter, count, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeTapPerm.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static void devModeTapPerm(final Game game) {
|
||||
game.getAction().invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final List<Card> untapped = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), Predicates.not(CardPredicates.Presets.TAPPED));
|
||||
InputSelectCardsFromList inp = new InputSelectCardsFromList(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeUntapPerm.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static void devModeUntapPerm(final Game game) {
|
||||
game.getAction().invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final List<Card> tapped = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.TAPPED);
|
||||
InputSelectCardsFromList inp = new InputSelectCardsFromList(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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeSetLife.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.1.3
|
||||
*/
|
||||
public static void devModeSetLife(final Game game) {
|
||||
final List<Player> players = game.getPlayers();
|
||||
final Player player = SGuiChoose.oneOrNone("Set life for which player?", players);
|
||||
if (player == null) { return; }
|
||||
|
||||
final Integer life = SGuiChoose.getInteger("Set life to what?", 0);
|
||||
if (life == null) { return; }
|
||||
|
||||
player.setLife(life, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeWinGame.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.5.23
|
||||
*/
|
||||
public static void devModeWinGame(final Game game, final LobbyPlayer guiPlayer) {
|
||||
Input input = GuiBase.getInterface().getInputQueue().getInput();
|
||||
if (!(input instanceof InputPassPriority)) {
|
||||
SOptionPane.showMessageDialog("You must have priority to use this feature.", "Win Game", SOptionPane.INFORMATION_ICON);
|
||||
return;
|
||||
}
|
||||
|
||||
//set life of all other players to 0
|
||||
final List<Player> 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeTutorAnyCard.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.2.7
|
||||
*/
|
||||
public static void devModeCardToHand(final Game game) {
|
||||
final List<Player> players = game.getPlayers();
|
||||
final Player p = SGuiChoose.oneOrNone("Put card in hand for which player?", players);
|
||||
if (null == p) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<PaperCard> cards = Lists.newArrayList(FModel.getMagicDb().getCommonCards().getUniqueCards());
|
||||
Collections.sort(cards);
|
||||
|
||||
// use standard forge's list selection dialog
|
||||
final IPaperCard c = SGuiChoose.oneOrNone("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 List<Player> players = game.getPlayers();
|
||||
final Player p = SGuiChoose.oneOrNone("Put card in play for which player?", players);
|
||||
if (null == p) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<PaperCard> cards = Lists.newArrayList(FModel.getMagicDb().getCommonCards().getUniqueCards());
|
||||
Collections.sort(cards);
|
||||
|
||||
// use standard forge's list selection dialog
|
||||
final IPaperCard c = SGuiChoose.oneOrNone("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<SpellAbility> choices = forgeCard.getBasicSpells();
|
||||
if (choices.isEmpty()) {
|
||||
return; // when would it happen?
|
||||
}
|
||||
|
||||
final SpellAbility sa = choices.size() == 1 ? choices.get(0) : SGuiChoose.oneOrNone("Choose", choices);
|
||||
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(game, sa, true);
|
||||
}
|
||||
game.getStack().addAllTriggeredAbilitiesToStack(); // playSa could fire some triggers
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void devModeRiggedPlanarRoll(final Game game) {
|
||||
final List<Player> players = game.getPlayers();
|
||||
final Player player = SGuiChoose.oneOrNone("Which player should roll?", players);
|
||||
if (player == null) { return; }
|
||||
|
||||
final PlanarDice res = SGuiChoose.oneOrNone("Choose result", PlanarDice.values());
|
||||
if (res == null) { return; }
|
||||
|
||||
System.out.println("Rigging planar dice roll: " + res.toString());
|
||||
|
||||
//DBG
|
||||
//System.out.println("ActivePlanes: " + getGame().getActivePlanes());
|
||||
//System.out.println("CommandPlanes: " + getGame().getCardsIn(ZoneType.Command));
|
||||
|
||||
|
||||
|
||||
game.getAction().invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlanarDice.roll(player, res);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void devModePlaneswalkTo(final Game game) {
|
||||
if (!game.getRules().hasAppliedVariant(GameType.Planechase)) { return; }
|
||||
final Player p = game.getPhaseHandler().getPlayerTurn();
|
||||
|
||||
final List<PaperCard> allPlanars = new ArrayList<PaperCard>();
|
||||
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("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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -17,508 +17,21 @@
|
||||
*/
|
||||
package forge.util;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.GuiBase;
|
||||
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.properties.ForgeConstants;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.util.gui.SGuiChoose;
|
||||
import forge.util.gui.SGuiDialog;
|
||||
import forge.util.gui.SOptionPane;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public final class GuiDisplayUtil {
|
||||
|
||||
private GuiDisplayUtil() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static void devModeGenerateMana() {
|
||||
Player pPriority = getGame().getPhaseHandler().getPriorityPlayer();
|
||||
if (pPriority == null) {
|
||||
SGuiDialog.message("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<String, String> produced = new HashMap<String, String>();
|
||||
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);
|
||||
getGame().getAction().invoke(new Runnable() {
|
||||
@Override public void run() { abMana.produceMana(null); }
|
||||
});
|
||||
}
|
||||
|
||||
public static void devSetupGameState() {
|
||||
int humanLife = -1;
|
||||
int computerLife = -1;
|
||||
|
||||
final Map<ZoneType, String> humanCardTexts = new EnumMap<ZoneType, String>(ZoneType.class);
|
||||
final Map<ZoneType, String> aiCardTexts = new EnumMap<ZoneType, String>(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 = GuiBase.getInterface().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("File not found: " + filename);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
SOptionPane.showErrorDialog("Error loading battle setup file!");
|
||||
return;
|
||||
}
|
||||
|
||||
setupGameState(humanLife, computerLife, humanCardTexts, aiCardTexts, tChangePlayer, tChangePhase);
|
||||
}
|
||||
|
||||
private static void setupGameState(final int humanLife, final int computerLife, final Map<ZoneType, String> humanCardTexts,
|
||||
final Map<ZoneType, String> aiCardTexts, final String tChangePlayer, final String tChangePhase) {
|
||||
|
||||
final Game game = getGame();
|
||||
Player pPriority = game.getPhaseHandler().getPriorityPlayer();
|
||||
if (pPriority == null) {
|
||||
SGuiDialog.message("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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void devSetupPlayerState(int life, Map<ZoneType, String> cardTexts, final Player p) {
|
||||
Map<ZoneType, List<Card>> humanCards = new EnumMap<ZoneType, List<Card>>(ZoneType.class);
|
||||
for(Entry<ZoneType, String> kv : cardTexts.entrySet()) {
|
||||
humanCards.put(kv.getKey(), GuiDisplayUtil.devProcessCardsForZone(kv.getValue().split(";"), p));
|
||||
}
|
||||
|
||||
if (life > 0) p.setLife(life, null);
|
||||
for (Entry<ZoneType, List<Card>> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devProcessCardsForZone.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> devProcessCardsForZone(final String[] data, final Player player) {
|
||||
final List<Card> cl = new ArrayList<Card>();
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeTutor.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static void devModeTutor() {
|
||||
Player pPriority = getGame().getPhaseHandler().getPriorityPlayer();
|
||||
if (pPriority == null) {
|
||||
SGuiDialog.message("No player has priority at the moment, so their deck can't be tutored from.");
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Card> lib = pPriority.getCardsIn(ZoneType.Library);
|
||||
final Card card = SGuiChoose.oneOrNone("Choose a card", lib);
|
||||
if (card == null) { return; }
|
||||
|
||||
getGame().getAction().invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getGame().getAction().moveToHand(card);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeAddCounter.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static void devModeAddCounter() {
|
||||
final Card card = SGuiChoose.oneOrNone("Add counters to which card?", getGame().getCardsIn(ZoneType.Battlefield));
|
||||
if (card == null) { return; }
|
||||
|
||||
final CounterType counter = SGuiChoose.oneOrNone("Which type of counter?", CounterType.values());
|
||||
if (counter == null) { return; }
|
||||
|
||||
final Integer count = SGuiChoose.getInteger("How many counters?", 1, Integer.MAX_VALUE, 10);
|
||||
if (count == null) { return; }
|
||||
|
||||
card.addCounter(counter, count, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeTapPerm.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static void devModeTapPerm() {
|
||||
final Game game = getGame();
|
||||
game.getAction().invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final List<Card> untapped = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), Predicates.not(CardPredicates.Presets.TAPPED));
|
||||
InputSelectCardsFromList inp = new InputSelectCardsFromList(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeUntapPerm.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static void devModeUntapPerm() {
|
||||
final Game game = getGame();
|
||||
game.getAction().invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final List<Card> tapped = CardLists.filter(game.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.TAPPED);
|
||||
InputSelectCardsFromList inp = new InputSelectCardsFromList(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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeSetLife.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.1.3
|
||||
*/
|
||||
public static void devModeSetLife() {
|
||||
final List<Player> players = getGame().getPlayers();
|
||||
final Player player = SGuiChoose.oneOrNone("Set life for which player?", players);
|
||||
if (player == null) { return; }
|
||||
|
||||
final Integer life = SGuiChoose.getInteger("Set life to what?", 0);
|
||||
if (life == null) { return; }
|
||||
|
||||
player.setLife(life, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeWinGame.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.5.23
|
||||
*/
|
||||
public static void devModeWinGame() {
|
||||
Input input = GuiBase.getInterface().getInputQueue().getInput();
|
||||
if (!(input instanceof InputPassPriority)) {
|
||||
SOptionPane.showMessageDialog("You must have priority to use this feature.", "Win Game", SOptionPane.INFORMATION_ICON);
|
||||
return;
|
||||
}
|
||||
|
||||
//set life of all other players to 0
|
||||
LobbyPlayer guiPlayer = GuiBase.getInterface().getGuiPlayer();
|
||||
final List<Player> players = getGame().getPlayers();
|
||||
for (Player player : players) {
|
||||
if (player.getLobbyPlayer() != guiPlayer) {
|
||||
player.setLife(0, null);
|
||||
}
|
||||
}
|
||||
|
||||
//pass priority so that causes gui player to win
|
||||
input.selectButtonOK();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* devModeTutorAnyCard.
|
||||
* </p>
|
||||
*
|
||||
* @since 1.2.7
|
||||
*/
|
||||
public static void devModeCardToHand() {
|
||||
final List<Player> players = getGame().getPlayers();
|
||||
final Player p = SGuiChoose.oneOrNone("Put card in hand for which player?", players);
|
||||
if (null == p) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<PaperCard> cards = Lists.newArrayList(FModel.getMagicDb().getCommonCards().getUniqueCards());
|
||||
Collections.sort(cards);
|
||||
|
||||
// use standard forge's list selection dialog
|
||||
final IPaperCard c = SGuiChoose.oneOrNone("Name the card", cards);
|
||||
if (c == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
getGame().getAction().invoke(new Runnable() { @Override public void run() {
|
||||
getGame().getAction().moveToHand(Card.fromPaperCard(c, p));
|
||||
}});
|
||||
}
|
||||
|
||||
public static void devModeCardToBattlefield() {
|
||||
final List<Player> players = getGame().getPlayers();
|
||||
final Player p = SGuiChoose.oneOrNone("Put card in play for which player?", players);
|
||||
if (null == p) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<PaperCard> cards = Lists.newArrayList(FModel.getMagicDb().getCommonCards().getUniqueCards());
|
||||
Collections.sort(cards);
|
||||
|
||||
// use standard forge's list selection dialog
|
||||
final IPaperCard c = SGuiChoose.oneOrNone("Name the card", cards);
|
||||
if (c == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Game game = getGame();
|
||||
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<SpellAbility> choices = forgeCard.getBasicSpells();
|
||||
if (choices.isEmpty()) {
|
||||
return; // when would it happen?
|
||||
}
|
||||
|
||||
final SpellAbility sa = choices.size() == 1 ? choices.get(0) : SGuiChoose.oneOrNone("Choose", choices);
|
||||
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(game, sa, true);
|
||||
}
|
||||
game.getStack().addAllTriggeredAbilitiesToStack(); // playSa could fire some triggers
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void devModeRiggedPlanarRoll() {
|
||||
final List<Player> players = getGame().getPlayers();
|
||||
final Player player = SGuiChoose.oneOrNone("Which player should roll?", players);
|
||||
if (player == null) { return; }
|
||||
|
||||
final PlanarDice res = SGuiChoose.oneOrNone("Choose result", PlanarDice.values());
|
||||
if (res == null) { return; }
|
||||
|
||||
System.out.println("Rigging planar dice roll: " + res.toString());
|
||||
|
||||
//DBG
|
||||
//System.out.println("ActivePlanes: " + getGame().getActivePlanes());
|
||||
//System.out.println("CommandPlanes: " + getGame().getCardsIn(ZoneType.Command));
|
||||
|
||||
|
||||
|
||||
getGame().getAction().invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlanarDice.roll(player, res);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void devModePlaneswalkTo() {
|
||||
final Game game = getGame();
|
||||
if (!game.getRules().hasAppliedVariant(GameType.Planechase)) { return; }
|
||||
final Player p = game.getPhaseHandler().getPlayerTurn();
|
||||
|
||||
final List<PaperCard> allPlanars = new ArrayList<PaperCard>();
|
||||
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("Name the card", allPlanars);
|
||||
if (c == null) { return; }
|
||||
final Card forgeCard = Card.fromPaperCard(c, p);
|
||||
|
||||
forgeCard.setOwner(p);
|
||||
getGame().getAction().invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getGame().getAction().changeZone(null, p.getZone(ZoneType.PlanarDeck), forgeCard, 0);
|
||||
PlanarDice.roll(p, PlanarDice.Planeswalk);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static Game getGame() {
|
||||
return GuiBase.getInterface().getGame();
|
||||
}
|
||||
|
||||
public static String getPlayerName() {
|
||||
return FModel.getPreferences().getPref(FPref.PLAYER_NAME);
|
||||
}
|
||||
|
||||
public static String personalizeHuman(String text) {
|
||||
String playerName = FModel.getPreferences().getPref(FPref.PLAYER_NAME);
|
||||
public static String personalizeHuman(final String text) {
|
||||
final String playerName = FModel.getPreferences().getPref(FPref.PLAYER_NAME);
|
||||
return text.replaceAll("(?i)human", playerName);
|
||||
}
|
||||
|
||||
|
||||
} // end class GuiDisplayUtil
|
||||
|
||||
@@ -58,4 +58,20 @@ public interface IGameView {
|
||||
public abstract boolean getDisableAutoYields();
|
||||
public abstract void setDisableAutoYields(boolean b);
|
||||
|
||||
public abstract void autoPassUntilEndOfTurn();
|
||||
public abstract void autoPassCancel();
|
||||
|
||||
public abstract void devTogglePlayManyLands(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();
|
||||
}
|
||||
Reference in New Issue
Block a user