2013-04-12 19:32:25 -07:00
|
|
|
package magic.data;
|
|
|
|
|
|
|
|
import magic.MagicMain;
|
|
|
|
import magic.ai.MagicAI;
|
|
|
|
import magic.ai.MagicAIImpl;
|
|
|
|
import magic.model.MagicColor;
|
2014-03-13 03:24:17 -07:00
|
|
|
import magic.model.MagicDeckProfile;
|
2014-03-11 01:12:15 -07:00
|
|
|
import magic.model.player.AiPlayer;
|
2014-03-06 01:45:19 -08:00
|
|
|
import magic.model.player.PlayerProfile;
|
|
|
|
import magic.model.player.PlayerProfiles;
|
2013-04-12 19:32:25 -07:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
public class DuelConfig {
|
|
|
|
|
|
|
|
private static final DuelConfig INSTANCE=new DuelConfig();
|
|
|
|
|
|
|
|
private static final String ANY_DECK="@";
|
|
|
|
private static final String ANY_THREE="***";
|
|
|
|
private static final String ANY_TWO="**";
|
|
|
|
private static final String ANY_ONE="*";
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-06 01:45:19 -08:00
|
|
|
private static final String CONFIG_FILENAME="newduel.cfg";
|
2013-04-12 19:32:25 -07:00
|
|
|
private static final String START_LIFE="life";
|
|
|
|
private static final String HAND_SIZE="hand";
|
|
|
|
private static final String GAMES="games";
|
|
|
|
private static final String PLAYER="player";
|
|
|
|
private static final String OPPONENT="opponent";
|
|
|
|
private static final String CUBE="cube";
|
|
|
|
|
2014-03-06 01:45:19 -08:00
|
|
|
// default values.
|
|
|
|
private int startLife = 20;
|
|
|
|
private int handSize = 7;
|
|
|
|
private int games = 7;
|
|
|
|
private String playerOneDeckGenerator = ANY_THREE;
|
|
|
|
private String playerTwoDeckGenerator = ANY_THREE;
|
|
|
|
private String cube = CubeDefinitions.getCubeNames()[0];
|
|
|
|
private PlayerProfile playerOne = null;
|
|
|
|
private PlayerProfile playerTwo = null;
|
|
|
|
|
|
|
|
// CTR
|
2013-04-12 19:32:25 -07:00
|
|
|
public DuelConfig() {
|
2014-03-06 01:45:19 -08:00
|
|
|
// Ensure DuelConfig has valid PlayerProfile references.
|
|
|
|
// If missing then creates default profiles.
|
|
|
|
PlayerProfiles.refreshMap();
|
2014-03-08 02:31:29 -08:00
|
|
|
playerOne = PlayerProfiles.getDefaultHumanPlayer();
|
|
|
|
playerTwo = PlayerProfiles.getDefaultAiPlayer();
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-06 01:45:19 -08:00
|
|
|
// CTR: copy constructor - a common way of creating a copy of an existing object.
|
2013-04-12 19:32:25 -07:00
|
|
|
public DuelConfig(final DuelConfig duelConfig) {
|
|
|
|
startLife=duelConfig.startLife;
|
|
|
|
handSize=duelConfig.handSize;
|
|
|
|
games=duelConfig.games;
|
2014-03-06 01:45:19 -08:00
|
|
|
playerOneDeckGenerator=duelConfig.playerOneDeckGenerator;
|
|
|
|
playerTwoDeckGenerator=duelConfig.playerTwoDeckGenerator;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-06 01:45:19 -08:00
|
|
|
public PlayerProfile getPlayerOneProfile() {
|
|
|
|
return playerOne;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2014-03-06 01:45:19 -08:00
|
|
|
public void setPlayerOneProfile(PlayerProfile playerProfile) {
|
|
|
|
this.playerOne = playerProfile;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-06 01:45:19 -08:00
|
|
|
public PlayerProfile getPlayerTwoProfile() {
|
|
|
|
return playerTwo;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2014-03-06 01:45:19 -08:00
|
|
|
public void setPlayerTwoProfile(PlayerProfile playerProfile) {
|
|
|
|
this.playerTwo = playerProfile;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getStartLife() {
|
|
|
|
return startLife;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setStartLife(final int startLife) {
|
|
|
|
this.startLife = startLife;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getHandSize() {
|
|
|
|
return handSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setHandSize(final int handSize) {
|
|
|
|
this.handSize = handSize;
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public void setNrOfGames(final int aGames) {
|
2013-06-23 18:33:35 -07:00
|
|
|
this.games = aGames;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public int getNrOfGames() {
|
|
|
|
return games;
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-13 03:24:17 -07:00
|
|
|
private static MagicDeckProfile getMagicPlayerProfile(final String colorText) {
|
2013-04-12 19:32:25 -07:00
|
|
|
if (ANY_DECK.equals(colorText)) {
|
2014-03-13 03:24:17 -07:00
|
|
|
return new MagicDeckProfile("");
|
2013-04-12 19:32:25 -07:00
|
|
|
} else if (ANY_THREE.equals(colorText)) {
|
2014-03-13 03:24:17 -07:00
|
|
|
return new MagicDeckProfile(MagicColor.getRandomColors(3));
|
2013-04-12 19:32:25 -07:00
|
|
|
} else if (ANY_TWO.equals(colorText)) {
|
2014-03-13 03:24:17 -07:00
|
|
|
return new MagicDeckProfile(MagicColor.getRandomColors(2));
|
2013-04-12 19:32:25 -07:00
|
|
|
} else if (ANY_ONE.equals(colorText)) {
|
2014-03-13 03:24:17 -07:00
|
|
|
return new MagicDeckProfile(MagicColor.getRandomColors(1));
|
2013-04-12 19:32:25 -07:00
|
|
|
} else if (DeckGenerators.getInstance().getGeneratorNames().contains(colorText)) {
|
|
|
|
// custom deck generator
|
2014-03-13 03:24:17 -07:00
|
|
|
return new MagicDeckProfile("", colorText);
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2014-03-13 03:24:17 -07:00
|
|
|
return new MagicDeckProfile(colorText);
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-13 03:24:17 -07:00
|
|
|
public MagicDeckProfile getMagicPlayerProfile() {
|
2014-03-06 01:45:19 -08:00
|
|
|
return getMagicPlayerProfile(playerOneDeckGenerator);
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-06 01:45:19 -08:00
|
|
|
public String getPlayerOneDeckGenerator() {
|
|
|
|
return playerOneDeckGenerator;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-06 01:45:19 -08:00
|
|
|
public void setPlayerOneDeckGenerator(final String deckGenerator) {
|
|
|
|
playerOneDeckGenerator = deckGenerator;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-06 01:45:19 -08:00
|
|
|
public String getPlayerTwoDeckGenerator() {
|
|
|
|
return playerTwoDeckGenerator;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-06 01:45:19 -08:00
|
|
|
public void setPlayerTwoDeckGenerator(final String deckGenerator) {
|
|
|
|
playerTwoDeckGenerator = deckGenerator;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-13 03:24:17 -07:00
|
|
|
public MagicDeckProfile getMagicOpponentProfile() {
|
2014-03-06 01:45:19 -08:00
|
|
|
return getMagicPlayerProfile(playerTwoDeckGenerator);
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public String getCube() {
|
|
|
|
return cube;
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public void setCube(final String cube) {
|
|
|
|
this.cube=cube;
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public MagicAI[] getPlayerAIs() {
|
2014-03-11 01:12:15 -07:00
|
|
|
final MagicAI playerAI;
|
|
|
|
if (playerTwo instanceof AiPlayer) {
|
|
|
|
final AiPlayer aiPlayer = (AiPlayer)playerTwo;
|
2014-03-11 04:49:45 -07:00
|
|
|
playerAI = aiPlayer.getAiType().getAI();
|
2014-03-11 01:12:15 -07:00
|
|
|
} else {
|
2014-03-11 04:49:45 -07:00
|
|
|
playerAI = MagicAIImpl.MMAB.getAI();
|
2014-03-11 01:12:15 -07:00
|
|
|
}
|
2013-04-12 19:32:25 -07:00
|
|
|
return new MagicAI[]{playerAI, playerAI};
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public void load(final Properties properties) {
|
2014-03-06 01:45:19 -08:00
|
|
|
setPlayerOneProfile(PlayerProfile.getHumanPlayer(properties.getProperty("HumanPlayer")));
|
|
|
|
setPlayerTwoProfile(PlayerProfile.getAiPlayer(properties.getProperty("AiPlayer")));
|
2013-04-12 19:32:25 -07:00
|
|
|
startLife=Integer.parseInt(properties.getProperty(START_LIFE,Integer.toString(startLife)));
|
|
|
|
handSize=Integer.parseInt(properties.getProperty(HAND_SIZE,Integer.toString(handSize)));
|
|
|
|
games=Integer.parseInt(properties.getProperty(GAMES,Integer.toString(games)));
|
2014-03-06 01:45:19 -08:00
|
|
|
playerOneDeckGenerator=properties.getProperty(PLAYER,playerOneDeckGenerator);
|
|
|
|
playerTwoDeckGenerator=properties.getProperty(OPPONENT,playerTwoDeckGenerator);
|
2013-04-12 19:32:25 -07:00
|
|
|
cube=properties.getProperty(CUBE,cube);
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public void load() {
|
2014-03-06 01:45:19 -08:00
|
|
|
final File configFile = getConfigFile();
|
|
|
|
final Properties properties = configFile.exists() ? FileIO.toProp(configFile) : new Properties();
|
|
|
|
load(properties);
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public void save(final Properties properties) {
|
2014-03-06 01:45:19 -08:00
|
|
|
properties.setProperty("HumanPlayer", getPlayerOneProfile().getId());
|
|
|
|
properties.setProperty("AiPlayer", getPlayerTwoProfile().getId());
|
|
|
|
properties.setProperty(START_LIFE, Integer.toString(startLife));
|
|
|
|
properties.setProperty(HAND_SIZE, Integer.toString(handSize));
|
2013-04-12 19:32:25 -07:00
|
|
|
properties.setProperty(GAMES, Integer.toString(games));
|
2014-03-06 01:45:19 -08:00
|
|
|
properties.setProperty(PLAYER, playerOneDeckGenerator);
|
|
|
|
properties.setProperty(OPPONENT, playerTwoDeckGenerator);
|
|
|
|
properties.setProperty(CUBE, cube);
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public void save() {
|
|
|
|
final Properties properties=new Properties();
|
|
|
|
save(properties);
|
|
|
|
try { //save config
|
2013-06-23 18:33:35 -07:00
|
|
|
FileIO.toFile(getConfigFile(), properties, "Duel configuration");
|
2013-04-12 19:32:25 -07:00
|
|
|
System.err.println("Saved duel config");
|
|
|
|
} catch (final IOException ex) {
|
|
|
|
System.err.println("ERROR! Unable to save duel config");
|
|
|
|
}
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
private static File getConfigFile() {
|
2013-12-17 10:16:08 -08:00
|
|
|
return new File(MagicMain.getSavedDuelsPath(), CONFIG_FILENAME);
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public static DuelConfig getInstance() {
|
|
|
|
return INSTANCE;
|
|
|
|
}
|
2014-03-11 01:12:15 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dependent on AI type, but approximately the maximum number of
|
|
|
|
* seconds the AI has to to make a decision.
|
|
|
|
* <p>
|
|
|
|
* Currently, this a user-adjustable setting from 1 to 8 seconds.
|
|
|
|
*/
|
|
|
|
public int getAiDifficulty() {
|
|
|
|
if (playerTwo instanceof AiPlayer) {
|
|
|
|
final AiPlayer player = (AiPlayer)playerTwo;
|
|
|
|
return player.getAiLevel();
|
|
|
|
} else {
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getAiExtraLife() {
|
|
|
|
if (playerTwo instanceof AiPlayer) {
|
|
|
|
final AiPlayer aiPlayer = (AiPlayer)playerTwo;
|
|
|
|
return aiPlayer.getExtraLife();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|