Ejemplo n.º 1
0
        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;
                }
            }
        }
Ejemplo n.º 2
0
        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;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load a game session from the specified XML document. The session will be saved to the specified path.
        /// </summary>
        public GameSession(SubmarineInfo submarineInfo, List <SubmarineInfo> ownedSubmarines, XDocument doc, string saveFile) : this(submarineInfo, ownedSubmarines)
        {
            this.SavePath        = saveFile;
            GameMain.GameSession = this;
            //selectedSub.Name = doc.Root.GetAttributeString("submarine", selectedSub.Name);

            foreach (XElement subElement in doc.Root.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
#if CLIENT
                case "gamemode":     //legacy support
                case "singleplayercampaign":
                    CrewManager = new CrewManager(true);
                    var campaign = SinglePlayerCampaign.Load(subElement);
                    campaign.LoadNewLevel();
                    GameMode = campaign;
                    break;
#endif
                case "multiplayercampaign":
                    CrewManager = new CrewManager(false);
                    var mpCampaign = MultiPlayerCampaign.LoadNew(subElement);
                    GameMode = mpCampaign;
                    if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
                    {
                        mpCampaign.LoadNewLevel();
                        //save to ensure the campaign ID in the save file matches the one that got assigned to this campaign instance
                        SaveUtil.SaveGame(saveFile);
                    }
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        private GameMode InstantiateGameMode(GameModePreset gameModePreset, string seed, MissionPrefab missionPrefab = null, MissionType missionType = MissionType.None)
        {
            if (gameModePreset.GameModeType == typeof(MissionMode))
            {
                return(missionPrefab != null ?
                       new MissionMode(gameModePreset, missionPrefab) :
                       new MissionMode(gameModePreset, missionType, seed ?? ToolBox.RandomSeed(8)));
            }
            else if (gameModePreset.GameModeType == typeof(MultiPlayerCampaign))
            {
                return(MultiPlayerCampaign.StartNew(seed ?? ToolBox.RandomSeed(8)));
            }
#if CLIENT
            else if (gameModePreset.GameModeType == typeof(SinglePlayerCampaign))
            {
                return(SinglePlayerCampaign.StartNew(seed ?? ToolBox.RandomSeed(8)));
            }
            else if (gameModePreset.GameModeType == typeof(TutorialMode))
            {
                return(new TutorialMode(gameModePreset));
            }
            else if (gameModePreset.GameModeType == typeof(TestGameMode))
            {
                return(new TestGameMode(gameModePreset));
            }
#endif
            else if (gameModePreset.GameModeType == typeof(GameMode))
            {
                return(new GameMode(gameModePreset));
            }
            else
            {
                throw new Exception($"Could not find a game mode of the type \"{gameModePreset.GameModeType}\"");
            }
        }
Ejemplo n.º 5
0
        public static MultiPlayerCampaign LoadNew(XElement element)
        {
            MultiPlayerCampaign campaign = new MultiPlayerCampaign();

            campaign.Load(element);
            campaign.InitProjSpecific();
            campaign.IsFirstRound = false;
            return(campaign);
        }
Ejemplo n.º 6
0
        public static MultiPlayerCampaign LoadNew(XElement element)
        {
            MultiPlayerCampaign campaign = new MultiPlayerCampaign(GameModePreset.List.Find(gm => gm.Identifier == "multiplayercampaign"), null);

            campaign.Load(element);
            campaign.SetDelegates();

            return(campaign);
        }
Ejemplo n.º 7
0
        public static MultiPlayerCampaign StartNew(string mapSeed)
        {
            MultiPlayerCampaign campaign = new MultiPlayerCampaign();

            //only the server generates the map, the clients load it from a save file
            if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
            {
                campaign.map = new Map(campaign, mapSeed);
            }
            campaign.InitProjSpecific();
            return(campaign);
        }
Ejemplo n.º 8
0
        private GameMode InstantiateGameMode(GameModePreset gameModePreset, string seed, SubmarineInfo selectedSub, CampaignSettings settings, IEnumerable <MissionPrefab> missionPrefabs = null, MissionType missionType = MissionType.None)
        {
            if (gameModePreset.GameModeType == typeof(CoOpMode))
            {
                return(missionPrefabs != null ?
                       new CoOpMode(gameModePreset, missionPrefabs) :
                       new CoOpMode(gameModePreset, missionType, seed ?? ToolBox.RandomSeed(8)));
            }
            else if (gameModePreset.GameModeType == typeof(PvPMode))
            {
                return(missionPrefabs != null ?
                       new PvPMode(gameModePreset, missionPrefabs) :
                       new PvPMode(gameModePreset, missionType, seed ?? ToolBox.RandomSeed(8)));
            }
            else if (gameModePreset.GameModeType == typeof(MultiPlayerCampaign))
            {
                var campaign = MultiPlayerCampaign.StartNew(seed ?? ToolBox.RandomSeed(8), selectedSub, settings);
                if (campaign != null && selectedSub != null)
                {
                    campaign.Money = Math.Max(MultiPlayerCampaign.MinimumInitialMoney, campaign.Money - selectedSub.Price);
                }
                return(campaign);
            }
#if CLIENT
            else if (gameModePreset.GameModeType == typeof(SinglePlayerCampaign))
            {
                var campaign = SinglePlayerCampaign.StartNew(seed ?? ToolBox.RandomSeed(8), selectedSub, settings);
                if (campaign != null && selectedSub != null)
                {
                    campaign.Money = Math.Max(SinglePlayerCampaign.MinimumInitialMoney, campaign.Money - selectedSub.Price);
                }
                return(campaign);
            }
            else if (gameModePreset.GameModeType == typeof(TutorialMode))
            {
                return(new TutorialMode(gameModePreset));
            }
            else if (gameModePreset.GameModeType == typeof(TestGameMode))
            {
                return(new TestGameMode(gameModePreset));
            }
#endif
            else if (gameModePreset.GameModeType == typeof(GameMode))
            {
                return(new GameMode(gameModePreset));
            }
            else
            {
                throw new Exception($"Could not find a game mode of the type \"{gameModePreset.GameModeType}\"");
            }
        }
Ejemplo n.º 9
0
        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("randomizeseed", "randomizeseed: Toggles level seed randomization on/off.", (string[] args) =>
            {
                GameMain.Server.RandomizeSeed = !GameMain.Server.RandomizeSeed;
                NewMessage((GameMain.Server.RandomizeSeed ? "Enabled" : "Disabled") + " level seed randomization.", Color.Cyan);
            }));

            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);
            },
                                     () =>
            {
                return(new string[][]
                {
                    GameModePreset.list.Select(gm => gm.Name).ToArray()
                });
            }));

            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);
            },
                                     () =>
            {
                return(new string[][]
                {
                    MissionPrefab.MissionTypes.ToArray()
                });
            }));

            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);
            },
                                     () =>
            {
                return(new string[][]
                {
                    Submarine.Loaded.Select(s => s.Name).ToArray()
                });
            }));

            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);
            },
                                     () =>
            {
                return(new string[][]
                {
                    Submarine.Loaded.Select(s => s.Name).ToArray()
                });
            }));

            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("entitydata", "", (string[] args) =>
            {
                if (args.Length == 0)
                {
                    return;
                }
                Entity ent = Entity.FindEntityByID(Convert.ToUInt16(args[0]));
                if (ent != null)
                {
                    NewMessage(ent.ToString(), Color.Lime);
                }
            }));

            //"dummy commands" that only exist so that the server can give clients permissions to use them
            commands.Add(new Command("control|controlcharacter", "control [character name]: Start controlling the specified character (client-only).", null));
            commands.Add(new Command("los", "Toggle the line of sight effect on/off (client-only).", null));
            commands.Add(new Command("lighting|lights", "Toggle lighting on/off (client-only).", null));
            commands.Add(new Command("debugdraw", "Toggle the debug drawing mode on/off (client-only).", null));
            commands.Add(new Command("togglehud|hud", "Toggle the character HUD (inventories, icons, buttons, etc) on/off (client-only).", null));
            commands.Add(new Command("followsub", "Toggle whether the camera should follow the nearest submarine (client-only).", null));
            commands.Add(new Command("toggleaitargets|aitargets", "Toggle the visibility of AI targets (= targets that enemies can detect and attack/escape from) (client-only).", null));

#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
        }
        //static because we may need to instantiate the campaign if it hasn't been done yet
        public static void ClientRead(NetBuffer msg)
        {
            byte   campaignID           = msg.ReadByte();
            UInt16 updateID             = msg.ReadUInt16();
            UInt16 saveID               = msg.ReadUInt16();
            string mapSeed              = msg.ReadString();
            UInt16 currentLocIndex      = msg.ReadUInt16();
            UInt16 selectedLocIndex     = msg.ReadUInt16();
            byte   selectedMissionIndex = msg.ReadByte();

            UInt16 startWatchmanID = msg.ReadUInt16();
            UInt16 endWatchmanID   = msg.ReadUInt16();

            int  money = msg.ReadInt32();
            bool purchasedHullRepairs = msg.ReadBoolean();
            bool purchasedItemRepairs = msg.ReadBoolean();

            UInt16 purchasedItemCount           = msg.ReadUInt16();
            List <PurchasedItem> purchasedItems = new List <PurchasedItem>();

            for (int i = 0; i < purchasedItemCount; i++)
            {
                UInt16 itemPrefabIndex = msg.ReadUInt16();
                UInt16 itemQuantity    = msg.ReadUInt16();
                purchasedItems.Add(new PurchasedItem(MapEntityPrefab.List[itemPrefabIndex] as ItemPrefab, itemQuantity));
            }

            bool          hasCharacterData = msg.ReadBoolean();
            CharacterInfo myCharacterInfo  = null;

            if (hasCharacterData)
            {
                myCharacterInfo = CharacterInfo.ClientRead(Character.HumanConfigFile, msg);
            }

            MultiPlayerCampaign campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;

            if (campaign == null || campaignID != campaign.CampaignID)
            {
                string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer);

                GameMain.GameSession = new GameSession(null, savePath,
                                                       GameModePreset.List.Find(g => g.Identifier == "multiplayercampaign"));

                campaign            = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                campaign.CampaignID = campaignID;
                campaign.GenerateMap(mapSeed);
                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
            }


            //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;
            }

            if (NetIdUtils.IdMoreRecent(updateID, campaign.lastUpdateID))
            {
                campaign.Map.SetLocation(currentLocIndex == UInt16.MaxValue ? -1 : currentLocIndex);
                campaign.Map.SelectLocation(selectedLocIndex == UInt16.MaxValue ? -1 : selectedLocIndex);
                campaign.Map.SelectMission(selectedMissionIndex);

                campaign.startWatchmanID = startWatchmanID;
                campaign.endWatchmanID   = endWatchmanID;

                campaign.Money = money;
                campaign.PurchasedHullRepairs = purchasedHullRepairs;
                campaign.PurchasedItemRepairs = purchasedItemRepairs;
                campaign.CargoManager.SetPurchasedItems(purchasedItems);

                if (myCharacterInfo != null)
                {
                    GameMain.Client.CharacterInfo = myCharacterInfo;
                    GameMain.NetLobbyScreen.SetCampaignCharacterInfo(myCharacterInfo);
                }
                else
                {
                    GameMain.NetLobbyScreen.SetCampaignCharacterInfo(null);
                }

                campaign.lastUpdateID = updateID;
            }
        }
Ejemplo n.º 11
0
        private GameMode InstantiateGameMode(GameModePreset gameModePreset, string seed, SubmarineInfo selectedSub, CampaignSettings settings, IEnumerable <MissionPrefab> missionPrefabs = null, MissionType missionType = MissionType.None)
        {
            if (gameModePreset.GameModeType == typeof(CoOpMode) || gameModePreset.GameModeType == typeof(PvPMode))
            {
                //don't allow hidden mission types (e.g. GoTo) in single mission modes
                var missionTypes = (MissionType[])Enum.GetValues(typeof(MissionType));
                for (int i = 0; i < missionTypes.Length; i++)
                {
                    if (MissionPrefab.HiddenMissionClasses.Contains(missionTypes[i]))
                    {
                        missionType &= ~missionTypes[i];
                    }
                }
            }
            if (gameModePreset.GameModeType == typeof(CoOpMode))
            {
                return(missionPrefabs != null ?
                       new CoOpMode(gameModePreset, missionPrefabs) :
                       new CoOpMode(gameModePreset, missionType, seed ?? ToolBox.RandomSeed(8)));
            }
            else if (gameModePreset.GameModeType == typeof(PvPMode))
            {
                return(missionPrefabs != null ?
                       new PvPMode(gameModePreset, missionPrefabs) :
                       new PvPMode(gameModePreset, missionType, seed ?? ToolBox.RandomSeed(8)));
            }
            else if (gameModePreset.GameModeType == typeof(MultiPlayerCampaign))
            {
                var campaign = MultiPlayerCampaign.StartNew(seed ?? ToolBox.RandomSeed(8), selectedSub, settings);
                if (campaign != null && selectedSub != null)
                {
                    campaign.Money = Math.Max(MultiPlayerCampaign.MinimumInitialMoney, campaign.Money - selectedSub.Price);
                }
                return(campaign);
            }
#if CLIENT
            else if (gameModePreset.GameModeType == typeof(SinglePlayerCampaign))
            {
                var campaign = SinglePlayerCampaign.StartNew(seed ?? ToolBox.RandomSeed(8), selectedSub, settings);
                if (campaign != null && selectedSub != null)
                {
                    campaign.Money = Math.Max(SinglePlayerCampaign.MinimumInitialMoney, campaign.Money - selectedSub.Price);
                }
                return(campaign);
            }
            else if (gameModePreset.GameModeType == typeof(TutorialMode))
            {
                return(new TutorialMode(gameModePreset));
            }
            else if (gameModePreset.GameModeType == typeof(TestGameMode))
            {
                return(new TestGameMode(gameModePreset));
            }
#endif
            else if (gameModePreset.GameModeType == typeof(GameMode))
            {
                return(new GameMode(gameModePreset));
            }
            else
            {
                throw new Exception($"Could not find a game mode of the type \"{gameModePreset.GameModeType}\"");
            }
        }
Ejemplo n.º 12
0
        //static because we may need to instantiate the campaign if it hasn't been done yet
        public static void ClientRead(NetBuffer msg)
        {
            byte   campaignID       = msg.ReadByte();
            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 <PurchasedItem> purchasedItems = new List <PurchasedItem>();

            for (int i = 0; i < purchasedItemCount; i++)
            {
                UInt16 itemPrefabIndex = msg.ReadUInt16();
                UInt16 itemQuantity    = msg.ReadUInt16();
                purchasedItems.Add(new PurchasedItem(MapEntityPrefab.List[itemPrefabIndex] as ItemPrefab, itemQuantity));
            }

            MultiPlayerCampaign campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;

            if (campaign == null || campaignID != campaign.CampaignID)
            {
                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.CampaignID = campaignID;
                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;
            }
        }
Ejemplo n.º 13
0
        public void DefaultServerStartup()
        {
            Boolean startcampaign = false;

            //Default Mission Parameters
            if (GameMain.NilMod.DefaultGamemode.ToLowerInvariant() == "mission")
            {
                GameMain.NetLobbyScreen.SelectedModeIndex = 1;
                //GameMain.NilMod.DefaultMissionType = "Cargo";
                //Only select this default if we actually default to mission mode
                switch (GameMain.NilMod.DefaultMissionType.ToLowerInvariant())
                {
                case "random":
                    GameMain.NetLobbyScreen.MissionTypeIndex = 0;
                    break;

                case "salvage":
                    GameMain.NetLobbyScreen.MissionTypeIndex = 1;
                    break;

                case "monster":
                    GameMain.NetLobbyScreen.MissionTypeIndex = 2;
                    break;

                case "cargo":
                    GameMain.NetLobbyScreen.MissionTypeIndex = 3;
                    break;

                case "combat":
                    GameMain.NetLobbyScreen.MissionTypeIndex = 4;
                    break;

                //Random if no valid mission type
                default:
                    GameMain.NetLobbyScreen.MissionTypeIndex = 0;
                    break;
                }
            }
            else if (GameMain.NilMod.DefaultGamemode.ToLowerInvariant() == "campaign")
            {
                startcampaign = true;
                GameMain.NetLobbyScreen.SelectedModeIndex = 1;
            }
            else
            {
                GameMain.NetLobbyScreen.SelectedModeIndex = 0;
            }

            if (GameMain.NilMod.DefaultLevelSeed != "")
            {
                GameMain.NetLobbyScreen.LevelSeed = GameMain.NilMod.DefaultLevelSeed;
            }

            if (GameMain.NilMod.DefaultSubmarine != "")
            {
                Submarine sub = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == GameMain.NilMod.DefaultSubmarine.ToLower());

                if (sub != null)
                {
                    GameMain.NetLobbyScreen.SelectedSub = sub;
                }
                else
                {
                    sub = GameMain.NetLobbyScreen.SelectedSub;
                    DebugConsole.NewMessage("Default submarine: " + GameMain.NilMod.DefaultSubmarine + " not found, using " + sub.Name + " instead", Color.Red);
                }
            }

            if (GameMain.NilMod.DefaultRespawnShuttle != "")
            {
                Submarine shuttle = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == GameMain.NilMod.DefaultRespawnShuttle.ToLower());

                if (shuttle != null)
                {
                    GameMain.NetLobbyScreen.SelectedShuttle = shuttle;
                }
                else
                {
                    shuttle = GameMain.NetLobbyScreen.SelectedShuttle;
                    DebugConsole.NewMessage("Default shuttle: " + GameMain.NilMod.DefaultRespawnShuttle + " not found, using " + shuttle.Name + " instead", Color.Red);
                }
            }

            DebugConsole.NewMessage(
                "Save Server Logs: " + (GameMain.Server.SaveServerLogs ? "YES" : "NO") +
                ", Allow File Transfers: " + (GameMain.Server.AllowFileTransfers ? "YES" : "NO"), Color.Cyan);

            DebugConsole.NewMessage(
                "Allow Spectating: " + (GameMain.Server.AllowSpectating ? "YES" : "NO"), Color.Cyan);

            //LevelSeed = ToolBox.RandomSeed(8);



            DebugConsole.NewMessage(" ", Color.Cyan);

            DebugConsole.NewMessage(
                "Auto Restart: " + (GameMain.Server.AutoRestart ? "YES" : "NO") +
                ", Auto Restart Interval: " + ToolBox.SecondsToReadableTime(GameMain.Server.AutoRestartInterval), Color.Cyan);

            DebugConsole.NewMessage(
                "End Round At Level End: " + (GameMain.Server.EndRoundAtLevelEnd ? "YES" : "NO") +
                ", End Vote Required Ratio: " + (GameMain.Server.EndVoteRequiredRatio * 100) + "%", Color.Cyan);

            DebugConsole.NewMessage(
                "Allow Vote Kick: " + (GameMain.Server.AllowVoteKick ? "YES" : "NO") +
                ", Kick Vote Required Ratio: " + (GameMain.Server.KickVoteRequiredRatio * 100) + "%", Color.Cyan);

            DebugConsole.NewMessage(" ", Color.Cyan);

            DebugConsole.NewMessage(
                "Allow Respawns: " + (GameMain.Server.AllowRespawn ? "YES" : "NO") +
                ", Min Respawn Ratio:" + GameMain.Server.MinRespawnRatio, Color.Cyan);

            DebugConsole.NewMessage(
                "Respawn Interval: " + ToolBox.SecondsToReadableTime(GameMain.Server.RespawnInterval) +
                ", Max Transport Time:" + ToolBox.SecondsToReadableTime(GameMain.Server.MaxTransportTime), Color.Cyan);

            DebugConsole.NewMessage(" ", Color.Cyan);

            DebugConsole.NewMessage(
                "Gamemode Selection: " + GameMain.Server.ModeSelectionMode.ToString() +
                ", Submarine Selection: " + GameMain.Server.SubSelectionMode.ToString(), Color.Cyan);

            DebugConsole.NewMessage(
                "Default Gamemode: " + GameMain.NetLobbyScreen.SelectedModeName +
                ", Default Mission Type: " + GameMain.NetLobbyScreen.MissionTypeName, Color.Cyan);

            DebugConsole.NewMessage("TraitorsEnabled: " + GameMain.Server.TraitorsEnabled.ToString(), Color.Cyan);

            DebugConsole.NewMessage(" ", Color.Cyan);

            if (!startcampaign)
            {
                DebugConsole.NewMessage("Starting with Level Seed: " + GameMain.NetLobbyScreen.LevelSeed, Color.Cyan);
                DebugConsole.NewMessage("On submarine: " + GameMain.NetLobbyScreen.SelectedSub.Name, Color.Cyan);
                DebugConsole.NewMessage("Using respawn shuttle: " + GameMain.NetLobbyScreen.SelectedShuttle.Name, Color.Cyan);
            }
            else
            {
                if (GameMain.NilMod.CampaignDefaultSaveName != "")
                {
                    MultiPlayerCampaign.StartCampaignSetup(true);
                }
                else
                {
                    DebugConsole.NewMessage("Nilmod default campaign savefile not specified. Please setup the campaign or specify a filename in nilmodsettings.xml", Color.Cyan);
                    MultiPlayerCampaign.StartCampaignSetup(false);
                }
                DebugConsole.NewMessage(" ", Color.Cyan);
            }
        }