replace call to setDifficulty and setAIs with MagicPlayerDefinition constructor that takes a player profile

master
melvinzhang 2015-04-04 21:22:07 +08:00
parent bc248c6009
commit 37ab9d56a2
2 changed files with 38 additions and 34 deletions

View File

@ -9,6 +9,9 @@ import magic.model.MagicGame;
import magic.model.MagicPlayer;
import magic.model.MagicPlayerDefinition;
import magic.model.phase.MagicMainPhase;
import magic.model.player.AiPlayer;
import magic.model.player.HumanPlayer;
import magic.model.player.PlayerProfile;
import magic.test.TestGameBuilder;
public final class GameLoader {
@ -31,31 +34,43 @@ public final class GameLoader {
private static MagicDuel getDuelState(final GameState gameState) {
final MagicDuel duel = new MagicDuel();
duel.setDifficulty(gameState.getDifficulty());
PlayerProfile pp1;
if (gameState.getPlayer(0).isAi()) {
final MagicAIImpl ai = MagicAIImpl.valueOf(gameState.getPlayer(0).getAiType());
final AiPlayer ap = new AiPlayer();
ap.setPlayerName(gameState.getPlayer(0).getName());
ap.setAiType(ai);
ap.setAiLevel(gameState.getDifficulty());
pp1 = ap;
} else {
final HumanPlayer hp = new HumanPlayer();
hp.setPlayerName(gameState.getPlayer(0).getName());
pp1 = hp;
}
final MagicDeckProfile deckProfile1 = new MagicDeckProfile(gameState.getPlayer(0).getDeckProfileColors());
final MagicPlayerDefinition playerDef1 =
new MagicPlayerDefinition(
gameState.getPlayer(0).getName(),
gameState.getPlayer(0).isAi(),
deckProfile1);
final MagicPlayerDefinition playerDef1 = new MagicPlayerDefinition(pp1, deckProfile1);
PlayerProfile pp2;
if (gameState.getPlayer(1).isAi()) {
final MagicAIImpl ai = MagicAIImpl.valueOf(gameState.getPlayer(1).getAiType());
final AiPlayer ap = new AiPlayer();
ap.setPlayerName(gameState.getPlayer(1).getName());
ap.setAiType(ai);
ap.setAiLevel(gameState.getDifficulty());
pp2 = ap;
} else {
final HumanPlayer hp = new HumanPlayer();
hp.setPlayerName(gameState.getPlayer(1).getName());
pp2 = hp;
}
final MagicDeckProfile deckProfile2 = new MagicDeckProfile(gameState.getPlayer(1).getDeckProfileColors());
final MagicPlayerDefinition playerDef2 =
new MagicPlayerDefinition(
gameState.getPlayer(1).getName(),
gameState.getPlayer(1).isAi(),
deckProfile2);
final MagicPlayerDefinition playerDef2 = new MagicPlayerDefinition(pp2, deckProfile2);
duel.setPlayers(new MagicPlayerDefinition[]{playerDef1, playerDef2});
duel.setStartPlayer(gameState.getStartPlayerIndex());
// AI
MagicAI ai1 = null;
if (gameState.getPlayer(0).isAi()) {
ai1 = MagicAIImpl.valueOf(gameState.getPlayer(0).getAiType()).getAI();
}
MagicAI ai2 = null;
if (gameState.getPlayer(1).isAi()) {
ai2 = MagicAIImpl.valueOf(gameState.getPlayer(1).getAiType()).getAI();
}
duel.setAIs(new MagicAI[]{ai1, ai2});
return duel;
}

View File

@ -20,7 +20,7 @@ public final class GameStateSnapshot {
final GameState gameState = new GameState();
gameState.setDifficulty(game.getDuel().getDifficulty());
gameState.setDifficulty(game.getPlayer(1).getPlayerDefinition().getPlayerProfile().getAiLevel());
// will always be 0 since it is not possible to save when AI has priority.
gameState.setStartPlayerIndex(game.getPriorityPlayer().getIndex());
@ -32,17 +32,6 @@ public final class GameStateSnapshot {
return gameState;
}
private static String getAiType(final MagicAI ai) {
if (ai != null) {
for (MagicAIImpl aiType : MagicAIImpl.SUPPORTED_AIS) {
if (aiType.getAI() == ai) {
return aiType.name();
}
}
}
return "";
}
private static void saveGamePlayerState(final int playerIndex, final GameState gameState, final MagicGame game) {
final MagicDuel duel = game.getDuel();
final MagicPlayerDefinition playerDef = duel.getPlayer(playerIndex);
@ -51,7 +40,7 @@ public final class GameStateSnapshot {
// gamePlayerState.setFace(playerDef.getAvatar().getFace());
gamePlayerState.setDeckProfileColors(playerDef.getDeckProfile().getColorText());
if (playerDef.isArtificial()) {
gamePlayerState.setAiType(getAiType(duel.getAIs()[playerIndex]));
gamePlayerState.setAiType(playerDef.getPlayerProfile().getAiType().toString());
}
final MagicPlayer player = game.getPlayer(playerIndex);
gamePlayerState.setLife(player.getLife());