Пример #1
0
        private void InitCharacters(Submarine submarine)
        {
            characters.Clear();
            characterItems.Clear();

            if (characterConfig == null)
            {
                return;
            }

            foreach (XElement element in characterConfig.Elements())
            {
                if (GameMain.NetworkMember == null && element.GetAttributeBool("multiplayeronly", false))
                {
                    continue;
                }

                int defaultCount = element.GetAttributeInt("count", -1);
                if (defaultCount < 0)
                {
                    defaultCount = element.GetAttributeInt("amount", 1);
                }
                int min   = Math.Min(element.GetAttributeInt("min", defaultCount), 255);
                int max   = Math.Min(Math.Max(min, element.GetAttributeInt("max", defaultCount)), 255);
                int count = Rand.Range(min, max + 1);

                if (element.Attribute("identifier") != null && element.Attribute("from") != null)
                {
                    string      characterIdentifier = element.GetAttributeString("identifier", "");
                    string      characterFrom       = element.GetAttributeString("from", "");
                    HumanPrefab humanPrefab         = NPCSet.Get(characterFrom, characterIdentifier);
                    if (humanPrefab == null)
                    {
                        DebugConsole.ThrowError("Couldn't spawn a character for abandoned outpost mission: character prefab \"" + characterIdentifier + "\" not found");
                        continue;
                    }
                    for (int i = 0; i < count; i++)
                    {
                        LoadHuman(humanPrefab, element, submarine);
                    }
                }
                else
                {
                    string speciesName     = element.GetAttributeString("character", element.GetAttributeString("identifier", ""));
                    var    characterPrefab = CharacterPrefab.FindBySpeciesName(speciesName);
                    if (characterPrefab == null)
                    {
                        DebugConsole.ThrowError("Couldn't spawn a character for abandoned outpost mission: character prefab \"" + speciesName + "\" not found");
                        continue;
                    }
                    for (int i = 0; i < count; i++)
                    {
                        LoadMonster(characterPrefab, element, submarine);
                    }
                }
            }
        }
        public static HumanPrefab?Get(string identifier, string npcidentifier)
        {
            HumanPrefab prefab = Sets.Where(set => set.Identifier == identifier).SelectMany(npcSet => npcSet.Humans.Where(npcSetHuman => npcSetHuman.Identifier == npcidentifier)).FirstOrDefault();

            if (prefab == null)
            {
                DebugConsole.ThrowError($"Could not find human prefab \"{npcidentifier}\" from \"{identifier}\".");
                return(null);
            }
            return(new HumanPrefab(prefab.Element, prefab.FilePath));
        }
        protected OutpostGenerationParams(XElement element, string filePath)
        {
            Identifier             = element.GetAttributeString("identifier", "");
            Name                   = element.GetAttributeString("name", Identifier);
            allowedLocationTypes   = element.GetAttributeStringArray("allowedlocationtypes", Array.Empty <string>()).ToList();
            SerializableProperties = SerializableProperty.DeserializeProperties(this, element);

            if (element == null)
            {
                return;
            }
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "modulecount":
                    string moduleFlag = (subElement.GetAttributeString("flag", null) ?? subElement.GetAttributeString("moduletype", "")).ToLowerInvariant();
                    moduleCounts[moduleFlag] = subElement.GetAttributeInt("count", 0);
                    break;

                case "npcs":
                    humanPrefabLists.Add(new List <HumanPrefab>());
                    foreach (XElement npcElement in subElement.Elements())
                    {
                        string from = npcElement.GetAttributeString("from", string.Empty);

                        // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                        if (!string.IsNullOrWhiteSpace(from))
                        {
                            HumanPrefab prefab = NPCSet.Get(from, npcElement.GetAttributeString("identifier", string.Empty));
                            if (prefab != null)
                            {
                                humanPrefabLists.Last().Add(prefab);
                            }
                        }
                        else
                        {
                            humanPrefabLists.Last().Add(new HumanPrefab(npcElement, filePath));
                        }
                    }
                    break;
                }
            }
        }
Пример #4
0
        private void LoadHuman(HumanPrefab humanPrefab, XElement element, Submarine submarine)
        {
            string[]       moduleFlags    = element.GetAttributeStringArray("moduleflags", null);
            string[]       spawnPointTags = element.GetAttributeStringArray("spawnpointtags", null);
            ISpatialEntity spawnPos       = SpawnAction.GetSpawnPos(
                SpawnAction.SpawnLocationType.Outpost, SpawnType.Human,
                moduleFlags ?? humanPrefab.GetModuleFlags(),
                spawnPointTags ?? humanPrefab.GetSpawnPointTags(),
                element.GetAttributeBool("asfaraspossible", false));

            if (spawnPos == null)
            {
                spawnPos = submarine.GetHulls(alsoFromConnectedSubs: false).GetRandom();
            }

            var       characterInfo    = new CharacterInfo(CharacterPrefab.HumanSpeciesName, jobPrefab: humanPrefab.GetJobPrefab(Rand.RandSync.Server), randSync: Rand.RandSync.Server);
            Character spawnedCharacter = Character.Create(characterInfo.SpeciesName, spawnPos.WorldPosition, ToolBox.RandomSeed(8), characterInfo, createNetworkEvent: false);

            if (element.GetAttributeBool("requirerescue", false))
            {
                requireRescue.Add(spawnedCharacter);
                spawnedCharacter.TeamID = CharacterTeamType.FriendlyNPC;
#if CLIENT
                GameMain.GameSession.CrewManager.AddCharacterToCrewList(spawnedCharacter);
#endif
            }
            else
            {
                spawnedCharacter.TeamID = CharacterTeamType.None;
            }
            humanPrefab.InitializeCharacter(spawnedCharacter, spawnPos);
            humanPrefab.GiveItems(spawnedCharacter, Submarine.MainSub, Rand.RandSync.Server, createNetworkEvents: false);
            if (spawnPos is WayPoint wp)
            {
                spawnedCharacter.GiveIdCardTags(wp);
            }
            if (element.GetAttributeBool("requirekill", false))
            {
                requireKill.Add(spawnedCharacter);
            }
            characters.Add(spawnedCharacter);
            characterItems.Add(spawnedCharacter, spawnedCharacter.Inventory.FindAllItems(recursive: true));
        }
Пример #5
0
        // putting these here since both escort and pirate missions need them. could be tucked away into another class that they can inherit from (or use composition)
        protected HumanPrefab GetHumanPrefabFromElement(XElement element)
        {
            if (element.Attribute("name") != null)
            {
                DebugConsole.ThrowError("Error in mission \"" + Name + "\" - use character identifiers instead of names to configure the characters.");

                return(null);
            }

            string      characterIdentifier = element.GetAttributeString("identifier", "");
            string      characterFrom       = element.GetAttributeString("from", "");
            HumanPrefab humanPrefab         = NPCSet.Get(characterFrom, characterIdentifier);

            if (humanPrefab == null)
            {
                DebugConsole.ThrowError("Couldn't spawn character for mission: character prefab \"" + characterIdentifier + "\" not found");
                return(null);
            }

            return(humanPrefab);
        }
Пример #6
0
        protected Character CreateHuman(HumanPrefab humanPrefab, List <Character> characters, Dictionary <Character, List <Item> > characterItems, Submarine submarine, CharacterTeamType teamType, ISpatialEntity positionToStayIn = null, Rand.RandSync humanPrefabRandSync = Rand.RandSync.Server, bool giveTags = true)
        {
            if (positionToStayIn == null)
            {
                positionToStayIn = WayPoint.GetRandom(SpawnType.Human, null, submarine);
            }

            var characterInfo = humanPrefab.GetCharacterInfo(Rand.RandSync.Server) ?? new CharacterInfo(CharacterPrefab.HumanSpeciesName, npcIdentifier: humanPrefab.Identifier, jobPrefab: humanPrefab.GetJobPrefab(humanPrefabRandSync), randSync: humanPrefabRandSync);

            characterInfo.TeamID = teamType;
            Character spawnedCharacter = Character.Create(characterInfo.SpeciesName, positionToStayIn.WorldPosition, ToolBox.RandomSeed(8), characterInfo, createNetworkEvent: false);

            spawnedCharacter.Prefab = humanPrefab;
            humanPrefab.InitializeCharacter(spawnedCharacter, positionToStayIn);
            humanPrefab.GiveItems(spawnedCharacter, submarine, Rand.RandSync.Server, createNetworkEvents: false);

            characters.Add(spawnedCharacter);
            characterItems.Add(spawnedCharacter, spawnedCharacter.Inventory.FindAllItems(recursive: true));

            return(spawnedCharacter);
        }
        private void LoadHuman(HumanPrefab humanPrefab, XElement element, Submarine submarine)
        {
            string[]       moduleFlags    = element.GetAttributeStringArray("moduleflags", null);
            string[]       spawnPointTags = element.GetAttributeStringArray("spawnpointtags", null);
            ISpatialEntity spawnPos       = SpawnAction.GetSpawnPos(
                SpawnAction.SpawnLocationType.Outpost, SpawnType.Human,
                moduleFlags ?? humanPrefab.GetModuleFlags(),
                spawnPointTags ?? humanPrefab.GetSpawnPointTags(),
                element.GetAttributeBool("asfaraspossible", false));

            if (spawnPos == null)
            {
                spawnPos = submarine.GetHulls(alsoFromConnectedSubs: false).GetRandom();
            }

            bool requiresRescue = element.GetAttributeBool("requirerescue", false);

            Character spawnedCharacter = CreateHuman(humanPrefab, characters, characterItems, submarine, requiresRescue ? CharacterTeamType.FriendlyNPC : CharacterTeamType.None, spawnPos, giveTags: true);

            if (spawnPos is WayPoint wp)
            {
                spawnedCharacter.GiveIdCardTags(wp);
            }

            if (requiresRescue)
            {
                requireRescue.Add(spawnedCharacter);
#if CLIENT
                GameMain.GameSession.CrewManager.AddCharacterToCrewList(spawnedCharacter);
#endif
            }

            if (element.GetAttributeBool("requirekill", false))
            {
                requireKill.Add(spawnedCharacter);
            }
        }
Пример #8
0
        void TryToTriggerTerrorists()
        {
            if (terroristsShouldAct)
            {
                // decoupled from range check to prevent from weirdness if players handcuff a terrorist and move backwards
                foreach (Character character in terroristCharacters)
                {
                    if (character.HasTeamChange(TerroristTeamChangeIdentifier))
                    {
                        // already triggered
                        continue;
                    }

                    if (IsAlive(character) && !character.IsIncapacitated && !character.LockHands)
                    {
                        character.TryAddNewTeamChange(TerroristTeamChangeIdentifier, new ActiveTeamChange(CharacterTeamType.None, ActiveTeamChange.TeamChangePriorities.Willful, aggressiveBehavior: true));
                        character.Speak(TextManager.Get("dialogterroristannounce"), null, Rand.Range(0.5f, 3f));
                        XElement randomElement = itemConfig.Elements().GetRandom(e => e.GetAttributeFloat(0f, "mindifficulty") <= Level.Loaded.Difficulty);
                        if (randomElement != null)
                        {
                            HumanPrefab.InitializeItem(character, randomElement, character.Submarine, humanPrefab: null, createNetworkEvents: true);
                        }
                    }
                }
            }
            else if (Vector2.DistanceSquared(Submarine.MainSub.WorldPosition, Level.Loaded.EndPosition) < terroristDistanceSquared)
            {
                foreach (Character character in terroristCharacters)
                {
                    if (character.AIController is HumanAIController humanAI)
                    {
                        humanAI.ObjectiveManager.AddObjective(new AIObjectiveEscapeHandcuffs(character, humanAI.ObjectiveManager, shouldSwitchTeams: false, beginInstantly: true));
                    }
                }
                terroristsShouldAct = true;
            }
        }