mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Initial commit of the Draft Tournament for Quests.
This commit is contained in:
@@ -64,6 +64,8 @@ public interface IGuiBase {
|
||||
void updatePhase();
|
||||
void updateTurn(GameEventTurnBegan event, Game game);
|
||||
void updatePlayerControl();
|
||||
void enableOverlay();
|
||||
void disableOverlay();
|
||||
void finishGame();
|
||||
void updateStack();
|
||||
void updateZones(List<Pair<Player, ZoneType>> zonesToUpdate);
|
||||
|
||||
@@ -154,6 +154,23 @@ public final class BoosterDraft implements IBoosterDraft {
|
||||
draft.pack = draft.get8BoosterPack();
|
||||
return draft;
|
||||
}
|
||||
|
||||
public static BoosterDraft createDraft(final LimitedPoolType draftType, final CardBlock block, final String[] boosters) {
|
||||
|
||||
BoosterDraft draft = new BoosterDraft(draftType);
|
||||
|
||||
final int nPacks = boosters.length;
|
||||
|
||||
for (int i = 0; i < nPacks; i++) {
|
||||
draft.product.add(block.getBooster(boosters[i]));
|
||||
}
|
||||
|
||||
IBoosterDraft.LAND_SET_CODE[0] = block.getLandSet();
|
||||
|
||||
draft.pack = draft.get8BoosterPack();
|
||||
return draft;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -17,12 +17,20 @@
|
||||
*/
|
||||
package forge.quest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.game.GameFormat;
|
||||
import forge.game.event.GameEvent;
|
||||
import forge.game.event.GameEventMulligan;
|
||||
@@ -43,9 +51,6 @@ import forge.quest.io.QuestChallengeReader;
|
||||
import forge.util.storage.IStorage;
|
||||
import forge.util.storage.StorageBase;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
@@ -76,6 +81,9 @@ public class QuestController {
|
||||
|
||||
// This is used by shop. Had no idea where else to place this
|
||||
private static transient IStorage<PreconDeck> preconManager = null;
|
||||
|
||||
private transient IStorage<DeckGroup> draftDecks;
|
||||
|
||||
|
||||
/** The Constant RANK_TITLES. */
|
||||
public static final String[] RANK_TITLES = new String[] { "Level 0 - Confused Wizard", "Level 1 - Mana Mage",
|
||||
@@ -91,8 +99,7 @@ public class QuestController {
|
||||
|
||||
/** */
|
||||
public static final int MAX_PET_SLOTS = 2;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Write javadoc for this method.
|
||||
@@ -142,6 +149,10 @@ public class QuestController {
|
||||
public IStorage<Deck> getMyDecks() {
|
||||
return this.decks;
|
||||
}
|
||||
|
||||
public IStorage<DeckGroup> getDraftDecks() {
|
||||
return draftDecks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current format if any.
|
||||
@@ -209,6 +220,8 @@ public class QuestController {
|
||||
this.myCards = this.model == null ? null : new QuestUtilCards(this);
|
||||
this.questFormat = this.model == null ? null : this.model.getFormat();
|
||||
this.currentEvent = null;
|
||||
|
||||
this.draftDecks = this.model == null ? null : this.model.getAssets().getDraftDeckStorage();
|
||||
|
||||
this.resetDuelsManager();
|
||||
this.resetChallengesManager();
|
||||
|
||||
60
forge-gui/src/main/java/forge/quest/QuestDeckGroupMap.java
Normal file
60
forge-gui/src/main/java/forge/quest/QuestDeckGroupMap.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.quest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.util.storage.StorageBase;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class QuestDeckGroupMap extends StorageBase<DeckGroup> {
|
||||
|
||||
/**
|
||||
* Instantiates a new quest deck map.
|
||||
*/
|
||||
public QuestDeckGroupMap(Map<String, DeckGroup> in) {
|
||||
super("Quest draft decks", in == null ? new HashMap<String, DeckGroup>() : in);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.util.IFolderMap#add(forge.util.IHasName)
|
||||
*/
|
||||
@Override
|
||||
public void add(final DeckGroup deck) {
|
||||
this.map.put(deck.getName(), deck);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.util.IFolderMap#delete(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void delete(final String deckName) {
|
||||
this.map.remove(deckName);
|
||||
}
|
||||
|
||||
}
|
||||
459
forge-gui/src/main/java/forge/quest/QuestEventDraft.java
Normal file
459
forge-gui/src/main/java/forge/quest/QuestEventDraft.java
Normal file
@@ -0,0 +1,459 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.quest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.card.CardEdition;
|
||||
import forge.limited.LimitedPoolType;
|
||||
import forge.model.CardBlock;
|
||||
import forge.model.FModel;
|
||||
import forge.quest.io.ReadPriceList;
|
||||
import forge.util.NameGenerator;
|
||||
import forge.util.storage.IStorage;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* QuestEvent.
|
||||
* </p>
|
||||
*
|
||||
* MODEL - A basic event instance in Quest mode. Can be extended for use in
|
||||
* unique event types: battles, quests, and others.
|
||||
*/
|
||||
public class QuestEventDraft {
|
||||
|
||||
public static final String UNDETERMINED = "quest_draft_undetermined_place";
|
||||
public static final String HUMAN = "quest_draft_human_place";
|
||||
public static final String DECK_NAME = "Tournament Deck";
|
||||
|
||||
public static final Function<QuestEventDraft, String> FN_GET_NAME = new Function<QuestEventDraft, String>() {
|
||||
@Override public final String apply(QuestEventDraft qe) { return qe.title; }
|
||||
};
|
||||
|
||||
private static transient final ReadPriceList PRICE_LIST_READER = new ReadPriceList();
|
||||
private static transient final Map<String, Integer> MAP_PRICES = PRICE_LIST_READER.getPriceList();
|
||||
|
||||
private String title = "Mystery Draft";
|
||||
private String boosterConfiguration = "";
|
||||
private String block = "";
|
||||
|
||||
private int entryFee = 0;
|
||||
|
||||
private String[] standings = new String[15];
|
||||
private String[] aiNames = new String[7];
|
||||
|
||||
private int[] aiIcons = new int[7];
|
||||
|
||||
public QuestEventDraft(final String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public final String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public final String[] getBoosterConfiguration() {
|
||||
return boosterConfiguration.split("/");
|
||||
}
|
||||
|
||||
public final void setBoosterConfiguration(final String boosterConfiguration) {
|
||||
this.boosterConfiguration = boosterConfiguration;
|
||||
}
|
||||
|
||||
public final void setEntryFee(final int entryFee) {
|
||||
this.entryFee = entryFee;
|
||||
}
|
||||
|
||||
public final int getEntryFee() {
|
||||
return entryFee;
|
||||
}
|
||||
|
||||
public final void setBlock(final String block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public final String getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public void setTitle(final String title0) {
|
||||
this.title = title0;
|
||||
}
|
||||
|
||||
public void setStanding(int position, String player) {
|
||||
standings[position] = player;
|
||||
}
|
||||
|
||||
public void setStandings(String[] standings) {
|
||||
this.standings = standings;
|
||||
}
|
||||
|
||||
public String[] getStandings() {
|
||||
return standings;
|
||||
}
|
||||
|
||||
public String[] getAINames() {
|
||||
return aiNames;
|
||||
}
|
||||
|
||||
public void setAINames(final String[] names) {
|
||||
aiNames = names;
|
||||
}
|
||||
|
||||
public int[] getAIIcons() {
|
||||
return aiIcons;
|
||||
}
|
||||
|
||||
public void setAIIcons(final int[] icons) {
|
||||
aiIcons = icons;
|
||||
}
|
||||
|
||||
public int getHumanLatestStanding() {
|
||||
int humanIndex = 0;
|
||||
for (int i = getStandings().length - 1; i >= 0; i--) {
|
||||
if (getStandings()[i].equals(HUMAN)) {
|
||||
humanIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return humanIndex;
|
||||
}
|
||||
|
||||
public int getOpponentIndex(int playerIndex) {
|
||||
int result = (playerIndex % 2 == 0) ? playerIndex + 1 : playerIndex - 1;
|
||||
if (result == 15) {
|
||||
result = -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setWinner(String playerName) {
|
||||
|
||||
boolean isHumanPlayer = true;
|
||||
|
||||
for (String name : aiNames) {
|
||||
if (playerName.equals(name)) {
|
||||
isHumanPlayer = false;
|
||||
}
|
||||
}
|
||||
|
||||
int playerIndex = -1;
|
||||
|
||||
if (isHumanPlayer) {
|
||||
for (int i = standings.length - 1; i >= 0; i--) {
|
||||
if (standings[i].equals(HUMAN)) {
|
||||
playerIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
String aiIndex = "";
|
||||
|
||||
for (int i = aiNames.length - 1; i >= 0; i--) {
|
||||
if (aiNames[i].equals(playerName)) {
|
||||
aiIndex = "" + (i + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = standings.length - 1; i >= 0; i--) {
|
||||
if (standings[i].equals(aiIndex)) {
|
||||
playerIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch (playerIndex) {
|
||||
case 0:
|
||||
case 1:
|
||||
standings[8] = standings[playerIndex];
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
standings[9] = standings[playerIndex];
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
standings[10] = standings[playerIndex];
|
||||
break;
|
||||
case 6:
|
||||
case 7:
|
||||
standings[11] = standings[playerIndex];
|
||||
break;
|
||||
case 8:
|
||||
case 9:
|
||||
standings[12] = standings[playerIndex];
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
standings[13] = standings[playerIndex];
|
||||
break;
|
||||
case 12:
|
||||
case 13:
|
||||
standings[14] = standings[playerIndex];
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random draft event based on the provided quest's limitations.
|
||||
* Returns null in the event no draft could be created.
|
||||
* @param quest
|
||||
* @return
|
||||
*/
|
||||
public static QuestEventDraft getRandomDraftOrNull(final QuestController quest) {
|
||||
|
||||
List<CardBlock> possibleBlocks = new ArrayList<CardBlock>();
|
||||
List<CardEdition> allowedQuestSets = new ArrayList<CardEdition>();
|
||||
|
||||
boolean questUsesLimitedCardPool = quest.getFormat() != null;
|
||||
|
||||
if (questUsesLimitedCardPool) {
|
||||
|
||||
List<String> allowedSetCodes = quest.getFormat().getAllowedSetCodes();
|
||||
|
||||
for (String setCode : allowedSetCodes) {
|
||||
allowedQuestSets.add(FModel.getMagicDb().getEditions().get(setCode));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LimitedPoolType draftType = LimitedPoolType.Block;
|
||||
|
||||
List<CardBlock> blocks = new ArrayList<CardBlock>();
|
||||
IStorage<CardBlock> storage = draftType == LimitedPoolType.Block ? FModel.getBlocks() : FModel.getFantasyBlocks();
|
||||
|
||||
for (CardBlock b : storage) {
|
||||
if (b.getCntBoostersDraft() > 0) {
|
||||
blocks.add(b);
|
||||
}
|
||||
}
|
||||
|
||||
if (questUsesLimitedCardPool) {
|
||||
for (CardBlock block : blocks) {
|
||||
|
||||
boolean blockAllowed = true;
|
||||
|
||||
for (CardEdition set : block.getSets()) {
|
||||
if (!allowedQuestSets.contains(set)) {
|
||||
blockAllowed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (blockAllowed) {
|
||||
possibleBlocks.add(block);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
possibleBlocks.addAll(blocks);
|
||||
}
|
||||
|
||||
if (possibleBlocks.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Collections.shuffle(possibleBlocks);
|
||||
CardBlock selectedBlock = possibleBlocks.get(0);
|
||||
|
||||
final Stack<String> sets = new Stack<String>();
|
||||
for (int k = selectedBlock.getSets().length - 1; k >= 0; k--) {
|
||||
sets.add(selectedBlock.getSets()[k].getCode());
|
||||
}
|
||||
|
||||
for (String setCode : selectedBlock.getMetaSetNames()) {
|
||||
if (selectedBlock.getMetaSet(setCode).isDraftable()) {
|
||||
sets.push(setCode);
|
||||
}
|
||||
}
|
||||
|
||||
QuestEventDraft event = new QuestEventDraft(selectedBlock.getName());
|
||||
|
||||
if (selectedBlock.getNumberSets() == 1) {
|
||||
String boosterConfiguration = "";
|
||||
for (int i = 0; i < selectedBlock.getCntBoostersDraft(); i++) {
|
||||
boosterConfiguration += selectedBlock.getSets()[0].getCode();
|
||||
if (i != selectedBlock.getCntBoostersDraft() - 1) {
|
||||
boosterConfiguration += "/";
|
||||
}
|
||||
event.boosterConfiguration = boosterConfiguration;
|
||||
}
|
||||
} else {
|
||||
List<String> possibleSetCombinations = getSetCombos(sets);
|
||||
Collections.shuffle(possibleSetCombinations);
|
||||
event.boosterConfiguration = possibleSetCombinations.get(0);
|
||||
}
|
||||
|
||||
event.block = selectedBlock.getName();
|
||||
event.entryFee = calculateEntryFee(event.boosterConfiguration.split("/"));
|
||||
|
||||
List<String> players = new ArrayList<String>();
|
||||
players.add(HUMAN);
|
||||
players.add("1");
|
||||
players.add("2");
|
||||
players.add("3");
|
||||
players.add("4");
|
||||
players.add("5");
|
||||
players.add("6");
|
||||
players.add("7");
|
||||
|
||||
Collections.shuffle(players);
|
||||
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
event.standings[i] = players.get(i);
|
||||
}
|
||||
|
||||
for (int i = 8; i < event.standings.length; i++) {
|
||||
event.standings[i] = UNDETERMINED;
|
||||
}
|
||||
|
||||
List<String> usedNames = new ArrayList<String>();
|
||||
usedNames.add(GuiBase.getInterface().getGuiPlayer().getName());
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
event.aiNames[i] = NameGenerator.getRandomName("Any", "Any", usedNames);
|
||||
usedNames.add(event.aiNames[i]);
|
||||
}
|
||||
|
||||
int numberOfIcons = GuiBase.getInterface().getAvatarCount();
|
||||
List<Integer> usedIcons = new ArrayList<Integer>();
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
|
||||
int icon = -1;
|
||||
int attempts = 50;
|
||||
|
||||
do {
|
||||
icon = (int) Math.floor(Math.random() * numberOfIcons);
|
||||
} while ((icon < 0 || usedIcons.contains(icon)) && attempts-- > 0);
|
||||
|
||||
event.aiIcons[i] = icon;
|
||||
usedNames.add(event.aiNames[i]);
|
||||
|
||||
}
|
||||
|
||||
return event;
|
||||
|
||||
}
|
||||
|
||||
private static int calculateEntryFee(String[] boosters) {
|
||||
|
||||
int entryFee = 0;
|
||||
|
||||
for (String boosterSet : boosters) {
|
||||
|
||||
int value = 0;
|
||||
String boosterName = FModel.getMagicDb().getEditions().get(boosterSet).getName() + " Booster Pack";
|
||||
|
||||
if (MAP_PRICES.containsKey(boosterName)) {
|
||||
value = MAP_PRICES.get(boosterName);
|
||||
} else {
|
||||
value = 395;
|
||||
}
|
||||
|
||||
entryFee += value;
|
||||
|
||||
}
|
||||
|
||||
return (int) (entryFee * 1.5);
|
||||
|
||||
}
|
||||
|
||||
private static List<String> getSetCombos(final List<String> setz) {
|
||||
String[] sets = setz.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
|
||||
List<String> setCombos = new ArrayList<String>();
|
||||
if (sets.length >= 2) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[0], sets[0], sets[1]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[0], sets[1], sets[1]));
|
||||
if (sets.length >= 3) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[0], sets[1], sets[2]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[0], sets[2], sets[2]));
|
||||
}
|
||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[1]));
|
||||
if (sets.length >= 3) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[2]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[2], sets[2]));
|
||||
}
|
||||
}
|
||||
if (sets.length >= 3) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[1]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[2]));
|
||||
} // Beyond 3, skimp on the choice configurations, or the list will be enormous!
|
||||
if (sets.length >= 4) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[3], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[3], sets[2], sets[1]));
|
||||
}
|
||||
if (sets.length >= 5) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[4], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[4], sets[3], sets[2]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[4], sets[2], sets[0]));
|
||||
}
|
||||
if (sets.length >= 6) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[5], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[5], sets[3], sets[2]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[5], sets[4], sets[3]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[5], sets[2], sets[0]));
|
||||
}
|
||||
if (sets.length >= 7) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[6], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[6], sets[3], sets[2]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[6], sets[5], sets[4]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[6], sets[3], sets[0]));
|
||||
}
|
||||
if (sets.length >= 8) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[7], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[7], sets[3], sets[2]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[7], sets[5], sets[4]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[7], sets[6], sets[5]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[7], sets[3], sets[0]));
|
||||
}
|
||||
if (sets.length >= 9) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[8], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[8], sets[3], sets[2]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[8], sets[5], sets[4]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[8], sets[7], sets[6]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[8], sets[4], sets[0]));
|
||||
}
|
||||
return setCombos;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package forge.quest.data;
|
||||
|
||||
import forge.model.FModel;
|
||||
import forge.quest.data.QuestPreferences.DifficultyPrefs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.model.FModel;
|
||||
import forge.quest.QuestEventDraft;
|
||||
import forge.quest.data.QuestPreferences.DifficultyPrefs;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
@@ -18,6 +19,11 @@ public class QuestAchievements {
|
||||
|
||||
private List<String> completedChallenges = new ArrayList<String>();
|
||||
private List<String> currentChallenges = new ArrayList<String>();
|
||||
|
||||
private QuestEventDraftContainer drafts = new QuestEventDraftContainer();
|
||||
private int currentDraft = -1;
|
||||
private int draftTokensAvailable = 3;
|
||||
private int winCountAtEndOfDraft = 0;
|
||||
|
||||
private int win;
|
||||
private int winstreakBest = 0;
|
||||
@@ -34,6 +40,17 @@ public class QuestAchievements {
|
||||
public QuestAchievements(int diff) {
|
||||
difficulty = diff;
|
||||
}
|
||||
|
||||
public void deleteDraft(QuestEventDraft draft) {
|
||||
drafts.remove(draft);
|
||||
}
|
||||
|
||||
public void endCurrentTournament() {
|
||||
drafts.remove(drafts.get(currentDraft));
|
||||
currentDraft = -1;
|
||||
winCountAtEndOfDraft = win;
|
||||
FModel.getQuest().save();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
@@ -45,6 +62,13 @@ public class QuestAchievements {
|
||||
public void addWin() { // changes getRank()
|
||||
this.win++;
|
||||
this.winstreakCurrent++;
|
||||
|
||||
//Every 5 wins, allow a tournament to be generated.
|
||||
if ((win - winCountAtEndOfDraft) % 5 == 0) {
|
||||
if (draftTokensAvailable < 3) {
|
||||
draftTokensAvailable++;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.winstreakCurrent > this.winstreakBest) {
|
||||
this.winstreakBest = this.winstreakCurrent;
|
||||
@@ -176,4 +200,48 @@ public class QuestAchievements {
|
||||
return this.difficulty;
|
||||
}
|
||||
|
||||
public QuestEventDraftContainer getDraftEvents() {
|
||||
return drafts;
|
||||
}
|
||||
|
||||
public boolean isTournamentActive() {
|
||||
return currentDraft >= 0;
|
||||
}
|
||||
|
||||
public void generateNewTournaments() {
|
||||
|
||||
if (drafts == null) {
|
||||
drafts = new QuestEventDraftContainer();
|
||||
draftTokensAvailable = 3;
|
||||
}
|
||||
|
||||
int draftsToGenerate = 3 - drafts.size();
|
||||
if (draftsToGenerate > draftTokensAvailable) {
|
||||
draftsToGenerate = draftTokensAvailable;
|
||||
}
|
||||
|
||||
for (int i = 0; i < draftsToGenerate; i++) {
|
||||
QuestEventDraft draft = QuestEventDraft.getRandomDraftOrNull(FModel.getQuest());
|
||||
if (draft != null) {
|
||||
drafts.add(draft);
|
||||
draftTokensAvailable--;
|
||||
}
|
||||
}
|
||||
|
||||
FModel.getQuest().save();
|
||||
|
||||
}
|
||||
|
||||
public void addDraftToken() {
|
||||
draftTokensAvailable++;
|
||||
}
|
||||
|
||||
public void setCurrentDraft(final QuestEventDraft draft) {
|
||||
currentDraft = drafts.indexOf(draft);
|
||||
}
|
||||
|
||||
public QuestEventDraft getCurrentDraft() {
|
||||
return drafts.get(currentDraft);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,10 +17,16 @@
|
||||
*/
|
||||
package forge.quest.data;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.quest.QuestDeckGroupMap;
|
||||
import forge.quest.QuestDeckMap;
|
||||
import forge.quest.QuestMode;
|
||||
import forge.quest.QuestUtilCards;
|
||||
@@ -28,10 +34,6 @@ import forge.quest.bazaar.QuestItemType;
|
||||
import forge.quest.data.QuestPreferences.QPref;
|
||||
import forge.util.ItemPool;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** */
|
||||
public class QuestAssets {
|
||||
|
||||
@@ -62,6 +64,8 @@ public class QuestAssets {
|
||||
|
||||
// Much the same like other map, but keyed by string (to support a lot of custom pets)
|
||||
private final Map<String, QuestItemCondition> combatPets = new HashMap<String, QuestItemCondition>();
|
||||
|
||||
private final HashMap<String, DeckGroup> draftDecks = new HashMap<String, DeckGroup>();
|
||||
/**
|
||||
* Checks for item.
|
||||
*
|
||||
@@ -263,4 +267,11 @@ public class QuestAssets {
|
||||
return new QuestDeckMap(this.myDecks);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tournament deck storage
|
||||
*/
|
||||
public QuestDeckGroupMap getDraftDeckStorage() {
|
||||
return new QuestDeckGroupMap(this.draftDecks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.Map;
|
||||
*/
|
||||
public final class QuestData {
|
||||
/** Holds the latest version of the Quest Data. */
|
||||
public static final int CURRENT_VERSION_NUMBER = 8;
|
||||
public static final int CURRENT_VERSION_NUMBER = 9;
|
||||
|
||||
// This field places the version number into QD instance,
|
||||
// but only when the object is created through the constructor
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package forge.quest.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import forge.quest.QuestEventDraft;
|
||||
|
||||
public class QuestEventDraftContainer extends ArrayList<QuestEventDraft> {
|
||||
private static final long serialVersionUID = -417036762608756613L;
|
||||
}
|
||||
@@ -27,12 +27,14 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
import forge.card.CardEdition;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.error.BugReporter;
|
||||
import forge.item.*;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.quest.QuestController;
|
||||
import forge.quest.QuestEventDraft;
|
||||
import forge.quest.QuestMode;
|
||||
import forge.quest.bazaar.QuestItemType;
|
||||
import forge.quest.data.*;
|
||||
@@ -79,6 +81,7 @@ public class QuestDataIO {
|
||||
final XStream xStream = isIgnoring ? new IgnoringXStream() : new XStream();
|
||||
xStream.registerConverter(new ItemPoolToXml());
|
||||
xStream.registerConverter(new DeckToXml());
|
||||
xStream.registerConverter(new DraftTournamentToXml());
|
||||
xStream.registerConverter(new GameFormatQuestToXml());
|
||||
xStream.registerConverter(new QuestModeToXml());
|
||||
xStream.autodetectAnnotations(true);
|
||||
@@ -184,10 +187,10 @@ public class QuestDataIO {
|
||||
QuestDataIO.setFinalField(QuestData.class, "petSlots", newData, new HashMap<Integer, String>());
|
||||
}
|
||||
|
||||
if(saveVersion < 8) {
|
||||
if (saveVersion < 8) {
|
||||
QuestDataIO.setFinalField(QuestData.class, "isCharmActive", newData, false);
|
||||
}
|
||||
|
||||
|
||||
final QuestAssets qS = newData.getAssets();
|
||||
final QuestAchievements qA = newData.getAchievements();
|
||||
|
||||
@@ -316,7 +319,10 @@ public class QuestDataIO {
|
||||
if (!(lc instanceof String))
|
||||
qA.getCurrentChallenges().set(i, lc.toString());
|
||||
}
|
||||
|
||||
|
||||
case 8:
|
||||
QuestDataIO.setFinalField(QuestAssets.class, "draftDecks", qS, new HashMap<String, DeckGroup>());
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -469,6 +475,161 @@ public class QuestDataIO {
|
||||
return QuestMode.smartValueOf(value, QuestMode.Classic);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DraftTournamentToXml implements Converter {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean canConvert(Class type) {
|
||||
return type.equals(QuestEventDraftContainer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshal(Object source, HierarchicalStreamWriter writer,
|
||||
MarshallingContext context) {
|
||||
|
||||
QuestEventDraftContainer drafts = (QuestEventDraftContainer) source;
|
||||
|
||||
for (QuestEventDraft draft : drafts) {
|
||||
|
||||
writer.startNode("draft");
|
||||
|
||||
writer.startNode("title");
|
||||
writer.setValue(draft.getTitle());
|
||||
writer.endNode();
|
||||
|
||||
writer.startNode("packs");
|
||||
String output = "";
|
||||
for (int i = 0; i < draft.getBoosterConfiguration().length; i++) {
|
||||
output += draft.getBoosterConfiguration()[i];
|
||||
if (i != draft.getBoosterConfiguration().length - 1) {
|
||||
output += "/";
|
||||
}
|
||||
}
|
||||
writer.setValue(output);
|
||||
writer.endNode();
|
||||
|
||||
writer.startNode("entryFee");
|
||||
writer.setValue(String.valueOf(draft.getEntryFee()));
|
||||
writer.endNode();
|
||||
|
||||
writer.startNode("block");
|
||||
writer.setValue(draft.getBlock());
|
||||
writer.endNode();
|
||||
|
||||
writer.startNode("standings");
|
||||
int i = 0;
|
||||
for (String standing : draft.getStandings()) {
|
||||
writer.startNode("s" + i++);
|
||||
writer.setValue(standing);
|
||||
writer.endNode();
|
||||
}
|
||||
writer.endNode();
|
||||
|
||||
writer.startNode("aiNames");
|
||||
i = 0;
|
||||
for (String name : draft.getAINames()) {
|
||||
writer.startNode("ain" + i++);
|
||||
writer.setValue(name);
|
||||
writer.endNode();
|
||||
}
|
||||
writer.endNode();
|
||||
|
||||
writer.startNode("aiIcons");
|
||||
i = 0;
|
||||
for (int icon : draft.getAIIcons()) {
|
||||
writer.startNode("aii" + i++);
|
||||
writer.setValue(icon + "");
|
||||
writer.endNode();
|
||||
}
|
||||
writer.endNode();
|
||||
|
||||
writer.endNode();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader,
|
||||
UnmarshallingContext context) {
|
||||
|
||||
QuestEventDraftContainer output = new QuestEventDraftContainer();
|
||||
|
||||
while (reader.hasMoreChildren()) {
|
||||
|
||||
reader.moveDown();
|
||||
|
||||
//TODO Use switch and hasMoreChildren()
|
||||
|
||||
reader.moveDown();
|
||||
String draftName = reader.getValue();
|
||||
reader.moveUp();
|
||||
|
||||
reader.moveDown();
|
||||
String boosterConfiguration = reader.getValue();
|
||||
reader.moveUp();
|
||||
|
||||
reader.moveDown();
|
||||
int entryFee = Integer.parseInt(reader.getValue());
|
||||
reader.moveUp();
|
||||
|
||||
reader.moveDown();
|
||||
String block = reader.getValue();
|
||||
reader.moveUp();
|
||||
|
||||
String[] standings = new String[15];
|
||||
|
||||
reader.moveDown();
|
||||
int i = 0;
|
||||
while (reader.hasMoreChildren()) {
|
||||
reader.moveDown();
|
||||
standings[i++] = reader.getValue();
|
||||
reader.moveUp();
|
||||
}
|
||||
reader.moveUp();
|
||||
|
||||
String[] aiNames = new String[7];
|
||||
|
||||
reader.moveDown();
|
||||
i = 0;
|
||||
while (reader.hasMoreChildren()) {
|
||||
reader.moveDown();
|
||||
aiNames[i++] = reader.getValue();
|
||||
reader.moveUp();
|
||||
}
|
||||
reader.moveUp();
|
||||
|
||||
int[] aiIcons = new int[7];
|
||||
|
||||
reader.moveDown();
|
||||
i = 0;
|
||||
while (reader.hasMoreChildren()) {
|
||||
reader.moveDown();
|
||||
aiIcons[i++] = Integer.parseInt(reader.getValue());
|
||||
reader.moveUp();
|
||||
}
|
||||
reader.moveUp();
|
||||
|
||||
QuestEventDraft draft = new QuestEventDraft(draftName);
|
||||
draft.setBoosterConfiguration(boosterConfiguration);
|
||||
draft.setEntryFee(entryFee);
|
||||
draft.setBlock(block);
|
||||
draft.setStandings(standings);
|
||||
draft.setAINames(aiNames);
|
||||
draft.setAIIcons(aiIcons);
|
||||
|
||||
output.add(draft);
|
||||
|
||||
reader.moveUp();
|
||||
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class DeckToXml extends ItemPoolToXml {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user