diff --git a/src/magic/game/state/GameLoader.java b/src/magic/game/state/GameLoader.java index 48c0588edf..19680dfaab 100644 --- a/src/magic/game/state/GameLoader.java +++ b/src/magic/game/state/GameLoader.java @@ -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; } diff --git a/src/magic/game/state/GameStateSnapshot.java b/src/magic/game/state/GameStateSnapshot.java index ce6f494a16..1246da45d3 100644 --- a/src/magic/game/state/GameStateSnapshot.java +++ b/src/magic/game/state/GameStateSnapshot.java @@ -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());