public bool LoadGame(string filename) { if (container == null) { container = new Burntime.Framework.States.StateManager(app.ResourceManager); } app.Clients.Clear(); Burntime.Framework.SaveGame game = new Burntime.Framework.SaveGame(filename); if (game.Game != "classic" || game.Version != BurntimeClassic.SavegameVersion) { return(false); } int player = game.Stream.ReadByte(); List <int> ids = new List <int>(); for (int i = 0; i < player; i++) { ids.Add(game.Stream.ReadByte()); } container.Load(game.Stream); game.Close(); app.Server = new Burntime.Framework.Network.GameServer(); app.GameServer = app.Server; app.GameServer.Create(container.Root, container); ClassicGame classic = container.Root as ClassicGame; // share container for all local player Burntime.Framework.States.StateManager sharedContainer = null; // if no synchronization mode is active, then share container with game server if (!BurntimeClassic.Instance.Settings["game"].GetBool("always_synchronize")) { sharedContainer = container; } if (!ids.Contains(0)) { app.Server.AddAI(new AI.AiPlayer(app, 0, container)); } else { Burntime.Framework.Network.GameClient client = new Burntime.Framework.Network.GameClient(app, 0, sharedContainer); sharedContainer = client.StateContainer; app.GameServer.AddClient(client); app.Clients.Add(client); } if (!ids.Contains(1)) { app.Server.AddAI(new AI.AiPlayer(app, 1, container)); } else { Burntime.Framework.Network.GameClient client = new Burntime.Framework.Network.GameClient(app, 1, sharedContainer); app.GameServer.AddClient(client); app.Clients.Add(client); } app.Server.AddAI(new AI.AiPlayer(app, 2, container)); app.Server.AddAI(new AI.AiPlayer(app, 3, container)); // disable already dead players foreach (Burntime.Framework.Network.GameClient client in app.Server.Clients) { if (classic.World.Players[client.Player].IsDead) { client.Die(); } } #warning TODO: store progressive setting properly foreach (Player p in classic.World.Players) { p.Flag.Object.Animation.Progressive = false; } app.Server.Run(); return(true); }
void AddPlayer(ClassicGame game, NewGameInfo Info, Burntime.Data.BurnGfx.Save.SaveGame gamdat, GameSettings settings) { // share container for all local player Burntime.Framework.States.StateManager sharedContainer = null; // if no synchronization mode is active, then share container with game server if (!BurntimeClassic.Instance.Settings["game"].GetBool("always_synchronize")) { sharedContainer = container; } // no ai mode bool disableAI = BurntimeClassic.Instance.Settings["game"].GetBool("disable_ai"); app.ActiveClient = Burntime.Framework.Network.GameClient.NoClient; PixelColor[] colors = new PixelColor[4] { new PixelColor(0, 208, 0), new PixelColor(240, 64, 56), new PixelColor(0, 0, 0), // not used new PixelColor(0, 0, 0) }; // not used PixelColor[] colorsdark = new PixelColor[4] { new PixelColor(0, 132, 0), new PixelColor(192, 0, 0), new PixelColor(80, 80, 132), new PixelColor(156, 156, 156) }; int[] iconIDs = new int[] { 0, 1, 3, 2 }; for (int i = 0; i < 4; i++) { game.World.Players.Add(container.Create <Player>(new object[] { i })); game.World.Players[i].Type = PlayerType.Ai; game.World.Players[i].IconID = iconIDs[i]; game.World.Players[i].Character = container.Create <PlayerCharacter>(); game.World.Players[i].Name = app.ResourceManager.GetString("burn?" + (170 + i).ToString()); game.World.Players[i].Character.Position = new Vector2(); game.World.Players[i].Character.Body = app.ResourceManager.GetData("syssze.raw?" + gamdat.Characters[i].SpriteId + "-" + (gamdat.Characters[i].SpriteId + 15)); game.World.Players[i].Character.Path = container.Create <PathFinding.ComplexPath>(); game.World.Players[i].Character.Mind = container.Create <AI.PlayerControlledMind>(new object[] { game.World.Players[i].Character }); game.World.Players[i].Character.Items.MaxCount = 6; game.World.Players[i].Flag = app.ResourceManager.GetData("[email protected]?" + gamdat.Player[i].Info.FlagId + "-" + (gamdat.Player[i].Info.FlagId + 3)); game.World.Players[i].Flag.Object.Animation.Progressive = false; game.World.Players[i].Character.Health = settings.StartHealth; game.World.Players[i].Character.Experience = settings.StartExperience; game.World.Players[i].Character.Food = settings.StartFood; game.World.Players[i].Character.Water = settings.StartWater; game.World.Players[i].Character.Class = (CharClass)gamdat.Characters[i].Type; game.World.Players[i].Character.Player = game.World.Players[i]; game.World.Players[i].Color = colors[i]; game.World.Players[i].ColorDark = colorsdark[i]; game.World.Players[i].OnMainMap = true; game.World.Players[i].BaseExperience = settings.StartExperience; game.World.AllCharacters += game.World.Players[i].Character; } if (Info.NameOne != "" && Info.NameOne != null) { game.World.Players[0].Name = Info.NameOne; game.World.Players[0].Character.FaceID = Info.FaceOne; game.World.Players[0].Type = PlayerType.Human; Burntime.Framework.Network.GameClient client = new Burntime.Framework.Network.GameClient(app, 0, sharedContainer); sharedContainer = client.StateContainer; app.GameServer.AddClient(client); app.Clients.Add(client); } else { Burntime.Framework.AI.GameClientAI client = new AI.AiPlayer(app, 0, container); app.Server.AddAI(client); } game.World.Players[0].Color = colors[(int)Info.ColorOne]; game.World.Players[0].ColorDark = colorsdark[(int)Info.ColorOne]; game.World.Players[0].IconID = Info.ColorOne == BurntimePlayerColor.Green ? 0 : 1; game.World.Players[0].BodyColorSet = Info.ColorOne == BurntimePlayerColor.Green ? 2 : 0; game.World.Players[0].Character.Body = Helper.GetCharacterBody(2, game.World.Players[0].BodyColorSet); game.World.Players[0].Flag = app.ResourceManager.GetData(Info.ColorOne == BurntimePlayerColor.Green ? "[email protected]?0-3" : "[email protected]?8-11"); if (Info.NameTwo != "" && Info.NameTwo != null) { game.World.Players[1].Name = Info.NameTwo; game.World.Players[1].Character.FaceID = Info.FaceTwo; game.World.Players[1].Type = PlayerType.Human; Burntime.Framework.Network.GameClient client = new Burntime.Framework.Network.GameClient(app, 1, sharedContainer); app.GameServer.AddClient(client); app.Clients.Add(client); } else { app.Server.AddAI(new AI.AiPlayer(app, 1, container)); } game.World.Players[1].Color = colors[(int)Info.ColorTwo]; game.World.Players[1].ColorDark = colorsdark[(int)Info.ColorTwo]; game.World.Players[1].IconID = Info.ColorTwo == BurntimePlayerColor.Green ? 0 : 1; game.World.Players[1].BodyColorSet = Info.ColorTwo == BurntimePlayerColor.Green ? 2 : 0; game.World.Players[1].Character.Body = Helper.GetCharacterBody(2, game.World.Players[1].BodyColorSet); game.World.Players[1].Flag = app.ResourceManager.GetData(Info.ColorTwo == BurntimePlayerColor.Green ? "[email protected]?0-3" : "[email protected]?8-11"); game.World.Players[2].BodyColorSet = -1; game.World.Players[3].BodyColorSet = 1; app.Server.AddAI(new AI.AiPlayer(app, 2, container)); app.Server.AddAI(new AI.AiPlayer(app, 3, container)); // add ai state objects foreach (Player p in game.World.Players) { if (p.Type == PlayerType.Ai) { p.AiState = container.Create <AI.ClassicAiState>(p, settings.AiSettings); } } // kill all ai player if (disableAI) { foreach (Player p in game.World.Players) { if (p.Type == PlayerType.Ai) { p.IsDead = true; } } foreach (Burntime.Framework.Network.GameClient client in app.Server.Clients) { if (game.World.Players[client.Player].Type == PlayerType.Ai) { client.Die(); } } } }