Ejemplo n.º 1
0
        public override void Start()
        {
            base.Start();
            CargoManager.CreatePurchasedItems();
            UpgradeManager.ApplyUpgrades();
            UpgradeManager.SanityCheckUpgrades(Submarine.MainSub);

            if (!savedOnStart)
            {
                GUI.SetSavingIndicatorState(true);
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                savedOnStart = true;
            }

            crewDead = false;
            endTimer = 5.0f;
            CrewManager.InitSinglePlayerRound();
            if (petsElement != null)
            {
                PetBehavior.LoadPets(petsElement);
            }
            CrewManager.LoadActiveOrders();

            GUI.DisableSavingIndicatorDelayed();
        }
Ejemplo n.º 2
0
        public static void QuitToMainMenu(bool save)
        {
            if (save)
            {
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            }

            if (GameMain.Client != null)
            {
                GameMain.Client.Disconnect();
                GameMain.Client = null;
            }

            CoroutineManager.StopCoroutines("EndCinematic");

            if (GameMain.GameSession != null)
            {
                if (Tutorial.Initialized)
                {
                    ((TutorialMode)GameMain.GameSession.GameMode).Tutorial?.Stop();
                }

                if (GameSettings.SendUserStatistics)
                {
                    Mission mission = GameMain.GameSession.Mission;
                    GameAnalyticsManager.AddDesignEvent("QuitRound:" + (save ? "Save" : "NoSave"));
                    GameAnalyticsManager.AddDesignEvent("EndRound:" + (mission == null ? "NoMission" : (mission.Completed ? "MissionCompleted" : "MissionFailed")));
                }
                GameMain.GameSession = null;
            }
            GUIMessageBox.CloseAll();
            GameMain.MainMenuScreen.Select();
        }
        private IEnumerable <object> DoEndCampaignCameraTransition()
        {
            if (Character.Controlled != null)
            {
                Character.Controlled.AIController.Enabled = false;
                Character.Controlled = null;
            }
            GUI.DisableHUD = true;
            ISpatialEntity endObject  = Level.Loaded.LevelObjectManager.GetAllObjects().FirstOrDefault(obj => obj.Prefab.SpawnPos == LevelObjectPrefab.SpawnPosType.LevelEnd);
            var            transition = new CameraTransition(endObject ?? Submarine.MainSub, GameMain.GameScreen.Cam,
                                                             null, Alignment.Center,
                                                             fadeOut: true,
                                                             duration: 10,
                                                             startZoom: null, endZoom: 0.2f);

            while (transition.Running)
            {
                yield return(CoroutineStatus.Running);
            }
            GameMain.GameSession.SubmarineInfo = new SubmarineInfo(GameMain.GameSession.Submarine);
            SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            GameMain.CampaignEndScreen.Select();
            GUI.DisableHUD = false;

            yield return(CoroutineStatus.Success);
        }
Ejemplo n.º 4
0
        private static bool QuitClicked(GUIButton button, object obj)
        {
            bool save = button.UserData as string == "save";

            if (save)
            {
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            }

            if (GameMain.NetworkMember != null)
            {
                GameMain.NetworkMember.Disconnect();
                GameMain.NetworkMember = null;
            }

            CoroutineManager.StopCoroutines("EndCinematic");

            if (GameMain.GameSession != null)
            {
                Mission mission = GameMain.GameSession.Mission;
                GameAnalyticsManager.AddDesignEvent("QuitRound:" + (save ? "Save" : "NoSave"));
                GameAnalyticsManager.AddDesignEvent("EndRound:" + (mission == null ? "NoMission" : (mission.Completed ? "MissionCompleted" : "MissionFailed")));
                GameMain.GameSession = null;
            }

            GameMain.MainMenuScreen.Select();

            return(true);
        }
Ejemplo n.º 5
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.º 6
0
        public static void StartCampaignSetup()
        {
            DebugConsole.NewMessage("********* CAMPAIGN SETUP *********", Color.White);
            DebugConsole.ShowQuestionPrompt("Do you want to start a new campaign? Y/N", (string arg) =>
            {
                if (arg.ToLowerInvariant() == "y" || arg.ToLowerInvariant() == "yes")
                {
                    DebugConsole.ShowQuestionPrompt("Enter a save name for the campaign:", (string saveName) =>
                    {
                        if (string.IsNullOrWhiteSpace(saveName))
                        {
                            return;
                        }

                        string savePath      = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, saveName);
                        GameMain.GameSession = new GameSession(new Submarine(GameMain.NetLobbyScreen.SelectedSub.FilePath, ""), savePath,
                                                               GameModePreset.List.Find(g => g.Identifier == "multiplayercampaign"));
                        var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                        campaign.GenerateMap(GameMain.NetLobbyScreen.LevelSeed);
                        campaign.SetDelegates();

                        GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                        GameMain.GameSession.Map.SelectRandomLocation(true);
                        SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                        campaign.LastSaveID++;

                        DebugConsole.NewMessage("Campaign started!", Color.Cyan);
                    });
                }
                else
                {
                    string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer);
                    DebugConsole.NewMessage("Saved campaigns:", Color.White);
                    for (int i = 0; i < saveFiles.Length; i++)
                    {
                        DebugConsole.NewMessage("   " + i + ". " + saveFiles[i], Color.White);
                    }
                    DebugConsole.ShowQuestionPrompt("Select a save file to load (0 - " + (saveFiles.Length - 1) + "):", (string selectedSave) =>
                    {
                        int saveIndex = -1;
                        if (!int.TryParse(selectedSave, out saveIndex))
                        {
                            return;
                        }

                        SaveUtil.LoadGame(saveFiles[saveIndex]);
                        ((MultiPlayerCampaign)GameMain.GameSession.GameMode).LastSaveID++;
                        GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                        GameMain.GameSession.Map.SelectRandomLocation(true);

                        DebugConsole.NewMessage("Campaign loaded!", Color.Cyan);
                    });
                }
            });
        }
Ejemplo n.º 7
0
        public static void StartNewCampaign(string savePath, string subPath, string seed, CampaignSettings settings)
        {
            if (string.IsNullOrWhiteSpace(savePath))
            {
                return;
            }

            GameMain.GameSession = new GameSession(new SubmarineInfo(subPath), savePath, GameModePreset.MultiPlayerCampaign, settings, seed);
            GameMain.NetLobbyScreen.ToggleCampaignMode(true);
            SaveUtil.SaveGame(GameMain.GameSession.SavePath);

            DebugConsole.NewMessage("Campaign started!", Color.Cyan);
            DebugConsole.NewMessage("Current location: " + GameMain.GameSession.Map.CurrentLocation.Name, Color.Cyan);
            ((MultiPlayerCampaign)GameMain.GameSession.GameMode).LoadInitialLevel();
        }
Ejemplo n.º 8
0
        public override void Start()
        {
            CargoManager.CreateItems();

            if (!savedOnStart)
            {
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                savedOnStart = true;
            }

            endTimer = 5.0f;

            isRunning = true;

            CrewManager.StartRound();
        }
        public override void Start()
        {
            base.Start();
            CargoManager.CreateItems();

            if (!savedOnStart)
            {
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                savedOnStart = true;
            }

            crewDead  = false;
            endTimer  = 5.0f;
            isRunning = true;
            CrewManager.InitSinglePlayerRound();
        }
        public override void Start()
        {
            base.Start();
            CargoManager.CreatePurchasedItems();
            UpgradeManager.ApplyUpgrades();
            UpgradeManager.SanityCheckUpgrades(Submarine.MainSub);

            if (!savedOnStart)
            {
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                savedOnStart = true;
            }

            crewDead = false;
            endTimer = 5.0f;
            CrewManager.InitSinglePlayerRound();
        }
Ejemplo n.º 11
0
        private static bool QuitClicked(GUIButton button, object obj)
        {
            if (button.UserData as string == "save")
            {
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            }

            if (GameMain.NetworkMember != null)
            {
                GameMain.NetworkMember.Disconnect();
                GameMain.NetworkMember = null;
            }

            CoroutineManager.StopCoroutines("EndCinematic");

            GameMain.GameSession = null;

            GameMain.MainMenuScreen.Select();
            //Game1.MainMenuScreen.SelectTab(null, (int)MainMenuScreen.Tabs.Main);

            return(true);
        }
        public static void StartNewCampaign(string savePath, string subPath, string seed)
        {
            if (string.IsNullOrWhiteSpace(savePath))
            {
                return;
            }

            GameMain.GameSession = new GameSession(new Submarine(subPath, ""), savePath,
                                                   GameModePreset.List.Find(g => g.Identifier == "multiplayercampaign"));
            var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);

            campaign.GenerateMap(seed);
            campaign.SetDelegates();

            GameMain.NetLobbyScreen.ToggleCampaignMode(true);
            GameMain.GameSession.Map.SelectRandomLocation(true);
            SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            campaign.LastSaveID++;

            DebugConsole.NewMessage("Campaign started!", Color.Cyan);
            DebugConsole.NewMessage(GameMain.GameSession.Map.CurrentLocation.Name + " -> " + GameMain.GameSession.Map.SelectedLocation.Name, Color.Cyan);
        }
Ejemplo n.º 13
0
        protected override IEnumerable <object> DoLevelTransition(TransitionType transitionType, LevelData newLevel, Submarine leavingSub, bool mirror, List <TraitorMissionResult> traitorResults)
        {
            lastUpdateID++;

            switch (transitionType)
            {
            case TransitionType.None:
                throw new InvalidOperationException("Level transition failed (no transitions available).");

            case TransitionType.ReturnToPreviousLocation:
                //deselect destination on map
                map.SelectLocation(-1);
                break;

            case TransitionType.ProgressToNextLocation:
                Map.MoveToNextLocation();
                break;

            case TransitionType.End:
                EndCampaign();
                IsFirstRound = true;
                break;
            }

            Map.ProgressWorld(transitionType, (float)(Timing.TotalTime - GameMain.GameSession.RoundStartTime));

            bool success = GameMain.Server.ConnectedClients.Any(c => c.InGame && c.Character != null && !c.Character.IsDead);

            GameMain.GameSession.EndRound("", traitorResults, transitionType);

            //--------------------------------------

            if (success)
            {
                List <CharacterCampaignData> prevCharacterData = new List <CharacterCampaignData>(characterData);
                //client character has spawned this round -> remove old data (and replace with an up-to-date one if the client still has a character)
                characterData.RemoveAll(cd => cd.HasSpawned);

                //refresh the character data of clients who are still in the server
                foreach (Client c in GameMain.Server.ConnectedClients)
                {
                    if (c.Character?.Info == null)
                    {
                        continue;
                    }
                    if (c.Character.IsDead && c.Character.CauseOfDeath?.Type != CauseOfDeathType.Disconnected)
                    {
                        continue;
                    }
                    c.CharacterInfo = c.Character.Info;
                    characterData.RemoveAll(cd => cd.MatchesClient(c));
                    characterData.Add(new CharacterCampaignData(c));
                }

                //refresh the character data of clients who aren't in the server anymore
                foreach (CharacterCampaignData data in prevCharacterData)
                {
                    if (data.HasSpawned && !characterData.Any(cd => cd.IsDuplicate(data)))
                    {
                        var character = Character.CharacterList.Find(c => c.Info == data.CharacterInfo && !c.IsHusk);
                        if (character != null && (!character.IsDead || character.CauseOfDeath?.Type == CauseOfDeathType.Disconnected))
                        {
                            data.Refresh(character);
                            characterData.Add(data);
                        }
                    }
                }

                characterData.ForEach(cd => cd.HasSpawned = false);

                //remove all items that are in someone's inventory
                foreach (Character c in Character.CharacterList)
                {
                    if (c.Inventory == null)
                    {
                        continue;
                    }
                    if (Level.Loaded.Type == LevelData.LevelType.Outpost && c.Submarine != Level.Loaded.StartOutpost)
                    {
                        Map.CurrentLocation.RegisterTakenItems(c.Inventory.Items.Where(it => it != null && it.SpawnedInOutpost && it.OriginalModuleIndex > 0).Distinct());
                    }

                    if (c.Info != null && c.IsBot)
                    {
                        if (c.IsDead && c.CauseOfDeath?.Type != CauseOfDeathType.Disconnected)
                        {
                            CrewManager.RemoveCharacterInfo(c.Info);
                        }
                        c.Info.HealthData = new XElement("health");
                        c.CharacterHealth.Save(c.Info.HealthData);
                        c.Info.InventoryData = new XElement("inventory");
                        c.SaveInventory(c.Inventory, c.Info.InventoryData);
                    }

                    c.Inventory.DeleteAllItems();
                }

                yield return(CoroutineStatus.Running);

                if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
                {
                    Submarine.MainSub = leavingSub;
                    GameMain.GameSession.Submarine = leavingSub;
                    var subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
                    foreach (Submarine sub in subsToLeaveBehind)
                    {
                        MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
                        LinkedSubmarine.CreateDummy(leavingSub, sub);
                    }
                }
                NextLevel = newLevel;
                GameMain.GameSession.SubmarineInfo = new SubmarineInfo(GameMain.GameSession.Submarine);

                if (PendingSubmarineSwitch != null)
                {
                    SubmarineInfo previousSub = GameMain.GameSession.SubmarineInfo;
                    GameMain.GameSession.SubmarineInfo = PendingSubmarineSwitch;
                    PendingSubmarineSwitch             = null;

                    for (int i = 0; i < GameMain.GameSession.OwnedSubmarines.Count; i++)
                    {
                        if (GameMain.GameSession.OwnedSubmarines[i].Name == previousSub.Name)
                        {
                            GameMain.GameSession.OwnedSubmarines[i] = previousSub;
                            break;
                        }
                    }
                }

                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            }
            else
            {
                PendingSubmarineSwitch = null;
                GameMain.Server.EndGame(TransitionType.None);
                LoadCampaign(GameMain.GameSession.SavePath);
                LastSaveID++;
                LastUpdateID++;
                yield return(CoroutineStatus.Success);
            }

            //--------------------------------------

            GameMain.Server.EndGame(transitionType);

            ForceMapUI = false;

            NextLevel   = newLevel;
            MirrorLevel = mirror;

            //give clients time to play the end cinematic before starting the next round
            if (transitionType == TransitionType.End)
            {
                yield return(new WaitForSeconds(EndCinematicDuration));
            }
            else
            {
                yield return(new WaitForSeconds(EndTransitionDuration * 0.5f));
            }

            GameMain.Server.StartGame();

            yield return(CoroutineStatus.Success);
        }
Ejemplo n.º 14
0
        public override void End(string endMessage = "")
        {
            isRunning = false;

            bool success = CrewManager.GetCharacters().Any(c => !c.IsDead);

            if (success)
            {
                if (subsToLeaveBehind == null || leavingSub == null)
                {
                    DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one");

                    leavingSub = GetLeavingSub();

                    subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
                }
            }

            GameMain.GameSession.EndRound("");

            if (success)
            {
                if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
                {
                    Submarine.MainSub = leavingSub;

                    GameMain.GameSession.Submarine = leavingSub;

                    foreach (Submarine sub in subsToLeaveBehind)
                    {
                        MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
                        LinkedSubmarine.CreateDummy(leavingSub, sub);
                    }
                }

                if (atEndPosition)
                {
                    Map.MoveToNextLocation();
                }

                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            }


            if (!success)
            {
                var summaryScreen = GUIMessageBox.VisibleBox;

                if (summaryScreen != null)
                {
                    summaryScreen = summaryScreen.children[0];
                    summaryScreen.RemoveChild(summaryScreen.children.Find(c => c is GUIButton));

                    var okButton = new GUIButton(new Rectangle(-120, 0, 100, 30), TextManager.Get("LoadGameButton"), Alignment.BottomRight, "", summaryScreen);
                    okButton.OnClicked += (GUIButton button, object obj) =>
                    {
                        GameMain.GameSession.LoadPrevious();
                        GameMain.LobbyScreen.Select();
                        GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox);
                        return(true);
                    };

                    var quitButton = new GUIButton(new Rectangle(0, 0, 100, 30), TextManager.Get("QuitButton"), Alignment.BottomRight, "", summaryScreen);
                    quitButton.OnClicked += GameMain.LobbyScreen.QuitToMainMenu;
                    quitButton.OnClicked += (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox); return(true); };
                }
            }

            CrewManager.EndRound();
            for (int i = Character.CharacterList.Count - 1; i >= 0; i--)
            {
                Character.CharacterList[i].Remove();
            }

            Submarine.Unload();

            GameMain.LobbyScreen.Select();
        }
Ejemplo n.º 15
0
        public static GUIComponent StartCampaignSetup()
        {
            GUIFrame background = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f, null);

            GUIFrame setupBox = new GUIFrame(new Rectangle(0, 0, 500, 500), null, Alignment.Center, "", background);

            setupBox.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
            new GUITextBlock(new Rectangle(0, 0, 10, 10), "Campaign Setup", "", setupBox, GUI.LargeFont);
            setupBox.Padding = new Vector4(20.0f, 80.0f, 20.0f, 20.0f);

            var newCampaignContainer  = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox);
            var loadCampaignContainer = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox);

            var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer);

            var newCampaignButton = new GUIButton(new Rectangle(0, 0, 120, 20), "New campaign", "", setupBox);

            newCampaignButton.OnClicked += (btn, obj) =>
            {
                newCampaignContainer.Visible  = true;
                loadCampaignContainer.Visible = false;
                return(true);
            };

            var loadCampaignButton = new GUIButton(new Rectangle(130, 0, 120, 20), "Load campaign", "", setupBox);

            loadCampaignButton.OnClicked += (btn, obj) =>
            {
                newCampaignContainer.Visible  = false;
                loadCampaignContainer.Visible = true;
                return(true);
            };

            loadCampaignContainer.Visible = false;

            campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) =>
            {
                GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName, GameModePreset.list.Find(g => g.Name == "Campaign"));
                var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                campaign.GenerateMap(mapSeed);
                campaign.SetDelegates();

                background.Visible = false;

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                campaign.LastSaveID++;
            };

            campaignSetupUI.LoadGame = (string fileName) =>
            {
                SaveUtil.LoadGame(fileName);
                var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                campaign.LastSaveID++;

                background.Visible = false;

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
            };

            var cancelButton = new GUIButton(new Rectangle(0, 0, 120, 30), "Cancel", Alignment.BottomLeft, "", setupBox);

            cancelButton.OnClicked += (btn, obj) =>
            {
                background.Visible = false;
                int otherModeIndex = 0;
                for (otherModeIndex = 0; otherModeIndex < GameMain.NetLobbyScreen.ModeList.children.Count; otherModeIndex++)
                {
                    if (GameMain.NetLobbyScreen.ModeList.children[otherModeIndex].UserData is MultiPlayerCampaign)
                    {
                        continue;
                    }
                    break;
                }

                GameMain.NetLobbyScreen.SelectMode(otherModeIndex);
                return(true);
            };

            return(background);
        }
        protected override IEnumerable <object> DoLevelTransition(TransitionType transitionType, LevelData newLevel, Submarine leavingSub, bool mirror, List <TraitorMissionResult> traitorResults = null)
        {
            NextLevel = newLevel;
            bool success = CrewManager.GetCharacters().Any(c => !c.IsDead);

            SoundPlayer.OverrideMusicType     = success ? "endround" : "crewdead";
            SoundPlayer.OverrideMusicDuration = 18.0f;
            crewDead = false;

            GameMain.GameSession.EndRound("", traitorResults, transitionType);
            var          continueButton = GameMain.GameSession.RoundSummary?.ContinueButton;
            RoundSummary roundSummary   = null;

            if (GUIMessageBox.VisibleBox?.UserData is RoundSummary)
            {
                roundSummary = GUIMessageBox.VisibleBox?.UserData as RoundSummary;
            }
            if (continueButton != null)
            {
                continueButton.Visible = false;
            }

            lastControlledCharacter = Character.Controlled;
            Character.Controlled    = null;

            switch (transitionType)
            {
            case TransitionType.None:
                throw new InvalidOperationException("Level transition failed (no transitions available).");

            case TransitionType.ReturnToPreviousLocation:
                //deselect destination on map
                map.SelectLocation(-1);
                break;

            case TransitionType.ProgressToNextLocation:
                Map.MoveToNextLocation();
                break;
            }

            Map.ProgressWorld(transitionType, (float)(Timing.TotalTime - GameMain.GameSession.RoundStartTime));

            var endTransition = new CameraTransition(Submarine.MainSub, GameMain.GameScreen.Cam, null,
                                                     transitionType == TransitionType.LeaveLocation ? Alignment.BottomCenter : Alignment.Center,
                                                     fadeOut: false,
                                                     duration: EndTransitionDuration);

            GUI.ClearMessages();

            Location portraitLocation = Map.SelectedLocation ?? Map.CurrentLocation;

            overlaySprite = portraitLocation.Type.GetPortrait(portraitLocation.PortraitId);
            float fadeOutDuration = endTransition.Duration;
            float t = 0.0f;

            while (t < fadeOutDuration || endTransition.Running)
            {
                t           += CoroutineManager.UnscaledDeltaTime;
                overlayColor = Color.Lerp(Color.Transparent, Color.White, t / fadeOutDuration);
                yield return(CoroutineStatus.Running);
            }
            overlayColor = Color.White;
            yield return(CoroutineStatus.Running);

            //--------------------------------------

            bool save = false;

            if (success)
            {
                if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
                {
                    Submarine.MainSub = leavingSub;
                    GameMain.GameSession.Submarine = leavingSub;
                    var subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
                    foreach (Submarine sub in subsToLeaveBehind)
                    {
                        MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
                        LinkedSubmarine.CreateDummy(leavingSub, sub);
                    }
                }

                GameMain.GameSession.SubmarineInfo = new SubmarineInfo(GameMain.GameSession.Submarine);

                if (PendingSubmarineSwitch != null)
                {
                    SubmarineInfo previousSub = GameMain.GameSession.SubmarineInfo;
                    GameMain.GameSession.SubmarineInfo = PendingSubmarineSwitch;
                    PendingSubmarineSwitch             = null;

                    for (int i = 0; i < GameMain.GameSession.OwnedSubmarines.Count; i++)
                    {
                        if (GameMain.GameSession.OwnedSubmarines[i].Name == previousSub.Name)
                        {
                            GameMain.GameSession.OwnedSubmarines[i] = previousSub;
                            break;
                        }
                    }
                }

                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            }
            else
            {
                PendingSubmarineSwitch = null;
                EnableRoundSummaryGameOverState();
            }

            //--------------------------------------

            SelectSummaryScreen(roundSummary, newLevel, mirror, () =>
            {
                GameMain.GameScreen.Select();
                if (continueButton != null)
                {
                    continueButton.Visible = true;
                }

                GUI.DisableHUD = false;
                GUI.ClearCursorWait();
                overlayColor = Color.Transparent;
            });

            yield return(CoroutineStatus.Success);
        }
Ejemplo n.º 17
0
        public static void StartCampaignSetup(Boolean AutoSetup = false)
        {
            if (!AutoSetup)
            {
                DebugConsole.NewMessage("********* CAMPAIGN SETUP *********", Color.White);
                DebugConsole.ShowQuestionPrompt("Do you want to start a new campaign? Y/N", (string arg) =>
                {
                    if (arg.ToLowerInvariant() == "y" || arg.ToLowerInvariant() == "yes")
                    {
                        DebugConsole.ShowQuestionPrompt("Enter a save name for the campaign:", (string saveName) =>
                        {
                            if (string.IsNullOrWhiteSpace(saveName))
                            {
                                return;
                            }

                            string savePath      = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, saveName);
                            GameMain.GameSession = new GameSession(new Submarine(GameMain.NetLobbyScreen.SelectedSub.FilePath, ""), savePath, GameModePreset.list.Find(g => g.Name == "Campaign"));
                            var campaign         = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                            campaign.GenerateMap(GameMain.NetLobbyScreen.LevelSeed);
                            campaign.SetDelegates();

                            GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                            GameMain.GameSession.Map.SelectRandomLocation(true);
                            SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                            campaign.LastSaveID++;

                            campaign.AutoPurchaseNew();

                            DebugConsole.NewMessage("Campaign started!", Color.Cyan);
                        });
                    }
                    else
                    {
                        string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer);
                        DebugConsole.NewMessage("Saved campaigns:", Color.White);
                        for (int i = 0; i < saveFiles.Length; i++)
                        {
                            DebugConsole.NewMessage("   " + i + ". " + saveFiles[i], Color.White);
                        }
                        DebugConsole.ShowQuestionPrompt("Select a save file to load (0 - " + (saveFiles.Length - 1) + "):", (string selectedSave) =>
                        {
                            int saveIndex = -1;
                            if (!int.TryParse(selectedSave, out saveIndex))
                            {
                                return;
                            }

                            SaveUtil.LoadGame(saveFiles[saveIndex]);
                            var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                            campaign.LastSaveID++;
                            GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                            GameMain.GameSession.Map.SelectRandomLocation(true);

                            if (GameMain.NilMod.CampaignAutoPurchase)
                            {
                                //If money is exactly the same as what we start as, assume its actually a new game that was saved and reloaded!
                                if (campaign.Money == GameMain.NilMod.CampaignInitialMoney)
                                {
                                    campaign.AutoPurchaseNew();
                                }
                            }
                            //Money is not the default amount on loading, so its likely a game in progress
                            else
                            {
                                campaign.AutoPurchaseExisting();
                            }

                            DebugConsole.NewMessage("Campaign loaded!", Color.Cyan);
                        });
                    }
                });
            }
        }
Ejemplo n.º 18
0
        public static GUIComponent StartCampaignSetup()
        {
            GUIFrame background = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker");

            GUIFrame setupBox = new GUIFrame(new RectTransform(new Vector2(0.25f, 0.45f), background.RectTransform, Anchor.Center)
            {
                MinSize = new Point(500, 500)
            });
            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), setupBox.RectTransform, Anchor.Center))
            {
                Stretch = true
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), paddedFrame.RectTransform, Anchor.TopCenter),
                             TextManager.Get("CampaignSetup"), font: GUI.LargeFont);

            var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), paddedFrame.RectTransform)
            {
                RelativeOffset = new Vector2(0.0f, 0.1f)
            }, isHorizontal: true)
            {
                RelativeSpacing = 0.02f
            };

            var campaignContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.8f), paddedFrame.RectTransform, Anchor.BottomLeft), style: null);

            var newCampaignContainer  = new GUIFrame(new RectTransform(Vector2.One, campaignContainer.RectTransform, Anchor.BottomLeft), style: null);
            var loadCampaignContainer = new GUIFrame(new RectTransform(Vector2.One, campaignContainer.RectTransform, Anchor.BottomLeft), style: null);

            var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer);

            var newCampaignButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonContainer.RectTransform),
                                                  TextManager.Get("NewCampaign"))
            {
                OnClicked = (btn, obj) =>
                {
                    newCampaignContainer.Visible  = true;
                    loadCampaignContainer.Visible = false;
                    return(true);
                }
            };

            var loadCampaignButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.00f), buttonContainer.RectTransform),
                                                   TextManager.Get("LoadCampaign"))
            {
                OnClicked = (btn, obj) =>
                {
                    newCampaignContainer.Visible  = false;
                    loadCampaignContainer.Visible = true;
                    return(true);
                }
            };

            loadCampaignContainer.Visible = false;

            campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) =>
            {
                GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName,
                                                       GameModePreset.List.Find(g => g.Identifier == "multiplayercampaign"));
                var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                campaign.GenerateMap(mapSeed);
                campaign.SetDelegates();

                background.Visible = false;

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                campaign.LastSaveID++;
            };

            campaignSetupUI.LoadGame = (string fileName) =>
            {
                SaveUtil.LoadGame(fileName);
                if (!(GameMain.GameSession.GameMode is MultiPlayerCampaign))
                {
                    DebugConsole.ThrowError("Failed to load the campaign. The save file appears to be for a single player campaign.");
                    return;
                }

                var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                campaign.LastSaveID++;

                background.Visible = false;

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
            };

            var cancelButton = new GUIButton(new RectTransform(new Vector2(0.2f, 0.05f), paddedFrame.RectTransform, Anchor.BottomLeft), TextManager.Get("Cancel"))
            {
                OnClicked = (btn, obj) =>
                {
                    //find the first mode that's not multiplayer campaign and switch to that
                    background.Visible = false;
                    int otherModeIndex = 0;
                    for (otherModeIndex = 0; otherModeIndex < GameMain.NetLobbyScreen.ModeList.Content.CountChildren; otherModeIndex++)
                    {
                        if (GameMain.NetLobbyScreen.ModeList.Content.GetChild(otherModeIndex).UserData is MultiPlayerCampaign)
                        {
                            continue;
                        }
                        break;
                    }

                    GameMain.NetLobbyScreen.SelectMode(otherModeIndex);
                    return(true);
                }
            };

            return(background);
        }
Ejemplo n.º 19
0
        public override void End(string endMessage = "")
        {
            isRunning = false;

            bool success = CrewManager.GetCharacters().Any(c => !c.IsDead);

            crewDead = false;

            if (success)
            {
                if (subsToLeaveBehind == null || leavingSub == null)
                {
                    DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one");

                    leavingSub = GetLeavingSub();

                    subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
                }
            }

            GameMain.GameSession.EndRound("");

            if (success)
            {
                if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
                {
                    Submarine.MainSub = leavingSub;

                    GameMain.GameSession.Submarine = leavingSub;

                    foreach (Submarine sub in subsToLeaveBehind)
                    {
                        MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
                        LinkedSubmarine.CreateDummy(leavingSub, sub);
                    }
                }

                if (atEndPosition)
                {
                    Map.MoveToNextLocation();
                }
                else
                {
                    Map.SelectLocation(-1);
                }
                Map.ProgressWorld();

                //save and remove all items that are in someone's inventory
                foreach (Character c in Character.CharacterList)
                {
                    if (c.Info == null || c.Inventory == null)
                    {
                        continue;
                    }
                    var inventoryElement = new XElement("inventory");
                    c.SaveInventory(c.Inventory, inventoryElement);
                    c.Info.InventoryData = inventoryElement;
                    c.Inventory?.DeleteAllItems();
                }
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            }

            if (!success)
            {
                var summaryScreen = GUIMessageBox.VisibleBox;

                if (summaryScreen != null)
                {
                    summaryScreen = summaryScreen.Children.First();
                    var buttonArea = summaryScreen.Children.First().FindChild("buttonarea");
                    buttonArea.ClearChildren();


                    summaryScreen.RemoveChild(summaryScreen.Children.FirstOrDefault(c => c is GUIButton));

                    var okButton = new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), buttonArea.RectTransform),
                                                 TextManager.Get("LoadGameButton"))
                    {
                        OnClicked = (GUIButton button, object obj) =>
                        {
                            GameMain.GameSession.LoadPrevious();
                            GameMain.LobbyScreen.Select();
                            GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox);
                            return(true);
                        }
                    };

                    var quitButton = new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), buttonArea.RectTransform),
                                                   TextManager.Get("QuitButton"));
                    quitButton.OnClicked += GameMain.LobbyScreen.QuitToMainMenu;
                    quitButton.OnClicked += (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox); return(true); };
                    quitButton.OnClicked += (GUIButton button, object obj) => { if (ContextualTutorial.Initialized)
                                                                                {
                                                                                    ContextualTutorial.Stop();
                                                                                }
                                                                                return(true); };
                }
            }

            CrewManager.EndRound();
            for (int i = Character.CharacterList.Count - 1; i >= 0; i--)
            {
                Character.CharacterList[i].Remove();
            }

            Submarine.Unload();

            GameMain.LobbyScreen.Select();
        }
Ejemplo n.º 20
0
        public override void End(string endMessage = "")
        {
            isRunning = false;

            if (GameMain.Client != null)
            {
                GameMain.GameSession.EndRound("");
#if CLIENT
                GameMain.GameSession.CrewManager.EndRound();
#endif
                return;
            }

            lastUpdateID++;

            bool success =
                (GameMain.Server.ConnectedClients.Any(c => c.InGame && c.Character != null && !c.Character.IsDead) ||
                 (GameMain.Server.Character != null && !GameMain.Server.Character.IsDead)) && (!GameMain.NilMod.RoundEnded || Submarine.MainSub.AtEndPosition);

            /*if (success)
             * {
             *  if (subsToLeaveBehind == null || leavingSub == null)
             *  {
             *      DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one");
             *
             *      leavingSub = GetLeavingSub();
             *
             *      subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
             *  }
             * }*/

            GameMain.GameSession.EndRound("");

            //TODO: save player inventories between mp campaign rounds

            //remove all items that are in someone's inventory
            foreach (Character c in Character.CharacterList)
            {
                if (c.Inventory == null)
                {
                    continue;
                }
                //Character is inside of a submarine and still alive in some form
                if (c.Submarine != null)
                {
                    CheckSubInventory(c.Inventory.Items);
                }
                //Not on the submarine or dead, just remove everything.
                else
                {
                    foreach (Item item in c.Inventory.Items)
                    {
                        if (item != null)
                        {
                            item.Remove();
                        }
                    }
                }
            }

            //Code for removing items from the level which started in a players inventory, makes a bit of a mess though.
            for (int i = Item.ItemList.ToArray().Length - 1; i >= 0; i--)
            {
                if (Item.ItemList[i] == null)
                {
                    continue;
                }
                if (Item.ItemList[i].Submarine == null)
                {
                    continue;
                }
                if (Item.ItemList[i] != null)
                {
                    if (Item.ItemList[i].HasTag("Starter_Item") && Item.ItemList[i].ContainedItems != null)
                    {
                        CheckSubInventory(Item.ItemList[i].ContainedItems);
                        Item.ItemList[i].Remove();
                    }
                    else if (Item.ItemList[i].HasTag("Starter_Item"))
                    {
                        Item.ItemList[i].Remove();
                    }
                }
            }

#if CLIENT
            GameMain.GameSession.CrewManager.EndRound();
            if (GameSession.inGameInfo != null)
            {
                GameSession.inGameInfo.ResetGUIListData();
            }
#endif

            if (success)
            {
                GameMain.NilMod.CampaignStart = false;
                //Make the save last longer if its being successful.
                if (GameMain.NilMod.CampaignFails > 0)
                {
                    GameMain.NilMod.CampaignFails -= GameMain.NilMod.CampaignSuccessFailReduction;
                    if (GameMain.NilMod.CampaignFails < 0)
                    {
                        GameMain.NilMod.CampaignFails = 0;
                    }
                }
                bool atEndPosition = Submarine.MainSub.AtEndPosition;

                /*if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
                 * {
                 *  Submarine.MainSub = leavingSub;
                 *
                 *  GameMain.GameSession.Submarine = leavingSub;
                 *
                 *  foreach (Submarine sub in subsToLeaveBehind)
                 *  {
                 *      MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
                 *      LinkedSubmarine.CreateDummy(leavingSub, sub);
                 *  }
                 * }*/

                if (atEndPosition)
                {
                    Map.MoveToNextLocation();

                    //select a random location to make sure we've got some destination
                    //to head towards even if the host/clients don't select anything
                    map.SelectRandomLocation(true);
                }

                //Repair submarine walls
                foreach (Structure w in Structure.WallList)
                {
                    for (int i = 0; i < w.SectionCount; i++)
                    {
                        w.AddDamage(i, -100000.0f);
                    }
                }

                //Remove water, replenish oxygen, Extinguish fires
                foreach (Hull hull in Hull.hullList)
                {
                    hull.OxygenPercentage = 100.0f;
                    hull.WaterVolume      = 0f;

                    for (int i = hull.FireSources.Count - 1; i >= 0; i--)
                    {
                        hull.FireSources[i].Remove();
                    }
                }

                //Repair devices, electricals and shutdown reactors.
                foreach (Item it in Item.ItemList)
                {
                    if (it.GetComponent <Barotrauma.Items.Components.Powered>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.Reactor>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.Engine>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.Steering>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.Radar>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.MiniMap>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.Door>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.RelayComponent>() != null)
                    {
                        it.Condition = it.Prefab.Health;
                    }

                    if (it.GetComponent <Barotrauma.Items.Components.Reactor>() != null)
                    {
                        //Compatability for BTE.
                        if (it.Prefab.Name == "Diesel-Electric Generator")
                        {
                            continue;
                        }
                        Barotrauma.Items.Components.Reactor reactor = it.GetComponent <Barotrauma.Items.Components.Reactor>();
                        reactor.AutoTemp    = false;
                        reactor.FissionRate = 0;
                        reactor.CoolingRate = 100;
                        reactor.Temperature = 0;
                    }

                    if (it.GetComponent <Barotrauma.Items.Components.PowerContainer>() != null)
                    {
                        var powerContainer = it.GetComponent <Barotrauma.Items.Components.PowerContainer>();
                        powerContainer.Charge = Math.Min(powerContainer.Capacity * 0.9f, powerContainer.Charge);
                    }
                }

                Money += GameMain.NilMod.CampaignSurvivalReward;

                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                lastSaveID += 1;
            }
            else
            {
                GameMain.NilMod.CampaignFails += 1;

                if (GameMain.NilMod.CampaignDefaultSaveName != "" && GameMain.Client == null)
                {
                    if (GameMain.NilMod.CampaignFails > GameMain.NilMod.CampaignMaxFails)
                    {
                        GameMain.NilMod.CampaignFails = 0;
                        CoroutineManager.StartCoroutine(ResetCampaignMode(), "ResetCampaign");

                        foreach (Client c in GameMain.Server.ConnectedClients)
                        {
                            NilMod.NilModEventChatter.SendServerMessage("Campaign Info: No more chances remain, the campaign is lost!", c);
                            NilMod.NilModEventChatter.SendServerMessage("Starting a new campaign...", c);
                        }
                        GameMain.NetworkMember.AddChatMessage("Campaign Info: No more chances remain, the campaign is lost!", ChatMessageType.Server, "", null);
                        GameMain.NetworkMember.AddChatMessage("Starting a new campaign...", ChatMessageType.Server, "", null);
                    }
                    else
                    {
                        if ((GameMain.NilMod.CampaignMaxFails - GameMain.NilMod.CampaignFails) < 3)
                        {
                            foreach (Client c in GameMain.Server.ConnectedClients)
                            {
                                NilMod.NilModEventChatter.SendServerMessage("Campaign Info: There are " + (GameMain.NilMod.CampaignMaxFails - GameMain.NilMod.CampaignFails) + " Attempts remaining on this save unless you start pulling off some success!", c);
                            }
                            GameMain.NetworkMember.AddChatMessage("Campaign: There are " + (GameMain.NilMod.CampaignMaxFails - GameMain.NilMod.CampaignFails) + " Attempts remaining on this save unless you start pulling off some success!", ChatMessageType.Server, "", null);
                        }
                        //Reload the game and such
                        SaveUtil.LoadGame(GameMain.GameSession.SavePath);
#if CLIENT
                        GameMain.NetLobbyScreen.modeList.Select(2, true);
#endif
                        GameMain.GameSession.Map.SelectRandomLocation(true);
                        LastSaveID += 1;
                    }
                }
            }

            //If its campaign start, add the starter items to the buy menu
            if (GameMain.NilMod.CampaignAutoPurchase)
            {
                var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);

                if (GameMain.NilMod.CampaignStart)
                {
                    AutoPurchaseNew();
                }
                //If its a round that wasn't the first, buy the mid-round items!
                else
                {
                    AutoPurchaseExisting();
                }
            }
        }
Ejemplo n.º 21
0
        public static void StartCampaignSetup()
        {
            var setupBox = new GUIMessageBox("Campaign Setup", "", new string [0], 500, 500);

            setupBox.InnerFrame.Padding = new Vector4(20.0f, 80.0f, 20.0f, 20.0f);

            var newCampaignContainer  = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox.InnerFrame);
            var loadCampaignContainer = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox.InnerFrame);

            var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer);

            var newCampaignButton = new GUIButton(new Rectangle(0, 0, 120, 20), "New campaign", "", setupBox.InnerFrame);

            newCampaignButton.OnClicked += (btn, obj) =>
            {
                newCampaignContainer.Visible  = true;
                loadCampaignContainer.Visible = false;
                return(true);
            };

            var loadCampaignButton = new GUIButton(new Rectangle(130, 0, 120, 20), "Load campaign", "", setupBox.InnerFrame);

            loadCampaignButton.OnClicked += (btn, obj) =>
            {
                newCampaignContainer.Visible  = false;
                loadCampaignContainer.Visible = true;
                return(true);
            };

            loadCampaignContainer.Visible = false;

            campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) =>
            {
                GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName, GameModePreset.list.Find(g => g.Name == "Campaign"));
                var campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode);
                campaign.GenerateMap(mapSeed);
                campaign.SetDelegates();

                setupBox.Close();

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                campaign.LastSaveID++;
            };

            campaignSetupUI.LoadGame = (string fileName) =>
            {
                SaveUtil.LoadGame(fileName);
                var campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode);
                campaign.LastSaveID++;

                setupBox.Close();

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
            };

            var cancelButton = new GUIButton(new Rectangle(0, 0, 120, 30), "Cancel", Alignment.BottomLeft, "", setupBox.InnerFrame);

            cancelButton.OnClicked += (btn, obj) =>
            {
                setupBox.Close();
                int otherModeIndex = 0;
                for (otherModeIndex = 0; otherModeIndex < GameMain.NetLobbyScreen.ModeList.children.Count; otherModeIndex++)
                {
                    if (GameMain.NetLobbyScreen.ModeList.children[otherModeIndex].UserData is MultiplayerCampaign)
                    {
                        continue;
                    }
                    break;
                }

                GameMain.NetLobbyScreen.SelectMode(otherModeIndex);
                return(true);
            };
        }
Ejemplo n.º 22
0
        protected override IEnumerable <object> DoLevelTransition(TransitionType transitionType, LevelData newLevel, Submarine leavingSub, bool mirror, List <TraitorMissionResult> traitorResults)
        {
            lastUpdateID++;

            switch (transitionType)
            {
            case TransitionType.None:
                throw new InvalidOperationException("Level transition failed (no transitions available).");

            case TransitionType.ReturnToPreviousLocation:
                //deselect destination on map
                map.SelectLocation(-1);
                break;

            case TransitionType.ProgressToNextLocation:
                Map.MoveToNextLocation();
                break;

            case TransitionType.End:
                EndCampaign();
                IsFirstRound = true;
                break;
            }

            Map.ProgressWorld(transitionType, (float)(Timing.TotalTime - GameMain.GameSession.RoundStartTime));

            bool success = GameMain.Server.ConnectedClients.Any(c => c.InGame && c.Character != null && !c.Character.IsDead);

            GameMain.GameSession.EndRound("", traitorResults, transitionType);

            //--------------------------------------

            if (success)
            {
                SaveInventories();

                yield return(CoroutineStatus.Running);

                if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
                {
                    Submarine.MainSub = leavingSub;
                    GameMain.GameSession.Submarine     = leavingSub;
                    GameMain.GameSession.SubmarineInfo = leavingSub.Info;
                    leavingSub.Info.FilePath           = System.IO.Path.Combine(SaveUtil.TempPath, leavingSub.Info.Name + ".sub");
                    var subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
                    GameMain.GameSession.OwnedSubmarines.Add(leavingSub.Info);
                    foreach (Submarine sub in subsToLeaveBehind)
                    {
                        GameMain.GameSession.OwnedSubmarines.RemoveAll(s => s != leavingSub.Info && s.Name == sub.Info.Name);
                        MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
                        LinkedSubmarine.CreateDummy(leavingSub, sub);
                    }
                }
                NextLevel = newLevel;
                GameMain.GameSession.SubmarineInfo = new SubmarineInfo(GameMain.GameSession.Submarine);

                if (PendingSubmarineSwitch != null)
                {
                    SubmarineInfo previousSub = GameMain.GameSession.SubmarineInfo;
                    GameMain.GameSession.SubmarineInfo = PendingSubmarineSwitch;
                    PendingSubmarineSwitch             = null;

                    for (int i = 0; i < GameMain.GameSession.OwnedSubmarines.Count; i++)
                    {
                        if (GameMain.GameSession.OwnedSubmarines[i].Name == previousSub.Name)
                        {
                            GameMain.GameSession.OwnedSubmarines[i] = previousSub;
                            break;
                        }
                    }
                }

                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            }
            else
            {
                PendingSubmarineSwitch = null;
                GameMain.Server.EndGame(TransitionType.None);
                LoadCampaign(GameMain.GameSession.SavePath);
                LastSaveID++;
                LastUpdateID++;
                yield return(CoroutineStatus.Success);
            }

            CrewManager?.ClearCurrentOrders();

            //--------------------------------------

            GameMain.Server.EndGame(transitionType);

            ForceMapUI = false;

            NextLevel   = newLevel;
            MirrorLevel = mirror;

            //give clients time to play the end cinematic before starting the next round
            if (transitionType == TransitionType.End)
            {
                yield return(new WaitForSeconds(EndCinematicDuration));
            }
            else
            {
                yield return(new WaitForSeconds(EndTransitionDuration * 0.5f));
            }

            GameMain.Server.StartGame();

            yield return(CoroutineStatus.Success);
        }
Ejemplo n.º 23
0
        public override void End(string endMessage = "")
        {
            isRunning = false;

            if (GameMain.Client != null)
            {
                GameMain.GameSession.EndRound("");
#if CLIENT
                GameMain.GameSession.CrewManager.EndRound();
#endif
                return;
            }

            lastUpdateID++;

            bool success =
                GameMain.Server.ConnectedClients.Any(c => c.InGame && c.Character != null && !c.Character.IsDead) ||
                (GameMain.Server.Character != null && !GameMain.Server.Character.IsDead);

            /*if (success)
             * {
             *  if (subsToLeaveBehind == null || leavingSub == null)
             *  {
             *      DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one");
             *
             *      leavingSub = GetLeavingSub();
             *
             *      subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
             *  }
             * }*/

            GameMain.GameSession.EndRound("");

            //TODO: save player inventories between mp campaign rounds

            //remove all items that are in someone's inventory
            foreach (Character c in Character.CharacterList)
            {
                if (c.Inventory == null)
                {
                    continue;
                }
                foreach (Item item in c.Inventory.Items)
                {
                    if (item != null)
                    {
                        item.Remove();
                    }
                }
            }

#if CLIENT
            GameMain.GameSession.CrewManager.EndRound();
#endif

            if (success)
            {
                bool atEndPosition = Submarine.MainSub.AtEndPosition;

                /*if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
                 * {
                 *  Submarine.MainSub = leavingSub;
                 *
                 *  GameMain.GameSession.Submarine = leavingSub;
                 *
                 *  foreach (Submarine sub in subsToLeaveBehind)
                 *  {
                 *      MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
                 *      LinkedSubmarine.CreateDummy(leavingSub, sub);
                 *  }
                 * }*/

                if (atEndPosition)
                {
                    Map.MoveToNextLocation();

                    //select a random location to make sure we've got some destination
                    //to head towards even if the host/clients don't select anything
                    map.SelectRandomLocation(true);
                }

                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            }
        }
Ejemplo n.º 24
0
        public override void End(string endMessage = "")
        {
            isRunning = false;

#if CLIENT
            if (GameMain.Client != null)
            {
                GameMain.GameSession.EndRound("");
                GameMain.GameSession.CrewManager.EndRound();
                return;
            }
#endif

#if SERVER
            lastUpdateID++;

            bool success =
                GameMain.Server.ConnectedClients.Any(c => c.InGame && c.Character != null && !c.Character.IsDead);

            success = success || (GameMain.Server.Character != null && !GameMain.Server.Character.IsDead);

            /*if (success)
             * {
             *  if (subsToLeaveBehind == null || leavingSub == null)
             *  {
             *      DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one");
             *
             *      leavingSub = GetLeavingSub();
             *
             *      subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
             *  }
             * }*/

            GameMain.GameSession.EndRound("");

            foreach (Client c in GameMain.Server.ConnectedClients)
            {
                if (c.HasSpawned)
                {
                    //client has spawned this round -> remove old data (and replace with new one if the client still has an alive character)
                    characterData.RemoveAll(cd => cd.MatchesClient(c));
                }

                if (c.Character?.Info != null && !c.Character.IsDead)
                {
                    characterData.Add(new CharacterCampaignData(c));
                }
            }

            //remove all items that are in someone's inventory
            foreach (Character c in Character.CharacterList)
            {
                c.Inventory?.DeleteAllItems();
            }

            if (success)
            {
                bool atEndPosition = Submarine.MainSub.AtEndPosition;

                /*if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
                 * {
                 *  Submarine.MainSub = leavingSub;
                 *
                 *  GameMain.GameSession.Submarine = leavingSub;
                 *
                 *  foreach (Submarine sub in subsToLeaveBehind)
                 *  {
                 *      MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
                 *      LinkedSubmarine.CreateDummy(leavingSub, sub);
                 *  }
                 * }*/

                if (atEndPosition)
                {
                    map.MoveToNextLocation();

                    //select a random location to make sure we've got some destination
                    //to head towards even if the host/clients don't select anything
                    map.SelectRandomLocation(true);
                }
                map.ProgressWorld();

                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
            }
#endif
        }
Ejemplo n.º 25
0
        public static GUIComponent StartCampaignSetup(Boolean AutoSetup = false)
        {
            if (!AutoSetup)
            {
                GUIFrame background = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f, null);

                GUIFrame setupBox = new GUIFrame(new Rectangle(0, 0, 500, 500), null, Alignment.Center, "", background);
                setupBox.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
                new GUITextBlock(new Rectangle(0, 0, 10, 10), "Campaign Setup", "", setupBox, GUI.LargeFont);
                setupBox.Padding = new Vector4(20.0f, 80.0f, 20.0f, 20.0f);

                var newCampaignContainer  = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox);
                var loadCampaignContainer = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox);

                var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer);

                var newCampaignButton = new GUIButton(new Rectangle(0, 0, 120, 20), "New campaign", "", setupBox);
                newCampaignButton.OnClicked += (btn, obj) =>
                {
                    newCampaignContainer.Visible  = true;
                    loadCampaignContainer.Visible = false;
                    return(true);
                };

                var loadCampaignButton = new GUIButton(new Rectangle(130, 0, 120, 20), "Load campaign", "", setupBox);
                loadCampaignButton.OnClicked += (btn, obj) =>
                {
                    newCampaignContainer.Visible  = false;
                    loadCampaignContainer.Visible = true;
                    return(true);
                };

                loadCampaignContainer.Visible = false;

                campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) =>
                {
                    GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName, GameModePreset.list.Find(g => g.Name == "Campaign"));
                    var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                    campaign.GenerateMap(mapSeed);
                    campaign.SetDelegates();

                    background.Visible = false;

                    GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                    campaign.Map.SelectRandomLocation(true);
                    SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                    campaign.LastSaveID++;

                    campaign.AutoPurchaseNew();
                };

                campaignSetupUI.LoadGame = (string fileName) =>
                {
                    SaveUtil.LoadGame(fileName);
                    var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                    campaign.LastSaveID++;

                    background.Visible = false;

                    GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                    campaign.Map.SelectRandomLocation(true);

                    if (GameMain.NilMod.CampaignAutoPurchase)
                    {
                        //If money is exactly the same as what we start as, assume its actually a new game that was saved and reloaded!
                        if (campaign.Money == GameMain.NilMod.CampaignInitialMoney)
                        {
                            campaign.AutoPurchaseNew();
                        }
                    }
                    //Money is not the default amount on loading, so its likely a game in progress
                    else
                    {
                        campaign.AutoPurchaseExisting();
                    }
                };

                var cancelButton = new GUIButton(new Rectangle(0, 0, 120, 30), "Cancel", Alignment.BottomLeft, "", setupBox);
                cancelButton.OnClicked += (btn, obj) =>
                {
                    background.Visible = false;
                    int otherModeIndex = 0;
                    for (otherModeIndex = 0; otherModeIndex < GameMain.NetLobbyScreen.ModeList.children.Count; otherModeIndex++)
                    {
                        if (GameMain.NetLobbyScreen.ModeList.children[otherModeIndex].UserData is MultiPlayerCampaign)
                        {
                            continue;
                        }
                        break;
                    }

                    GameMain.NetLobbyScreen.SelectMode(otherModeIndex);
                    return(true);
                };

                return(background);
            }
            else
            {
                string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer);
                string   Savepath  = "Data" + System.IO.Path.DirectorySeparatorChar + "Saves" + System.IO.Path.DirectorySeparatorChar + "Multiplayer" + System.IO.Path.DirectorySeparatorChar + GameMain.NilMod.CampaignDefaultSaveName + ".save";
                if (saveFiles.Contains(Savepath))
                {
                    SaveUtil.LoadGame(Savepath);
                    var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                    campaign.LastSaveID++;
                    GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                    GameMain.GameSession.Map.SelectRandomLocation(true);

                    //If money is exactly the same as what we start as, assume its actually a new game that was saved and reloaded!
                    if (campaign.Money == GameMain.NilMod.CampaignInitialMoney)
                    {
                        campaign.AutoPurchaseNew();
                    }
                    //Money is not the default amount on loading, so its likely a game in progress
                    else
                    {
                        campaign.AutoPurchaseExisting();
                    }

                    DebugConsole.NewMessage(@"Campaign save """ + GameMain.NilMod.CampaignDefaultSaveName + @""" automatically loaded!", Color.Cyan);
                    DebugConsole.NewMessage("On Submarine: " + GameMain.GameSession.Submarine.Name, Color.Cyan);
                    DebugConsole.NewMessage("Using Level Seed: " + GameMain.NetLobbyScreen.LevelSeed, Color.Cyan);
                    DebugConsole.NewMessage(GameMain.NetLobbyScreen.SelectedMode.Name, Color.Cyan);
                }
                else
                {
                    string    savePath    = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, GameMain.NilMod.CampaignDefaultSaveName);
                    Submarine CampaignSub = null;

                    var subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus)).ToList <Submarine>();

                    if (!GameMain.NilMod.CampaignUseRandomSubmarine)
                    {
                        if (GameMain.NilMod.DefaultSubmarine != "" && subsToShow.Count >= 0)
                        {
                            CampaignSub = subsToShow.Find(s => s.Name.ToLowerInvariant() == GameMain.NilMod.DefaultSubmarine.ToLowerInvariant());

                            if (CampaignSub == null)
                            {
                                subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus) && !s.HasTag(SubmarineTag.Shuttle)).ToList <Submarine>();
                                if (subsToShow.Count > 0)
                                {
                                    CampaignSub = subsToShow[Rand.Range((int)0, subsToShow.Count())];
                                }
                                else
                                {
                                    subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus)).ToList <Submarine>();
                                    if (subsToShow.Count > 0)
                                    {
                                        DebugConsole.NewMessage("Error - No default submarine found in nilmodsettings, a random submarine has been chosen", Color.Red);
                                        CampaignSub = subsToShow[Rand.Range((int)0, subsToShow.Count())];
                                    }
                                    else
                                    {
                                        DebugConsole.NewMessage("Error - No saved submarines to initialize campaign with.", Color.Red);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus) && !s.HasTag(SubmarineTag.Shuttle)).ToList <Submarine>();

                        if (subsToShow.Count >= 0)
                        {
                            CampaignSub = subsToShow[Rand.Range((int)0, subsToShow.Count())];
                        }
                        else
                        {
                            subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus)).ToList <Submarine>();
                            if (subsToShow.Count >= 0)
                            {
                                CampaignSub = subsToShow[Rand.Range((int)0, subsToShow.Count())];
                            }
                        }
                    }

                    if (CampaignSub != null)
                    {
                        GameMain.NilMod.CampaignFails = 0;
                        GameMain.GameSession          = new GameSession(new Submarine(CampaignSub.FilePath, ""), savePath, GameModePreset.list.Find(g => g.Name == "Campaign"));
                        var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                        campaign.GenerateMap(GameMain.NetLobbyScreen.LevelSeed);
                        campaign.SetDelegates();

                        GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                        GameMain.GameSession.Map.SelectRandomLocation(true);

                        GameMain.NilMod.CampaignStart = true;

                        SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                        campaign.LastSaveID++;

                        campaign.AutoPurchaseNew();



                        DebugConsole.NewMessage(@"New campaign """ + GameMain.NilMod.CampaignDefaultSaveName + @""" automatically started!", Color.Cyan);
                        DebugConsole.NewMessage("On Submarine: " + CampaignSub.Name, Color.Cyan);
                        DebugConsole.NewMessage("Using Level Seed: " + GameMain.NetLobbyScreen.LevelSeed, Color.Cyan);
                    }
                    else
                    {
                        GameMain.NetLobbyScreen.ToggleCampaignMode(false);
                        GameMain.NetLobbyScreen.SelectedModeIndex = 0;
                        GameMain.NetLobbyScreen.SelectMode(0);
                        //Cancel it here
                    }
                }
                return(null);
            }
        }