mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Initial commit for Planar Conquest mode
This commit is contained in:
@@ -38,6 +38,8 @@ import forge.gauntlet.GauntletData;
|
||||
import forge.interfaces.IProgressBar;
|
||||
import forge.itemmanager.ItemManagerConfig;
|
||||
import forge.limited.GauntletMini;
|
||||
import forge.planarconquest.ConquestController;
|
||||
import forge.planarconquest.ConquestPreferences;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.properties.ForgePreferences;
|
||||
@@ -70,6 +72,7 @@ public class FModel {
|
||||
private static StaticData magicDb;
|
||||
|
||||
private static QuestPreferences questPreferences;
|
||||
private static ConquestPreferences conquestPreferences;
|
||||
private static ForgePreferences preferences;
|
||||
|
||||
private static Map<GameType, AchievementCollection> achievements;
|
||||
@@ -79,6 +82,7 @@ public class FModel {
|
||||
private static GauntletMini gauntlet;
|
||||
|
||||
private static QuestController quest;
|
||||
private static ConquestController conquest;
|
||||
private static CardCollections decks;
|
||||
|
||||
private static IStorage<CardBlock> blocks;
|
||||
@@ -153,6 +157,7 @@ public class FModel {
|
||||
formats = new GameFormat.Collection(new GameFormat.Reader(new File(ForgeConstants.BLOCK_DATA_DIR + "formats.txt")));
|
||||
blocks = new StorageBase<CardBlock>("Block definitions", new CardBlock.Reader(ForgeConstants.BLOCK_DATA_DIR + "blocks.txt", magicDb.getEditions()));
|
||||
questPreferences = new QuestPreferences();
|
||||
conquestPreferences = new ConquestPreferences();
|
||||
fantasyBlocks = new StorageBase<CardBlock>("Custom blocks", new CardBlock.Reader(ForgeConstants.BLOCK_DATA_DIR + "fantasyblocks.txt", magicDb.getEditions()));
|
||||
worlds = new StorageBase<QuestWorld>("Quest worlds", new QuestWorld.Reader(ForgeConstants.QUEST_WORLD_DIR + "worlds.txt"));
|
||||
|
||||
@@ -169,6 +174,7 @@ public class FModel {
|
||||
|
||||
decks = new CardCollections();
|
||||
quest = new QuestController();
|
||||
conquest = new ConquestController();
|
||||
|
||||
CardPreferences.load();
|
||||
DeckPreferences.load();
|
||||
@@ -187,7 +193,11 @@ public class FModel {
|
||||
public static QuestController getQuest() {
|
||||
return quest;
|
||||
}
|
||||
|
||||
|
||||
public static ConquestController getConquest() {
|
||||
return conquest;
|
||||
}
|
||||
|
||||
private static boolean keywordsLoaded = false;
|
||||
|
||||
/**
|
||||
@@ -292,12 +302,16 @@ public class FModel {
|
||||
|
||||
public static IStorage<CardBlock> getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
|
||||
public static QuestPreferences getQuestPreferences() {
|
||||
return questPreferences;
|
||||
}
|
||||
|
||||
public static ConquestPreferences getConquestPreferences() {
|
||||
return conquestPreferences;
|
||||
}
|
||||
|
||||
public static GauntletData getGauntletData() {
|
||||
return gauntletData;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* 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.planarconquest;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.event.GameEvent;
|
||||
import forge.util.storage.IStorage;
|
||||
|
||||
public class ConquestController {
|
||||
private ConquestData model;
|
||||
private CardPool cardPool;
|
||||
private transient IStorage<Deck> decks;
|
||||
|
||||
public ConquestController() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return model == null ? null : model.getName();
|
||||
}
|
||||
|
||||
public CardPool getCardPool() {
|
||||
return cardPool;
|
||||
}
|
||||
|
||||
public IStorage<Deck> getDecks() {
|
||||
return decks;
|
||||
}
|
||||
|
||||
public void load(final ConquestData model0) {
|
||||
model = model0;
|
||||
cardPool = model == null ? null : model.getCardPool();
|
||||
decks = model == null ? null : model.getDeckStorage();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (model != null) {
|
||||
model.saveData();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void receiveGameEvent(GameEvent ev) { // Receives events only during planar conquest games
|
||||
|
||||
}
|
||||
}
|
||||
140
forge-gui/src/main/java/forge/planarconquest/ConquestData.java
Normal file
140
forge-gui/src/main/java/forge/planarconquest/ConquestData.java
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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.planarconquest;
|
||||
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.item.PaperCard;
|
||||
import forge.properties.ForgeConstants;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public final class ConquestData {
|
||||
/** Holds the latest version of the Conquest Data. */
|
||||
public static final int CURRENT_VERSION_NUMBER = 0;
|
||||
|
||||
// This field places the version number into QD instance,
|
||||
// but only when the object is created through the constructor
|
||||
// DO NOT RENAME THIS FIELD
|
||||
private int versionNumber = ConquestData.CURRENT_VERSION_NUMBER;
|
||||
|
||||
private String name;
|
||||
private int wins, losses;
|
||||
private int winStreakBest = 0;
|
||||
private int winStreakCurrent = 0;
|
||||
private int difficulty;
|
||||
private ConquestPlane startingPlane, currentPlane;
|
||||
private List<PaperCard> commanders = new ArrayList<PaperCard>();
|
||||
|
||||
private final CardPool cardPool = new CardPool();
|
||||
private final HashMap<String, Deck> decks = new HashMap<String, Deck>();
|
||||
|
||||
public ConquestData() { //needed for XML serialization
|
||||
}
|
||||
|
||||
public ConquestData(String name0, int difficulty0, ConquestPlane startingPlane0, PaperCard startingCommander0) {
|
||||
name = name0;
|
||||
difficulty = difficulty0;
|
||||
startingPlane = startingPlane0;
|
||||
currentPlane = startingPlane0;
|
||||
commanders.add(startingCommander0);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public ConquestPlane getStartingPlane() {
|
||||
return startingPlane;
|
||||
}
|
||||
|
||||
public ConquestPlane getCurrentPlane() {
|
||||
return currentPlane;
|
||||
}
|
||||
|
||||
public CardPool getCardPool() {
|
||||
return cardPool;
|
||||
}
|
||||
|
||||
public ConquestDeckMap getDeckStorage() {
|
||||
return new ConquestDeckMap(decks);
|
||||
}
|
||||
|
||||
public void addWin() {
|
||||
wins++;
|
||||
winStreakCurrent++;
|
||||
|
||||
if (winStreakCurrent > winStreakBest) {
|
||||
winStreakBest = winStreakCurrent;
|
||||
}
|
||||
}
|
||||
|
||||
public void addLoss() {
|
||||
losses++;
|
||||
winStreakCurrent = 0;
|
||||
}
|
||||
|
||||
public int getWins() {
|
||||
return wins;
|
||||
}
|
||||
|
||||
public int getLosses() {
|
||||
return losses;
|
||||
}
|
||||
|
||||
public int getWinStreakBest() {
|
||||
return winStreakBest;
|
||||
}
|
||||
|
||||
public int getWinStreakCurrent() {
|
||||
return winStreakCurrent;
|
||||
}
|
||||
|
||||
// SERIALIZATION - related things
|
||||
// This must be called by XML-serializer via reflection
|
||||
public Object readResolve() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void saveData() {
|
||||
ConquestDataIO.saveData(this);
|
||||
}
|
||||
|
||||
public int getVersionNumber() {
|
||||
return versionNumber;
|
||||
}
|
||||
public void setVersionNumber(final int versionNumber0) {
|
||||
versionNumber = versionNumber0;
|
||||
}
|
||||
|
||||
public void rename(final String newName) {
|
||||
File newpath = new File(ForgeConstants.CONQUEST_SAVE_DIR, newName + ".dat");
|
||||
File oldpath = new File(ForgeConstants.CONQUEST_SAVE_DIR, name + ".dat");
|
||||
oldpath.renameTo(newpath);
|
||||
|
||||
name = newName;
|
||||
saveData();
|
||||
}
|
||||
}
|
||||
144
forge-gui/src/main/java/forge/planarconquest/ConquestDataIO.java
Normal file
144
forge-gui/src/main/java/forge/planarconquest/ConquestDataIO.java
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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.planarconquest;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import forge.deck.CardPool;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.IgnoringXStream;
|
||||
import forge.util.ItemPool;
|
||||
|
||||
public class ConquestDataIO {
|
||||
static {
|
||||
//ensure save directory exists if this class is used
|
||||
FileUtil.ensureDirectoryExists(ForgeConstants.CONQUEST_SAVE_DIR);
|
||||
}
|
||||
|
||||
protected static XStream getSerializer(final boolean isIgnoring) {
|
||||
final XStream xStream = isIgnoring ? new IgnoringXStream() : new XStream();
|
||||
xStream.autodetectAnnotations(true);
|
||||
xStream.alias("CardPool", ItemPool.class);
|
||||
xStream.alias("DeckSection", CardPool.class);
|
||||
return xStream;
|
||||
}
|
||||
|
||||
public static ConquestData loadData(final File xmlSaveFile) {
|
||||
try {
|
||||
ConquestData data = null;
|
||||
|
||||
final GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
||||
final StringBuilder xml = new StringBuilder();
|
||||
final char[] buf = new char[1024];
|
||||
final InputStreamReader reader = new InputStreamReader(zin);
|
||||
while (reader.ready()) {
|
||||
final int len = reader.read(buf);
|
||||
if (len == -1) {
|
||||
break;
|
||||
} // when end of stream was reached
|
||||
xml.append(buf, 0, len);
|
||||
}
|
||||
|
||||
zin.close();
|
||||
|
||||
String bigXML = xml.toString();
|
||||
data = (ConquestData) ConquestDataIO.getSerializer(true).fromXML(bigXML);
|
||||
|
||||
if (data.getVersionNumber() != ConquestData.CURRENT_VERSION_NUMBER) {
|
||||
try {
|
||||
ConquestDataIO.updateSaveFile(data, bigXML, xmlSaveFile.getName().replace(".dat", ""));
|
||||
}
|
||||
catch (final Exception e) {
|
||||
//BugReporter.reportException(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
catch (final Exception ex) {
|
||||
//BugReporter.reportException(ex, "Error loading Conquest Data");
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateSaveFile(final ConquestData newData, final String input, String filename) throws ParserConfigurationException, SAXException, IOException, IllegalAccessException, NoSuchFieldException {
|
||||
//final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
final InputSource is = new InputSource();
|
||||
is.setCharacterStream(new StringReader(input));
|
||||
//final Document document = builder.parse(is);
|
||||
|
||||
final int saveVersion = newData.getVersionNumber();
|
||||
switch (saveVersion) {
|
||||
// There should be a fall-through between the cases so that each
|
||||
// version's changes get applied progressively
|
||||
case 0:
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// mark the QD as the latest version
|
||||
newData.setVersionNumber(ConquestData.CURRENT_VERSION_NUMBER);
|
||||
}
|
||||
|
||||
public static synchronized void saveData(final ConquestData qd) {
|
||||
try {
|
||||
final XStream xStream = ConquestDataIO.getSerializer(false);
|
||||
|
||||
final File f = new File(ForgeConstants.CONQUEST_SAVE_DIR, qd.getName());
|
||||
ConquestDataIO.savePacked(f + ".dat", xStream, qd);
|
||||
// ConquestDataIO.saveUnpacked(f + ".xml", xStream, qd);
|
||||
}
|
||||
catch (final Exception ex) {
|
||||
//BugReporter.reportException(ex, "Error saving Conquest Data.");
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void savePacked(final String f, final XStream xStream, final ConquestData qd) throws IOException {
|
||||
final BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(f));
|
||||
final GZIPOutputStream zout = new GZIPOutputStream(bout);
|
||||
xStream.toXML(qd, zout);
|
||||
zout.flush();
|
||||
zout.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused") // used only for debug purposes
|
||||
private static void saveUnpacked(final String f, final XStream xStream, final ConquestData qd) throws IOException {
|
||||
final BufferedOutputStream boutUnp = new BufferedOutputStream(new FileOutputStream(f));
|
||||
xStream.toXML(qd, boutUnp);
|
||||
boutUnp.flush();
|
||||
boutUnp.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.planarconquest;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.util.storage.StorageBase;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ConquestDeckMap extends StorageBase<Deck> {
|
||||
public ConquestDeckMap(Map<String, Deck> in) {
|
||||
super("Conquest decks", in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final Deck deck) {
|
||||
map.put(deck.getName(), deck);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(final String deckName) {
|
||||
map.remove(deckName);
|
||||
}
|
||||
}
|
||||
329
forge-gui/src/main/java/forge/planarconquest/ConquestPlane.java
Normal file
329
forge-gui/src/main/java/forge/planarconquest/ConquestPlane.java
Normal file
@@ -0,0 +1,329 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* 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.planarconquest;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.card.CardEdition.CardInSet;
|
||||
import forge.card.CardType;
|
||||
import forge.card.MagicColor;
|
||||
import forge.deck.CardPool;
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.util.FCollection;
|
||||
import forge.util.FCollectionView;
|
||||
|
||||
|
||||
public enum ConquestPlane {
|
||||
Alara("Alara", new String[] {
|
||||
"ALA", "CON", "ARB"
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Azoria("Azoria", new String[] {
|
||||
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
BolasMeditationRealm("Bolas's Meditation Realm", new String[] {
|
||||
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Dominaria("Dominaria", new String[] {
|
||||
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Equilor("Equilor", new String[] {
|
||||
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Gastal("Gastal", new String[] {
|
||||
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Innistrad("Innistrad", new String[] {
|
||||
"ISD", "DKA", "AVR"
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Kamigawa("Kamigawa", new String[] {
|
||||
"CHK", "BOK", "SOK"
|
||||
}, new Region[] {
|
||||
new Region("Towabara", "", CardRulesPredicates.hasColorIdentity(MagicColor.WHITE),
|
||||
new String[] { "Towabara", "Plains" }),
|
||||
new Region("Minamo Academy", "", CardRulesPredicates.hasColorIdentity(MagicColor.BLUE),
|
||||
new String[] { "Minamo", "Academy", "Island" }),
|
||||
new Region("Takenuma", "", CardRulesPredicates.hasColorIdentity(MagicColor.BLACK),
|
||||
new String[] { "Takenuma", "Swamp" }),
|
||||
new Region("Sokenzan Mountains", "", CardRulesPredicates.hasColorIdentity(MagicColor.RED),
|
||||
new String[] { "Sokenzan", "Mountain" }),
|
||||
new Region("Jukai Forest", "", CardRulesPredicates.hasColorIdentity(MagicColor.GREEN),
|
||||
new String[] { "Jukai", "Forest" })
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Lorwyn("Lorwyn", new String[] {
|
||||
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Mercadia("Mercadia", new String[] {
|
||||
"MMQ", "NEM", "PCY"
|
||||
}, new Region[] {
|
||||
new Region("Deepwood", "", CardRulesPredicates.hasCreatureType("Zombie", "Ghoul", "Dryad"),
|
||||
new String[] { }),
|
||||
new Region("Mercadia City", "", CardRulesPredicates.hasCreatureType("Goblin"),
|
||||
new String[] { }),
|
||||
new Region("Rishada", "", CardRulesPredicates.hasCreatureType("Pirate", "Rebel", "Mercenary"),
|
||||
new String[] { }),
|
||||
new Region("Rushwood", "", CardRulesPredicates.hasCreatureType("Beast", "Troll"),
|
||||
new String[] { }),
|
||||
new Region("Saprazzo", "", CardRulesPredicates.hasCreatureType("Merfolk", "Human"),
|
||||
new String[] { })
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Mirrodin("Mirrodin", new String[] {
|
||||
"MRD", "DST", "5DN", "SOM", "MBS", "NPH"
|
||||
}, new Region[] {
|
||||
new Region("Mirrodin's Core", "Mirrodin's Core", null,
|
||||
new String[] { "Core", "Mycosynth", "Memnarch" }),
|
||||
new Region("The Glimmervoid", "Glimmervoid", CardRulesPredicates.hasKeyword("Sunburst"),
|
||||
new String[] { "Glimmervoid" }),
|
||||
new Region("Mephidross", "", CardRulesPredicates.hasColorIdentity(MagicColor.BLACK),
|
||||
new String[] { "Dross", "Mephidross" }),
|
||||
new Region("The Oxidda Chain", "", CardRulesPredicates.hasColorIdentity(MagicColor.RED),
|
||||
new String[] { "Oxidda", "Chain", "Mountain" }),
|
||||
new Region("The Quicksilver Sea", "", CardRulesPredicates.hasColorIdentity(MagicColor.BLUE),
|
||||
new String[] { "Quicksilver", "Sea", "Island" }),
|
||||
new Region("The Razor Fields", "", CardRulesPredicates.hasColorIdentity(MagicColor.WHITE),
|
||||
new String[] { "Razor", "Fields", "Plains" }),
|
||||
new Region("The Tangle", "", CardRulesPredicates.hasColorIdentity(MagicColor.GREEN),
|
||||
new String[] { "Tangle", "Forest" })
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Rabiah("Rabiah", new String[] {
|
||||
"ARN"
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Rath("Rath", new String[] {
|
||||
"TMP", "STH", "EXO"
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Ravnica("Ravnica", new String[] {
|
||||
"RAV", "GPT", "DIS", "RTR", "GTC", "DGM"
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Segovia("Segovia", new String[] {
|
||||
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
SerraRealm("Serra's Realm", new String[] {
|
||||
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Shandalar("Shandalar", new String[] {
|
||||
"2ED", "ARN", "ATQ", "3ED", "LEG", "DRK", "4ED"
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Ulgrotha("Ulgrotha", new String[] {
|
||||
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Theros("Theros", new String[] {
|
||||
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
}),
|
||||
Zendikar("Zendikar", new String[] {
|
||||
"ZEN", "WWK", "ROE"
|
||||
}, new Region[] {
|
||||
|
||||
}, new String[] {
|
||||
|
||||
});
|
||||
|
||||
private final String name;
|
||||
private final FCollection<CardEdition> editions = new FCollection<CardEdition>();
|
||||
private final FCollection<Region> regions;
|
||||
private final FCollection<String> bannedCards;
|
||||
private final CardPool cardPool = new CardPool();
|
||||
private final FCollection<PaperCard> commanders = new FCollection<PaperCard>();
|
||||
|
||||
private ConquestPlane(String name0, String[] setCodes0, Region[] regions0, String[] bannedCards0) {
|
||||
name = name0;
|
||||
regions = new FCollection<Region>(regions0);
|
||||
bannedCards = new FCollection<String>(bannedCards0);
|
||||
for (String setCode : setCodes0) {
|
||||
CardEdition edition = FModel.getMagicDb().getEditions().get(setCode);
|
||||
if (edition != null) {
|
||||
editions.add(edition);
|
||||
for (CardInSet card : edition.getCards()) {
|
||||
if (!bannedCards.contains(card.name)) {
|
||||
PaperCard pc = FModel.getMagicDb().getCommonCards().getCard(card.name, setCode);
|
||||
if (pc != null) {
|
||||
CardType type = pc.getRules().getType();
|
||||
if (!type.isBasicLand()) { //don't include basic lands
|
||||
boolean isCommander = type.isLegendary() && type.isCreature();
|
||||
cardPool.add(pc);
|
||||
if (isCommander) {
|
||||
commanders.add(pc);
|
||||
}
|
||||
int count = 0;
|
||||
for (Region region : regions) {
|
||||
if (region.pred.apply(pc)) {
|
||||
region.cardPool.add(pc);
|
||||
if (isCommander) {
|
||||
region.commanders.add(pc);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
//if card doesn't match any region's predicate,
|
||||
//make card available to all regions
|
||||
if (count == 0) {
|
||||
for (Region region : regions) {
|
||||
region.cardPool.add(pc);
|
||||
if (isCommander) {
|
||||
region.commanders.add(pc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public FCollectionView<CardEdition> getEditions() {
|
||||
return editions;
|
||||
}
|
||||
|
||||
public FCollectionView<String> getBannedCards() {
|
||||
return bannedCards;
|
||||
}
|
||||
|
||||
public FCollectionView<Region> getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
public CardPool getCardPool() {
|
||||
return cardPool;
|
||||
}
|
||||
|
||||
public FCollectionView<PaperCard> getCommanders() {
|
||||
return commanders;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static class Region {
|
||||
private final String name;
|
||||
private final String artCardName;
|
||||
private final Predicate<PaperCard> pred;
|
||||
private final CardPool cardPool = new CardPool();
|
||||
private final FCollection<PaperCard> commanders = new FCollection<PaperCard>();
|
||||
|
||||
private Region(String name0, String artCardName0, final Predicate<CardRules> rulesPred, final String[] keywords) {
|
||||
name = name0;
|
||||
artCardName = artCardName0;
|
||||
|
||||
pred = new Predicate<PaperCard>() {
|
||||
@Override
|
||||
public boolean apply(PaperCard pc) {
|
||||
if (rulesPred != null && rulesPred.apply(pc.getRules())) {
|
||||
return true;
|
||||
}
|
||||
for (String s : keywords) {
|
||||
if (pc.getName().contains(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CardPool getCardPool() {
|
||||
return cardPool;
|
||||
}
|
||||
|
||||
public FCollectionView<PaperCard> getCommanders() {
|
||||
return commanders;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.planarconquest;
|
||||
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.properties.PreferencesStore;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ConquestPreferences extends PreferencesStore<ConquestPreferences.CQPref> implements Serializable {
|
||||
/**
|
||||
* Preference identifiers, and their default values.
|
||||
*/
|
||||
public static enum CQPref {
|
||||
CURRENT_CONQUEST("DEFAULT");
|
||||
|
||||
private final String strDefaultVal;
|
||||
|
||||
CQPref(final String s0) {
|
||||
this.strDefaultVal = s0;
|
||||
}
|
||||
|
||||
public String getDefault() {
|
||||
return this.strDefaultVal;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum DifficultyPrefs {
|
||||
}
|
||||
|
||||
public ConquestPreferences() {
|
||||
super(ForgeConstants.CONQUEST_PREFS_FILE, CQPref.class);
|
||||
}
|
||||
|
||||
protected CQPref[] getEnumValues() {
|
||||
return CQPref.values();
|
||||
}
|
||||
|
||||
protected CQPref valueOf(String name) {
|
||||
try {
|
||||
return CQPref.valueOf(name);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected String getPrefDefault(CQPref key) {
|
||||
return key.getDefault();
|
||||
}
|
||||
|
||||
public String getPref(DifficultyPrefs pref, int difficultyIndex) {
|
||||
String newCQPref = pref.toString();
|
||||
|
||||
switch (difficultyIndex) {
|
||||
case 0:
|
||||
newCQPref += "_EASY";
|
||||
break;
|
||||
case 1:
|
||||
newCQPref += "_MEDIUM";
|
||||
break;
|
||||
case 2:
|
||||
newCQPref += "_HARD";
|
||||
break;
|
||||
case 3:
|
||||
newCQPref += "_EXPERT";
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
throw new Exception();
|
||||
} catch (final Exception e1) {
|
||||
System.err.println("Difficulty index out of bounds: " + difficultyIndex);
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return getPref(CQPref.valueOf(newCQPref));
|
||||
}
|
||||
|
||||
public int getPrefInt(DifficultyPrefs pref, int difficultyIndex) {
|
||||
return Integer.parseInt(this.getPref(pref, difficultyIndex));
|
||||
}
|
||||
|
||||
public static String getDifficulty(int difficultyIndex) {
|
||||
String s;
|
||||
switch (difficultyIndex) {
|
||||
case 1:
|
||||
s = "EASY";
|
||||
break;
|
||||
case 2:
|
||||
s = "MEDIUM";
|
||||
break;
|
||||
case 3:
|
||||
s = "HARD";
|
||||
break;
|
||||
case 4:
|
||||
s = "EXPERT";
|
||||
break;
|
||||
default:
|
||||
s = "UNKNOWN";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public String validatePreference(CQPref qpref, int val) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,7 @@ public final class ForgeConstants {
|
||||
|
||||
// data that is only in the profile dirs
|
||||
public static final String USER_QUEST_DIR = USER_DIR + "quest/";
|
||||
public static final String USER_CONQUEST_DIR = USER_DIR + "conquest/";
|
||||
public static final String USER_PREFS_DIR = USER_DIR + "preferences/";
|
||||
public static final String USER_GAMES_DIR = USER_DIR + "games/";
|
||||
public static final String LOG_FILE = USER_DIR + "forge.log";
|
||||
@@ -113,10 +114,12 @@ public final class ForgeConstants {
|
||||
public static final String DECK_PLANE_DIR = DECK_BASE_DIR + "planar/";
|
||||
public static final String DECK_COMMANDER_DIR = DECK_BASE_DIR + "commander/";
|
||||
public static final String QUEST_SAVE_DIR = USER_QUEST_DIR + "saves/";
|
||||
public static final String CONQUEST_SAVE_DIR = USER_CONQUEST_DIR + "saves/";
|
||||
public static final String MAIN_PREFS_FILE = USER_PREFS_DIR + "forge.preferences";
|
||||
public static final String CARD_PREFS_FILE = USER_PREFS_DIR + "card.preferences";
|
||||
public static final String DECK_PREFS_FILE = USER_PREFS_DIR + "deck.preferences";
|
||||
public static final String QUEST_PREFS_FILE = USER_PREFS_DIR + "quest.preferences";
|
||||
public static final String CONQUEST_PREFS_FILE = USER_PREFS_DIR + "conquest.preferences";
|
||||
public static final String ITEM_VIEW_PREFS_FILE = USER_PREFS_DIR + "item_view.preferences";
|
||||
|
||||
// data that has defaults in the program dir but overrides/additions in the user dir
|
||||
|
||||
Reference in New Issue
Block a user