Ejemplo n.º 1
0
 public SubTestMode(GameModePreset preset, object param)
     : base(preset, param)
 {
     foreach (JobPrefab jobPrefab in JobPrefab.Prefabs)
     {
         for (int i = 0; i < jobPrefab.InitialCount; i++)
         {
             var variant = Rand.Range(0, jobPrefab.Variants);
             CrewManager.AddCharacterInfo(new CharacterInfo(CharacterPrefab.HumanSpeciesName, jobPrefab: jobPrefab, variant: variant));
         }
     }
 }
Ejemplo n.º 2
0
        public override void End(string endMessage = "")
        {
            isRunning = false;

            GameMain.GameSession.EndRound("");

            CrewManager.EndRound();

            Submarine.Unload();

            GameMain.SubEditorScreen.Select();
        }
Ejemplo n.º 3
0
        public GameSession(SubmarineInfo submarineInfo, string savePath, GameModePreset gameModePreset, MissionPrefab missionPrefab)
            : this(submarineInfo, savePath)
        {
            CrewManager = new CrewManager(gameModePreset != null && gameModePreset.IsSinglePlayer);
            GameMode    = gameModePreset.Instantiate(missionPrefab);

#if CLIENT
            if (GameMode is SubTestMode)
            {
                EventManager = null;
            }
#endif
        }
Ejemplo n.º 4
0
        public bool TryHireCharacter(HireManager hireManager, CharacterInfo characterInfo)
        {
            if (Money < characterInfo.Salary)
            {
                return(false);
            }

            hireManager.availableCharacters.Remove(characterInfo);
            CrewManager.AddCharacterInfo(characterInfo);
            Money -= characterInfo.Salary;

            return(true);
        }
Ejemplo n.º 5
0
        public bool TryHireCharacter(Location location, CharacterInfo characterInfo)
        {
            if (Money < characterInfo.Salary)
            {
                return(false);
            }

            location.RemoveHireableCharacter(characterInfo);
            CrewManager.AddCharacterInfo(characterInfo);
            Money -= characterInfo.Salary;

            return(true);
        }
Ejemplo n.º 6
0
        public override void Save(XElement element)
        {
            element.Add(new XAttribute("campaignid", CampaignID));
            XElement modeElement = new XElement("MultiPlayerCampaign",
                                                new XAttribute("money", Money),
                                                new XAttribute("cheatsenabled", CheatsEnabled));

            CampaignMetadata?.Save(modeElement);
            Map.Save(modeElement);
            CargoManager?.SavePurchasedItems(modeElement);
            UpgradeManager?.SavePendingUpgrades(modeElement, UpgradeManager?.PendingUpgrades);

            if (petsElement != null)
            {
                modeElement.Add(petsElement);
            }

            // save bots
            CrewManager.SaveMultiplayer(modeElement);

            // save available submarines
            XElement availableSubsElement = new XElement("AvailableSubs");

            for (int i = 0; i < GameMain.NetLobbyScreen.CampaignSubmarines.Count; i++)
            {
                availableSubsElement.Add(new XElement("Sub", new XAttribute("name", GameMain.NetLobbyScreen.CampaignSubmarines[i].Name)));
            }
            modeElement.Add(availableSubsElement);

            element.Add(modeElement);

            //save character data to a separate file
            string    characterDataPath = GetCharacterDataSavePath();
            XDocument characterDataDoc  = new XDocument(new XElement("CharacterData"));

            foreach (CharacterCampaignData cd in characterData)
            {
                characterDataDoc.Root.Add(cd.Save());
            }
            try
            {
                characterDataDoc.SaveSafe(characterDataPath);
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Saving multiplayer campaign characters to \"" + characterDataPath + "\" failed!", e);
            }

            lastSaveID++;
            DebugConsole.Log("Campaign saved, save ID " + lastSaveID);
        }
Ejemplo n.º 7
0
        private GameSession(Submarine submarine, string savePath)
        {
            Submarine.MainSub    = submarine;
            this.submarine       = submarine;
            GameMain.GameSession = this;
            EventManager         = new EventManager(this);
            this.savePath        = savePath;
#if CLIENT
            CrewManager = new CrewManager();

            infoButton           = new GUIButton(new Rectangle(10, 10, 100, 20), "Info", "", null);
            infoButton.OnClicked = ToggleInfoFrame;
#endif
        }
Ejemplo n.º 8
0
        private bool EndRound(Submarine leavingSub)
        {
            isRunning = false;

            //var cinematic = new RoundEndCinematic(leavingSub, GameMain.GameScreen.Cam, 5.0f);

            SoundPlayer.OverrideMusicType     = CrewManager.GetCharacters().Any(c => !c.IsDead) ? "endround" : "crewdead";
            SoundPlayer.OverrideMusicDuration = 18.0f;

            //CoroutineManager.StartCoroutine(EndCinematic(cinematic), "EndCinematic");
            End("");

            return(true);
        }
 /// <summary>
 /// Instantiates a new single player campaign
 /// </summary>
 private SinglePlayerCampaign(string mapSeed) : base(GameModePreset.SinglePlayerCampaign)
 {
     CampaignMetadata = new CampaignMetadata(this);
     UpgradeManager   = new UpgradeManager(this);
     map = new Map(this, mapSeed);
     foreach (JobPrefab jobPrefab in JobPrefab.Prefabs)
     {
         for (int i = 0; i < jobPrefab.InitialCount; i++)
         {
             var variant = Rand.Range(0, jobPrefab.Variants);
             CrewManager.AddCharacterInfo(new CharacterInfo(CharacterPrefab.HumanSpeciesName, jobPrefab: jobPrefab, variant: variant));
         }
     }
     InitCampaignData();
     InitUI();
 }
Ejemplo n.º 10
0
        public override void AddToGUIUpdateList()
        {
            if (!isRunning)
            {
                return;
            }

            base.AddToGUIUpdateList();
            CrewManager.AddToGUIUpdateList();
            endRoundButton.AddToGUIUpdateList();

            if (ContextualTutorial.Initialized)
            {
                ContextualTutorial.AddToGUIUpdateList();
            }
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
        public override void Save(XElement element)
        {
            XElement modeElement = new XElement("SinglePlayerCampaign",
                                                new XAttribute("money", Money),
                                                new XAttribute("cheatsenabled", CheatsEnabled));

            CrewManager.Save(modeElement);
            Map.Save(modeElement);

            if (ContextualTutorial.Initialized)
            {
                ContextualTutorial.SavePartiallyComplete(modeElement);
            }

            element.Add(modeElement);
        }
Ejemplo n.º 13
0
        protected void CreateDialog(List <Character> speakers, string conversationTag, float minInterval)
        {
            if (dialogLastSpoken.TryGetValue(conversationTag, out double lastTime))
            {
                if (Timing.TotalTime - lastTime < minInterval)
                {
                    return;
                }
            }

            CrewManager.AddConversation(
                NPCConversation.CreateRandom(speakers, new List <string>()
            {
                conversationTag
            }));
            dialogLastSpoken[conversationTag] = Timing.TotalTime;
        }
        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.º 15
0
        public override void Save(XElement element)
        {
            XElement modeElement = new XElement("SinglePlayerCampaign",
                                                new XAttribute("money", Money),
                                                new XAttribute("purchasedlostshuttles", PurchasedLostShuttles),
                                                new XAttribute("purchasedhullrepairs", PurchasedHullRepairs),
                                                new XAttribute("purchaseditemrepairs", PurchasedItemRepairs),
                                                new XAttribute("cheatsenabled", CheatsEnabled));

            modeElement.Add(Settings.Save());

            //save and remove all items that are in someone's inventory so they don't get included in the sub file as well
            foreach (Character c in Character.CharacterList)
            {
                if (c.Info == null)
                {
                    continue;
                }
                if (c.IsDead)
                {
                    CrewManager.RemoveCharacterInfo(c.Info);
                }
                c.Info.LastControlled = c == lastControlledCharacter;
                c.Info.HealthData     = new XElement("health");
                c.CharacterHealth.Save(c.Info.HealthData);
                if (c.Inventory != null)
                {
                    c.Info.InventoryData = new XElement("inventory");
                    c.SaveInventory();
                    c.Inventory?.DeleteAllItems();
                }
                c.Info.SaveOrderData();
            }

            petsElement = new XElement("pets");
            PetBehavior.SavePets(petsElement);
            modeElement.Add(petsElement);

            CrewManager.Save(modeElement);
            CampaignMetadata.Save(modeElement);
            Map.Save(modeElement);
            CargoManager?.SavePurchasedItems(modeElement);
            UpgradeManager?.Save(modeElement);
            element.Add(modeElement);
        }
Ejemplo n.º 16
0
 public override void AddToGUIUpdateList()
 {
     if (ShowCampaignUI || ForceMapUI)
     {
         campaignUIContainer?.AddToGUIUpdateList();
         if (CampaignUI?.UpgradeStore?.HoveredItem != null)
         {
             if (CampaignUI.SelectedTab != InteractionType.Upgrade)
             {
                 return;
             }
             CampaignUI?.UpgradeStore?.ItemInfoFrame.AddToGUIUpdateList(order: 1);
         }
     }
     base.AddToGUIUpdateList();
     CrewManager.AddToGUIUpdateList();
     endRoundButton.AddToGUIUpdateList();
 }
Ejemplo n.º 17
0
        public SinglePlayerCampaign(GameModePreset preset, object param)
            : base(preset, param)
        {
            int buttonHeight = (int)(HUDLayoutSettings.ButtonAreaTop.Height * 0.7f);

            endRoundButton = new GUIButton(HUDLayoutSettings.ToRectTransform(new Rectangle(HUDLayoutSettings.ButtonAreaTop.Right - 200, HUDLayoutSettings.ButtonAreaTop.Center.Y - buttonHeight / 2, 200, buttonHeight), GUICanvas.Instance),
                                           TextManager.Get("EndRound"), textAlignment: Alignment.Center)
            {
                Font      = GUI.SmallFont,
                OnClicked = TryEndRound
            };

            foreach (JobPrefab jobPrefab in JobPrefab.List)
            {
                for (int i = 0; i < jobPrefab.InitialCount; i++)
                {
                    CrewManager.AddCharacterInfo(new CharacterInfo(Character.HumanConfigFile, "", Gender.None, jobPrefab));
                }
            }
        }
Ejemplo n.º 18
0
        public SinglePlayerCampaign(GameModePreset preset, object param)
            : base(preset, param)
        {
            int buttonHeight = (int)(HUDLayoutSettings.ButtonAreaTop.Height * 0.7f);

            endRoundButton = new GUIButton(HUDLayoutSettings.ToRectTransform(new Rectangle(HUDLayoutSettings.ButtonAreaTop.Right - 200, HUDLayoutSettings.ButtonAreaTop.Center.Y - buttonHeight / 2, 200, buttonHeight), GUICanvas.Instance),
                                           TextManager.Get("EndRound"), textAlignment: Alignment.Center)
            {
                Font      = GUI.SmallFont,
                OnClicked = (btn, userdata) => { TryEndRound(GetLeavingSub()); return(true); }
            };

            foreach (JobPrefab jobPrefab in JobPrefab.List.Values)
            {
                for (int i = 0; i < jobPrefab.InitialCount; i++)
                {
                    CrewManager.AddCharacterInfo(new CharacterInfo(Character.HumanSpeciesName, "", jobPrefab));
                }
            }
        }
Ejemplo n.º 19
0
        public GameSession(Submarine submarine, string saveFile, GameModePreset gameModePreset = null, string missionType = "")
        {
            Submarine.MainSub = submarine;

            GameMain.GameSession = this;

            CrewManager = new CrewManager();

            TaskManager = new TaskManager(this);

            this.saveFile = saveFile;

            infoButton           = new GUIButton(new Rectangle(10, 10, 100, 20), "Info", "", null);
            infoButton.OnClicked = ToggleInfoFrame;

            if (gameModePreset != null)
            {
                gameMode = gameModePreset.Instantiate(missionType);
            }
            this.submarine = submarine;
        }
Ejemplo n.º 20
0
        public GameSession(Submarine selectedSub, string saveFile, XDocument doc)
            : this(selectedSub, saveFile)
        {
            Submarine.MainSub = submarine;

            GameMain.GameSession = this;

            CrewManager = new CrewManager();

            selectedSub.Name = ToolBox.GetAttributeString(doc.Root, "submarine", selectedSub.Name);

            foreach (XElement subElement in doc.Root.Elements())
            {
                if (subElement.Name.ToString().ToLowerInvariant() != "gamemode")
                {
                    continue;
                }

                gameMode = new SinglePlayerMode(subElement);
            }
        }
Ejemplo n.º 21
0
        public GameSession(Submarine submarine, string savePath, GameModePreset gameModePreset = null, string missionType = "")
        {
            Submarine.MainSub = submarine;

            GameMain.GameSession = this;

            EventManager = new EventManager(this);

            this.savePath = savePath;

#if CLIENT
            CrewManager = new CrewManager();

            infoButton           = new GUIButton(new Rectangle(10, 10, 100, 20), "Info", "", null);
            infoButton.OnClicked = ToggleInfoFrame;
#endif

            if (gameModePreset != null)
            {
                GameMode = gameModePreset.Instantiate(missionType);
            }
            this.submarine = submarine;
        }
Ejemplo n.º 22
0
        private bool SelectInfoFrameTab(GUIButton button, object userData)
        {
            selectedTab = (InfoFrameTab)userData;

            CreateInfoFrame();

            switch (selectedTab)
            {
            case InfoFrameTab.Crew:
                CrewManager.CreateCrewListFrame(CrewManager.GetCharacters(), infoFrameContent);
                break;

            case InfoFrameTab.Mission:
                CreateMissionInfo(infoFrameContent);
                break;

            case InfoFrameTab.ManagePlayers:
                GameMain.Server.ManagePlayersFrame(infoFrameContent);
                break;
            }

            return(true);
        }
Ejemplo n.º 23
0
        private bool SelectInfoFrameTab(GUIButton button, object userData)
        {
            selectedTab = (InfoFrameTab)userData;

            CreateInfoFrame();

            switch (selectedTab)
            {
            case InfoFrameTab.Crew:
                CrewManager.CreateCrewFrame(CrewManager.characters, infoFrame.children[0] as GUIFrame);
                break;

            case InfoFrameTab.Mission:
                CreateMissionInfo(infoFrame.children[0] as GUIFrame);
                break;

            case InfoFrameTab.ManagePlayers:
                GameMain.Server.ManagePlayersFrame(infoFrame.children[0] as GUIFrame);
                break;
            }

            return(true);
        }
Ejemplo n.º 24
0
        private bool EndRound(GUIButton button, object obj)
        {
            isRunning = false;

            List <Submarine> leavingSubs = obj as List <Submarine>;

            if (leavingSubs == null)
            {
                leavingSubs = new List <Submarine>()
                {
                    GetLeavingSub()
                }
            }
            ;

            var cinematic = new TransitionCinematic(leavingSubs, GameMain.GameScreen.Cam, 5.0f);

            SoundPlayer.OverrideMusicType     = CrewManager.GetCharacters().Any(c => !c.IsDead) ? "endround" : "crewdead";
            SoundPlayer.OverrideMusicDuration = 18.0f;

            CoroutineManager.StartCoroutine(EndCinematic(cinematic), "EndCinematic");

            return(true);
        }
        public override void Start()
        {
            base.Start();

            CrewManager.InitSinglePlayerRound();
            foreach (Submarine submarine in Submarine.Loaded)
            {
                submarine.NeutralizeBallast();
            }

            if (SpawnOutpost)
            {
                GenerateOutpost(Submarine.MainSub);
            }

            if (TriggeredEvent != null)
            {
                scriptedEvent = new List <Event> {
                    TriggeredEvent.CreateInstance()
                };
                GameMain.GameSession.EventManager.PinnedEvent = scriptedEvent.Last();

                createEventButton = new GUIButton(new RectTransform(new Point(128, 64), GUI.Canvas, Anchor.TopCenter)
                {
                    ScreenSpaceOffset = new Point(0, 32)
                }, TextManager.Get("create"))
                {
                    OnClicked = delegate
                    {
                        scriptedEvent.Add(TriggeredEvent.CreateInstance());
                        GameMain.GameSession.EventManager.PinnedEvent = scriptedEvent.Last();
                        return(true);
                    }
                };
            }
        }
Ejemplo n.º 26
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);
            }

            GUI.DisableSavingIndicatorDelayed();
        }
Ejemplo n.º 27
0
 public virtual void Update(float deltaTime)
 {
     CrewManager?.Update(deltaTime);
 }
Ejemplo n.º 28
0
        private IEnumerable <object> DoLevelTransition()
        {
            SoundPlayer.OverrideMusicType     = CrewManager.GetCharacters().Any(c => !c.IsDead) ? "endround" : "crewdead";
            SoundPlayer.OverrideMusicDuration = 18.0f;

            Level prevLevel = Level.Loaded;

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

            crewDead = false;

            var continueButton = GameMain.GameSession.RoundSummary?.ContinueButton;

            if (continueButton != null)
            {
                continueButton.Visible = false;
            }

            Character.Controlled = null;

            yield return(new WaitForSeconds(0.1f));

            GameMain.Client.EndCinematic?.Stop();
            var endTransition = new CameraTransition(Submarine.MainSub, GameMain.GameScreen.Cam, null,
                                                     Alignment.Center,
                                                     fadeOut: false,
                                                     duration: EndTransitionDuration);

            GameMain.Client.EndCinematic = endTransition;

            Location portraitLocation = Map?.SelectedLocation ?? Map?.CurrentLocation ?? Level.Loaded?.StartLocation;

            if (portraitLocation != null)
            {
                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);

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

            //wait for the new level to be loaded
            DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, seconds: 30);

            while (Level.Loaded == prevLevel || Level.Loaded == null)
            {
                if (DateTime.Now > timeOut || Screen.Selected != GameMain.GameScreen)
                {
                    break;
                }
                yield return(CoroutineStatus.Running);
            }

            endTransition.Stop();
            overlayColor = Color.Transparent;

            if (DateTime.Now > timeOut)
            {
                GameMain.NetLobbyScreen.Select();
            }
            if (!(Screen.Selected is RoundSummaryScreen))
            {
                if (continueButton != null)
                {
                    continueButton.Visible = true;
                }
            }

            yield return(CoroutineStatus.Success);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Loads the campaign from an XML element. Creates the map if it hasn't been created yet, otherwise updates the state of the map.
        /// </summary>
        private void Load(XElement element)
        {
            Money = element.GetAttributeInt("money", 0);
            PurchasedLostShuttles = element.GetAttributeBool("purchasedlostshuttles", false);
            PurchasedHullRepairs  = element.GetAttributeBool("purchasedhullrepairs", false);
            PurchasedItemRepairs  = element.GetAttributeBool("purchaseditemrepairs", false);
            CheatsEnabled         = element.GetAttributeBool("cheatsenabled", false);
            if (CheatsEnabled)
            {
                DebugConsole.CheatsEnabled = true;
#if USE_STEAM
                if (!SteamAchievementManager.CheatsEnabled)
                {
                    SteamAchievementManager.CheatsEnabled = true;
#if CLIENT
                    new GUIMessageBox("Cheats enabled", "Cheat commands have been enabled on the server. You will not receive Steam Achievements until you restart the game.");
#else
                    DebugConsole.NewMessage("Cheat commands have been enabled.", Color.Red);
#endif
                }
#endif
            }

#if SERVER
            List <SubmarineInfo> availableSubs = new List <SubmarineInfo>();
            List <SubmarineInfo> sourceList    = new List <SubmarineInfo>();
            sourceList.AddRange(SubmarineInfo.SavedSubmarines);
#endif

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "campaignsettings":
                    Settings = new CampaignSettings(subElement);
                    break;

                case "map":
                    if (map == null)
                    {
                        //map not created yet, loading this campaign for the first time
                        map = Map.Load(this, subElement, Settings);
                    }
                    else
                    {
                        //map already created, update it
                        //if we're not downloading the initial save file (LastSaveID > 0),
                        //show notifications about location type changes
                        map.LoadState(subElement, LastSaveID > 0);
                    }
                    break;

                case "metadata":
                    CampaignMetadata = new CampaignMetadata(this, subElement);
                    break;

                case "upgrademanager":
                case "pendingupgrades":
                    UpgradeManager = new UpgradeManager(this, subElement, isSingleplayer: false);
                    break;

                case "bots" when GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer:
                    CrewManager.HasBots = subElement.GetAttributeBool("hasbots", false);
                    CrewManager.AddCharacterElements(subElement);
                    CrewManager.ActiveOrdersElement = subElement.GetChildElement("activeorders");
                    break;

                case "cargo":
                    CargoManager?.LoadPurchasedItems(subElement);
                    break;

                case "pets":
                    petsElement = subElement;
                    break;

#if SERVER
                case "availablesubs":
                    foreach (XElement availableSub in subElement.Elements())
                    {
                        string        subName     = availableSub.GetAttributeString("name", "");
                        SubmarineInfo matchingSub = sourceList.Find(s => s.Name == subName);
                        if (matchingSub != null)
                        {
                            availableSubs.Add(matchingSub);
                        }
                    }
                    break;
#endif
                }
            }

            CampaignMetadata ??= new CampaignMetadata(this);
            UpgradeManager ??= new UpgradeManager(this);

            InitCampaignData();
#if SERVER
            // Fallback if using a save with no available subs assigned, use vanilla submarines
            if (availableSubs.Count == 0)
            {
                GameMain.NetLobbyScreen.CampaignSubmarines.AddRange(sourceList.FindAll(s => s.IsCampaignCompatible && s.IsVanillaSubmarine()));
            }

            GameMain.NetLobbyScreen.CampaignSubmarines = availableSubs;

            characterData.Clear();
            string characterDataPath = GetCharacterDataSavePath();
            if (!File.Exists(characterDataPath))
            {
                DebugConsole.ThrowError($"Failed to load the character data for the campaign. Could not find the file \"{characterDataPath}\".");
            }
            else
            {
                var characterDataDoc = XMLExtensions.TryLoadXml(characterDataPath);
                if (characterDataDoc?.Root == null)
                {
                    return;
                }
                foreach (XElement subElement in characterDataDoc.Root.Elements())
                {
                    characterData.Add(new CharacterCampaignData(subElement));
                }
            }
#endif
        }
Ejemplo n.º 30
0
        public override void Start()
        {
            base.Start();

            CrewManager.InitSinglePlayerRound();
        }