public void SaveGame(string filename) { Burntime.Framework.SaveGame game = new Burntime.Framework.SaveGame(filename, "classic", BurntimeClassic.SavegameVersion); game.Stream.WriteByte((byte)app.Clients.Count); for (int i = 0; i < app.Clients.Count; i++) { game.Stream.WriteByte((byte)app.Clients[i].Player); } //app.Server.StateContainer.Save(game.Stream); app.ActiveClient.StateContainer.Save(game.Stream); game.Close(); }
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); }