2013-04-12 19:32:25 -07:00
|
|
|
package magic.data;
|
|
|
|
|
2014-08-17 01:16:03 -07:00
|
|
|
import java.io.File;
|
|
|
|
import java.util.Properties;
|
2020-01-15 12:02:42 -08:00
|
|
|
|
2016-12-19 00:29:17 -08:00
|
|
|
import magic.model.DuelPlayerConfig;
|
2014-03-13 03:24:17 -07:00
|
|
|
import magic.model.MagicDeckProfile;
|
2015-04-17 07:38:45 -07:00
|
|
|
import magic.model.MagicDuel;
|
2014-03-06 01:45:19 -08:00
|
|
|
import magic.model.player.PlayerProfile;
|
|
|
|
import magic.model.player.PlayerProfiles;
|
2016-12-19 00:29:17 -08:00
|
|
|
import magic.utility.FileIO;
|
2016-03-07 00:05:15 -08:00
|
|
|
import magic.utility.SortedProperties;
|
2015-04-19 15:17:27 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public class DuelConfig {
|
|
|
|
|
|
|
|
private static final DuelConfig INSTANCE=new DuelConfig();
|
|
|
|
|
2014-03-13 04:58:48 -07:00
|
|
|
// Properties file keys.
|
2015-04-19 15:19:42 -07:00
|
|
|
private static final String START_LIFE = "config.life";
|
|
|
|
private static final String HAND_SIZE = "config.hand";
|
|
|
|
private static final String GAMES = "config.games";
|
|
|
|
private static final String CUBE = "config.cube";
|
2015-04-19 15:29:31 -07:00
|
|
|
private static final String PLAYER_ONE = "p1.profile";
|
|
|
|
private static final String PLAYER_TWO = "p2.profile";
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-13 04:58:48 -07:00
|
|
|
public static final int MAX_PLAYERS = 2;
|
2017-05-10 04:49:39 -07:00
|
|
|
public static final int DEFAULT_GAMES = 7;
|
2017-05-10 05:20:23 -07:00
|
|
|
public static final int DEFAULT_LIFE = 20;
|
2013-04-12 19:32:25 -07:00
|
|
|
|
2014-03-06 01:45:19 -08:00
|
|
|
// default values.
|
2017-05-10 05:20:23 -07:00
|
|
|
private int startLife = DEFAULT_LIFE;
|
2014-03-06 01:45:19 -08:00
|
|
|
private int handSize = 7;
|
2017-05-10 04:49:39 -07:00
|
|
|
private int games = DEFAULT_GAMES;
|
2015-06-20 02:33:31 -07:00
|
|
|
private MagicFormat cube = MagicFormat.ALL;
|
2015-04-19 12:29:20 -07:00
|
|
|
private DuelPlayerConfig[] players = new DuelPlayerConfig[MAX_PLAYERS];
|
2014-03-06 01:45:19 -08:00
|
|
|
|
|
|
|
// CTR
|
2013-04-12 19:32:25 -07:00
|
|
|
public DuelConfig() {
|
2015-04-19 12:29:20 -07:00
|
|
|
players[0] = new DuelPlayerConfig(
|
2015-04-17 08:07:20 -07:00
|
|
|
PlayerProfiles.getDefaultHumanPlayer(),
|
|
|
|
MagicDeckProfile.getDeckProfile(MagicDeckProfile.ANY_THREE)
|
|
|
|
);
|
2015-04-19 12:29:20 -07:00
|
|
|
players[1] = new DuelPlayerConfig(
|
2015-04-17 08:07:20 -07:00
|
|
|
PlayerProfiles.getDefaultAiPlayer(),
|
|
|
|
MagicDeckProfile.getDeckProfile(MagicDeckProfile.ANY_THREE)
|
|
|
|
);
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2017-08-07 22:13:13 -07:00
|
|
|
public int getStartingLife(final int idx) {
|
|
|
|
return startLife + players[idx].getProfile().getExtraLife();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
public int getNrOfGames() {
|
|
|
|
return games;
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2015-06-20 02:33:31 -07:00
|
|
|
public MagicFormat getCube() {
|
2015-05-26 06:20:29 -07:00
|
|
|
return cube;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2015-06-20 02:33:31 -07:00
|
|
|
public void setCube(final MagicFormat aCube) {
|
2015-05-26 06:37:56 -07:00
|
|
|
this.cube = aCube;
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-13 04:58:48 -07:00
|
|
|
public PlayerProfile getPlayerProfile(final int playerIndex) {
|
2015-04-19 12:29:20 -07:00
|
|
|
return players[playerIndex].getProfile();
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2014-03-13 04:58:48 -07:00
|
|
|
public void setPlayerProfile(final int playerIndex, final PlayerProfile playerProfile) {
|
2015-04-19 12:29:20 -07:00
|
|
|
players[playerIndex].setProfile(playerProfile);
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-03-13 04:58:48 -07:00
|
|
|
public MagicDeckProfile getPlayerDeckProfile(final int playerIndex) {
|
2015-04-19 12:29:20 -07:00
|
|
|
return players[playerIndex].getDeckProfile();
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2015-04-17 08:07:20 -07:00
|
|
|
|
2014-03-13 04:58:48 -07:00
|
|
|
public void setPlayerDeckProfile(final int playerIndex, final DeckType deckType, final String deckValue) {
|
2015-04-19 12:29:20 -07:00
|
|
|
players[playerIndex].setDeckProfile(MagicDeckProfile.getDeckProfile(deckType, deckValue));
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2015-04-24 06:22:21 -07:00
|
|
|
public void load(final Properties properties, final boolean loadPlayerDecks) {
|
2015-05-26 05:44:19 -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)));
|
2015-06-19 22:19:47 -07:00
|
|
|
cube = MagicCustomFormat.get(properties.getProperty(CUBE, cube.getName()));
|
2015-05-02 17:23:50 -07:00
|
|
|
loadPlayerConfigs(properties, loadPlayerDecks);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadPlayerConfigs(final Properties properties, final boolean loadPlayerDecks) {
|
2014-03-13 04:58:48 -07:00
|
|
|
setPlayerProfile(0, PlayerProfile.getHumanPlayer(properties.getProperty(PLAYER_ONE)));
|
|
|
|
setPlayerProfile(1, PlayerProfile.getAiPlayer(properties.getProperty(PLAYER_TWO)));
|
2015-05-02 17:23:50 -07:00
|
|
|
for (int i = 0; i < getPlayerConfigs().length; i++) {
|
|
|
|
getPlayerConfig(i).setDeckProfile(
|
|
|
|
properties.getProperty(
|
|
|
|
getPlayerPrefix(i) + "deckProfile",
|
2016-12-19 00:29:17 -08:00
|
|
|
DeckType.Random.name() + ";" + MagicDeckProfile.ANY_THREE)
|
2015-05-02 17:23:50 -07:00
|
|
|
);
|
|
|
|
if (loadPlayerDecks) {
|
|
|
|
getPlayerConfig(i).loadDeck(properties, getPlayerPrefix(i));
|
2015-04-24 06:22:21 -07:00
|
|
|
}
|
2015-04-17 13:36:59 -07:00
|
|
|
}
|
2014-03-13 04:58:48 -07:00
|
|
|
}
|
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public void load() {
|
2015-04-19 15:17:27 -07:00
|
|
|
final File configFile = MagicDuel.getLatestDuelFile();
|
2016-03-07 00:05:15 -08:00
|
|
|
final Properties properties = configFile.exists() ? FileIO.toProp(configFile) : new SortedProperties();
|
2015-04-24 06:22:21 -07:00
|
|
|
load(properties, false);
|
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(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));
|
2015-05-26 05:44:19 -07:00
|
|
|
properties.setProperty(CUBE, cube.getName());
|
2015-04-19 14:52:41 -07:00
|
|
|
properties.setProperty(PLAYER_ONE, players[0].getProfile().getId());
|
|
|
|
properties.setProperty(PLAYER_TWO, players[1].getProfile().getId());
|
2015-04-19 15:41:53 -07:00
|
|
|
|
2015-04-19 15:43:13 -07:00
|
|
|
for (int i = 0; i < getPlayerConfigs().length; i++) {
|
|
|
|
getPlayerConfig(i).save(properties, getPlayerPrefix(i));
|
2015-04-17 13:36:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getPlayerPrefix(final int index) {
|
2015-04-19 15:41:53 -07:00
|
|
|
return "p" + (index + 1) + ".";
|
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
|
|
|
|
2015-03-22 13:15:37 -07:00
|
|
|
public int getGamesRequiredToWinDuel() {
|
|
|
|
return (int)Math.ceil(getNrOfGames()/2.0);
|
|
|
|
}
|
2015-04-17 08:07:20 -07:00
|
|
|
|
2015-04-19 14:43:56 -07:00
|
|
|
public DuelPlayerConfig getPlayerConfig(final int index) {
|
2015-04-19 12:29:20 -07:00
|
|
|
return players[index];
|
2015-04-17 08:07:20 -07:00
|
|
|
}
|
2015-04-17 13:36:59 -07:00
|
|
|
|
2015-04-19 14:45:52 -07:00
|
|
|
public DuelPlayerConfig[] getPlayerConfigs() {
|
2015-04-19 12:29:20 -07:00
|
|
|
return players;
|
2015-04-17 13:36:59 -07:00
|
|
|
}
|
|
|
|
|
2015-04-19 14:41:38 -07:00
|
|
|
public void setPlayerConfigs(DuelPlayerConfig[] aConfigs) {
|
|
|
|
players = aConfigs;
|
2015-04-17 13:36:59 -07:00
|
|
|
}
|
2015-04-19 14:52:41 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|