Refactored QuestMatchState

GameInfo is renamed to GameSummary and is now an observer for game state. It's purpose is now to hold statistic data on game and actions performed by players. The former functionality moved to ColorChanger and Phase (all combat damage prevention due to Fog spell). Since then game turns calculation is done properly (no need to add/substract 1)
Total cleanup at Gui_WinLose, removed all references to global objects for quest and match-related entites. 
Some of quest rewards calculations use now special functions in QuestData class.
Tracking of win and lose conditions refactored (see Player and Upkeep classes)
This commit is contained in:
Maxmtg
2011-08-22 00:02:22 +00:00
parent 6afac1c7e0
commit a04d035129
31 changed files with 806 additions and 843 deletions

8
.gitattributes vendored
View File

@@ -9449,6 +9449,7 @@ src/main/java/forge/Card_Color.java svneol=native#text/plain
src/main/java/forge/Card_PT.java svneol=native#text/plain
src/main/java/forge/Card_Type.java svneol=native#text/plain
src/main/java/forge/Color.java svneol=native#text/plain
src/main/java/forge/ColorChanger.java -text
src/main/java/forge/Combat.java svneol=native#text/plain
src/main/java/forge/CombatUtil.java svneol=native#text/plain
src/main/java/forge/Command.java svneol=native#text/plain
@@ -9480,7 +9481,6 @@ src/main/java/forge/GUI_DeckAnalysis.java svneol=native#text/plain
src/main/java/forge/GUI_ImportPicture.java svneol=native#text/plain
src/main/java/forge/GameAction.java svneol=native#text/plain
src/main/java/forge/GameActionUtil.java svneol=native#text/plain
src/main/java/forge/GameInfo.java svneol=native#text/plain
src/main/java/forge/GuiDisplay4.java svneol=native#text/plain
src/main/java/forge/GuiDisplayUtil.java svneol=native#text/plain
src/main/java/forge/GuiFilter.java svneol=native#text/plain
@@ -9663,6 +9663,12 @@ src/main/java/forge/error/BugzReporter.java svneol=native#text/plain
src/main/java/forge/error/ErrorViewer.java svneol=native#text/plain
src/main/java/forge/error/ExceptionHandler.java svneol=native#text/plain
src/main/java/forge/error/package-info.java svneol=native#text/plain
src/main/java/forge/game/GameEndReason.java -text
src/main/java/forge/game/GameLossReason.java -text
src/main/java/forge/game/GamePlayerRating.java -text
src/main/java/forge/game/GameSummary.java svneol=native#text/plain
src/main/java/forge/game/PlayerIndex.java -text
src/main/java/forge/game/package-info.java -text
src/main/java/forge/gui/ForgeAction.java svneol=native#text/plain
src/main/java/forge/gui/GuiUtils.java svneol=native#text/plain
src/main/java/forge/gui/ListChooser.java svneol=native#text/plain

View File

@@ -6,9 +6,11 @@ import forge.card.cardFactory.PreloadingCardFactory;
import forge.card.mana.ManaPool;
import forge.card.trigger.TriggerHandler;
import forge.deck.DeckManager;
import forge.game.GameSummary;
import forge.gui.input.InputControl;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.quest.data.QuestMatchState;
import java.util.HashMap;
import java.util.Iterator;
@@ -40,6 +42,8 @@ public class AllZone implements NewConstants {
private static Quest_Assignment QuestAssignment = null;
/** Constant <code>NameChanger</code> */
private static final NameChanger NameChanger = new NameChanger();
/** Constant <code>ColorChanger</code> */
private static final ColorChanger colorChanger = new ColorChanger();
/** Constant <code>EndOfTurn</code> */
private static EndOfTurn EndOfTurn = new EndOfTurn();
@@ -62,8 +66,11 @@ public class AllZone implements NewConstants {
private static final GameAction GameAction = new GameAction();
/** Constant <code>StaticEffects</code> */
private static final StaticEffects StaticEffects = new StaticEffects();
/** Constant <code>GameInfo</code> */
private static final GameInfo GameInfo = new GameInfo();
/** Game state observer <code>GameSummary</code> collects statistics and players' performance*/
private static GameSummary gameInfo = new GameSummary();
/** Match State for quests are stored in a <code>QuestMatchState</code> class instance*/
public static QuestMatchState matchState = new QuestMatchState();
/** Constant <code>TriggerHandler</code> */
private static final TriggerHandler TriggerHandler = new TriggerHandler();
@@ -308,11 +315,11 @@ public class AllZone implements NewConstants {
/**
* <p>getGameInfo.</p>
*
* @return a {@link forge.GameInfo} object.
* @return a {@link forge.GameSummary} object.
* @since 1.0.15
*/
public static GameInfo getGameInfo() {
return GameInfo;
public static GameSummary getGameInfo() {
return gameInfo;
}
/**
@@ -606,4 +613,54 @@ public class AllZone implements NewConstants {
timestamp++;
return timestamp;
}
/**
* <p>Resets everything possible to set a new game</p>
*/
public static void newGameCleanup() {
gameInfo = new GameSummary();
getHumanPlayer().reset();
getComputerPlayer().reset();
getPhase().reset();
getStack().reset();
getCombat().reset();
getDisplay().showCombat("");
getDisplay().loadPrefs();
getHumanGraveyard().reset();
getHumanHand().reset();
getHumanLibrary().reset();
getHumanBattlefield().reset();
getHumanExile().reset();
getComputerGraveyard().reset();
getComputerHand().reset();
getComputerLibrary().reset();
getComputerBattlefield().reset();
getComputerExile().reset();
getInputControl().clearInput();
getStaticEffects().reset();
getColorChanger().reset();
// player.reset() now handles this
//AllZone.getHumanPlayer().clearHandSizeOperations();
//AllZone.getComputerPlayer().clearHandSizeOperations();
getTriggerHandler().clearRegistered();
}
public static QuestMatchState getMatchState() {
return matchState;
}
public static ColorChanger getColorChanger() {
// TODO Auto-generated method stub
return colorChanger;
}
}//AllZone

View File

@@ -1200,7 +1200,7 @@ public class Card extends MyObservable implements Comparable<Card> {
return new Card_Color(this);
}
Card_Color colors = null;
ArrayList<Card_Color> globalChanges = AllZone.getGameInfo().getColorChanges();
ArrayList<Card_Color> globalChanges = AllZone.getColorChanger().getColorChanges();
colors = determineColor(globalChanges);
colors.fixColorless();
return colors;
@@ -1227,7 +1227,8 @@ public class Card extends MyObservable implements Comparable<Card> {
Card_Color determineColor(ArrayList<Card_Color> globalChanges) {
Card_Color colors = new Card_Color(this);
int i = cardColor.size() - 1;
int j = globalChanges.size() - 1;
int j = -1;
if (globalChanges != null) { j = globalChanges.size() - 1; }
// if both have changes, see which one is most recent
while (i >= 0 && j >= 0) {
Card_Color cc = null;

View File

@@ -0,0 +1,72 @@
package forge;
import java.util.ArrayList;
import forge.card.mana.ManaCost;
public class ColorChanger {
private ArrayList<Card_Color> globalColorChanges = new ArrayList<Card_Color>();
/**
* <p>addColorChanges.</p>
*
* @param s a {@link java.lang.String} object.
* @param c a {@link forge.Card} object.
* @param addToColors a boolean.
* @param bIncrease a boolean.
* @return a long.
*/
public long addColorChanges(String s, Card c, boolean addToColors, boolean bIncrease) {
if (bIncrease) {
Card_Color.increaseTimestamp();
}
globalColorChanges.add(new Card_Color(new ManaCost(s), c, addToColors, false));
return Card_Color.getTimestamp();
}
/**
* <p>removeColorChanges.</p>
*
* @param s a {@link java.lang.String} object.
* @param c a {@link forge.Card} object.
* @param addTo a boolean.
* @param timestamp a long.
*/
public final void removeColorChanges(String s, Card c, boolean addTo, long timestamp) {
Card_Color removeCol = null;
for (Card_Color cc : globalColorChanges) {
if (cc.equals(s, c, addTo, timestamp)) {
removeCol = cc;
}
}
if (removeCol != null) {
globalColorChanges.remove(removeCol);
}
}
/**
* <p>reset = clearColorChanges.</p>
*/
public final void reset() {
clearColorChanges();
}
/**
* <p>clearColorChanges.</p>
*/
public final void clearColorChanges() {
// clear the global color changes at end of each game
globalColorChanges.clear();
}
/**
* <p>getColorChanges.</p>
*
* @return a {@link java.util.ArrayList} object.
*/
public final ArrayList<Card_Color> getColorChanges() {
return globalColorChanges;
}
}

View File

@@ -2,7 +2,6 @@ package forge;
import forge.deck.Deck;
import forge.quest.data.QuestMatchState;
import java.util.Arrays;
import java.util.Collections;
@@ -24,7 +23,7 @@ public interface Constant {
public static final Deck[] HumanDeck = new Deck[1];
public static final Deck[] ComputerDeck = new Deck[1];
public static final String[] GameType = new String[1];
public static final QuestMatchState matchState = new QuestMatchState();
public static final boolean[] Smooth = new boolean[1];
public static final boolean[] Mill = new boolean[1];
public static final boolean[] DevMode = new boolean[1]; // one for normal mode one for quest mode
@@ -161,6 +160,11 @@ public interface Constant {
public static final boolean loaded[] = {false};
public static final Constant_StringArrayList NonStackingList[] = new Constant_StringArrayList[1];
}
}//Constant

View File

@@ -61,7 +61,6 @@ public class EndOfTurn implements java.io.Serializable {
AllZone.getPhase().getPlayerTurn().setMustAttackEntity(null);
GameActionUtil.removeAttackedBlockedThisTurn();
AllZone.getGameInfo().setPreventCombatDamageThisTurn(false);
AllZone.getStaticEffects().rePopulateStateBasedList();

View File

@@ -11,6 +11,9 @@ import forge.card.spellability.*;
import forge.card.staticAbility.StaticAbility;
import forge.card.trigger.Trigger;
import forge.deck.Deck;
import forge.game.GameEndReason;
import forge.game.GameSummary;
import forge.game.PlayerIndex;
import forge.gui.GuiUtils;
import forge.gui.input.Input_Mulligan;
import forge.gui.input.Input_PayManaCost;
@@ -559,43 +562,48 @@ public class GameAction {
*/
public boolean checkEndGameSate() {
// Win / Lose
GameSummary game = AllZone.getGameInfo();
boolean humanWins = false;
boolean computerWins = false;
Player computer = AllZone.getComputerPlayer();
Player human = AllZone.getHumanPlayer();
int gameWon = Constant.Runtime.matchState.getWin();
if (human.hasWon()) { // Winning Conditions can be worth more than losing conditions
if ( human.hasWon() || computer.hasLost() ) { // Winning Conditions can be worth more than losing conditions
// Human wins
humanWins = true;
if (human.getAltWin()) {
Constant.Runtime.matchState.setWinMethod(gameWon, human.getWinCondition());
game.end(GameEndReason.WinsGameSpellEffect, PlayerIndex.HUMAN, human.getWinConditionSource());
} else {
game.end(GameEndReason.AllOpponentsLost, PlayerIndex.HUMAN, null);
}
Constant.Runtime.matchState.addWin();
} else if (computer.hasLost()) {
// Human wins
humanWins = true;
if (computer.getAltLose()) {
Constant.Runtime.matchState.setWinMethod(gameWon, computer.getLoseCondition());
}
Constant.Runtime.matchState.addWin();
}
if (computer.hasWon() || human.hasLost()) {
if (humanWins) {
// both players won/lost at the same time.
// TODO: Handle a Draw here
}
game.end(GameEndReason.Draw, PlayerIndex.DRAW, null);
} else {
computerWins = true;
// Computer wins
computerWins = true;
Constant.Runtime.matchState.addLose();
if (computer.getAltWin()) {
game.end(GameEndReason.WinsGameSpellEffect, PlayerIndex.AI, computer.getWinConditionSource());
} else {
game.end(GameEndReason.AllOpponentsLost, PlayerIndex.AI, null);
}
}
}
return humanWins || computerWins;
boolean isGameDone = humanWins || computerWins;
if (isGameDone) {
game.getPlayerRating(PlayerIndex.AI).setLossReason(computer.getLossState());
game.getPlayerRating(PlayerIndex.HUMAN).setLossReason(human.getLossState());
AllZone.getMatchState().addGamePlayed(game);
}
return isGameDone;
}
@@ -616,7 +624,7 @@ public class GameAction {
if (checkEndGameSate()) {
AllZone.getDisplay().savePrefs();
frame.dispose();
new Gui_WinLose();
new Gui_WinLose( AllZone.getMatchState(), AllZone.getQuestData(), AllZone.getQuestAssignment() );
return;
}
@@ -1044,41 +1052,7 @@ public class GameAction {
//AllZone.getComputer() = new ComputerAI_Input(new ComputerAI_General());
Constant.Quest.fantasyQuest[0] = false;
AllZone.getGameInfo().setPreventCombatDamageThisTurn(false);
AllZone.getGameInfo().setHumanNumberOfTimesMulliganed(0);
AllZone.getGameInfo().setHumanMulliganedToZero(false);
AllZone.getGameInfo().setComputerStartedThisGame(false);
AllZone.getHumanPlayer().reset();
AllZone.getComputerPlayer().reset();
AllZone.getPhase().reset();
AllZone.getStack().reset();
AllZone.getCombat().reset();
AllZone.getDisplay().showCombat("");
AllZone.getDisplay().loadPrefs();
AllZone.getHumanGraveyard().reset();
AllZone.getHumanHand().reset();
AllZone.getHumanLibrary().reset();
AllZone.getHumanBattlefield().reset();
AllZone.getHumanExile().reset();
AllZone.getComputerGraveyard().reset();
AllZone.getComputerHand().reset();
AllZone.getComputerLibrary().reset();
AllZone.getComputerBattlefield().reset();
AllZone.getComputerExile().reset();
AllZone.getInputControl().clearInput();
AllZone.getStaticEffects().reset();
// player.reset() now handles this
//AllZone.getHumanPlayer().clearHandSizeOperations();
//AllZone.getComputerPlayer().clearHandSizeOperations();
AllZone.getTriggerHandler().clearRegistered();
AllZone.newGameCleanup();
forge.card.trigger.Trigger.resetIDs();
@@ -1216,13 +1190,13 @@ public class GameAction {
}
// Only cut/coin toss if it's the first game of the match
if (Constant.Runtime.matchState.countWinLose() == 0) {
if (AllZone.getMatchState().getGamesPlayedCount() == 0) {
// New code to determine who goes first. Delete this if it doesn't work properly
if (isStartCut())
seeWhoPlaysFirst();
else
seeWhoPlaysFirst_CoinToss();
} else if (Constant.Runtime.matchState.didWinRecently()) // if player won last, AI starts
} else if (AllZone.getMatchState().hasHumanWonLastGame()) // if player won last, AI starts
computerStartsGame();
for (int i = 0; i < 7; i++) {
@@ -1482,7 +1456,7 @@ public class GameAction {
*/
public void computerStartsGame() {
AllZone.getPhase().setPlayerTurn(AllZone.getComputerPlayer());
AllZone.getGameInfo().setComputerStartedThisGame(true);
AllZone.getGameInfo().setPlayerWhoGotFirstTurn(PlayerIndex.AI);
}
//if Card had the type "Aura" this method would always return true, since local enchantments are always attached to something

View File

@@ -4,6 +4,7 @@ package forge;
import forge.card.abilityFactory.AbilityFactory;
import forge.card.cardFactory.CardFactoryUtil;
import forge.card.spellability.*;
import forge.game.GameLossReason;
import forge.gui.GuiUtils;
import forge.gui.input.Input;
import forge.gui.input.Input_PayManaCostUtil;
@@ -632,9 +633,6 @@ public class GameActionUtil {
if (c.getCreatureGotBlockedThisCombat()) c.setCreatureGotBlockedThisCombat(false);
}
AllZone.getGameInfo().setAssignedFirstStrikeDamageThisCombat(false);
AllZone.getGameInfo().setResolvedFirstStrikeDamageThisCombat(false);
}
/**
@@ -1025,7 +1023,7 @@ public class GameActionUtil {
CardList nonTokens = AllZoneUtil.getPlayerCardsInPlay(player);
nonTokens = nonTokens.filter(AllZoneUtil.nonToken);
if (nonTokens.size() == 0) {
player.altLoseConditionMet("Lich");
player.loseConditionMet( GameLossReason.SpellEffect, lich.getName());
} else player.sacrificePermanent("Select a permanent to sacrifice", nonTokens);
}
}

View File

@@ -1,194 +0,0 @@
package forge;
import forge.card.mana.ManaCost;
import java.util.ArrayList;
/**
* <p>GameInfo class.</p>
*
* @author Forge
* @version $Id$
*/
public class GameInfo {
private boolean computerStartedThisGame = false;
private int humanNumberOfTimesMulliganed;
private boolean humanMulliganedToZero;
private boolean preventCombatDamageThisTurn;
private boolean assignedFirstStrikeDamageThisCombat;
private boolean resolvedFirstStrikeDamageThisCombat;
private ArrayList<Card_Color> globalColorChanges = new ArrayList<Card_Color>();
/**
* <p>Getter for the field <code>humanNumberOfTimesMulliganed</code>.</p>
*
* @return a int.
*/
public int getHumanNumberOfTimesMulliganed() {
return humanNumberOfTimesMulliganed;
}
/**
* <p>addHumanNumberOfTimesMulliganed.</p>
*
* @param n a int.
*/
public void addHumanNumberOfTimesMulliganed(int n) {
humanNumberOfTimesMulliganed += n;
}
/**
* <p>Setter for the field <code>humanNumberOfTimesMulliganed</code>.</p>
*
* @param n a int.
*/
public void setHumanNumberOfTimesMulliganed(int n) {
humanNumberOfTimesMulliganed = n;
}
/**
* <p>Getter for the field <code>humanMulliganedToZero</code>.</p>
*
* @return a boolean.
*/
public boolean getHumanMulliganedToZero() {
return humanMulliganedToZero;
}
/**
* <p>Setter for the field <code>humanMulliganedToZero</code>.</p>
*
* @param b a boolean.
*/
public void setHumanMulliganedToZero(boolean b) {
humanMulliganedToZero = b;
}
/**
* <p>Setter for the field <code>preventCombatDamageThisTurn</code>.</p>
*
* @param b a boolean.
*/
public void setPreventCombatDamageThisTurn(boolean b) {
preventCombatDamageThisTurn = b;
}
/**
* <p>isPreventCombatDamageThisTurn.</p>
*
* @return a boolean.
*/
public boolean isPreventCombatDamageThisTurn() {
return preventCombatDamageThisTurn;
}
/**
* <p>Setter for the field <code>assignedFirstStrikeDamageThisCombat</code>.</p>
*
* @param b a boolean.
*/
public void setAssignedFirstStrikeDamageThisCombat(boolean b) {
assignedFirstStrikeDamageThisCombat = b;
}
/**
* <p>Getter for the field <code>assignedFirstStrikeDamageThisCombat</code>.</p>
*
* @return a boolean.
*/
public boolean getAssignedFirstStrikeDamageThisCombat() {
return assignedFirstStrikeDamageThisCombat;
}
/**
* <p>Setter for the field <code>resolvedFirstStrikeDamageThisCombat</code>.</p>
*
* @param b a boolean.
*/
public void setResolvedFirstStrikeDamageThisCombat(boolean b) {
resolvedFirstStrikeDamageThisCombat = b;
}
/**
* <p>Getter for the field <code>resolvedFirstStrikeDamageThisCombat</code>.</p>
*
* @return a boolean.
*/
public boolean getResolvedFirstStrikeDamageThisCombat() {
return resolvedFirstStrikeDamageThisCombat;
}
/**
* <p>Setter for the field <code>computerStartedThisGame</code>.</p>
*
* @param computerStartedThisGame a boolean.
*/
public void setComputerStartedThisGame(boolean computerStartedThisGame) {
this.computerStartedThisGame = computerStartedThisGame;
}
/**
* <p>isComputerStartedThisGame.</p>
*
* @return a boolean.
*/
public boolean isComputerStartedThisGame() {
return computerStartedThisGame;
}
/**
* <p>addColorChanges.</p>
*
* @param s a {@link java.lang.String} object.
* @param c a {@link forge.Card} object.
* @param addToColors a boolean.
* @param bIncrease a boolean.
* @return a long.
*/
public long addColorChanges(String s, Card c, boolean addToColors, boolean bIncrease) {
if (bIncrease)
Card_Color.increaseTimestamp();
globalColorChanges.add(new Card_Color(new ManaCost(s), c, addToColors, false));
return Card_Color.getTimestamp();
}
/**
* <p>removeColorChanges.</p>
*
* @param s a {@link java.lang.String} object.
* @param c a {@link forge.Card} object.
* @param addTo a boolean.
* @param timestamp a long.
*/
public void removeColorChanges(String s, Card c, boolean addTo, long timestamp) {
Card_Color removeCol = null;
for (Card_Color cc : globalColorChanges)
if (cc.equals(s, c, addTo, timestamp))
removeCol = cc;
if (removeCol != null)
globalColorChanges.remove(removeCol);
}
/**
* <p>clearColorChanges.</p>
*/
public void clearColorChanges() {
// clear the global color changes at end of each game
globalColorChanges.clear();
}
/**
* <p>getColorChanges.</p>
*
* @return a {@link java.util.ArrayList} object.
*/
public ArrayList<Card_Color> getColorChanges() {
return globalColorChanges;
}
}

View File

@@ -7,6 +7,7 @@ import arcane.ui.ViewPanel;
import arcane.ui.util.Animation;
import forge.card.cardFactory.CardFactoryUtil;
import forge.error.ErrorViewer;
import forge.game.GameLossReason;
import forge.gui.ForgeAction;
import forge.gui.GuiUtils;
import forge.gui.game.CardDetailPanel;
@@ -59,7 +60,6 @@ public class GuiDisplay4 extends JFrame implements CardContainer, Display, NewCo
Font lifeFont = new Font("Dialog", Font.PLAIN, 40);
// Font checkboxFont = new Font("Dialog", Font.PLAIN, 9);
/** Constant <code>greenColor</code> */
public static Color greenColor = new Color(0, 164, 0);
@@ -1134,10 +1134,8 @@ public class GuiDisplay4 extends JFrame implements CardContainer, Display, NewCo
* Exit the Application
*/
private void concede() {
savePrefs();
dispose();
Constant.Runtime.matchState.addLose();
new Gui_WinLose();
AllZone.getHumanPlayer().loseConditionMet(GameLossReason.Conceded, null );
AllZone.getGameAction().checkStateEffects();
}
// ********** Phase stuff in Display ******************

View File

@@ -1,25 +1,38 @@
package forge;
import forge.error.ErrorViewer;
import forge.error.E
import forge.game.GameEndReason;
rrorViewer;
import forge.game.GameLossReason;
import forge.game.GamePlayerRating;
import forge.game.GameSummary;
import forge.game.PlayerIndex;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.properties.NewConstants.LANG.Gui_WinLose.WINLOSE_TEXT;
import forge.quest.data.QuestData;
import forge.quest.data.QuestMatchState;
import forge.quest.data.QuestPreferences;
import forge.quest.gui.QuestFrame;
import forge.view.swing.OldGuiNewGame;
import net.miginfocom.swing.MigLayout;
import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import java.awt.Color;
import java.awt.*;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.ArrayList;
/**
* <p>Gui_WinLose class.</p>
@@ -31,14 +44,6 @@ public class Gui_WinLose extends JFrame implements NewConstants {
/** Constant <code>serialVersionUID=-5800412940994975483L</code> */
private static final long serialVersionUID = -5800412940994975483L;
//private CardList humanList;
//private CardList computerList;
//private int humanLife;
//private int computerLife;
//private boolean fantasyQuest = false;
private JLabel titleLabel = new JLabel();
private JButton continueButton = new JButton();
private JButton restartButton = new JButton();
@@ -52,51 +57,22 @@ public class Gui_WinLose extends JFrame implements NewConstants {
// border1
private Border border1;
/**
* <p>Constructor for Gui_WinLose.</p>
*
* @param human a {@link forge.CardList} object.
* @param computer a {@link forge.CardList} object.
* @param hLife a int.
* @param cLife a int.
*/
public Gui_WinLose(CardList human, CardList computer, int hLife, int cLife) {
/*
fantasyQuest = true;
humanList = human;
computerList = computer;
humanLife = hLife;
computerLife= cLife;
*/
try {
jbInit();
} catch (Exception ex) {
ErrorViewer.showError(ex);
}
setup();
Dimension screen = this.getToolkit().getScreenSize();
setBounds(screen.width / 3, 100, //position
215, 370); //size
setVisible(true);
private class WinLoseModel {
public QuestMatchState match;
public QuestData quest;
public Quest_Assignment qa;
}
private WinLoseModel model;
/**
* <p>Constructor for Gui_WinLose.</p>
*/
public Gui_WinLose() {
/*
fantasyQuest = false;
humanList = new CardList();
computerList = new CardList();
humanLife = 20;
computerLife= 20;
*/
public Gui_WinLose(final QuestMatchState matchState, final QuestData quest, final Quest_Assignment qa) {
model = new WinLoseModel();
model.match = matchState;
model.quest = quest;
model.qa = qa;
try {
jbInit();
@@ -107,8 +83,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
setup();
Dimension screen = this.getToolkit().getScreenSize();
setBounds(screen.width / 3, 100, //position
215, 370); //size
setBounds(screen.width / 3, 100 /*position*/, 215, 370 /*size*/);
setVisible(true);
}
@@ -116,47 +91,28 @@ public class Gui_WinLose extends JFrame implements NewConstants {
* <p>setup.</p>
*/
private void setup() {
AllZone.getGameInfo().clearColorChanges();
QuestMatchState winLose = Constant.Runtime.matchState;
Phase.setGameBegins(0);
//3 is the match length, 3 is the number of games
//disable buttons if match is up, or human player won 2 or lost 2 games already
if ((winLose.countWinLose() == 3) || (winLose.getWin() == 2) || (winLose.getLose() == 2)) {
if (model.match.isMatchOver()) {
// editDeckButton.setEnabled(false);
continueButton.setEnabled(false);
quitButton.grabFocus();
}
if (winLose.getWin() == 2)
restartButton.setEnabled(false);
restartButton.setEnabled(!model.match.isMatchWonByHuman());
//show Wins and Loses
statsLabel.setText(ForgeProps.getLocalized(WINLOSE_TEXT.WON) + winLose.getWin() + ForgeProps.getLocalized(WINLOSE_TEXT.LOST) + winLose.getLose());
int humanWins = model.match.getGamesCountWonByHuman();
int humanLosses = model.match.getGamesCountLostByHuman();
statsLabel.setText(ForgeProps.getLocalized(WINLOSE_TEXT.WON) + humanWins
+ ForgeProps.getLocalized(WINLOSE_TEXT.LOST) + humanLosses);
//show "You Won" or "You Lost"
if (winLose.didWinRecently()) {
if (model.match.hasHumanWonLastGame()) {
titleLabel.setText(ForgeProps.getLocalized(WINLOSE_TEXT.WIN));
int game = 0;
if (winLose.getWinTurns()[0] != 0)
game = 1;
int turn = AllZone.getPhase().getTurn();
if (AllZone.getGameInfo().isComputerStartedThisGame())
turn--;
if (turn < 1)
turn = 1;
winLose.setWinTurn(game, turn);
winLose.setMulliganedToZero(game, AllZone.getGameInfo().getHumanMulliganedToZero());
//winLose.setWinTurn(winLose.countWinLose()-1, AllZone.getPhase().getTurn());
//System.out.println("CountwinLose:" + winLose.countWinLose());
//System.out.println("You won by turn: " + AllZone.getPhase().getTurn());
} else {
titleLabel.setText(ForgeProps.getLocalized(WINLOSE_TEXT.LOSE));
//System.out.println("You lost by turn: " + AllZone.getPhase().getTurn());
}
}//setup();
@@ -174,21 +130,15 @@ public class Gui_WinLose extends JFrame implements NewConstants {
this.getContentPane().setLayout(new MigLayout("fill"));
continueButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.CONTINUE));
continueButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
continueButton_actionPerformed(e);
}
public void actionPerformed(ActionEvent e) { continueButton_actionPerformed(e); }
});
restartButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.RESTART));
restartButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
restartButton_actionPerformed(e);
}
public void actionPerformed(ActionEvent e) { restartButton_actionPerformed(e); }
});
quitButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.QUIT));
quitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
quitButton_actionPerformed(e);
}
public void actionPerformed(ActionEvent e) { quitButton_actionPerformed(e); }
});
statsLabel.setFont(new java.awt.Font("Dialog", 0, 16));
statsLabel.setHorizontalAlignment(SwingConstants.CENTER);
@@ -196,9 +146,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
jPanel2.setLayout(new MigLayout("align center"));
this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
this_windowClosing(e);
}
public void windowClosing(WindowEvent e) { this_windowClosing(e); }
});
this.getContentPane().add(titleLabel, "align center, grow, wrap");
this.getContentPane().add(statsLabel, "align center, grow, wrap");
@@ -209,26 +157,6 @@ public class Gui_WinLose extends JFrame implements NewConstants {
}
/**
* <p>editDeckButton_actionPerformed.</p>
*
* @param e a {@link java.awt.event.ActionEvent} object.
*/
void editDeckButton_actionPerformed(ActionEvent e) {
Command exit = new Command() {
private static final long serialVersionUID = 4735992294414389187L;
public void execute() {
new Gui_WinLose();
}
};
Gui_DeckEditor editor = new Gui_DeckEditor();
editor.show(exit);
dispose();
}//editDeckButton_actionPerformed()
/**
* <p>continueButton_actionPerformed.</p>
*
@@ -236,32 +164,36 @@ public class Gui_WinLose extends JFrame implements NewConstants {
*/
void continueButton_actionPerformed(ActionEvent e) {
//open up "Game" screen
//AllZone.getComputerPlay().reset();//sometimes computer has creature in play in the 2nd game of the match
if (!Constant.Quest.fantasyQuest[0])
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]);
else {
PrepareForNextRound();
AllZone.getDisplay().setVisible(true);
dispose();
}
void PrepareForNextRound()
{
if (Constant.Quest.fantasyQuest[0]) {
int extraLife = 0;
if (AllZone.getQuestAssignment() != null) {
forge.quest.data.QuestUtil.setupQuest(AllZone.getQuestAssignment());
if (AllZone.getQuestData().getInventory().hasItem("Zeppelin"))
if (model.qa != null) {
forge.quest.data.QuestUtil.setupQuest(model.qa);
if (model.quest.getInventory().hasItem("Zeppelin"))
extraLife = 3;
}
//AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, computerList, humanLife, computerLife);
CardList humanList = forge.quest.data.QuestUtil.getHumanPlantAndPet(AllZone.getQuestData(), AllZone.getQuestAssignment());
CardList humanList = forge.quest.data.QuestUtil.getHumanPlantAndPet(model.quest, model.qa);
CardList computerList = new CardList();
int humanLife = AllZone.getQuestData().getLife() + extraLife;
int humanLife = model.quest.getLife() + extraLife;
int computerLife = 20;
if (AllZone.getQuestAssignment() != null)
computerLife = AllZone.getQuestAssignment().getComputerLife();
if ( model.qa != null )
computerLife = model.qa.getComputerLife();
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, computerList, humanLife, computerLife, AllZone.getQuestAssignment());
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, computerList, humanLife, computerLife, model.qa );
} else {
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]);
}
AllZone.getDisplay().setVisible(true);
dispose();
}
/**
@@ -270,33 +202,9 @@ public class Gui_WinLose extends JFrame implements NewConstants {
* @param e a {@link java.awt.event.ActionEvent} object.
*/
void restartButton_actionPerformed(ActionEvent e) {
Constant.Runtime.matchState.reset();
if (!Constant.Quest.fantasyQuest[0])
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]);
else {
int extraLife = 0;
//AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, computerList, humanLife, computerLife);
if (AllZone.getQuestAssignment() != null) {
forge.quest.data.QuestUtil.setupQuest(AllZone.getQuestAssignment());
if (AllZone.getQuestData().getInventory().hasItem("Zeppelin"))
extraLife = 3;
}
CardList humanList = forge.quest.data.QuestUtil.getHumanPlantAndPet(AllZone.getQuestData(), AllZone.getQuestAssignment());
//CardList computerList = QuestUtil.getComputerCreatures(AllZone.getQuestData(), AllZone.getQuestAssignment());
CardList computerList = new CardList();
int humanLife = AllZone.getQuestData().getLife() + extraLife;
int computerLife = 20;
if (AllZone.getQuestAssignment() != null)
computerLife = AllZone.getQuestAssignment().getComputerLife();
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, computerList, humanLife, computerLife, AllZone.getQuestAssignment());
}
model.match.reset();
PrepareForNextRound();
AllZone.getDisplay().setVisible(true);
dispose();
}
@@ -304,88 +212,82 @@ public class Gui_WinLose extends JFrame implements NewConstants {
* <p>getWinText.</p>
*
* @param creds a long.
* @param winLose a {@link forge.quest.data.QuestMatchState} object.
* @param matchState a {@link forge.quest.data.QuestMatchState} object.
* @param q a {@link forge.quest.data.QuestData} object.
* @return a {@link java.lang.String} object.
*/
private String getWinText(long creds, QuestMatchState winLose, forge.quest.data.QuestData q) {
private String getCreditsAwardedText(final long creds, final QuestMatchState matchState, final forge.quest.data.QuestData q) {
// TODO use q.qdPrefs to write bonus credits in prefs file
StringBuilder sb = new StringBuilder();
String[] wins = winLose.getWinMethods();
StringBuilder sb = new StringBuilder("<html>");
sb.append("<html>");
boolean hasNeverLost = true;
for (GameSummary game : matchState.getGamesPlayed()) {
if (game.isAIWinner()) {
hasNeverLost = true;
continue; // no rewards for losing a game
}
for (String s : wins) {
if (s != null) {
sb.append("Alternate win condition: ");
sb.append("<u>");
sb.append(s);
sb.append("</u>");
sb.append("! Bonus: <b>+");
GamePlayerRating aiRating = game.getPlayerRating(PlayerIndex.AI);
GamePlayerRating humanRating = game.getPlayerRating(PlayerIndex.HUMAN);
GameLossReason whyAiLost = aiRating.getLossReason();
if (s.equals("Poison Counters"))
sb.append(QuestPreferences.getMatchRewardPoisonWinBonus());
else if (s.equals("Milled"))
sb.append(QuestPreferences.getMatchRewardMilledWinBonus());
else if (s.equals("Battle of Wits") ||
s.equals("Felidar Sovereign") || s.equals("Helix Pinnacle") || s.equals("Epic Struggle") ||
s.equals("Door to Nothingness") || s.equals("Barren Glory") || s.equals("Near-Death Experience") ||
s.equals("Mortal Combat") || s.equals("Test of Endurance")) {
sb.append(QuestPreferences.getMatchRewardAltWinBonus());
int rewardAltWinCondition = q.getCreditsRewardForAltWin(whyAiLost);
if (rewardAltWinCondition > 0) {
String winConditionName = "Unknown (bug)";
if ( game.getWinCondition() == GameEndReason.WinsGameSpellEffect ) {
winConditionName = game.getWinSpellEffect();
} else {
switch( whyAiLost ) {
case Poisoned: winConditionName = "Poison"; break;
case Milled: winConditionName = "Milled"; break;
default: break;
}
}
sb.append(" credits</b>.<br>");
String bonus = String.format("Alternate win condition: <u>%s</u>! Bonus: <b>+%d credits</b>.<br>",
winConditionName, rewardAltWinCondition);
sb.append(bonus);
}
int winTurn = game.getTurnGameEnded();
int turnCredits = q.getCreditsRewardForWinByTurn(winTurn);
if (winTurn == 0) { // this case should never happen - anyway, no reward if we got here
} else if (winTurn == 1) { sb.append("Won in one turn!");
} else if (winTurn <= 5) { sb.append("Won by turn 5!");
} else if (winTurn <= 10) { sb.append("Won by turn 10!");
} else if (winTurn <= 15) { sb.append("Won by turn 15!");
}
if (turnCredits > 0) {
sb.append(String.format(" Bonus: <b>+%d credits</b>.<br>", turnCredits));
}
int cntCardsHumanStartedWith = humanRating.getOpeningHandSize();
if ( 0 == cntCardsHumanStartedWith )
{
int reward = QuestPreferences.getMatchMullToZero();
sb.append(String.format("Mulliganed to zero and still won! Bonus: <b>%d credits</b>.<br>", reward));
}
}
int[] winTurns = winLose.getWinTurns();
for (int i : winTurns) {
System.out.println("Quest, won by turn:" + i);
if (i != 0) {
int turnCredits = 0;
if (i == 1) {
sb.append("Won in one turn!");
turnCredits += QuestPreferences.getMatchRewardWinFirst();
} else if (i <= 5) {
sb.append("Won by turn 5!");
turnCredits += QuestPreferences.getMatchRewardWinByFifth();
} else if (i <= 10) {
sb.append("Won by turn 10!");
turnCredits += QuestPreferences.getMatchRewardWinByTen();
} else if (i <= 15) {
sb.append("Won by turn 15!");
turnCredits += QuestPreferences.getMatchRewardWinByFifteen();
}
if (turnCredits > 0)
sb.append(" Bonus: <b>+").append(turnCredits).append(" credits</b>.<br>");
}
if (hasNeverLost) {
int reward = QuestPreferences.getMatchRewardNoLosses();
sb.append(String.format("You have not lost once! Bonus: <b>+%d credits</b>.<br>", reward));
}
boolean[] mulliganedToZero = winLose.getMulliganedToZero();
int estatesLevel = q.getInventory().getItemLevel("Estates");
for (boolean b : mulliganedToZero) {
if (b) {
sb.append("Mulliganed to zero and still won! Bonus: <b>+");
sb.append(QuestPreferences.getMatchMullToZero()).append(" credits</b>.<br>");
}
}
if (winLose.getLose() == 0)
sb.append("You have not lost once! Bonus: <b>+");
sb.append(QuestPreferences.getMatchRewardNoLosses()).append(" credits</b>.<br>");
if (q.getInventory().getItemLevel("Estates") == 1)
if (estatesLevel == 1) {
sb.append("Estates bonus: <b>10%</b>.<br>");
else if (q.getInventory().getItemLevel("Estates") == 2)
} else if (estatesLevel == 2) {
sb.append("Estates bonus: <b>15%</b>.<br>");
else if (q.getInventory().getItemLevel("Estates") == 3)
} else if (estatesLevel == 3) {
sb.append("Estates bonus: <b>20%</b>.<br>");
}
sb.append("You have earned <b>" + creds + " credits</b> in total.");
sb.append("</html>");
@@ -428,110 +330,30 @@ public class Gui_WinLose extends JFrame implements NewConstants {
if (AllZone.getQuestData() == null) {
new OldGuiNewGame();
} else { //Quest
QuestMatchState matchState = Constant.Runtime.matchState;
forge.quest.data.QuestData quest = AllZone.getQuestData();
boolean wonMatch = false;
if (matchState.getWin() == 2) {
quest.addWin();
if (model.match.isMatchWonByHuman()) {
model.quest.addWin();
wonMatch = true;
} else quest.addLost();
} else {
model.quest.addLost();
}
//System.out.println("QuestData cardpoolsize:" + AllZone.getQuestData().getCardpool().size());
if (AllZone.getQuestData().getShopList() != null)
AllZone.getQuestData().clearShopList();
if (AllZone.getQuestData().getAvailableQuests() != null)
AllZone.getQuestData().clearAvailableQuests();
if (quest.shouldAddCards(wonMatch)) {
quest.addCards();
String fileName = "BookIcon.png";
ImageIcon icon = getIcon(fileName);
StringBuilder sb = new StringBuilder();
sb.append("You have won the following new cards:\n");
for (int i = 0; i < quest.getAddedCards().size(); i++)
sb.append(quest.getAddedCards().get(i) + "\n");
JOptionPane.showMessageDialog(null, sb.toString(), "", JOptionPane.INFORMATION_MESSAGE, icon);
if (model.quest.getShopList() != null) {
model.quest.clearShopList();
}
if (wonMatch) {
long creds = quest.getCreditsToAdd(matchState);
String s = getWinText(creds, matchState, quest);
String fileName = "GoldIcon.png";
ImageIcon icon = getIcon(fileName);
JOptionPane.showMessageDialog(null, s, "", JOptionPane.INFORMATION_MESSAGE, icon);
int wins = quest.getWin();
if (wins > 0 && wins % 80 == 0) // at every 80 wins, give 10 random rares
{
quest.addRandomRare(10);
fileName = "BoxIcon.png";
icon = getIcon(fileName);
JOptionPane.showMessageDialog(null, "You just won 10 random rares!", "", JOptionPane.INFORMATION_MESSAGE, icon);
}
if (AllZone.getQuestAssignment() != null) {
AllZone.getQuestData().addQuestsPlayed();
Quest_Assignment qa = AllZone.getQuestAssignment();
StringBuilder sb = new StringBuilder();
sb.append("Quest Completed - \r\n");
if (qa.getCardRewardList() != null) {
sb.append("You won the following cards:\r\n\r\n");
for (String cardName : qa.getCardRewardList()) {
sb.append(cardName);
sb.append("\r\n");
AllZone.getQuestData().addCard(cardName);
}
AllZone.getQuestData().addToNewList(qa.getCardRewardList());
sb.append("\r\n");
}
sb.append("Quest Bounty: ");
sb.append(qa.getCreditsReward());
AllZone.getQuestData().addCredits(qa.getCreditsReward());
fileName = "BoxIcon.png";
icon = getIcon(fileName);
JOptionPane.showMessageDialog(null, sb.toString(), "Quest Rewards for " + qa.getName(), JOptionPane.INFORMATION_MESSAGE, icon);
}/*
else if(quest.getDifficultyIndex() == 4) {
Card c = AllZone.getCardFactory().getCard(quest.addRandomRare(), AllZone.getHumanPlayer());
c.setCurSetCode(c.getMostRecentSet());
fileName = CardUtil.buildFilename(c) +".jpg";
icon = getCardIcon(fileName);
JOptionPane.showMessageDialog(null, "", "You have won a random rare for winning against a very hard deck.", JOptionPane.INFORMATION_MESSAGE, icon);
}*/
} else {
quest.subtractCredits(15);
String fileName = "HeartIcon.png";
ImageIcon icon = getIcon(fileName);
JOptionPane.showMessageDialog(null, "You lose! You have lost 15 credits.", "Awwww", JOptionPane.INFORMATION_MESSAGE, icon);
if (model.quest.getAvailableQuests() != null) {
model.quest.clearAvailableQuests();
}
if (quest.shouldAddAdditionalCards(wonMatch)) {
Card c = AllZone.getCardFactory().getCard(quest.addRandomRare(), AllZone.getHumanPlayer());
c.setCurSetCode(c.getMostRecentSet());
String fileName = CardUtil.buildFilename(c) + ".jpg";
ImageIcon icon = getCardIcon(fileName);
JOptionPane.showMessageDialog(null, "", "You have won a random rare.", JOptionPane.INFORMATION_MESSAGE, icon);
}
matchState.reset();
giveQuestRewards(wonMatch);
model.match.reset();
AllZone.setQuestAssignment(null);
quest.saveData();
model.quest.saveData();
new QuestFrame();
}//else - on quest
@@ -552,4 +374,106 @@ public class Gui_WinLose extends JFrame implements NewConstants {
void this_windowClosing(WindowEvent e) {
quitButton_actionPerformed(null);
}
protected void giveQuestRewards(final boolean wonMatch) {
// Award a random booster, as frequent as set in difficulty setup
if (model.quest.shouldAddCards(wonMatch)) {
ArrayList<String> cardsWon = model.quest.addCards();
StringBuilder sb = new StringBuilder();
sb.append("You have won the following new cards:\n");
for (String cardName : cardsWon) {
sb.append(cardName + "\n");
}
String fileName = "BookIcon.png";
ImageIcon icon = getIcon(fileName);
JOptionPane.showMessageDialog(null, sb.toString(), "", JOptionPane.INFORMATION_MESSAGE, icon);
}
// Award credits
if (wonMatch) {
long creds = model.quest.getCreditsToAdd(model.match);
model.quest.addCredits(creds);
String s = getCreditsAwardedText(creds, model.match, model.quest);
String fileName = "GoldIcon.png";
ImageIcon icon = getIcon(fileName);
JOptionPane.showMessageDialog(null, s, "", JOptionPane.INFORMATION_MESSAGE, icon);
}
// Award 10 rares for 80 games won
if (wonMatch) {
int wins = model.quest.getWin();
if (wins > 0 && wins % 80 == 0) // at every 80 wins, give 10 random rares
{
model.quest.addRandomRare(10);
String fileName = "BoxIcon.png";
ImageIcon icon = getIcon(fileName);
String title = "You just won 10 random rares!";
JOptionPane.showMessageDialog(null, title, "", JOptionPane.INFORMATION_MESSAGE, icon);
}
}
// Rewards from QuestAssignment
if (wonMatch && model.qa != null) {
model.quest.addQuestsPlayed();
ArrayList<String> questRewardCards = model.qa.getCardRewardList();
long questRewardCredits = model.qa.getCreditsReward();
StringBuilder sb = new StringBuilder();
sb.append("Quest Completed - \r\n");
if (questRewardCards != null) {
sb.append("You won the following cards:\r\n\r\n");
for (String cardName : questRewardCards) {
sb.append(cardName);
sb.append("\r\n");
model.quest.addCard(cardName);
}
model.quest.addToNewList(questRewardCards);
sb.append("\r\n");
}
sb.append("Quest Bounty: ");
sb.append(questRewardCredits);
model.quest.addCredits(questRewardCredits);
String fileName = "BoxIcon.png";
ImageIcon icon = getIcon(fileName);
String title = "Quest Rewards for " + model.qa.getName();
JOptionPane.showMessageDialog(null, sb.toString(), title, JOptionPane.INFORMATION_MESSAGE, icon);
}
/*
else if(quest.getDifficultyIndex() == 4) {
Card c = AllZone.getCardFactory().getCard(quest.addRandomRare(), AllZone.getHumanPlayer());
c.setCurSetCode(c.getMostRecentSet());
fileName = CardUtil.buildFilename(c) +".jpg";
icon = getCardIcon(fileName);
JOptionPane.showMessageDialog(null, "", "You have won a random rare for winning against a very hard deck.", JOptionPane.INFORMATION_MESSAGE, icon);
}*/
// Loss match penalty
if (!wonMatch) {
model.quest.subtractCredits(15);
String fileName = "HeartIcon.png";
ImageIcon icon = getIcon(fileName);
String text = "You lose! You have lost 15 credits.";
JOptionPane.showMessageDialog(null, text, "Awwww", JOptionPane.INFORMATION_MESSAGE, icon);
}
// Random rare given at 50% chance (65% with luck upgrade)
if (model.quest.shouldAddAdditionalCards(wonMatch)) {
Card c = AllZone.getCardFactory().getCard(model.quest.addRandomRare(), AllZone.getHumanPlayer());
c.setCurSetCode(c.getMostRecentSet());
String fileName = CardUtil.buildFilename(c) + ".jpg";
ImageIcon icon = getCardIcon(fileName);
String title = "You have won a random rare.";
JOptionPane.showMessageDialog(null, "", title, JOptionPane.INFORMATION_MESSAGE, icon);
}
}
}

View File

@@ -46,6 +46,7 @@ public class Phase extends MyObservable implements java.io.Serializable {
private int extraCombats;
private int nCombatsThisTurn;
private boolean bPreventCombatDamageThisTurn;
private Player playerTurn = AllZone.getHumanPlayer();
@@ -247,6 +248,7 @@ public class Phase extends MyObservable implements java.io.Serializable {
extraTurns.clear();
nCombatsThisTurn = 0;
extraCombats = 0;
bPreventCombatDamageThisTurn = false;
bCombat = false;
bRepeat = false;
this.updateObservers();
@@ -316,7 +318,7 @@ public class Phase extends MyObservable implements java.io.Serializable {
AllZone.getPhase().setNeedToNextPhase(true);
else {
if (!AllZone.getGameInfo().isPreventCombatDamageThisTurn())
if (!AllZone.getPhase().isPreventCombatDamageThisTurn())
Combat.dealAssignedDamage();
AllZone.getGameAction().checkStateEffects();
@@ -331,7 +333,7 @@ public class Phase extends MyObservable implements java.io.Serializable {
AllZone.getCombat().setAssignedDamage();
if (!AllZone.getGameInfo().isPreventCombatDamageThisTurn())
if (!AllZone.getPhase().isPreventCombatDamageThisTurn())
Combat.dealAssignedDamage();
AllZone.getGameAction().checkStateEffects();
@@ -383,6 +385,10 @@ public class Phase extends MyObservable implements java.io.Serializable {
resetPriority();
}
public boolean isPreventCombatDamageThisTurn() {
return bPreventCombatDamageThisTurn;
}
/**
* <p>nextPhase.</p>
*/
@@ -420,9 +426,11 @@ public class Phase extends MyObservable implements java.io.Serializable {
this.bCombat = false;
}
if (phaseOrder[phaseIndex].equals(Constant.Phase.Cleanup))
if (phaseOrder[phaseIndex].equals(Constant.Phase.Cleanup)) {
bPreventCombatDamageThisTurn = false;
if (!bRepeat)
AllZone.getPhase().setPlayerTurn(handleNextTurn());
}
if (is(Constant.Phase.Combat_Declare_Blockers)) {
AllZone.getStack().unfreezeStack();
@@ -666,9 +674,6 @@ public class Phase extends MyObservable implements java.io.Serializable {
if (c.getCreatureBlockedThisCombat()) c.setCreatureBlockedThisCombat(false);
if (c.getCreatureGotBlockedThisCombat()) c.setCreatureGotBlockedThisCombat(false);
AllZone.getGameInfo().setAssignedFirstStrikeDamageThisCombat(false);
AllZone.getGameInfo().setResolvedFirstStrikeDamageThisCombat(false);
}
}
@@ -1026,4 +1031,8 @@ public class Phase extends MyObservable implements java.io.Serializable {
static void setComputerInstantSpellCount(int i) {
ComputerInstantSpellCount = (i);
}
public void setPreventCombatDamageThisTurn(boolean b) {
bPreventCombatDamageThisTurn = true;
}
}

View File

@@ -38,6 +38,7 @@ public class PhaseUtil {
Player turn = AllZone.getPhase().getPlayerTurn();
AllZone.getPhase().turnReset();
AllZone.getGameInfo().notifyNextTurn();
AllZone.getCombat().reset();
AllZone.getCombat().setAttackingPlayer(turn);

View File

@@ -1,5 +1,6 @@
package forge;
import forge.game.GameLossReason;
import forge.card.cardFactory.CardFactoryUtil;
import forge.card.mana.ManaPool;
import forge.card.spellability.Ability;
@@ -24,9 +25,10 @@ public abstract class Player extends MyObservable {
protected int numPowerSurgeLands;
protected boolean altWin = false;
protected String winCondition = "";
protected String altWinSourceName;
protected boolean altLose = false;
protected String loseCondition = "";
protected GameLossReason lossState = GameLossReason.DidNotLoseYet;
protected String loseConditionSpell;
protected int nTurns = 0;
protected boolean skipNextUntap = false;
@@ -44,6 +46,7 @@ public abstract class Player extends MyObservable {
protected Object mustAttackEntity = null;
/**
* <p>Constructor for Player.</p>
*
@@ -81,9 +84,10 @@ public abstract class Player extends MyObservable {
slowtripList = new CardList();
nTurns = 0;
altWin = false;
altWinSourceName = null;
altLose = false;
winCondition = "";
loseCondition = "";
lossState = GameLossReason.DidNotLoseYet;
loseConditionSpell = null;
maxLandsToPlay = 1;
numLandsPlayed = 0;
@@ -907,7 +911,8 @@ public abstract class Player extends MyObservable {
//lose:
else if (!Constant.Runtime.DevMode[0] || AllZone.getDisplay().canLoseByDecking()) {
// if devMode is off, or canLoseByDecking is Enabled, run Lose Condition
if (altLoseConditionMet("Milled")) {
if (!cantLose()) {
loseConditionMet(GameLossReason.Milled, null);
AllZone.getGameAction().checkStateEffects();
}
}
@@ -1424,22 +1429,14 @@ public abstract class Player extends MyObservable {
return altWin;
}
/**
* <p>Getter for the field <code>altLose</code>.</p>
*
* @return a boolean.
*/
public boolean getAltLose() {
return altLose;
}
/**
* <p>Getter for the field <code>winCondition</code>.</p>
*
* @return a {@link java.lang.String} object.
*/
public String getWinCondition() {
return winCondition;
public String getWinConditionSource()
{
return altWinSourceName;
}
/**
@@ -1447,8 +1444,8 @@ public abstract class Player extends MyObservable {
*
* @return a {@link java.lang.String} object.
*/
public String getLoseCondition() {
return loseCondition;
public GameLossReason getLossState() {
return lossState;
}
/**
@@ -1456,13 +1453,13 @@ public abstract class Player extends MyObservable {
*
* @param s a {@link java.lang.String} object.
*/
public void altWinConditionMet(String s) {
public void altWinBySpellEffect( String sourceName ) {
if (cantWin()) {
System.out.println("Tried to win, but currently can't.");
return;
}
altWin = true;
winCondition = s;
altWinSourceName = sourceName;
}
/**
@@ -1471,16 +1468,18 @@ public abstract class Player extends MyObservable {
* @param s a {@link java.lang.String} object.
* @return a boolean.
*/
public boolean altLoseConditionMet(String s) {
public boolean loseConditionMet(GameLossReason state, String spellName ) {
if (cantLose()) {
System.out.println("Tried to lose, but currently can't.");
return false;
}
altLose = true;
loseCondition = s;
lossState = state;
loseConditionSpell = spellName;
return true;
}
/**
* <p>cantLose.</p>
*
@@ -1539,12 +1538,12 @@ public abstract class Player extends MyObservable {
if (cantLose())
return false;
if (altLose) {
if (lossState != GameLossReason.DidNotLoseYet) {
return true;
}
if (poisonCounters >= 10) {
altLoseConditionMet("Poison Counters");
loseConditionMet( GameLossReason.Poisoned, null );
return true;
}
@@ -1552,7 +1551,13 @@ public abstract class Player extends MyObservable {
return false;
}
return getLife() <= 0;
boolean hasNoLife = getLife() <= 0;
if (hasNoLife) {
loseConditionMet( GameLossReason.LifeReachedZero, null);
return true;
}
return false;
}

View File

@@ -2345,7 +2345,7 @@ public class Upkeep implements java.io.Serializable {
@Override
public void resolve() {
if (player.getLife() >= 40)
player.altWinConditionMet(source.getName());
player.altWinBySpellEffect(source.getName());
}
};// Ability
@@ -2377,7 +2377,7 @@ public class Upkeep implements java.io.Serializable {
CardList grave = AllZoneUtil.getPlayerGraveyard(player);
grave = grave.filter(AllZoneUtil.creatures);
if (grave.size() >= 20)
player.altWinConditionMet(source.getName());
player.altWinBySpellEffect(source.getName());
}
};// Ability
@@ -2405,7 +2405,7 @@ public class Upkeep implements java.io.Serializable {
@Override
public void resolve() {
if (c.getCounters(Counters.TOWER) >= 100)
player.altWinConditionMet(c.getName());
player.altWinBySpellEffect(c.getName());
}
};// Ability
@@ -2435,7 +2435,7 @@ public class Upkeep implements java.io.Serializable {
@Override
public void resolve() {
if (player.getLife() == 1)
player.altWinConditionMet(source.getName());
player.altWinBySpellEffect(source.getName());
}
};// Ability
@@ -2465,7 +2465,7 @@ public class Upkeep implements java.io.Serializable {
@Override
public void resolve() {
if (player.getLife() >= 50)
player.altWinConditionMet(source.getName());
player.altWinBySpellEffect(source.getName());
}
};// Ability
@@ -2507,7 +2507,7 @@ public class Upkeep implements java.io.Serializable {
playList.remove(source);
if (playList.size() == 0 && handList.size() == 0)
player.altWinConditionMet(source.getName());
player.altWinBySpellEffect(source.getName());
}
};// Ability

View File

@@ -166,7 +166,7 @@ public class AbilityFactory_Combat {
if (AllZone.getStack().size() != 0) return false;
// Don't cast it, if the effect is already in place
if (AllZone.getGameInfo().isPreventCombatDamageThisTurn()) return false;
if (AllZone.getPhase().isPreventCombatDamageThisTurn()) return false;
Ability_Sub subAb = sa.getSubAbility();
if (subAb != null)
@@ -234,7 +234,7 @@ public class AbilityFactory_Combat {
public static void fogResolve(final AbilityFactory af, final SpellAbility sa) {
// Expand Fog keyword here depending on what we need out of it.
AllZone.getGameInfo().setPreventCombatDamageThisTurn(true);
AllZone.getPhase().setPreventCombatDamageThisTurn(true);
}
//**************************************************************

View File

@@ -5,6 +5,7 @@ import forge.Card;
import forge.ComputerUtil;
import forge.Player;
import forge.card.spellability.*;
import forge.game.GameLossReason;
import java.util.ArrayList;
@@ -213,7 +214,7 @@ public class AbilityFactory_EndGameCondition {
ArrayList<Player> players = AbilityFactory.getDefinedPlayers(card, af.getMapParams().get("Defined"), sa);
for (Player p : players)
p.altWinConditionMet(card.getName());
p.altWinBySpellEffect(card.getName());
}
// ***********************************************************************************************
@@ -449,7 +450,7 @@ public class AbilityFactory_EndGameCondition {
}
for (Player p : players)
p.altLoseConditionMet(card.getName());
p.loseConditionMet( GameLossReason.SpellEffect, card.getName());
}
}

View File

@@ -26,6 +26,7 @@ import forge.PlayerZone;
import forge.card.abilityFactory.AbilityFactory;
import forge.card.spellability.*;
import forge.card.trigger.Trigger;
import forge.game.GameLossReason;
import forge.gui.GuiUtils;
import forge.gui.input.Input;
import forge.gui.input.Input_PayManaCost;
@@ -1804,7 +1805,7 @@ public abstract class AbstractCardFactory implements NewConstants, CardFactoryIn
final SpellAbility loseGame = new Ability(card, "0") {
@Override
public void resolve() {
card.getController().altLoseConditionMet(card.getName());
card.getController().loseConditionMet( GameLossReason.SpellEffect, card.getName());
}
};

View File

@@ -876,7 +876,6 @@ public class CardFactory_Creatures {
Object o = GuiUtils.getChoice("Choose color", colors);
color[0] = (String) o;
card.setChosenColor(color[0]);
} else {
// AI chooses the color that appears in the keywords of the most cards in its deck, hand and on battlefield
CardList list = new CardList();
@@ -895,11 +894,11 @@ public class CardFactory_Creatures {
color[0] = c;
}
}
card.setChosenColor(color[0]);
}
card.setChosenColor(color[0]);
String s = CardUtil.getShortColor(color[0]);
timeStamp[0] = AllZone.getGameInfo().addColorChanges(s, card, true, true);
timeStamp[0] = AllZone.getColorChanger().addColorChanges(s, card, true, true);
}
};//Command
@@ -908,7 +907,7 @@ public class CardFactory_Creatures {
public void execute() {
String s = CardUtil.getShortColor(color[0]);
AllZone.getGameInfo().removeColorChanges(s, card, true, timeStamp[0]);
AllZone.getColorChanger().removeColorChanges(s, card, true, timeStamp[0]);
}
};

View File

@@ -0,0 +1,10 @@
package forge.game;
public enum GameEndReason {
AllOpponentsLost,
// Noone won
Draw, // Having little idea how they can reach a draw, so I didn't enumerate possible reasons here
// Special conditions, they force one player to win and thus end the game
WinsGameSpellEffect // ones that could be both hardcoded (felidar) and scripted ( such as Mayael's Aria )
}

View File

@@ -0,0 +1,36 @@
package forge.game;
public enum GameLossReason {
DidNotLoseYet, // a winner must have this status by the end of the game
Conceded, // rule 104.3a
LifeReachedZero, // rule 104.3b
Milled, // 104.3c
Poisoned, // 104.3d
// 104.3e and others
SpellEffect
/*DoorToNothingness, // Door To Nothingness's ability activated
// TODO: Implement game logics for the ones below
Transcendence20Life, // When you have 20 or more life, you lose the game.
FailedToPayPactUpkeep, // Pacts from Future Sight series (cost 0 but you must pay their real cost at next turn's upkeep, otherwise GL)
PhageTheUntouchableDamage, // Whenever Phage deals combat damage to a player, that player loses the game.
PhageTheUntouchableWrongETB, // When Phage the Untouchable ETB, if you didn't cast it from your hand, you lose the game.
NefariousLichLeavesTB, // When Nefarious Lich leaves the battlefield, you lose the game.
NefariousLichCannotExileGrave, // If damage would be dealt to you, exile that many cards from your graveyard instead. If you can't, you lose the game.
LichWasPutToGraveyard, // When Lich is put into a graveyard from the battlefield, you lose the game.
FinalFortune, // same as Warrior's Oath - lose at the granted extra turn's end step
ImmortalCoilEmptyGraveyard, // When there are no cards in your graveyard, you lose the game.
ForbiddenCryptEmptyGraveyard, // If you would draw a card, return a card from your graveyard to your hand instead. If you can't, you lose the game.
// Amulet of quoz skipped for using ante,
// Form of the Squirrel and Rocket-Powered Turbo Slug skipped for being part of UN- set
*/
// refer to http://gatherer.wizards.com/Pages/Search/Default.aspx?output=standard&text=+[%22lose+the+game%22] for more cards when they are printed
}

View File

@@ -0,0 +1,41 @@
package forge.game;
/**
*
* @author Max
*
*/
public class GamePlayerRating {
boolean hasWonTheCoin;
protected int turnsMade = 0;
protected int openingHandSize = 7;
protected int timesMulliganed = 0;
protected GameLossReason lossReason = GameLossReason.DidNotLoseYet;
public final GameLossReason getLossReason() {
return lossReason;
}
public void setLossReason(GameLossReason loseCondition) {
lossReason = loseCondition;
}
public final int getOpeningHandSize() {
return openingHandSize;
}
public final void notifyHasMulliganed() {
timesMulliganed++;
}
public final int getMulliganCount() {
return timesMulliganed;
}
public final void notifyOpeningHandSize(final int newHand) {
openingHandSize = newHand;
}
}

View File

@@ -0,0 +1,67 @@
package forge.game;
/**
* <p>GameInfo class.</p>
*
* @author Forge
* @version $Id$
*/
// This should be divided into two: the very summary (immutable with only getters) and
// GameObserver class - who should be notified of any considerable ingame event
public class GameSummary {
protected int playerWinner = PlayerIndex.UNDEFINED;
protected int playerGotFirstTurn = PlayerIndex.UNDEFINED;
protected int lastTurnNumber = 0;
protected GameEndReason winCondition;
protected String spellEffectWin;
protected GamePlayerRating playerRating[] = new GamePlayerRating[2/*players*/];
public GameSummary()
{
playerRating[PlayerIndex.AI] = new GamePlayerRating();
playerRating[PlayerIndex.HUMAN] = new GamePlayerRating();
}
public final void end( final GameEndReason condition, int iPlayerWinner, String spellEffectWin )
{
winCondition = condition;
playerWinner = iPlayerWinner;
this.spellEffectWin = spellEffectWin;
}
public final boolean isHumanWinner() { return PlayerIndex.HUMAN == playerWinner; }
public final boolean isAIWinner() { return PlayerIndex.AI == playerWinner; }
public final boolean isDraw() { return PlayerIndex.DRAW == playerWinner; }
public GameEndReason getWinCondition() { return winCondition; }
public GamePlayerRating getPlayerRating(int iPlayer) {
if (iPlayer >= 0 && iPlayer < playerRating.length) {
return playerRating[iPlayer];
}
return null;
}
public int getTurnGameEnded() {
return lastTurnNumber;
}
public final void setPlayerWhoGotFirstTurn(int iPlayer)
{
playerGotFirstTurn = iPlayer;
}
public void notifyNextTurn() {
lastTurnNumber++;
}
public String getWinSpellEffect() {
return spellEffectWin;
}
}

View File

@@ -0,0 +1,8 @@
package forge.game;
public interface PlayerIndex {
int UNDEFINED = Integer.MIN_VALUE;
int DRAW = -1;
int HUMAN = 0;
int AI = 1;
}

View File

@@ -0,0 +1,2 @@
/** Forge Card Game */
package forge.game;

View File

@@ -1,6 +1,9 @@
package forge.gui.input;
import forge.*;
import forge.game.GamePlayerRating;
import forge.game.PlayerIndex;
import forge.quest.data.QuestData;
/**
* <p>Input_Mulligan class.</p>
@@ -12,6 +15,9 @@ public class Input_Mulligan extends Input {
/** Constant <code>serialVersionUID=-8112954303001155622L</code> */
private static final long serialVersionUID = -8112954303001155622L;
private static final int MAGIC_NUMBER_OF_SHUFFLES = 100;
private static final int AI_MULLIGAN_THRESHOLD = 5;
/** {@inheritDoc} */
@Override
public void showMessage() {
@@ -27,31 +33,32 @@ public class Input_Mulligan extends Input {
end();
}
public int doMulligan( Player player, GamePlayerRating playerRating ) {
CardList hand = AllZoneUtil.getPlayerHand(player);
for (Card c : hand) { AllZone.getGameAction().moveToLibrary(c); }
for (int i = 0; i < MAGIC_NUMBER_OF_SHUFFLES; i++) { player.shuffle(); }
int newHand = hand.size() - 1;
for (int i = 0; i < newHand; i++) { player.drawCard(); }
playerRating.notifyHasMulliganed();
playerRating.notifyOpeningHandSize(newHand);
return newHand;
}
/** {@inheritDoc} */
@Override
public void selectButtonCancel() {
AllZone.getGameInfo().setHumanMulliganedToZero(false);
GamePlayerRating humanRating = AllZone.getGameInfo().getPlayerRating(PlayerIndex.HUMAN);
Player humanPlayer = AllZone.getHumanPlayer();
CardList hand = AllZoneUtil.getPlayerHand(AllZone.getHumanPlayer());
for (Card c : hand)
AllZone.getGameAction().moveToLibrary(c);
int newHand = doMulligan(humanPlayer, humanRating);
for (int i = 0; i < 100; i++)
AllZone.getHumanPlayer().shuffle();
int newHand = hand.size() - 1;
AllZone.getGameInfo().addHumanNumberOfTimesMulliganed(1);
if (AllZone.getQuestData() != null) {
if (AllZone.getQuestData().getInventory().hasItem("Sleight") && AllZone.getGameInfo().getHumanNumberOfTimesMulliganed() == 1)
newHand++;
}
for (int i = 0; i < newHand; i++)
QuestData quest = AllZone.getQuestData();
if (quest != null && quest.getInventory().hasItem("Sleight") && humanRating.getMulliganCount() == 1) {
AllZone.getHumanPlayer().drawCard();
humanRating.notifyOpeningHandSize(newHand + 1);
}
if (newHand == 0) {
AllZone.getGameInfo().setHumanMulliganedToZero(true);
end();
}
}//selectButtonOK()
@@ -61,29 +68,27 @@ public class Input_Mulligan extends Input {
*/
void end() {
//Computer mulligan
CardList CHandList = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer());
Player aiPlayer = AllZone.getComputerPlayer();
GamePlayerRating aiRating = AllZone.getGameInfo().getPlayerRating(PlayerIndex.AI);
boolean aiTakesMulligan = true;
Card dummy = CHandList.get(0);
//Computer mulligans if there are no cards with converted mana cost of 0 in its hand
while (CHandList.size() > 5 && CHandList.getValidCards("Card.cmcEQ0", AllZone.getComputerPlayer(), dummy).size() < 2) {
for (Card c : CHandList)
AllZone.getGameAction().moveToLibrary(c);
while (aiTakesMulligan) {
for (int i = 0; i < 100; i++)
AllZone.getComputerPlayer().shuffle();
CardList handList = AllZoneUtil.getPlayerHand(aiPlayer);
boolean hasLittleCmc0Cards = handList.getValidCards("Card.cmcEQ0", aiPlayer, null).size() < 2;
aiTakesMulligan = handList.size() > AI_MULLIGAN_THRESHOLD && hasLittleCmc0Cards;
int newHand = CHandList.size() - 1;
for (int i = 0; i < newHand; i++)
AllZone.getComputerPlayer().drawCard();
CHandList = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer());
if (aiTakesMulligan) {
doMulligan(aiPlayer, aiRating);
}
}
//Human Leylines
ButtonUtil.reset();
CardList HHandList = AllZoneUtil.getPlayerHand(AllZone.getHumanPlayer());
CardList humanOpeningHand = AllZoneUtil.getPlayerHand(AllZone.getHumanPlayer());
for (Card c : HHandList) {
for (Card c : humanOpeningHand) {
if (c.getName().startsWith("Leyline")) {
if (GameActionUtil.showYesNoDialog(c, "Put onto Battlefield?"))
AllZone.getGameAction().moveToPlay(c);
@@ -91,7 +96,8 @@ public class Input_Mulligan extends Input {
}
//Computer Leylines
for (Card c : CHandList) {
CardList aiOpeningHand = AllZoneUtil.getPlayerHand(AllZone.getComputerPlayer());
for (Card c : aiOpeningHand) {
if (c.getName().startsWith("Leyline") && !(c.getName().startsWith("Leyline of Singularity")
&& AllZoneUtil.getCardsInPlay("Leyline of Singularity").size() > 0)) {
AllZone.getGameAction().moveToPlay(c);
@@ -99,8 +105,8 @@ public class Input_Mulligan extends Input {
}
}
if (AllZone.getGameAction().isStartCut() && !(HHandList.contains(AllZone.getGameAction().getHumanCut())
|| CHandList.contains(AllZone.getGameAction().getComputerCut()))) {
if (AllZone.getGameAction().isStartCut() && !(humanOpeningHand.contains(AllZone.getGameAction().getHumanCut())
|| aiOpeningHand.contains(AllZone.getGameAction().getComputerCut()))) {
AllZone.getGameAction().moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.getHumanPlayer()), AllZone.getGameAction().getHumanCut());
AllZone.getGameAction().moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.getComputerPlayer()), AllZone.getGameAction().getComputerCut());
}

View File

@@ -3,6 +3,10 @@ package forge.quest.data;
import forge.*;
import forge.deck.Deck;
import forge.error.ErrorViewer;
import forge.game.GameLossReason;
import forge.game.GamePlayerRating;
import forge.game.GameSummary;
import forge.game.PlayerIndex;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.quest.data.item.QuestInventory;
@@ -482,63 +486,80 @@ public class QuestData {
}
}
public final int getCreditsRewardForAltWin(final GameLossReason whyAiLost) {
int rewardAltWinCondition = 0;
switch (whyAiLost) {
case LifeReachedZero:
break; // nothing special here, ordinary kill
case Milled:
rewardAltWinCondition = QuestPreferences.getMatchRewardMilledWinBonus();
break;
case Poisoned:
rewardAltWinCondition = QuestPreferences.getMatchRewardPoisonWinBonus();
break;
case DidNotLoseYet: // must be player's alternate win condition: felidar, helix pinnacle and like this
rewardAltWinCondition = QuestPreferences.getMatchRewardAltWinBonus();
break;
default: // this .checkstyle forces us to write some idiotic code
rewardAltWinCondition = 0;
}
return rewardAltWinCondition;
}
public final int getCreditsRewardForWinByTurn(final int iTurn) {
if (iTurn == 1) {
return QuestPreferences.getMatchRewardWinFirst();
} else if (iTurn <= 5) {
return QuestPreferences.getMatchRewardWinByFifth();
} else if (iTurn <= 10) {
return QuestPreferences.getMatchRewardWinByTen();
} else if (iTurn <= 15) {
return QuestPreferences.getMatchRewardWinByFifteen();
}
return 0;
}
/**
* <p>getCreditsToAdd.</p>
*
* @param matchState a {@link forge.quest.data.QuestMatchState} object.
* @return a long.
*/
public long getCreditsToAdd(QuestMatchState matchState) {
long creds = (long) (QuestPreferences.getMatchRewardBase() + (QuestPreferences.getMatchRewardTotalWins() * win));
String[] wins = matchState.getWinMethods();
int[] winTurns = matchState.getWinTurns();
boolean[] mulliganedToZero = matchState.getMulliganedToZero();
public final long getCreditsToAdd(final QuestMatchState matchState) {
long creds = (long) (QuestPreferences.getMatchRewardBase()
+ (QuestPreferences.getMatchRewardTotalWins() * win));
if (matchState.getLose() == 0) {
creds += QuestPreferences.getMatchRewardNoLosses();
}
for (String s : wins) {
if (s != null) {
if (s.equals("Poison Counters")) {
creds += QuestPreferences.getMatchRewardPoisonWinBonus();
} else if (s.equals("Milled")) {
creds += QuestPreferences.getMatchRewardMilledWinBonus();
} else if (s.equals("Battle of Wits") || s.equals("Felidar Sovereign") || s.equals("Helix Pinnacle") ||
s.equals("Epic Struggle") || s.equals("Door to Nothingness") || s.equals("Barren Glory") ||
s.equals("Near-Death Experience") || s.equals("Mortal Combat") || s.equals("Test of Endurance")) {
creds += QuestPreferences.getMatchRewardAltWinBonus();
}
boolean hasNeverLost = true;
for (GameSummary game : matchState.getGamesPlayed()) {
if (game.isAIWinner()) {
hasNeverLost = true;
continue; // no rewards for losing a game
}
}
for (int i : winTurns) {
if (i == 1) {
creds += QuestPreferences.getMatchRewardWinFirst();
} else if (i <= 5) {
creds += QuestPreferences.getMatchRewardWinByFifth();
} else if (i <= 10) {
creds += QuestPreferences.getMatchRewardWinByTen();
} else if (i <= 15) {
creds += QuestPreferences.getMatchRewardWinByFifteen();
}
}
GamePlayerRating aiRating = game.getPlayerRating(PlayerIndex.AI);
GamePlayerRating humanRating = game.getPlayerRating(PlayerIndex.HUMAN);
GameLossReason whyAiLost = aiRating.getLossReason();
for (boolean b : mulliganedToZero) {
if (b == true) {
creds += getCreditsRewardForAltWin(whyAiLost);
creds += getCreditsRewardForWinByTurn(game.getTurnGameEnded());
int cntCardsHumanStartedWith = humanRating.getOpeningHandSize();
if (0 == cntCardsHumanStartedWith) {
creds += QuestPreferences.getMatchMullToZero();
}
}
if (inventory.getItemLevel("Estates") == 1) {
creds *= 1.1;
} else if (inventory.getItemLevel("Estates") == 2) {
creds *= 1.15;
} else if (inventory.getItemLevel("Estates") == 3) {
creds *= 1.2;
if (hasNeverLost) {
creds += QuestPreferences.getMatchRewardNoLosses();
}
this.addCredits(creds);
switch(inventory.getItemLevel("Estates")) {
case 1: creds *= 1.1; break;
case 2: creds *= 1.15; break;
case 3: creds *= 1.2; break;
default: break;
}
return creds;
}

View File

@@ -1,163 +1,79 @@
package forge.quest.data;
import java.util.ArrayList;
import java.util.List;
import forge.game.GameSummary;
/**
* <p>QuestMatchState class.</p>
*
* @author Forge
* @version $Id$
*/
public class QuestMatchState {
//the way wins were achieved:
//Damage
//Poison Counters
//Battle of Wits
//Mortal Combat
//Milled
//Felidar Sovereign
//...
//
private String[] winMethods = new String[2];
private int[] winTurns = new int[2];
public static final int GAMES_PER_MATCH = 3;
public static final int MIN_GAMES_TO_WIN_MATCH = 2;
private boolean[] mulliganedToZero = new boolean[2];
private List<GameSummary> gamesPlayed = new ArrayList<GameSummary>();
//ArrayList<GameSpecialConditions>
private int win;
private int lose;
private boolean winRecently;
/**
* <p>reset.</p>
*/
public void reset() {
win = 0;
lose = 0;
winMethods = new String[2];
public final void addGamePlayed(final GameSummary completedGame) {
gamesPlayed.add(completedGame);
}
/**
* <p>addWin.</p>
*/
public void addWin() {
win++;
winRecently = true;
public final GameSummary[] getGamesPlayed() {
return gamesPlayed.toArray(new GameSummary[gamesPlayed.size()]);
}
/**
* <p>addLose.</p>
*/
public void addLose() {
lose++;
winRecently = false;
public final int getGamesPlayedCount() {
return gamesPlayed.size();
}
/**
* <p>Getter for the field <code>win</code>.</p>
*
* @return a int.
*/
public int getWin() {
return win;
public final boolean hasHumanWonLastGame() {
int iLastGame = gamesPlayed.size() - 1;
return iLastGame >= 0 ? gamesPlayed.get(iLastGame).isHumanWinner() : false;
}
/**
* <p>Getter for the field <code>lose</code>.</p>
*
* @return a int.
*/
public int getLose() {
return lose;
public final boolean isMatchOver() {
int winsHuman = 0;
int winsAI = 0;
int totalGames = 0;
for (GameSummary game : gamesPlayed) {
if (game.isAIWinner()) { winsAI++; }
if (game.isHumanWinner()) { winsHuman++; }
totalGames++;
}
return winsAI >= MIN_GAMES_TO_WIN_MATCH || winsHuman >= MIN_GAMES_TO_WIN_MATCH || totalGames >= GAMES_PER_MATCH;
}
/**
* <p>countWinLose.</p>
*
* @return a int.
*/
public int countWinLose() {
return win + lose;
public final int getGamesCountWonByHuman() {
int winsHuman = 0;
for (GameSummary game : gamesPlayed) {
if (game.isHumanWinner()) { winsHuman++; }
}
return winsHuman;
}
/**
* <p>setWinMethod.</p>
*
* @param gameNumber a int.
* @param method a {@link java.lang.String} object.
*/
public void setWinMethod(int gameNumber, String method) {
winMethods[gameNumber] = method;
public final int getGamesCountLostByHuman() {
int lossHuman = 0;
for (GameSummary game : gamesPlayed) {
if (!game.isHumanWinner()) { lossHuman++; }
}
return lossHuman;
}
/**
* <p>Getter for the field <code>winMethods</code>.</p>
*
* @return an array of {@link java.lang.String} objects.
*/
public String[] getWinMethods() {
return winMethods;
public final boolean isMatchWonByHuman() {
return getGamesCountWonByHuman() >= MIN_GAMES_TO_WIN_MATCH;
}
/**
* <p>setWinTurn.</p>
*
* @param gameNumber a int.
* @param turns a int.
*/
public void setWinTurn(int gameNumber, int turns) {
winTurns[gameNumber] = turns;
public final void reset() {
gamesPlayed.clear();
}
/**
* <p>Getter for the field <code>winTurns</code>.</p>
*
* @return an array of int.
*/
public int[] getWinTurns() {
return winTurns;
}
/**
* <p>Getter for the field <code>mulliganedToZero</code>.</p>
*
* @return an array of boolean.
*/
public boolean[] getMulliganedToZero() {
return mulliganedToZero;
}
/**
* <p>Setter for the field <code>mulliganedToZero</code>.</p>
*
* @param gameNumber a int.
* @param b a boolean.
*/
public void setMulliganedToZero(int gameNumber, boolean b) {
mulliganedToZero[gameNumber] = b;
}
/**
* <p>didWinRecently.</p>
*
* @return a boolean.
*/
public boolean didWinRecently() {
return winRecently;
}
/**
* <p>isMatchOver.</p>
* @return whether match is complete
*/
public boolean isMatchOver()
{
return win == 2 || lose == 2;
}
/**
* <p>isMatchOver.</p>
* @return whether match is won
*/
public boolean isMatchWon()
{
return win == 2;
}
}

View File

@@ -149,7 +149,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
*/
private JPanel createSidePanel() {
JPanel panel = new JPanel();
JPanel optionsPanel;//Create options checkbox list
JPanel optionsPanel; //Create options checkbox list
optionsPanel = createOptionsPanel();
List<Component> eastComponents = new ArrayList<Component>();
@@ -659,7 +659,7 @@ public class QuestMainPanel extends QuestAbstractPanel {
Constant.Runtime.Smooth[0] = smoothLandCheckBox.isSelected();
AllZone.getMatchState().reset();
if (isShowingQuests) {
setupQuest(humanDeck);
} else {

View File

@@ -126,7 +126,6 @@ public class OldGuiNewGame extends JFrame implements NewConstants, NewConstants.
AllZone.setQuestData(null);
allDecks = getDecks();
Constant.Runtime.matchState.reset();
if (Constant.Runtime.width[0] == 0) {
Constant.Runtime.width[0] = 70;

View File

@@ -3,6 +3,8 @@ package forge;
import org.testng.Assert;
import org.testng.annotations.Test;
import forge.quest.data.QuestMatchState;
/**
* Created by IntelliJ IDEA.
* User: dhudson
@@ -15,7 +17,7 @@ public class GuiWinLoseTest {
*/
@Test(groups = {"UnitTest", "fast"})
public void GuiWinLoseTest1() {
Gui_WinLose dialog = new Gui_WinLose();
Gui_WinLose dialog = new Gui_WinLose( new QuestMatchState(), null, null );
dialog.setVisible(true);
Assert.assertNotNull(dialog);
dialog.dispose();