Well, it's issue 0047 - decouple view from model+controller.
The main goal was to provide options for quest reward booster generation. Although it's somewhat easy, requiring just to add a parameter to QuestData.addCards, the way the Gui_WinLose code was organized didn't please me. It contained comparisons against strings for determining special win conditions, like that
- Code: Select all
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>+");
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());
}
sb.append(" credits</b>.<br>");
}
}
Moreover, this code has been duplicated at QuestData.java, but without stringbuilding that time.
Old code also calculated some victory conditions on the fly, that is exactly inside the Gui_WinLose class, I mean
- Code: Select all
// This is Gui_WinLose.setup() body!
if (winLose.didWinRecently()) {
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());
Here we can see some shamanism of determining the game number and calculating the number of turns taken in a GUI designated class.
So, considering this way of victory condition checks awful, I decided to rewrite the whole system.
Now it is extensible and allows us to introduce more stats and achievements, like total damage dealt to creatures, max number of creatures on battlefield, anmount of lives gained throughout the game and so on... We can analyse these metrics after the match is complete and award something in case they are somehow notable.
The original goal was committed in r9853: player can now choose cards from which format he would like to receive as a reward booster. Though, without proper UI this looks quite ugly - a choice window pops on, then a dialog, then another dialog about credits gained, and yet another one with random rare.