replace call to setDifficulty and setAIs with MagicPlayerDefinition constructor that takes a player profile
parent
bc248c6009
commit
37ab9d56a2
|
@ -9,6 +9,9 @@ import magic.model.MagicGame;
|
||||||
import magic.model.MagicPlayer;
|
import magic.model.MagicPlayer;
|
||||||
import magic.model.MagicPlayerDefinition;
|
import magic.model.MagicPlayerDefinition;
|
||||||
import magic.model.phase.MagicMainPhase;
|
import magic.model.phase.MagicMainPhase;
|
||||||
|
import magic.model.player.AiPlayer;
|
||||||
|
import magic.model.player.HumanPlayer;
|
||||||
|
import magic.model.player.PlayerProfile;
|
||||||
import magic.test.TestGameBuilder;
|
import magic.test.TestGameBuilder;
|
||||||
|
|
||||||
public final class GameLoader {
|
public final class GameLoader {
|
||||||
|
@ -31,31 +34,43 @@ public final class GameLoader {
|
||||||
|
|
||||||
private static MagicDuel getDuelState(final GameState gameState) {
|
private static MagicDuel getDuelState(final GameState gameState) {
|
||||||
final MagicDuel duel = new MagicDuel();
|
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 MagicDeckProfile deckProfile1 = new MagicDeckProfile(gameState.getPlayer(0).getDeckProfileColors());
|
||||||
final MagicPlayerDefinition playerDef1 =
|
final MagicPlayerDefinition playerDef1 = new MagicPlayerDefinition(pp1, deckProfile1);
|
||||||
new MagicPlayerDefinition(
|
|
||||||
gameState.getPlayer(0).getName(),
|
PlayerProfile pp2;
|
||||||
gameState.getPlayer(0).isAi(),
|
if (gameState.getPlayer(1).isAi()) {
|
||||||
deckProfile1);
|
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 MagicDeckProfile deckProfile2 = new MagicDeckProfile(gameState.getPlayer(1).getDeckProfileColors());
|
||||||
final MagicPlayerDefinition playerDef2 =
|
final MagicPlayerDefinition playerDef2 = new MagicPlayerDefinition(pp2, deckProfile2);
|
||||||
new MagicPlayerDefinition(
|
|
||||||
gameState.getPlayer(1).getName(),
|
|
||||||
gameState.getPlayer(1).isAi(),
|
|
||||||
deckProfile2);
|
|
||||||
duel.setPlayers(new MagicPlayerDefinition[]{playerDef1, playerDef2});
|
duel.setPlayers(new MagicPlayerDefinition[]{playerDef1, playerDef2});
|
||||||
duel.setStartPlayer(gameState.getStartPlayerIndex());
|
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;
|
return duel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public final class GameStateSnapshot {
|
||||||
|
|
||||||
final GameState gameState = new GameState();
|
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.
|
// will always be 0 since it is not possible to save when AI has priority.
|
||||||
gameState.setStartPlayerIndex(game.getPriorityPlayer().getIndex());
|
gameState.setStartPlayerIndex(game.getPriorityPlayer().getIndex());
|
||||||
|
|
||||||
|
@ -32,17 +32,6 @@ public final class GameStateSnapshot {
|
||||||
return gameState;
|
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) {
|
private static void saveGamePlayerState(final int playerIndex, final GameState gameState, final MagicGame game) {
|
||||||
final MagicDuel duel = game.getDuel();
|
final MagicDuel duel = game.getDuel();
|
||||||
final MagicPlayerDefinition playerDef = duel.getPlayer(playerIndex);
|
final MagicPlayerDefinition playerDef = duel.getPlayer(playerIndex);
|
||||||
|
@ -51,7 +40,7 @@ public final class GameStateSnapshot {
|
||||||
// gamePlayerState.setFace(playerDef.getAvatar().getFace());
|
// gamePlayerState.setFace(playerDef.getAvatar().getFace());
|
||||||
gamePlayerState.setDeckProfileColors(playerDef.getDeckProfile().getColorText());
|
gamePlayerState.setDeckProfileColors(playerDef.getDeckProfile().getColorText());
|
||||||
if (playerDef.isArtificial()) {
|
if (playerDef.isArtificial()) {
|
||||||
gamePlayerState.setAiType(getAiType(duel.getAIs()[playerIndex]));
|
gamePlayerState.setAiType(playerDef.getPlayerProfile().getAiType().toString());
|
||||||
}
|
}
|
||||||
final MagicPlayer player = game.getPlayer(playerIndex);
|
final MagicPlayer player = game.getPlayer(playerIndex);
|
||||||
gamePlayerState.setLife(player.getLife());
|
gamePlayerState.setLife(player.getLife());
|
||||||
|
|
Loading…
Reference in New Issue