public void Load(XElement saveElement) { foreach (XElement subElement in saveElement.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { #if CLIENT case "gamemode": //legacy support case "singleplayercampaign": GameMode = SinglePlayerCampaign.Load(subElement); break; #endif case "multiplayercampaign": MultiplayerCampaign mpCampaign = GameMode as MultiplayerCampaign; if (mpCampaign == null) { DebugConsole.ThrowError("Error while loading a save file: the save file is for a multiplayer campaign but the current gamemode is " + GameMode.GetType().ToString()); break; } mpCampaign.Load(subElement); break; } } }
public GameSession(Submarine selectedSub, string saveFile, XDocument doc) : this(selectedSub, saveFile) { Submarine.MainSub = submarine; GameMain.GameSession = this; selectedSub.Name = doc.Root.GetAttributeString("submarine", selectedSub.Name); #if CLIENT CrewManager = new CrewManager(); #endif foreach (XElement subElement in doc.Root.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { #if CLIENT case "gamemode": //legacy support case "singleplayercampaign": GameMode = SinglePlayerCampaign.Load(subElement); break; #endif case "multiplayercampaign": GameMode = MultiplayerCampaign.LoadNew(subElement); break; } } }
public static MultiplayerCampaign LoadNew(XElement element) { MultiplayerCampaign campaign = new MultiplayerCampaign(GameModePreset.list.Find(gm => gm.Name == "Campaign"), null); campaign.Load(element); campaign.SetDelegates(); return(campaign); }
public static void ClientRead(NetBuffer msg) { //static because we may need to instantiate the campaign if it hasn't been done yet UInt16 updateID = msg.ReadUInt16(); UInt16 saveID = msg.ReadUInt16(); string mapSeed = msg.ReadString(); UInt16 currentLocIndex = msg.ReadUInt16(); UInt16 selectedLocIndex = msg.ReadUInt16(); int money = msg.ReadInt32(); UInt16 purchasedItemCount = msg.ReadUInt16(); List <ItemPrefab> purchasedItems = new List <ItemPrefab>(); for (int i = 0; i < purchasedItemCount; i++) { UInt16 itemPrefabIndex = msg.ReadUInt16(); purchasedItems.Add(MapEntityPrefab.list[itemPrefabIndex] as ItemPrefab); } MultiplayerCampaign campaign = GameMain.GameSession?.GameMode as MultiplayerCampaign; if (campaign == null || mapSeed != campaign.Map.Seed) { string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer); GameMain.GameSession = new GameSession(null, savePath, GameModePreset.list.Find(g => g.Name == "Campaign")); campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode); campaign.GenerateMap(mapSeed); } GameMain.NetLobbyScreen.ToggleCampaignMode(true); if (NetIdUtils.IdMoreRecent(campaign.lastUpdateID, updateID)) { return; } //server has a newer save file if (NetIdUtils.IdMoreRecent(saveID, campaign.PendingSaveID)) { //stop any active campaign save transfers, they're outdated now List <FileReceiver.FileTransferIn> saveTransfers = GameMain.Client.FileReceiver.ActiveTransfers.FindAll(t => t.FileType == FileTransferType.CampaignSave); foreach (var transfer in saveTransfers) { GameMain.Client.FileReceiver.StopTransfer(transfer); } GameMain.Client.RequestFile(FileTransferType.CampaignSave, null, null); campaign.PendingSaveID = saveID; } //we've got the latest save file else if (!NetIdUtils.IdMoreRecent(saveID, campaign.lastSaveID)) { campaign.Map.SetLocation(currentLocIndex == UInt16.MaxValue ? -1 : currentLocIndex); campaign.Map.SelectLocation(selectedLocIndex == UInt16.MaxValue ? -1 : selectedLocIndex); campaign.Money = money; campaign.CargoManager.SetPurchasedItems(purchasedItems); campaign.lastUpdateID = updateID; } }
private static void InitProjectSpecific() { commands.Add(new Command("restart|reset", "restart/reset: Close and restart the server.", (string[] args) => { NewMessage("*****************", Color.Lime); NewMessage("RESTARTING SERVER", Color.Lime); NewMessage("*****************", Color.Lime); GameMain.Instance.CloseServer(); GameMain.Instance.StartServer(); })); commands.Add(new Command("exit|quit|close", "exit/quit/close: Exit the application.", (string[] args) => { GameMain.ShouldRun = false; })); commands.Add(new Command("say", "say [message]: Send a chat message that displays \"HOST\" as the sender.", (string[] args) => { string text = string.Join(" ", args); text = "HOST: " + text; GameMain.Server.SendChatMessage(text, ChatMessageType.Server); })); commands.Add(new Command("msg", "msg [message]: Send a chat message with no sender specified.", (string[] args) => { string text = string.Join(" ", args); GameMain.Server.SendChatMessage(text, ChatMessageType.Server); })); commands.Add(new Command("servername", "servername [name]: Change the name of the server.", (string[] args) => { GameMain.Server.Name = string.Join(" ", args); GameMain.NetLobbyScreen.ChangeServerName(string.Join(" ", args)); })); commands.Add(new Command("servermsg", "servermsg [message]: Change the message displayed in the server lobby.", (string[] args) => { GameMain.NetLobbyScreen.ChangeServerMessage(string.Join(" ", args)); })); commands.Add(new Command("seed|levelseed", "seed/levelseed: Changes the level seed for the next round.", (string[] args) => { GameMain.NetLobbyScreen.LevelSeed = string.Join(" ", args); })); commands.Add(new Command("gamemode", "gamemode [name]/[index]: Select the game mode for the next round. The parameter can either be the name or the index number of the game mode (0 = sandbox, 1 = mission, etc).", (string[] args) => { int index = -1; if (int.TryParse(string.Join(" ", args), out index)) { if (index > 0 && index < GameMain.NetLobbyScreen.GameModes.Length && GameMain.NetLobbyScreen.GameModes[index].Name == "Campaign") { MultiplayerCampaign.StartCampaignSetup(); } else { GameMain.NetLobbyScreen.SelectedModeIndex = index; } } else { string modeName = string.Join(" ", args); if (modeName.ToLowerInvariant() == "campaign") { MultiplayerCampaign.StartCampaignSetup(); } else { GameMain.NetLobbyScreen.SelectedModeName = modeName; } } NewMessage("Set gamemode to " + GameMain.NetLobbyScreen.SelectedModeName, Color.Cyan); })); commands.Add(new Command("mission", "mission [name]/[index]: Select the mission type for the next round. The parameter can either be the name or the index number of the mission type (0 = first mission type, 1 = second mission type, etc).", (string[] args) => { int index = -1; if (int.TryParse(string.Join(" ", args), out index)) { GameMain.NetLobbyScreen.MissionTypeIndex = index; } else { GameMain.NetLobbyScreen.MissionTypeName = string.Join(" ", args); } NewMessage("Set mission to " + GameMain.NetLobbyScreen.MissionTypeName, Color.Cyan); })); commands.Add(new Command("sub|submarine", "submarine [name]: Select the submarine for the next round.", (string[] args) => { Submarine sub = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == string.Join(" ", args).ToLower()); if (sub != null) { GameMain.NetLobbyScreen.SelectedSub = sub; } sub = GameMain.NetLobbyScreen.SelectedSub; NewMessage("Selected sub: " + sub.Name + (sub.HasTag(SubmarineTag.Shuttle) ? " (shuttle)" : ""), Color.Cyan); })); commands.Add(new Command("shuttle", "shuttle [name]: Select the specified submarine as the respawn shuttle for the next round.", (string[] args) => { Submarine shuttle = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == string.Join(" ", args).ToLower()); if (shuttle != null) { GameMain.NetLobbyScreen.SelectedShuttle = shuttle; } shuttle = GameMain.NetLobbyScreen.SelectedShuttle; NewMessage("Selected shuttle: " + shuttle.Name + (shuttle.HasTag(SubmarineTag.Shuttle) ? "" : " (not shuttle)"), Color.Cyan); })); commands.Add(new Command("startgame|startround|start", "start/startgame/startround: Start a new round.", (string[] args) => { if (Screen.Selected == GameMain.GameScreen) { return; } if (!GameMain.Server.StartGame()) { NewMessage("Failed to start a new round", Color.Yellow); } })); commands.Add(new Command("endgame|endround|end", "end/endgame/endround: End the current round.", (string[] args) => { if (Screen.Selected == GameMain.NetLobbyScreen) { return; } GameMain.Server.EndGame(); })); commands.Add(new Command("autorestart", "autorestart: Toggle automatic round restarting on/off.", (string[] args) => { if (GameMain.Server == null) { return; } GameMain.Server.AutoRestart = !GameMain.Server.AutoRestart; NewMessage(GameMain.Server.AutoRestart ? "Automatic restart enabled." : "Automatic restart disabled.", Color.White); })); commands.Add(new Command("entitydata", "", (string[] args) => { if (args.Length == 0) { return; } Entity ent = Entity.FindEntityByID(Convert.ToUInt16(args[0])); if (ent != null) { NewMessage(ent.ToString(), Color.Lime); } })); #if DEBUG commands.Add(new Command("eventdata", "", (string[] args) => { if (args.Length == 0) { return; } ServerEntityEvent ev = GameMain.Server.EntityEventManager.Events[Convert.ToUInt16(args[0])]; if (ev != null) { NewMessage(ev.StackTrace, Color.Lime); } })); commands.Add(new Command("spamchatmessages", "", (string[] args) => { int msgCount = 1000; if (args.Length > 0) { int.TryParse(args[0], out msgCount); } int msgLength = 50; if (args.Length > 1) { int.TryParse(args[1], out msgLength); } for (int i = 0; i < msgCount; i++) { GameMain.Server.SendChatMessage(ToolBox.RandomSeed(msgLength), ChatMessageType.Default); } })); #endif }