public SinglePlayerMode(GameModePreset preset, object param)
            : base(preset, param)
        {
            CargoManager = new CargoManager();

            endShiftButton           = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 220, 20, 200, 25), "End shift", null, Alignment.TopLeft, Alignment.Center, "");
            endShiftButton.Font      = GUI.SmallFont;
            endShiftButton.OnClicked = TryEndShift;

            for (int i = 0; i < 3; i++)
            {
                JobPrefab jobPrefab = null;
                switch (i)
                {
                case 0:
                    jobPrefab = JobPrefab.List.Find(jp => jp.Name == "Captain");
                    break;

                case 1:
                    jobPrefab = JobPrefab.List.Find(jp => jp.Name == "Engineer");
                    break;

                case 2:
                    jobPrefab = JobPrefab.List.Find(jp => jp.Name == "Mechanic");
                    break;
                }

                CharacterInfo characterInfo =
                    new CharacterInfo(Character.HumanConfigFile, "", Gender.None, jobPrefab);
                CrewManager.characterInfos.Add(characterInfo);
            }
        }
        public static Job Random(Rand.RandSync randSync = Rand.RandSync.Unsynced)
        {
            var prefab  = JobPrefab.Random(randSync);
            var variant = Rand.Range(0, prefab.Variants, randSync);

            return(new Job(prefab, variant));
        }
Exemple #3
0
        public void Init()
        {
            MissionPrefab.Init();
            MapEntityPrefab.Init();
            MapGenerationParams.Init();
            LevelGenerationParams.LoadPresets();
            ScriptedEventSet.LoadPrefabs();

            AfflictionPrefab.LoadAll(GetFilesOfType(ContentType.Afflictions));
            StructurePrefab.LoadAll(GetFilesOfType(ContentType.Structure));
            ItemPrefab.LoadAll(GetFilesOfType(ContentType.Item));
            JobPrefab.LoadAll(GetFilesOfType(ContentType.Jobs));
            ItemAssemblyPrefab.LoadAll();
            NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations));
            ItemAssemblyPrefab.LoadAll();
            LevelObjectPrefab.LoadAll();

            GameModePreset.Init();
            LocationType.Init();

            Submarine.RefreshSavedSubs();

            Screen.SelectNull();

            NetLobbyScreen = new NetLobbyScreen();

            CheckContentPackage();
        }
Exemple #4
0
        public void Init()
        {
            CharacterPrefab.LoadAll();
            MissionPrefab.Init();
            TraitorMissionPrefab.Init();
            MapEntityPrefab.Init();
            MapGenerationParams.Init();
            LevelGenerationParams.LoadPresets();
            ScriptedEventSet.LoadPrefabs();
            Order.Init();
            EventManagerSettings.Init();

            AfflictionPrefab.LoadAll(GetFilesOfType(ContentType.Afflictions));
            SkillSettings.Load(GetFilesOfType(ContentType.SkillSettings));
            StructurePrefab.LoadAll(GetFilesOfType(ContentType.Structure));
            ItemPrefab.LoadAll(GetFilesOfType(ContentType.Item));
            JobPrefab.LoadAll(GetFilesOfType(ContentType.Jobs));
            CorpsePrefab.LoadAll(GetFilesOfType(ContentType.Corpses));
            NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations));
            ItemAssemblyPrefab.LoadAll();
            LevelObjectPrefab.LoadAll();

            GameModePreset.Init();
            LocationType.Init();

            SubmarineInfo.RefreshSavedSubs();

            Screen.SelectNull();

            NetLobbyScreen = new NetLobbyScreen();

            CheckContentPackage();
        }
        private void SetSubmarineVotingText(Client starter, SubmarineInfo info, VoteType type)
        {
            string    name                = starter.Name;
            JobPrefab prefab              = starter?.Character?.Info?.Job?.Prefab;
            Color     nameColor           = prefab != null ? prefab.UIColor : Color.White;
            string    characterRichString = $"‖color:{nameColor.R},{nameColor.G},{nameColor.B}‖{name}‖color:end‖";
            string    submarineRichString = $"‖color:{submarineColor.R},{submarineColor.G},{submarineColor.B}‖{info.DisplayName}‖color:end‖";

            switch (type)
            {
            case VoteType.PurchaseAndSwitchSub:
                votingOnText = TextManager.GetWithVariables("submarinepurchaseandswitchvote", new string[] { "[playername]", "[submarinename]", "[amount]", "[currencyname]" }, new string[] { characterRichString, submarineRichString, info.Price.ToString(), TextManager.Get("credit").ToLower() });
                break;

            case VoteType.PurchaseSub:
                votingOnText = TextManager.GetWithVariables("submarinepurchasevote", new string[] { "[playername]", "[submarinename]", "[amount]", "[currencyname]" }, new string[] { characterRichString, submarineRichString, info.Price.ToString(), TextManager.Get("credit").ToLower() });
                break;

            case VoteType.SwitchSub:
                int deliveryFee = SubmarineSelection.DeliveryFeePerDistanceTravelled * GameMain.GameSession.Map.DistanceToClosestLocationWithOutpost(GameMain.GameSession.Map.CurrentLocation, out Location endLocation);

                if (deliveryFee > 0)
                {
                    votingOnText = TextManager.GetWithVariables("submarineswitchfeevote", new string[] { "[playername]", "[submarinename]", "[locationname]", "[amount]", "[currencyname]" }, new string[] { characterRichString, submarineRichString, endLocation.Name, deliveryFee.ToString(), TextManager.Get("credit").ToLower() });
                }
                else
                {
                    votingOnText = TextManager.GetWithVariables("submarineswitchnofeevote", new string[] { "[playername]", "[submarinename]" }, new string[] { characterRichString, submarineRichString });
                }
                break;
            }

            votingOnTextData = RichTextData.GetRichTextData(votingOnText, out votingOnText);
        }
Exemple #6
0
        public static WayPoint Load(XElement element, Submarine submarine, IdRemap idRemap)
        {
            Rectangle rect = new Rectangle(
                int.Parse(element.Attribute("x").Value),
                int.Parse(element.Attribute("y").Value),
                (int)Submarine.GridSize.X, (int)Submarine.GridSize.Y);


            Enum.TryParse(element.GetAttributeString("spawn", "Path"), out SpawnType spawnType);
            WayPoint w = new WayPoint(MapEntityPrefab.Find(null, spawnType == SpawnType.Path ? "waypoint" : "spawnpoint"), rect, submarine, idRemap.GetOffsetId(element));

            w.spawnType = spawnType;

            string idCardDescString = element.GetAttributeString("idcarddesc", "");

            if (!string.IsNullOrWhiteSpace(idCardDescString))
            {
                w.IdCardDesc = idCardDescString;
            }
            string idCardTagString = element.GetAttributeString("idcardtags", "");

            if (!string.IsNullOrWhiteSpace(idCardTagString))
            {
                w.IdCardTags = idCardTagString.Split(',');
            }

            w.tags = element.GetAttributeStringArray("tags", new string[0], convertToLowerInvariant: true).ToList();

            string jobIdentifier = element.GetAttributeString("job", "").ToLowerInvariant();

            if (!string.IsNullOrWhiteSpace(jobIdentifier))
            {
                w.AssignedJob =
                    JobPrefab.Get(jobIdentifier) ??
                    JobPrefab.Prefabs.Find(jp => jp.Name.Equals(jobIdentifier, StringComparison.OrdinalIgnoreCase));
            }

            w.linkedToID = new List <ushort>();
            w.ladderId   = idRemap.GetOffsetId(element.GetAttributeInt("ladders", 0));
            w.gapId      = idRemap.GetOffsetId(element.GetAttributeInt("gap", 0));

            int i = 0;

            while (element.Attribute("linkedto" + i) != null)
            {
                int srcId  = int.Parse(element.Attribute("linkedto" + i).Value);
                int destId = idRemap.GetOffsetId(srcId);
                if (destId > 0)
                {
                    w.linkedToID.Add((ushort)destId);
                }
                else
                {
                    w.unresolvedLinkedToID ??= new List <ushort>();
                    w.unresolvedLinkedToID.Add((ushort)srcId);
                }
                i += 1;
            }
            return(w);
        }
Exemple #7
0
        private Character SpawnWatchman(Submarine outpost)
        {
            WayPoint watchmanSpawnpoint = WayPoint.WayPointList.Find(wp => wp.Submarine == outpost);

            if (watchmanSpawnpoint == null)
            {
                DebugConsole.ThrowError("Failed to spawn a watchman at the outpost. No spawnpoints found inside the outpost.");
                return(null);
            }

            string seed = outpost == Level.Loaded.StartOutpost ? map.SelectedLocation.Name : map.CurrentLocation.Name;

            Rand.SetSyncedSeed(ToolBox.StringToInt(seed));

            JobPrefab     watchmanJob      = JobPrefab.List.Find(jp => jp.Identifier == "watchman");
            CharacterInfo characterInfo    = new CharacterInfo(Character.HumanConfigFile, jobPrefab: watchmanJob);
            var           spawnedCharacter = Character.Create(characterInfo, watchmanSpawnpoint.WorldPosition,
                                                              Level.Loaded.Seed + (outpost == Level.Loaded.StartOutpost ? "start" : "end"));

            InitializeWatchman(spawnedCharacter);
            (spawnedCharacter.AIController as HumanAIController)?.ObjectiveManager.SetOrder(
                new AIObjectiveGoTo(watchmanSpawnpoint, spawnedCharacter, repeat: true, getDivingGearIfNeeded: false));
            if (watchmanJob != null)
            {
                spawnedCharacter.GiveJobItems();
            }
            return(spawnedCharacter);
        }
Exemple #8
0
        public Job(XElement element)
        {
            string identifier = element.GetAttributeString("identifier", "").ToLowerInvariant();

            if (!JobPrefab.List.TryGetValue(identifier, out JobPrefab p))
            {
                DebugConsole.ThrowError($"Could not find the job {identifier}. Giving the character a random job.");
                p = JobPrefab.Random();
            }
            prefab = p;
            skills = new Dictionary <string, Skill>();
            foreach (XElement subElement in element.Elements())
            {
                if (subElement.Name.ToString().ToLowerInvariant() != "skill")
                {
                    continue;
                }
                string skillIdentifier = subElement.GetAttributeString("identifier", "");
                if (string.IsNullOrEmpty(skillIdentifier))
                {
                    continue;
                }
                skills.Add(
                    skillIdentifier,
                    new Skill(skillIdentifier, subElement.GetAttributeFloat("level", 0)));
            }
        }
        public Job(XElement element)
        {
            string    identifier = element.GetAttributeString("identifier", "").ToLowerInvariant();
            JobPrefab p;

            if (!JobPrefab.Prefabs.ContainsKey(identifier))
            {
                DebugConsole.ThrowError($"Could not find the job {identifier}. Giving the character a random job.");
                p = JobPrefab.Random();
            }
            else
            {
                p = JobPrefab.Prefabs[identifier];
            }
            prefab = p;
            skills = new Dictionary <string, Skill>();
            foreach (XElement subElement in element.Elements())
            {
                if (!subElement.Name.ToString().Equals("skill", System.StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                string skillIdentifier = subElement.GetAttributeString("identifier", "");
                if (string.IsNullOrEmpty(skillIdentifier))
                {
                    continue;
                }
                var skill = new Skill(skillIdentifier, subElement.GetAttributeFloat("level", 0));
                skills.Add(skillIdentifier, skill);
                if (skillIdentifier == prefab.PrimarySkill?.Identifier)
                {
                    PrimarySkill = skill;
                }
            }
        }
        private void QuickStart()
        {
            Submarine selectedSub = null;
            string    subName     = GameMain.Config.QuickStartSubmarineName;

            if (!string.IsNullOrEmpty(subName))
            {
                DebugConsole.NewMessage($"Loading the predefined quick start sub \"{subName}\"", Color.White);
                selectedSub = Submarine.SavedSubmarines.FirstOrDefault(s =>
                                                                       s.Name.ToLower() == subName.ToLower());

                if (selectedSub == null)
                {
                    DebugConsole.NewMessage($"Cannot find a sub that matches the name \"{subName}\".", Color.Red);
                }
            }
            if (selectedSub == null)
            {
                DebugConsole.NewMessage("Loading a random sub.", Color.White);
                var subs = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.Shuttle) && !s.HasTag(SubmarineTag.HideInMenus));
                selectedSub = subs.ElementAt(Rand.Int(subs.Count()));
            }
            var gamesession = new GameSession(
                selectedSub,
                "Data/Saves/test.xml",
                GameModePreset.List.Find(gm => gm.Identifier == "devsandbox"),
                missionPrefab: null);

            //(gamesession.GameMode as SinglePlayerCampaign).GenerateMap(ToolBox.RandomSeed(8));
            gamesession.StartRound(ToolBox.RandomSeed(8));
            GameMain.GameScreen.Select();
            // TODO: modding support
            string[] jobIdentifiers = new string[] { "captain", "engineer", "mechanic" };
            for (int i = 0; i < 3; i++)
            {
                var spawnPoint = WayPoint.GetRandom(SpawnType.Human, null, Submarine.MainSub);
                if (spawnPoint == null)
                {
                    DebugConsole.ThrowError("No spawnpoints found in the selected submarine. Quickstart failed.");
                    GameMain.MainMenuScreen.Select();
                    return;
                }
                var characterInfo = new CharacterInfo(
                    Character.HumanSpeciesName,
                    jobPrefab: JobPrefab.Get(jobIdentifiers[i]));
                if (characterInfo.Job == null)
                {
                    DebugConsole.ThrowError("Failed to find the job \"" + jobIdentifiers[i] + "\"!");
                }

                var newCharacter = Character.Create(Character.HumanSpeciesName, spawnPoint.WorldPosition, ToolBox.RandomSeed(8), characterInfo);
                newCharacter.GiveJobItems(spawnPoint);
                gamesession.CrewManager.AddCharacter(newCharacter);
                Character.Controlled = newCharacter;
            }
        }
Exemple #11
0
        public Job(JobPrefab jobPrefab)
        {
            prefab = jobPrefab;

            skills = new Dictionary <string, Skill>();
            foreach (SkillPrefab skillPrefab in prefab.Skills)
            {
                skills.Add(skillPrefab.Name, new Skill(skillPrefab));
            }
        }
Exemple #12
0
        public static CharacterInfo ClientRead(string speciesName, IReadMessage inc)
        {
            ushort infoID              = inc.ReadUInt16();
            string newName             = inc.ReadString();
            string originalName        = inc.ReadString();
            int    gender              = inc.ReadByte();
            int    race                = inc.ReadByte();
            int    headSpriteID        = inc.ReadByte();
            int    hairIndex           = inc.ReadByte();
            int    beardIndex          = inc.ReadByte();
            int    moustacheIndex      = inc.ReadByte();
            int    faceAttachmentIndex = inc.ReadByte();
            string ragdollFile         = inc.ReadString();

            string jobIdentifier = inc.ReadString();
            int    variant       = inc.ReadByte();

            JobPrefab jobPrefab = null;
            Dictionary <string, float> skillLevels = new Dictionary <string, float>();

            if (!string.IsNullOrEmpty(jobIdentifier))
            {
                jobPrefab = JobPrefab.Get(jobIdentifier);
                byte skillCount = inc.ReadByte();
                for (int i = 0; i < skillCount; i++)
                {
                    string skillIdentifier = inc.ReadString();
                    float  skillLevel      = inc.ReadSingle();
                    skillLevels.Add(skillIdentifier, skillLevel);
                }
            }

            // TODO: animations
            CharacterInfo ch = new CharacterInfo(speciesName, newName, originalName, jobPrefab, ragdollFile, variant)
            {
                ID = infoID,
            };

            ch.RecreateHead(headSpriteID, (Race)race, (Gender)gender, hairIndex, beardIndex, moustacheIndex, faceAttachmentIndex);
            if (ch.Job != null)
            {
                foreach (KeyValuePair <string, float> skill in skillLevels)
                {
                    Skill matchingSkill = ch.Job.Skills.Find(s => s.Identifier == skill.Key);
                    if (matchingSkill == null)
                    {
                        ch.Job.Skills.Add(new Skill(skill.Key, skill.Value));
                        continue;
                    }
                    matchingSkill.Level = skill.Value;
                }
                ch.Job.Skills.RemoveAll(s => !skillLevels.ContainsKey(s.Identifier));
            }
            return(ch);
        }
Exemple #13
0
        public Job(JobPrefab jobPrefab, int variant = 0)
        {
            prefab  = jobPrefab;
            Variant = variant;

            skills = new Dictionary <string, Skill>();
            foreach (SkillPrefab skillPrefab in prefab.Skills)
            {
                skills.Add(skillPrefab.Identifier, new Skill(skillPrefab));
            }
        }
Exemple #14
0
        public void GenerateCharacters(Location location, int amount)
        {
            for (int i = 0; i < amount; i++)
            {
                JobPrefab job = location.Type.GetRandomHireable();
                if (job == null)
                {
                    return;
                }

                availableCharacters.Add(new CharacterInfo(Character.HumanConfigFile, "", Gender.None, job));
            }
        }
Exemple #15
0
        public static WayPoint Load(XElement element, Submarine submarine)
        {
            Rectangle rect = new Rectangle(
                int.Parse(element.Attribute("x").Value),
                int.Parse(element.Attribute("y").Value),
                (int)Submarine.GridSize.X, (int)Submarine.GridSize.Y);


            Enum.TryParse(element.GetAttributeString("spawn", "Path"), out SpawnType spawnType);
            WayPoint w = new WayPoint(MapEntityPrefab.Find(null, spawnType == SpawnType.Path ? "waypoint" : "spawnpoint"), rect, submarine)
            {
                ID = (ushort)int.Parse(element.Attribute("ID").Value)
            };

            w.spawnType = spawnType;

            string idCardDescString = element.GetAttributeString("idcarddesc", "");

            if (!string.IsNullOrWhiteSpace(idCardDescString))
            {
                w.IdCardDesc = idCardDescString;
            }
            string idCardTagString = element.GetAttributeString("idcardtags", "");

            if (!string.IsNullOrWhiteSpace(idCardTagString))
            {
                w.IdCardTags = idCardTagString.Split(',');
            }

            string jobIdentifier = element.GetAttributeString("job", "").ToLowerInvariant();

            if (!string.IsNullOrWhiteSpace(jobIdentifier))
            {
                w.assignedJob =
                    JobPrefab.Get(jobIdentifier) ??
                    JobPrefab.Prefabs.Find(jp => jp.Name.Equals(jobIdentifier, StringComparison.OrdinalIgnoreCase));
            }

            w.ladderId = (ushort)element.GetAttributeInt("ladders", 0);
            w.gapId    = (ushort)element.GetAttributeInt("gap", 0);

            w.linkedToID = new List <ushort>();
            int i = 0;

            while (element.Attribute("linkedto" + i) != null)
            {
                w.linkedToID.Add((ushort)int.Parse(element.Attribute("linkedto" + i).Value));
                i += 1;
            }
            return(w);
        }
Exemple #16
0
            public static Character Spawn(string name, Vector2 worldPos)
            {
                Character spawnedCharacter = null;
                Vector2   spawnPosition    = worldPos;

                string    characterLowerCase = name.ToLowerInvariant();
                JobPrefab job = null;

                if (!JobPrefab.Prefabs.ContainsKey(characterLowerCase))
                {
                    job = JobPrefab.Prefabs.Find(jp => jp.Name != null && jp.Name.Equals(characterLowerCase, StringComparison.OrdinalIgnoreCase));
                }
                else
                {
                    job = JobPrefab.Prefabs[characterLowerCase];
                }
                bool human = job != null || characterLowerCase == CharacterPrefab.HumanSpeciesName;


                if (string.IsNullOrWhiteSpace(name))
                {
                    return(null);
                }

                if (human)
                {
                    var variant = job != null?Rand.Range(0, job.Variants, Rand.RandSync.Server) : 0;

                    CharacterInfo characterInfo = new CharacterInfo(CharacterPrefab.HumanSpeciesName, jobPrefab: job, variant: variant);
                    spawnedCharacter = Character.Create(characterInfo, spawnPosition, ToolBox.RandomSeed(8));
                    if (GameMain.GameSession != null)
                    {
                        //TODO: a way to select which team to spawn to?
                        spawnedCharacter.TeamID = Character.Controlled != null ? Character.Controlled.TeamID : CharacterTeamType.Team1;
#if CLIENT
                        GameMain.GameSession.CrewManager.AddCharacter(spawnedCharacter);
#endif
                    }
                    spawnedCharacter.GiveJobItems(null);
                    spawnedCharacter.Info.StartItemsGiven = true;
                }
                else
                {
                    if (CharacterPrefab.FindBySpeciesName(name) != null)
                    {
                        spawnedCharacter = Character.Create(name, spawnPosition, ToolBox.RandomSeed(8));
                    }
                }

                return(spawnedCharacter);
            }
Exemple #17
0
        public static CharacterInfo ClientRead(string configPath, NetBuffer inc)
        {
            ushort infoID              = inc.ReadUInt16();
            string newName             = inc.ReadString();
            int    gender              = inc.ReadByte();
            int    race                = inc.ReadByte();
            int    headSpriteID        = inc.ReadByte();
            int    hairIndex           = inc.ReadByte();
            int    beardIndex          = inc.ReadByte();
            int    moustacheIndex      = inc.ReadByte();
            int    faceAttachmentIndex = inc.ReadByte();
            string ragdollFile         = inc.ReadString();

            string    jobIdentifier = inc.ReadString();
            JobPrefab jobPrefab     = null;
            Dictionary <string, float> skillLevels = new Dictionary <string, float>();

            if (!string.IsNullOrEmpty(jobIdentifier))
            {
                jobPrefab = JobPrefab.List.Find(jp => jp.Identifier == jobIdentifier);
                for (int i = 0; i < jobPrefab.Skills.Count; i++)
                {
                    float skillLevel = inc.ReadSingle();
                    skillLevels.Add(jobPrefab.Skills[i].Identifier, skillLevel);
                }
            }

            // TODO: animations
            CharacterInfo ch = new CharacterInfo(configPath, newName, jobPrefab, ragdollFile)
            {
                ID = infoID,
            };

            ch.RecreateHead(headSpriteID, (Race)race, (Gender)gender, hairIndex, beardIndex, moustacheIndex, faceAttachmentIndex);
            System.Diagnostics.Debug.Assert(skillLevels.Count == ch.Job.Skills.Count);
            if (ch.Job != null)
            {
                foreach (KeyValuePair <string, float> skill in skillLevels)
                {
                    Skill matchingSkill = ch.Job.Skills.Find(s => s.Identifier == skill.Key);
                    if (matchingSkill == null)
                    {
                        DebugConsole.ThrowError("Skill \"" + skill.Key + "\" not found in character \"" + newName + "\"");
                        continue;
                    }
                    matchingSkill.Level = skill.Value;
                }
            }
            return(ch);
        }
Exemple #18
0
        public static void LoadAll(IEnumerable <string> filePaths)
        {
            List = new Dictionary <string, JobPrefab>();

            foreach (string filePath in filePaths)
            {
                XDocument doc = XMLExtensions.TryLoadXml(filePath);
                if (doc == null)
                {
                    continue;
                }
                var mainElement = doc.Root.IsOverride() ? doc.Root.FirstElement() : doc.Root;
                if (doc.Root.IsOverride())
                {
                    DebugConsole.ThrowError($"Error in '{filePath}': Cannot override all job prefabs, because many of them are required by the main game! Please try overriding jobs one by one.");
                }
                foreach (XElement element in mainElement.Elements())
                {
                    if (element.Name.ToString().ToLowerInvariant() == "nojob")
                    {
                        continue;
                    }
                    if (element.IsOverride())
                    {
                        var job = new JobPrefab(element.FirstElement());
                        if (List.TryGetValue(job.Identifier, out JobPrefab duplicate))
                        {
                            DebugConsole.NewMessage($"Overriding the job '{duplicate.Identifier}' with another defined in '{filePath}'", Color.Yellow);
                            List.Remove(duplicate.Identifier);
                        }
                        List.Add(job.Identifier, job);
                    }
                    else
                    {
                        if (List.TryGetValue(element.GetAttributeString("identifier", "").ToLowerInvariant(), out JobPrefab duplicate))
                        {
                            DebugConsole.ThrowError($"Error in '{filePath}': Duplicate job definition found for: '{duplicate.Identifier}'. Use the <override> XML element as the parent of job element's definition to override the existing job.");
                        }
                        else
                        {
                            var job = new JobPrefab(element);
                            List.Add(job.Identifier, job);
                        }
                    }
                }
                NoJobElement = NoJobElement ?? mainElement.Element("NoJob");
                NoJobElement = NoJobElement ?? mainElement.Element("nojob");
            }
        }
        public void GenerateCharacters(Location location, int amount)
        {
            availableCharacters.ForEach(c => c.Remove());
            availableCharacters.Clear();
            for (int i = 0; i < amount; i++)
            {
                JobPrefab job = location.Type.GetRandomHireable();
                if (job == null)
                {
                    return;
                }

                availableCharacters.Add(new CharacterInfo(Character.HumanSpeciesName, "", job));
            }
        }
Exemple #20
0
        public void GenerateCharacters(Location location, int amount)
        {
            AvailableCharacters.ForEach(c => c.Remove());
            AvailableCharacters.Clear();
            for (int i = 0; i < amount; i++)
            {
                JobPrefab job = location.Type.GetRandomHireable();
                if (job == null)
                {
                    return;
                }

                var variant = Rand.Range(0, job.Variants, Rand.RandSync.Server);
                AvailableCharacters.Add(new CharacterInfo(CharacterPrefab.HumanSpeciesName, jobPrefab: job, variant: variant));
            }
        }
Exemple #21
0
        private bool EnterAssignedJob(GUITextBox textBox, string text)
        {
            string trimmedName = text.ToLowerInvariant().Trim();

            assignedJob = JobPrefab.List.Find(jp => jp.Name.ToLowerInvariant() == trimmedName);

            if (assignedJob != null && trimmedName != "none")
            {
                textBox.Color = Color.Green;
                textBox.Text  = (assignedJob == null) ? "None" : assignedJob.Name;
            }

            textBox.Deselect();

            return(true);
        }
        public Job(JobPrefab jobPrefab, int variant = 0)
        {
            prefab  = jobPrefab;
            Variant = variant;

            skills = new Dictionary <string, Skill>();
            foreach (SkillPrefab skillPrefab in prefab.Skills)
            {
                var skill = new Skill(skillPrefab);
                skills.Add(skillPrefab.Identifier, skill);
                if (skillPrefab.IsPrimarySkill)
                {
                    PrimarySkill = skill;
                }
            }
        }
        private LocationType(XElement element)
        {
            name = element.Name.ToString();

            commonness   = element.GetAttributeInt("commonness", 1);
            totalWeight += commonness;

            nameFormats = new List <string>();
            foreach (XAttribute nameFormat in element.Element("nameformats").Attributes())
            {
                nameFormats.Add(nameFormat.Value);
            }

            hireableJobs = new List <Tuple <JobPrefab, float> >();
            foreach (XElement subElement in element.Elements())
            {
                if (subElement.Name.ToString().ToLowerInvariant() != "hireable")
                {
                    continue;
                }

                string jobName = subElement.GetAttributeString("name", "");

                JobPrefab jobPrefab = JobPrefab.List.Find(jp => jp.Name.ToLowerInvariant() == jobName.ToLowerInvariant());
                if (jobPrefab == null)
                {
                    DebugConsole.ThrowError("Invalid job name (" + jobName + ") in location type " + name);
                }

                float jobCommonness = subElement.GetAttributeFloat("commonness", 1.0f);
                totalHireableWeight += jobCommonness;

                Tuple <JobPrefab, float> hireableJob = new Tuple <JobPrefab, float>(jobPrefab, jobCommonness);

                hireableJobs.Add(hireableJob);
            }

            string spritePath = element.GetAttributeString("symbol", "Content/Map/beaconSymbol.png");

            symbolSprite = new Sprite(spritePath, new Vector2(0.5f, 0.5f));

            string backgroundPath = element.GetAttributeString("background", "");

            backGround = new Sprite(backgroundPath, Vector2.Zero);
        }
Exemple #24
0
        public static void LoadAll(IEnumerable <string> filePaths)
        {
            List = new List <JobPrefab>();

            foreach (string filePath in filePaths)
            {
                XDocument doc = XMLExtensions.TryLoadXml(filePath);
                if (doc == null || doc.Root == null)
                {
                    return;
                }

                foreach (XElement element in doc.Root.Elements())
                {
                    JobPrefab job = new JobPrefab(element);
                    List.Add(job);
                }
            }
        }
Exemple #25
0
        public void Init()
        {
            NPCSet.LoadSets();
            FactionPrefab.LoadFactions();
            CharacterPrefab.LoadAll();
            MissionPrefab.Init();
            TraitorMissionPrefab.Init();
            MapEntityPrefab.Init();
            MapGenerationParams.Init();
            LevelGenerationParams.LoadPresets();
            CaveGenerationParams.LoadPresets();
            OutpostGenerationParams.LoadPresets();
            EventSet.LoadPrefabs();
            Order.Init();
            EventManagerSettings.Init();
            ItemPrefab.LoadAll(GetFilesOfType(ContentType.Item));
            AfflictionPrefab.LoadAll(GetFilesOfType(ContentType.Afflictions));
            SkillSettings.Load(GetFilesOfType(ContentType.SkillSettings));
            StructurePrefab.LoadAll(GetFilesOfType(ContentType.Structure));
            UpgradePrefab.LoadAll(GetFilesOfType(ContentType.UpgradeModules));
            JobPrefab.LoadAll(GetFilesOfType(ContentType.Jobs));
            CorpsePrefab.LoadAll(GetFilesOfType(ContentType.Corpses));
            NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations));
            ItemAssemblyPrefab.LoadAll();
            LevelObjectPrefab.LoadAll();
            BallastFloraPrefab.LoadAll(GetFilesOfType(ContentType.MapCreature));
            TalentPrefab.LoadAll(GetFilesOfType(ContentType.Talents));
            TalentTree.LoadAll(GetFilesOfType(ContentType.TalentTrees));

            GameModePreset.Init();
            DecalManager = new DecalManager();
            LocationType.Init();

            SubmarineInfo.RefreshSavedSubs();

            Screen.SelectNull();

            NetLobbyScreen = new NetLobbyScreen();

            CheckContentPackage();
        }
Exemple #26
0
        public void Init()
        {
            Mission.Init();
            MapEntityPrefab.Init();
            LevelGenerationParams.LoadPresets();

            JobPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Jobs));
            StructurePrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Structure));

            ItemPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Item));

            GameModePreset.Init();

            LocationType.Init();

            Submarine.RefreshSavedSubs();

            Screen.SelectNull();

            NetLobbyScreen = new NetLobbyScreen();
        }
        public static void LoadFromFile(ContentFile file)
        {
            XDocument doc = XMLExtensions.TryLoadXml(file.Path);

            if (doc == null)
            {
                return;
            }
            var mainElement = doc.Root.IsOverride() ? doc.Root.FirstElement() : doc.Root;

            if (doc.Root.IsOverride())
            {
                DebugConsole.ThrowError($"Error in '{file.Path}': Cannot override all job prefabs, because many of them are required by the main game! Please try overriding jobs one by one.");
            }
            foreach (XElement element in mainElement.Elements())
            {
                if (element.Name.ToString().Equals("nojob", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (element.IsOverride())
                {
                    var job = new JobPrefab(element.FirstElement(), file.Path)
                    {
                        ContentPackage = file.ContentPackage
                    };
                    Prefabs.Add(job, true);
                }
                else
                {
                    var job = new JobPrefab(element, file.Path)
                    {
                        ContentPackage = file.ContentPackage
                    };
                    Prefabs.Add(job, false);
                }
            }
            NoJobElement = NoJobElement ?? mainElement.Element("NoJob");
            NoJobElement = NoJobElement ?? mainElement.Element("nojob");
        }
Exemple #28
0
        private Character SpawnWatchman(Submarine outpost)
        {
            WayPoint watchmanSpawnpoint = WayPoint.WayPointList.Find(wp => wp.Submarine == outpost);

            if (watchmanSpawnpoint == null)
            {
                DebugConsole.ThrowError("Failed to spawn a watchman at the outpost. No spawnpoints found inside the outpost.");
                return(null);
            }

            string seed = outpost == Level.Loaded.StartOutpost ? map.SelectedLocation.Name : map.CurrentLocation.Name;

            Rand.SetSyncedSeed(ToolBox.StringToInt(seed));

            JobPrefab     watchmanJob      = JobPrefab.Get("watchman");
            var           variant          = Rand.Range(0, watchmanJob.Variants, Rand.RandSync.Server);
            CharacterInfo characterInfo    = new CharacterInfo(CharacterPrefab.HumanSpeciesName, jobPrefab: watchmanJob, variant: variant);
            var           spawnedCharacter = Character.Create(characterInfo, watchmanSpawnpoint.WorldPosition,
                                                              Level.Loaded.Seed + (outpost == Level.Loaded.StartOutpost ? "start" : "end"));

            InitializeWatchman(spawnedCharacter);
            var objectiveManager = (spawnedCharacter.AIController as HumanAIController)?.ObjectiveManager;

            if (objectiveManager != null)
            {
                var moveOrder = new AIObjectiveGoTo(watchmanSpawnpoint, spawnedCharacter, objectiveManager, repeat: true, getDivingGearIfNeeded: false);
                moveOrder.Completed += () =>
                {
                    // Turn towards the center of the sub. Doesn't work in all possible cases, but this is the simplest solution for now.
                    spawnedCharacter.AnimController.TargetDir = spawnedCharacter.Submarine.WorldPosition.X > spawnedCharacter.WorldPosition.X ? Direction.Right : Direction.Left;
                };
                objectiveManager.SetOrder(moveOrder);
            }
            if (watchmanJob != null)
            {
                spawnedCharacter.GiveJobItems();
            }
            return(spawnedCharacter);
        }
Exemple #29
0
        public Job(XElement element)
        {
            string name = element.GetAttributeString("name", "").ToLowerInvariant();

            prefab = JobPrefab.List.Find(jp => jp.Name.ToLowerInvariant() == name);

            skills = new Dictionary <string, Skill>();
            foreach (XElement subElement in element.Elements())
            {
                if (subElement.Name.ToString().ToLowerInvariant() != "skill")
                {
                    continue;
                }
                string skillName = subElement.GetAttributeString("name", "");
                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }
                skills.Add(
                    skillName,
                    new Skill(skillName, subElement.GetAttributeInt("level", 0)));
            }
        }
Exemple #30
0
        public Job(XElement element)
        {
            string identifier = element.GetAttributeString("identifier", "").ToLowerInvariant();

            prefab = JobPrefab.List.Find(jp => jp.Identifier.ToLowerInvariant() == identifier);

            string name = "";

            if (prefab == null)
            {
                name   = element.GetAttributeString("name", "").ToLowerInvariant();
                prefab = JobPrefab.List.Find(jp => jp.Name.ToLowerInvariant() == name);
            }
            if (prefab == null)
            {
                DebugConsole.ThrowError("Could not find the job \"" + name + "\" (identifier " + identifier + "). Giving the character a random job.");
                prefab = JobPrefab.List[Rand.Int(JobPrefab.List.Count)];
            }

            skills = new Dictionary <string, Skill>();
            foreach (XElement subElement in element.Elements())
            {
                if (subElement.Name.ToString().ToLowerInvariant() != "skill")
                {
                    continue;
                }
                string skillIdentifier = subElement.GetAttributeString("identifier", "");
                if (string.IsNullOrEmpty(skillIdentifier))
                {
                    continue;
                }
                skills.Add(
                    skillIdentifier,
                    new Skill(skillIdentifier, subElement.GetAttributeFloat("level", 0)));
            }
        }