Deck moved to player (still hardcoded, but no longer in constants)

This commit is contained in:
Maxmtg
2012-10-02 07:40:16 +00:00
parent f91020a8b1
commit 3d732706eb
15 changed files with 62 additions and 73 deletions

View File

@@ -20,7 +20,6 @@ package forge;
import java.util.ArrayList;
import java.util.List;
import forge.deck.Deck;
import forge.game.GameType;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
@@ -42,36 +41,21 @@ public final class Constant {
* The Class Runtime.
*/
public static class Preferences {
/** The Constant Mill. */
public static boolean MILL;
/** The Constant DevMode. */
// one for normal mode, one for quest mode
public static boolean DEV_MODE;
/** The Constant UpldDrft. */
public static boolean UPLOAD_DRAFT;
/** The Constant RndCFoil. */
public static boolean RANDOM_FOIL;
}
public static class Runtime {
/** The Constant HumanDeck. */
public static final Deck[] HUMAN_DECK = new Deck[1];
/** The Constant ComputerDeck. */
public static final Deck[] COMPUTER_DECK = new Deck[1];
/** The skin name. */
private static String skinName = "default";
/** The game type. */
private static GameType gameType = GameType.Constructed;
/** The Constant Smooth. */
public static final boolean[] SMOOTH = new boolean[1];
/** The Constant NetConn. */
public static final boolean[] NET_CONN = new boolean[1];

View File

@@ -135,7 +135,7 @@ public class GameNew {
CMessage.SINGLETON_INSTANCE.updateGameInfo();
// friendliness
final boolean canRandomFoil = Preferences.RANDOM_FOIL
final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL)
&& Constant.Runtime.getGameType().equals(GameType.Constructed);
final Random generator = MyRandom.getRandom();
@@ -246,7 +246,7 @@ public class GameNew {
}
// do this instead of shuffling Computer's deck
final boolean smoothLand = Constant.Runtime.SMOOTH[0];
final boolean smoothLand = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_SMOOTH_LAND);
if (smoothLand) {
final Iterable<Card> c1 = GameNew.smoothComputerManaCurve(AllZone.getComputerPlayer().getCardsIn(ZoneType.Library));

View File

@@ -21,6 +21,7 @@ import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import java.util.List;
import forge.AllZone;
import forge.Constant;
import forge.Singletons;
import forge.deck.Deck;
@@ -91,8 +92,8 @@ public class GauntletMini {
public void resetCurrentRound() {
wins = 0;
losses = 0;
Constant.Runtime.HUMAN_DECK[0] = humanDeck;
Constant.Runtime.COMPUTER_DECK[0] = aiDecks.get(0);
AllZone.getHumanPlayer().setDeck(humanDeck);
AllZone.getComputerPlayer().setDeck(aiDecks.get(0));
currentRound = 1;
}
@@ -108,8 +109,8 @@ public class GauntletMini {
return;
}
Constant.Runtime.HUMAN_DECK[0] = humanDeck;
Constant.Runtime.COMPUTER_DECK[0] = aiDecks.get(currentRound);
AllZone.getHumanPlayer().setDeck(humanDeck);
AllZone.getComputerPlayer().setDeck(aiDecks.get(currentRound));
currentRound += 1;
}
@@ -163,7 +164,7 @@ public class GauntletMini {
Constant.Runtime.setGameType(gauntletType);
GameNew.newGame(Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0]);
GameNew.newGame(AllZone.getHumanPlayer().getDeck(), AllZone.getComputerPlayer().getDeck());
return null;
}

View File

@@ -48,6 +48,7 @@ import forge.card.replacement.ReplacementResult;
import forge.card.spellability.SpellAbility;
import forge.card.staticability.StaticAbility;
import forge.card.trigger.TriggerType;
import forge.deck.Deck;
import forge.game.GameLossReason;
import forge.game.phase.PhaseHandler;
import forge.game.zone.DefaultPlayerZone;
@@ -149,6 +150,10 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
public static final List<ZoneType> ALL_ZONES = Collections.unmodifiableList(Arrays.asList(ZoneType.Battlefield,
ZoneType.Library, ZoneType.Graveyard, ZoneType.Hand, ZoneType.Exile, ZoneType.Command, ZoneType.Ante, ZoneType.Stack));
// Moved deck here from Constants.Runtime
private Deck deck;
/**
* <p>
* Constructor for Player.
@@ -1304,7 +1309,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
AllZone.getTriggerHandler().runTrigger(TriggerType.Drawn, runParams);
}
// lose:
else if (!Preferences.DEV_MODE || Preferences.MILL) {
else if (!Preferences.DEV_MODE || Singletons.getModel().getPreferences().getPrefBoolean(FPref.DEV_MILLING_LOSS)) {
// if devMode is off, or canLoseByDecking is Enabled, run Lose condition
if (!this.cantLose()) {
this.loseConditionMet(GameLossReason.Milled, null);
@@ -2691,4 +2696,12 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
public int hashCode() {
return (41 * (41 + this.getName().hashCode()));
}
public Deck getDeck() {
return deck;
}
public void setDeck(Deck deck) {
this.deck = deck;
}
}

View File

@@ -20,7 +20,7 @@ package forge.gui.deckeditor.controllers;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import forge.Constant;
import forge.AllZone;
import forge.Singletons;
import forge.control.FControl;
import forge.deck.Deck;
@@ -169,7 +169,7 @@ public class CEditorDraftingProcess extends ACEditorBase<CardPrinted, DeckGroup>
*/
private Deck getPlayersDeck() {
final Deck deck = new Deck();
Constant.Runtime.HUMAN_DECK[0] = deck;
AllZone.getHumanPlayer().setDeck(deck);
// add sideboard to deck
deck.getSideboard().addAll(this.getTableDeck().getCards());

View File

@@ -27,7 +27,6 @@ import com.google.common.base.Function;
import com.google.common.base.Supplier;
import forge.AllZone;
import forge.Constant;
import forge.deck.Deck;
import forge.gui.deckeditor.SEditorIO;
import forge.gui.deckeditor.SEditorUtil;
@@ -222,8 +221,8 @@ public final class CEditorQuest extends ACEditorBase<CardPrinted, Deck> {
this.getTableCatalog().setup(VCardCatalog.SINGLETON_INSTANCE, columnsCatalog);
this.getTableDeck().setup(VCurrentDeck.SINGLETON_INSTANCE, columnsDeck);
Deck deck = Constant.Runtime.HUMAN_DECK[0] == null ? null : this.questData.getMyDecks().get(
Constant.Runtime.HUMAN_DECK[0].getName());
Deck deck = AllZone.getHumanPlayer().getDeck() == null ? null : this.questData.getMyDecks().get(
AllZone.getHumanPlayer().getDeck().getName());
if (deck == null) {
deck = new Deck();

View File

@@ -232,8 +232,8 @@ public class SSubmenuQuestUtil {
final SwingWorker<Object, Void> worker = new SwingWorker<Object, Void>() {
@Override
public Object doInBackground() {
Constant.Runtime.HUMAN_DECK[0] = SSubmenuQuestUtil.getCurrentDeck();
Constant.Runtime.COMPUTER_DECK[0] = event.getEventDeck();
AllZone.getHumanPlayer().setDeck(SSubmenuQuestUtil.getCurrentDeck());
AllZone.getComputerPlayer().setDeck(event.getEventDeck());
Constant.Runtime.setGameType(GameType.Quest);
qData.getChallengesManager().randomizeOpponents();
@@ -255,8 +255,8 @@ public class SSubmenuQuestUtil {
}
GameNew.newGame(
Constant.Runtime.HUMAN_DECK[0],
Constant.Runtime.COMPUTER_DECK[0],
AllZone.getHumanPlayer().getDeck(),
AllZone.getComputerPlayer().getDeck(),
QuestUtil.getHumanStartingCards(qData, event),
QuestUtil.getComputerStartingCards(event),
baseLifeHuman + extraLifeHuman,

View File

@@ -344,15 +344,15 @@ public enum CSubmenuConstructed implements ICDoc {
final SwingWorker<Object, Void> worker = new SwingWorker<Object, Void>() {
@Override
public Object doInBackground() {
Constant.Runtime.HUMAN_DECK[0] =
generateDeck(VSubmenuConstructed.SINGLETON_INSTANCE.getLstHumanDecks(), PlayerType.HUMAN);
Constant.Runtime.COMPUTER_DECK[0] =
generateDeck(VSubmenuConstructed.SINGLETON_INSTANCE.getLstAIDecks(), PlayerType.COMPUTER);
AllZone.getHumanPlayer().setDeck(
generateDeck(VSubmenuConstructed.SINGLETON_INSTANCE.getLstHumanDecks(), PlayerType.HUMAN));
AllZone.getComputerPlayer().setDeck(
generateDeck(VSubmenuConstructed.SINGLETON_INSTANCE.getLstAIDecks(), PlayerType.COMPUTER));
Constant.Runtime.setGameType(GameType.Constructed);
if (Constant.Runtime.HUMAN_DECK[0] != null && Constant.Runtime.COMPUTER_DECK[0] != null) {
GameNew.newGame(Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0]);
if (AllZone.getHumanPlayer().getDeck() != null && AllZone.getComputerPlayer().getDeck() != null) {
GameNew.newGame(AllZone.getHumanPlayer().getDeck(), AllZone.getComputerPlayer().getDeck());
}
return null;
}

View File

@@ -202,15 +202,15 @@ public enum CSubmenuDraft implements ICDoc {
public Object doInBackground() {
DeckGroup opponentDecks = Singletons.getModel().getDecks().getDraft().get(human.getName());
Constant.Runtime.HUMAN_DECK[0] = human;
Constant.Runtime.COMPUTER_DECK[0] = opponentDecks.getAiDecks().get(aiIndex); //zero is human deck, so it must be +1
AllZone.getHumanPlayer().setDeck(human);
AllZone.getComputerPlayer().setDeck(opponentDecks.getAiDecks().get(aiIndex)); //zero is human deck, so it must be +1
if (Constant.Runtime.COMPUTER_DECK[0] == null) {
if (AllZone.getComputerPlayer().getDeck() == null) {
throw new IllegalStateException("Draft: Computer deck is null!");
}
Constant.Runtime.setGameType(GameType.Draft);
GameNew.newGame(Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0]);
GameNew.newGame(AllZone.getHumanPlayer().getDeck(), AllZone.getComputerPlayer().getDeck());
return null;
}

View File

@@ -8,7 +8,6 @@ import java.awt.event.MouseEvent;
import org.apache.commons.lang3.text.WordUtils;
import forge.Command;
import forge.Constant;
import forge.Constant.Preferences;
import forge.Singletons;
import forge.control.RestartUtil;
@@ -120,9 +119,7 @@ public enum CSubmenuPreferences implements ICDoc {
view.getCbStackLand().addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent arg0) {
final boolean toggle = view.getCbStackLand().isSelected();
prefs.setPref(FPref.UI_SMOOTH_LAND, String.valueOf(toggle));
Constant.Runtime.SMOOTH[0] = toggle;
prefs.setPref(FPref.UI_SMOOTH_LAND, view.getCbRandomFoil().isSelected());
prefs.save();
}
});
@@ -130,9 +127,7 @@ public enum CSubmenuPreferences implements ICDoc {
view.getCbRandomFoil().addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent arg0) {
final boolean toggle = view.getCbRandomFoil().isSelected();
prefs.setPref(FPref.UI_RANDOM_FOIL, String.valueOf(toggle));
Preferences.RANDOM_FOIL = toggle;
prefs.setPref(FPref.UI_RANDOM_FOIL, view.getCbRandomFoil().isSelected());
prefs.save();
}
});

View File

@@ -91,10 +91,11 @@ public class ControlWinLose {
boolean isAnte = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ANTE);
GameType gameType = Constant.Runtime.getGameType();
Deck hDeck = AllZone.getHumanPlayer().getDeck();
Deck cDeck = AllZone.getComputerPlayer().getDeck();
//This is called from QuestWinLoseHandler also. If we're in a quest, this is already handled elsewhere
if (isAnte && !gameType.equals(GameType.Quest)) {
Deck hDeck = Constant.Runtime.HUMAN_DECK[0];
Deck cDeck = Constant.Runtime.COMPUTER_DECK[0];
if (Singletons.getModel().getMatchState().hasWonLastGame(AllZone.getHumanPlayer().getName())) {
List<Card> compAntes = AllZone.getComputerPlayer().getCardsIn(ZoneType.Ante);
@@ -104,8 +105,6 @@ public class ControlWinLose {
cDeck.getMain().remove(toRemove);
}
Constant.Runtime.COMPUTER_DECK[0] = cDeck;
List<Card> o = GuiChoose.noneOrMany("Select cards to add to your deck", compAntes);
if (null != o) {
for (Card c : o) {
@@ -121,11 +120,11 @@ public class ControlWinLose {
CardPrinted toRemove = CardDb.instance().getCard(c);
hDeck.getMain().remove(toRemove);
}
Constant.Runtime.HUMAN_DECK[0] = hDeck;
AllZone.getHumanPlayer().setDeck(hDeck);
}
}
Singletons.getModel().savePrefs();
GameNew.newGame(Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0]);
GameNew.newGame(hDeck, cDeck);
}
/**

View File

@@ -19,7 +19,6 @@ package forge.gui.match;
import forge.AllZone;
import forge.Card;
import forge.Constant;
import forge.Singletons;
import forge.control.FControl;
@@ -133,7 +132,7 @@ public class QuestWinLoseHandler extends ControlWinLose {
computerLife = ((QuestEventChallenge) qEvent).getAILife();
}
GameNew.newGame(Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0],
GameNew.newGame(AllZone.getHumanPlayer().getDeck(), AllZone.getComputerPlayer().getDeck(),
humanList, computerList, humanLife, computerLife, qEvent.getIconFilename());
} else {
super.startNextRound();

View File

@@ -36,7 +36,6 @@ import forge.Card;
import forge.CardListUtil;
import forge.CardPredicates.Presets;
import forge.Command;
import forge.Constant;
import forge.Singletons;
import forge.deck.Deck;
import forge.game.phase.CombatUtil;
@@ -194,10 +193,10 @@ public enum CDock implements ICDoc {
public void actionPerformed(final ActionEvent e) {
Deck targetDeck;
if (!Constant.Runtime.HUMAN_DECK[0].getMain().isEmpty()) {
targetDeck = Constant.Runtime.HUMAN_DECK[0];
} else if (!Constant.Runtime.COMPUTER_DECK[0].getMain().isEmpty()) {
targetDeck = Constant.Runtime.COMPUTER_DECK[0];
if (!AllZone.getHumanPlayer().getDeck().getMain().isEmpty()) {
targetDeck = AllZone.getHumanPlayer().getDeck();
} else if (!AllZone.getComputerPlayer().getDeck().getMain().isEmpty()) {
targetDeck = AllZone.getComputerPlayer().getDeck();
} else {
return;
}

View File

@@ -38,7 +38,6 @@ import javax.swing.border.MatteBorder;
import net.miginfocom.swing.MigLayout;
import forge.AllZone;
import forge.Command;
import forge.Constant;
import forge.Singletons;
import forge.control.FControl;
import forge.deck.CardCollections;
@@ -425,7 +424,7 @@ public class DeckLister extends JPanel implements ILocalRepaint {
private <T extends DeckBase> void editDeck(final Deck d0) {
switch (this.gametype) {
case Quest:
Constant.Runtime.HUMAN_DECK[0] = d0;
AllZone.getHumanPlayer().setDeck(d0);
final CEditorQuest qEditor = new CEditorQuest(AllZone.getQuest());
CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController(qEditor);
FControl.SINGLETON_INSTANCE.changeState(FControl.DECK_EDITOR_QUEST);

View File

@@ -234,14 +234,13 @@ public class ForgePreferences {
this.setPref(FPref.PHASE_HUMAN_COMBATDAMAGE, String.valueOf(fieldViews.get(1).getLblCombatDamage().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_ENDCOMBAT, String.valueOf(fieldViews.get(1).getLblEndCombat().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_MAIN2, String.valueOf(fieldViews.get(1).getLblMain2().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_EOT, String.valueOf(fieldViews.get(1).getLblEndTurn().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_CLEANUP, String.valueOf(fieldViews.get(1).getLblCleanup().getEnabled()));
this.setPref(FPref.PHASE_HUMAN_EOT, fieldViews.get(1).getLblEndTurn().getEnabled());
this.setPref(FPref.PHASE_HUMAN_CLEANUP, fieldViews.get(1).getLblCleanup().getEnabled());
final VDev v = VDev.SINGLETON_INSTANCE;
Preferences.MILL = v.getLblMilling().getEnabled();
this.setPref(FPref.DEV_MILLING_LOSS, String.valueOf(Preferences.MILL));
this.setPref(FPref.DEV_UNLIMITED_LAND, String.valueOf(v.getLblUnlimitedLands().getEnabled()));
this.setPref(FPref.DEV_MILLING_LOSS, v.getLblMilling().getEnabled());
this.setPref(FPref.DEV_UNLIMITED_LAND, v.getLblUnlimitedLands().getEnabled());
}
/**
@@ -251,9 +250,7 @@ public class ForgePreferences {
public void actuateMatchPreferences() {
final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews();
Preferences.MILL = this.getPrefBoolean(FPref.DEV_MILLING_LOSS);
Preferences.DEV_MODE = this.getPrefBoolean(FPref.DEV_MODE_ENABLED);
Preferences.RANDOM_FOIL = this.getPrefBoolean(FPref.UI_RANDOM_FOIL);
Preferences.UPLOAD_DRAFT = (Constant.Runtime.NET_CONN[0] ? this.getPrefBoolean(FPref.UI_UPLOAD_DRAFT) : false);
// AI field is at index [0]
@@ -336,6 +333,10 @@ public class ForgePreferences {
preferenceValues.put(q0, s0);
}
public void setPref(FPref q0, boolean val) {
setPref(q0, String.valueOf(val));
}
/**
* Returns a non-difficulty-indexed preference value.
*