Example #1
0
        private void LoadMonster(CharacterPrefab monsterPrefab, XElement element, Submarine submarine)
        {
            string[]       moduleFlags    = element.GetAttributeStringArray("moduleflags", null);
            string[]       spawnPointTags = element.GetAttributeStringArray("spawnpointtags", null);
            ISpatialEntity spawnPos       = SpawnAction.GetSpawnPos(SpawnAction.SpawnLocationType.Outpost, SpawnType.Enemy, moduleFlags, spawnPointTags, element.GetAttributeBool("asfaraspossible", false));

            if (spawnPos == null)
            {
                spawnPos = submarine.GetHulls(alsoFromConnectedSubs: false).GetRandom();
            }
            Character spawnedCharacter = Character.Create(monsterPrefab.Identifier, spawnPos.WorldPosition, ToolBox.RandomSeed(8), createNetworkEvent: false);

            characters.Add(spawnedCharacter);
            if (element.GetAttributeBool("requirekill", false))
            {
                requireKill.Add(spawnedCharacter);
            }
            if (spawnedCharacter.Inventory != null)
            {
                characterItems.Add(spawnedCharacter, spawnedCharacter.Inventory.FindAllItems(recursive: true));
            }
            if (submarine != null && spawnedCharacter.AIController is EnemyAIController enemyAi)
            {
                enemyAi.UnattackableSubmarines.Add(submarine);
                enemyAi.UnattackableSubmarines.Add(Submarine.MainSub);
                foreach (Submarine sub in Submarine.MainSub.DockedTo)
                {
                    enemyAi.UnattackableSubmarines.Add(sub);
                }
            }
        }
Example #2
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();
        }
Example #3
0
        private IEnumerable <object> CreateAIHusk()
        {
            character.Enabled = false;
            Entity.Spawner.AddToRemoveQueue(character);

            string          huskedSpeciesName = GetHuskedSpeciesName(character.SpeciesName, Prefab as AfflictionPrefabHusk);
            CharacterPrefab prefab            = CharacterPrefab.FindBySpeciesName(huskedSpeciesName);

            if (prefab == null)
            {
                DebugConsole.ThrowError("Failed to turn character \"" + character.Name + "\" into a husk - husk config file not found.");
                yield return(CoroutineStatus.Success);
            }
            var husk = Character.Create(huskedSpeciesName, character.WorldPosition, ToolBox.RandomSeed(8), character.Info, isRemotePlayer: false, hasAi: true);

            foreach (Limb limb in husk.AnimController.Limbs)
            {
                if (limb.type == LimbType.None)
                {
                    limb.body.SetTransform(character.SimPosition, 0.0f);
                    continue;
                }

                var matchingLimb = character.AnimController.GetLimb(limb.type);
                if (matchingLimb?.body != null)
                {
                    limb.body.SetTransform(matchingLimb.SimPosition, matchingLimb.Rotation);
                    limb.body.LinearVelocity  = matchingLimb.LinearVelocity;
                    limb.body.AngularVelocity = matchingLimb.body.AngularVelocity;
                }
            }

            if (character.Inventory != null && husk.Inventory != null)
            {
                if (character.Inventory.Items.Length != husk.Inventory.Items.Length)
                {
                    string errorMsg = "Failed to move items from the source character's inventory into a husk's inventory (inventory sizes don't match)";
                    DebugConsole.ThrowError(errorMsg);
                    GameAnalyticsManager.AddErrorEventOnce("AfflictionHusk.CreateAIHusk:InventoryMismatch", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
                    yield return(CoroutineStatus.Success);
                }
                for (int i = 0; i < character.Inventory.Items.Length && i < husk.Inventory.Items.Length; i++)
                {
                    if (character.Inventory.Items[i] == null)
                    {
                        continue;
                    }
                    husk.Inventory.TryPutItem(character.Inventory.Items[i], i, true, false, null);
                }
            }

            husk.SetStun(5);
            yield return(new WaitForSeconds(5, false));

#if CLIENT
            husk.PlaySound(CharacterSound.SoundType.Idle);
#endif
            yield return(CoroutineStatus.Success);
        }
Example #4
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);
                    }
                }
            }
        }
Example #5
0
        public MonsterEvent(EventPrefab prefab)
            : base(prefab)
        {
            speciesName = prefab.ConfigElement.GetAttributeString("characterfile", "");
            CharacterPrefab characterPrefab = CharacterPrefab.FindByFilePath(speciesName);

            if (characterPrefab != null)
            {
                speciesName = characterPrefab.Identifier;
            }

            if (string.IsNullOrEmpty(speciesName))
            {
                throw new Exception("speciesname is null!");
            }

            int defaultAmount = prefab.ConfigElement.GetAttributeInt("amount", 1);

            minAmount = prefab.ConfigElement.GetAttributeInt("minamount", defaultAmount);
            maxAmount = Math.Max(prefab.ConfigElement.GetAttributeInt("maxamount", 1), minAmount);

            maxAmountPerLevel = prefab.ConfigElement.GetAttributeInt("maxamountperlevel", int.MaxValue);

            var spawnPosTypeStr = prefab.ConfigElement.GetAttributeString("spawntype", "");

            if (string.IsNullOrWhiteSpace(spawnPosTypeStr) ||
                !Enum.TryParse(spawnPosTypeStr, true, out spawnPosType))
            {
                spawnPosType = Level.PositionType.MainPath;
            }

            //backwards compatibility
            if (prefab.ConfigElement.GetAttributeBool("spawndeep", false))
            {
                spawnPosType = Level.PositionType.Abyss;
            }

            spawnPointTag = prefab.ConfigElement.GetAttributeString("spawnpointtag", string.Empty);

            offset  = prefab.ConfigElement.GetAttributeFloat("offset", 0);
            scatter = Math.Clamp(prefab.ConfigElement.GetAttributeFloat("scatter", 500), 0, 3000);

            if (GameMain.NetworkMember != null)
            {
                List <string> monsterNames = GameMain.NetworkMember.ServerSettings.MonsterEnabled.Keys.ToList();
                string        tryKey       = monsterNames.Find(s => speciesName.ToLower() == s.ToLower());

                if (!string.IsNullOrWhiteSpace(tryKey))
                {
                    if (!GameMain.NetworkMember.ServerSettings.MonsterEnabled[tryKey])
                    {
                        disallowed = true; //spawn was disallowed by host
                    }
                }
            }
        }
Example #6
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);
            }
Example #7
0
        public override IEnumerable <ContentFile> GetFilesToPreload()
        {
            string path = CharacterPrefab.FindBySpeciesName(speciesName)?.FilePath;

            if (string.IsNullOrWhiteSpace(path))
            {
                DebugConsole.ThrowError($"Failed to find config file for species \"{speciesName}\"");
                yield break;
            }
            else
            {
                yield return(new ContentFile(path, ContentType.Character));
            }
        }
Example #8
0
        public MonsterMission(MissionPrefab prefab, Location[] locations)
            : base(prefab, locations)
        {
            string speciesName = prefab.ConfigElement.GetAttributeString("monsterfile", null);

            if (!string.IsNullOrEmpty(speciesName))
            {
                var characterPrefab = CharacterPrefab.FindBySpeciesName(speciesName);
                if (characterPrefab != null)
                {
                    int monsterCount = Math.Min(prefab.ConfigElement.GetAttributeInt("monstercount", 1), 255);
                    monsterPrefabs.Add(new Tuple <CharacterPrefab, Point>(characterPrefab, new Point(monsterCount)));
                }
                else
                {
                    DebugConsole.ThrowError($"Error in monster mission \"{prefab.Identifier}\". Could not find a character prefab with the name \"{speciesName}\".");
                }
            }

            maxSonarMarkerDistance = prefab.ConfigElement.GetAttributeFloat("maxsonarmarkerdistance", 10000.0f);

            foreach (var monsterElement in prefab.ConfigElement.GetChildElements("monster"))
            {
                speciesName = monsterElement.GetAttributeString("character", string.Empty);
                int defaultCount = monsterElement.GetAttributeInt("count", -1);
                if (defaultCount < 0)
                {
                    defaultCount = monsterElement.GetAttributeInt("amount", 1);
                }
                int min             = Math.Min(monsterElement.GetAttributeInt("min", defaultCount), 255);
                int max             = Math.Min(Math.Max(min, monsterElement.GetAttributeInt("max", defaultCount)), 255);
                var characterPrefab = CharacterPrefab.FindBySpeciesName(speciesName);
                if (characterPrefab != null)
                {
                    monsterPrefabs.Add(new Tuple <CharacterPrefab, Point>(characterPrefab, new Point(min, max)));
                }
                else
                {
                    DebugConsole.ThrowError($"Error in monster mission \"{prefab.Identifier}\". Could not find a character prefab with the name \"{speciesName}\".");
                }
            }

            if (monsterPrefabs.Any())
            {
                var characterParams = new CharacterParams(monsterPrefabs.First().Item1.FilePath);
                description = description.Replace("[monster]",
                                                  TextManager.Get("character." + characterParams.SpeciesTranslationOverride, returnNull: true) ??
                                                  TextManager.Get("character." + characterParams.SpeciesName));
            }
        }
Example #9
0
        public WanderingMonsterEvent(ScriptedEventPrefab prefab, String speciesNameIn, int amount, int minAmountIn, int maxAmountIn, String spawnTypeStr, bool spawnDeepIn)
            : base(prefab)
        {
            speciesName = speciesNameIn;
            CharacterPrefab characterPrefab = CharacterPrefab.FindByFilePath(speciesName);

            if (characterPrefab != null)
            {
                speciesName = characterPrefab.Identifier;
            }

            if (string.IsNullOrEmpty(speciesName))
            {
                throw new Exception("speciesname is null!");
            }

            int defaultAmount = amount;

            minAmount = minAmountIn;
            maxAmount = Math.Max(maxAmountIn, minAmount);

            offset  = 0;    //Cx change needs looked at
            scatter = 1000; //CX change needs looked at

            String spawnPosTypeStr = spawnTypeStr;

            if (string.IsNullOrWhiteSpace(spawnPosTypeStr) ||
                !Enum.TryParse(spawnPosTypeStr, true, out spawnPosType))
            {
                spawnPosType = Level.PositionType.MainPath;
            }

            spawnDeep = spawnDeepIn;

            if (GameMain.NetworkMember != null)
            {
                List <string> monsterNames = GameMain.NetworkMember.ServerSettings.MonsterEnabled.Keys.ToList();
                string        tryKey       = monsterNames.Find(s => speciesName.ToLower() == s.ToLower());

                if (!string.IsNullOrWhiteSpace(tryKey))
                {
                    if (!GameMain.NetworkMember.ServerSettings.MonsterEnabled[tryKey])
                    {
                        disallowed = true; //spawn was disallowed by host
                    }
                }
            }
        }
Example #10
0
        public MonsterEvent(ScriptedEventPrefab prefab)
            : base(prefab)
        {
            speciesName = prefab.ConfigElement.GetAttributeString("characterfile", "");
            CharacterPrefab characterPrefab = CharacterPrefab.FindByFilePath(speciesName);

            if (characterPrefab != null)
            {
                speciesName = characterPrefab.Identifier;
            }

            if (string.IsNullOrEmpty(speciesName))
            {
                throw new Exception("speciesname is null!");
            }

            int defaultAmount = prefab.ConfigElement.GetAttributeInt("amount", 1);

            minAmount = prefab.ConfigElement.GetAttributeInt("minamount", defaultAmount);
            maxAmount = Math.Max(prefab.ConfigElement.GetAttributeInt("maxamount", 1), minAmount);

            var spawnPosTypeStr = prefab.ConfigElement.GetAttributeString("spawntype", "");

            if (string.IsNullOrWhiteSpace(spawnPosTypeStr) ||
                !Enum.TryParse(spawnPosTypeStr, true, out spawnPosType))
            {
                spawnPosType = Level.PositionType.MainPath;
            }

            spawnDeep = prefab.ConfigElement.GetAttributeBool("spawndeep", false);

            if (GameMain.NetworkMember != null)
            {
                List <string> monsterNames = GameMain.NetworkMember.ServerSettings.MonsterEnabled.Keys.ToList();
                string        tryKey       = monsterNames.Find(s => speciesName.ToLower() == s.ToLower());

                if (!string.IsNullOrWhiteSpace(tryKey))
                {
                    if (!GameMain.NetworkMember.ServerSettings.MonsterEnabled[tryKey])
                    {
                        disallowed = true; //spawn was disallowed by host
                    }
                }
            }
        }
Example #11
0
        public NestMission(MissionPrefab prefab, Location[] locations, Submarine sub)
            : base(prefab, locations, sub)
        {
            itemConfig = prefab.ConfigElement.Element("Items");

            itemSpawnRadius     = prefab.ConfigElement.GetAttributeFloat("itemspawnradius", 800.0f);
            approachItemsRadius = prefab.ConfigElement.GetAttributeFloat("approachitemsradius", itemSpawnRadius * 2.0f);
            monsterSpawnRadius  = prefab.ConfigElement.GetAttributeFloat("monsterspawnradius", approachItemsRadius * 2.0f);

            nestObjectRadius = prefab.ConfigElement.GetAttributeFloat("nestobjectradius", itemSpawnRadius * 2.0f);
            nestObjectAmount = prefab.ConfigElement.GetAttributeInt("nestobjectamount", 10);

            requireDelivery = prefab.ConfigElement.GetAttributeBool("requiredelivery", false);

            string spawnPositionTypeStr = prefab.ConfigElement.GetAttributeString("spawntype", "");

            if (string.IsNullOrWhiteSpace(spawnPositionTypeStr) ||
                !Enum.TryParse(spawnPositionTypeStr, true, out spawnPositionType))
            {
                spawnPositionType = Level.PositionType.Cave | Level.PositionType.Ruin;
            }

            foreach (var monsterElement in prefab.ConfigElement.GetChildElements("monster"))
            {
                string speciesName  = monsterElement.GetAttributeString("character", string.Empty);
                int    defaultCount = monsterElement.GetAttributeInt("count", -1);
                if (defaultCount < 0)
                {
                    defaultCount = monsterElement.GetAttributeInt("amount", 1);
                }
                int min             = Math.Min(monsterElement.GetAttributeInt("min", defaultCount), 255);
                int max             = Math.Min(Math.Max(min, monsterElement.GetAttributeInt("max", defaultCount)), 255);
                var characterPrefab = CharacterPrefab.FindBySpeciesName(speciesName);
                if (characterPrefab != null)
                {
                    monsterPrefabs.Add(new Tuple <CharacterPrefab, Point>(characterPrefab, new Point(min, max)));
                }
                else
                {
                    DebugConsole.ThrowError($"Error in monster mission \"{prefab.Identifier}\". Could not find a character prefab with the name \"{speciesName}\".");
                }
            }
        }
Example #12
0
        public bool Load()
        {
            bool success = base.Load(File);

            if (doc.Root.IsCharacterVariant())
            {
                VariantFile = doc;
                var original = CharacterPrefab.FindBySpeciesName(doc.Root.GetAttributeString("inherit", string.Empty));
                success = Load(original.FilePath);
                CreateSubParams();
                TryLoadOverride(this, VariantFile.Root, SerializableProperties);
                foreach (XElement subElement in VariantFile.Root.Elements())
                {
                    var matchingParams = SubParams.FirstOrDefault(p => p.Name.Equals(subElement.Name.ToString(), StringComparison.OrdinalIgnoreCase));
                    if (matchingParams != null)
                    {
                        TryLoadOverride(matchingParams, subElement, matchingParams.SerializableProperties);
                        // TODO: Make recursive? In practice we don't have to go deeper than this, but the implementation would be a lot cleaner with recursion.
                        foreach (XElement subSubElement in subElement.Elements())
                        {
                            if (subSubElement.Name.ToString().Equals("item", StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }
                            var matchingSubParams = matchingParams.SubParams.FirstOrDefault(p => p.Name.Equals(subSubElement.Name.ToString(), StringComparison.OrdinalIgnoreCase));
                            if (matchingSubParams != null)
                            {
                                TryLoadOverride(matchingSubParams, subSubElement, matchingSubParams.SerializableProperties);
                            }
                        }
                    }
                }
                return(success);
            }
            if (string.IsNullOrEmpty(SpeciesName) && MainElement != null)
            {
                //backwards compatibility
                SpeciesName = MainElement.GetAttributeString("name", "");
            }
            CreateSubParams();
            return(success);
        }
Example #13
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();
        }
Example #14
0
        public MonsterMission(MissionPrefab prefab, Location[] locations)
            : base(prefab, locations)
        {
            monsterFile = prefab.ConfigElement.GetAttributeString("monsterfile", null);

            if (!string.IsNullOrEmpty(monsterFile))
            {
                var characterPrefab = CharacterPrefab.FindByFilePath(monsterFile);
                if (characterPrefab != null)
                {
                    monsterFile = characterPrefab.Identifier;
                }
            }

            maxSonarMarkerDistance = prefab.ConfigElement.GetAttributeFloat("maxsonarmarkerdistance", 10000.0f);

            monsterCount = Math.Min(prefab.ConfigElement.GetAttributeInt("monstercount", 1), 255);
            string monsterFileName = monsterFile;

            foreach (var monsterElement in prefab.ConfigElement.GetChildElements("monster"))
            {
                string monster = monsterElement.GetAttributeString("character", string.Empty);
                if (monsterFileName == null)
                {
                    monsterFileName = monster;
                }
                int defaultCount = monsterElement.GetAttributeInt("count", -1);
                if (defaultCount < 0)
                {
                    defaultCount = monsterElement.GetAttributeInt("amount", 1);
                }
                int min = Math.Min(monsterElement.GetAttributeInt("min", defaultCount), 255);
                int max = Math.Min(Math.Max(min, monsterElement.GetAttributeInt("max", defaultCount)), 255);
                monsterFiles.Add(new Tuple <string, Point>(monster, new Point(min, max)));
            }
            description = description.Replace("[monster]",
                                              TextManager.Get("character." + Barotrauma.IO.Path.GetFileNameWithoutExtension(monsterFileName)));
        }
Example #15
0
        public void PreloadContent(IEnumerable <ContentFile> contentFiles)
        {
            foreach (ContentFile file in contentFiles)
            {
                switch (file.Type)
                {
                case ContentType.Character:
#if CLIENT
                    CharacterPrefab characterPrefab = CharacterPrefab.FindByFilePath(file.Path);
                    if (characterPrefab?.XDocument == null)
                    {
                        throw new Exception($"Failed to load the character config file from {file.Path}!");
                    }
                    var doc         = characterPrefab.XDocument;
                    var rootElement = doc.Root;
                    var mainElement = rootElement.IsOverride() ? rootElement.FirstElement() : rootElement;

                    foreach (var soundElement in mainElement.GetChildElements("sound"))
                    {
                        var sound = Submarine.LoadRoundSound(soundElement);
                    }
                    string speciesName = mainElement.GetAttributeString("speciesname", null);
                    if (string.IsNullOrWhiteSpace(speciesName))
                    {
                        speciesName = mainElement.GetAttributeString("name", null);
                        if (!string.IsNullOrWhiteSpace(speciesName))
                        {
                            DebugConsole.NewMessage($"Error in {file.Path}: 'name' is deprecated! Use 'speciesname' instead.", Color.Orange);
                        }
                        else
                        {
                            throw new Exception($"Species name null in {file.Path}");
                        }
                    }

                    bool          humanoid = mainElement.GetAttributeBool("humanoid", false);
                    RagdollParams ragdollParams;
                    if (humanoid)
                    {
                        ragdollParams = RagdollParams.GetRagdollParams <HumanRagdollParams>(speciesName);
                    }
                    else
                    {
                        ragdollParams = RagdollParams.GetRagdollParams <FishRagdollParams>(speciesName);
                    }
                    if (ragdollParams != null)
                    {
                        HashSet <string> texturePaths = new HashSet <string>
                        {
                            ragdollParams.Texture
                        };
                        foreach (RagdollParams.LimbParams limb in ragdollParams.Limbs)
                        {
                            if (!string.IsNullOrEmpty(limb.normalSpriteParams?.Texture))
                            {
                                texturePaths.Add(limb.normalSpriteParams.Texture);
                            }
                            if (!string.IsNullOrEmpty(limb.deformSpriteParams?.Texture))
                            {
                                texturePaths.Add(limb.deformSpriteParams.Texture);
                            }
                            if (!string.IsNullOrEmpty(limb.damagedSpriteParams?.Texture))
                            {
                                texturePaths.Add(limb.damagedSpriteParams.Texture);
                            }
                            foreach (var decorativeSprite in limb.decorativeSpriteParams)
                            {
                                if (!string.IsNullOrEmpty(decorativeSprite.Texture))
                                {
                                    texturePaths.Add(decorativeSprite.Texture);
                                }
                            }
                        }
                        foreach (string texturePath in texturePaths)
                        {
                            preloadedSprites.Add(new Sprite(texturePath, Vector2.Zero));
                        }
                    }
#endif
                    break;
                }
            }
        }
Example #16
0
        private IEnumerable <object> Load(bool isSeparateThread)
        {
            if (GameSettings.VerboseLogging)
            {
                DebugConsole.NewMessage("LOADING COROUTINE", Color.Lime);
            }

            while (TitleScreen.WaitForLanguageSelection)
            {
                yield return(CoroutineStatus.Running);
            }

            SoundManager = new Sounds.SoundManager();
            SoundManager.SetCategoryGainMultiplier("default", Config.SoundVolume, 0);
            SoundManager.SetCategoryGainMultiplier("ui", Config.SoundVolume, 0);
            SoundManager.SetCategoryGainMultiplier("waterambience", Config.SoundVolume, 0);
            SoundManager.SetCategoryGainMultiplier("music", Config.MusicVolume, 0);
            SoundManager.SetCategoryGainMultiplier("voip", Math.Min(Config.VoiceChatVolume, 1.0f), 0);

            if (Config.EnableSplashScreen && !ConsoleArguments.Contains("-skipintro"))
            {
                var   pendingSplashScreens = TitleScreen.PendingSplashScreens;
                float baseVolume           = MathHelper.Clamp(Config.SoundVolume * 2.0f, 0.0f, 1.0f);
                pendingSplashScreens?.Enqueue(new LoadingScreen.PendingSplashScreen("Content/SplashScreens/Splash_UTG.webm", baseVolume * 0.5f));
                pendingSplashScreens?.Enqueue(new LoadingScreen.PendingSplashScreen("Content/SplashScreens/Splash_FF.webm", baseVolume));
                pendingSplashScreens?.Enqueue(new LoadingScreen.PendingSplashScreen("Content/SplashScreens/Splash_Daedalic.webm", baseVolume * 0.1f));
            }

            //if not loading in a separate thread, wait for the splash screens to finish before continuing the loading
            //otherwise the videos will look extremely choppy
            if (!isSeparateThread)
            {
                while (TitleScreen.PlayingSplashScreen || TitleScreen.PendingSplashScreens.Count > 0)
                {
                    yield return(CoroutineStatus.Running);
                }
            }

            GUI.Init(Window, Config.AllEnabledPackages, GraphicsDevice);
            DebugConsole.Init();

            if (Config.AutoUpdateWorkshopItems)
            {
                Config.WaitingForAutoUpdate = true;
                TaskPool.Add("AutoUpdateWorkshopItemsAsync",
                             SteamManager.AutoUpdateWorkshopItemsAsync(), (task) =>
                {
                    bool result = ((Task <bool>)task).Result;

                    Config.WaitingForAutoUpdate = false;
                });

                while (Config.WaitingForAutoUpdate)
                {
                    yield return(CoroutineStatus.Running);
                }
            }

#if DEBUG
            if (Config.ModBreakerMode)
            {
                Config.SelectCorePackage(ContentPackage.CorePackages.GetRandom());
                foreach (var regularPackage in ContentPackage.RegularPackages)
                {
                    if (Rand.Range(0.0, 1.0) <= 0.5)
                    {
                        Config.EnableRegularPackage(regularPackage);
                    }
                    else
                    {
                        Config.DisableRegularPackage(regularPackage);
                    }
                }
                ContentPackage.SortContentPackages(p =>
                {
                    return(Rand.Int(int.MaxValue));
                });
            }
#endif

            if (Config.AllEnabledPackages.None())
            {
                DebugConsole.Log("No content packages selected");
            }
            else
            {
                DebugConsole.Log("Selected content packages: " + string.Join(", ", Config.AllEnabledPackages.Select(cp => cp.Name)));
            }

#if DEBUG
            GameSettings.ShowUserStatisticsPrompt = false;
            GameSettings.SendUserStatistics       = false;
#endif

            InitUserStats();

            yield return(CoroutineStatus.Running);

            Debug.WriteLine("sounds");

            int i = 0;
            foreach (object crObj in SoundPlayer.Init())
            {
                CoroutineStatus status = (CoroutineStatus)crObj;
                if (status == CoroutineStatus.Success)
                {
                    break;
                }

                i++;
                TitleScreen.LoadState = SoundPlayer.SoundCount == 0 ?
                                        1.0f :
                                        Math.Min(40.0f * i / Math.Max(SoundPlayer.SoundCount, 1), 40.0f);

                yield return(CoroutineStatus.Running);
            }

            TitleScreen.LoadState = 40.0f;
            yield return(CoroutineStatus.Running);

            LightManager = new Lights.LightManager(base.GraphicsDevice, Content);

            TitleScreen.LoadState = 41.0f;
            yield return(CoroutineStatus.Running);

            GUI.LoadContent();
            TitleScreen.LoadState = 42.0f;

            yield return(CoroutineStatus.Running);

            TaskPool.Add("InitRelayNetworkAccess", SteamManager.InitRelayNetworkAccess(), (t) => { });

            FactionPrefab.LoadFactions();
            NPCSet.LoadSets();
            CharacterPrefab.LoadAll();
            MissionPrefab.Init();
            TraitorMissionPrefab.Init();
            MapEntityPrefab.Init();
            Tutorials.Tutorial.Init();
            MapGenerationParams.Init();
            LevelGenerationParams.LoadPresets();
            CaveGenerationParams.LoadPresets();
            OutpostGenerationParams.LoadPresets();
            WreckAIConfig.LoadAll();
            EventSet.LoadPrefabs();
            ItemPrefab.LoadAll(GetFilesOfType(ContentType.Item));
            AfflictionPrefab.LoadAll(GetFilesOfType(ContentType.Afflictions));
            SkillSettings.Load(GetFilesOfType(ContentType.SkillSettings));
            Order.Init();
            EventManagerSettings.Init();
            BallastFloraPrefab.LoadAll(GetFilesOfType(ContentType.MapCreature));
            HintManager.Init();
            TitleScreen.LoadState = 50.0f;
            yield return(CoroutineStatus.Running);

            StructurePrefab.LoadAll(GetFilesOfType(ContentType.Structure));
            TitleScreen.LoadState = 55.0f;
            yield return(CoroutineStatus.Running);

            UpgradePrefab.LoadAll(GetFilesOfType(ContentType.UpgradeModules));
            TitleScreen.LoadState = 56.0f;
            yield return(CoroutineStatus.Running);

            JobPrefab.LoadAll(GetFilesOfType(ContentType.Jobs));
            CorpsePrefab.LoadAll(GetFilesOfType(ContentType.Corpses));

            NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations));

            ItemAssemblyPrefab.LoadAll();
            TitleScreen.LoadState = 60.0f;
            yield return(CoroutineStatus.Running);

            GameModePreset.Init();

            SaveUtil.DeleteDownloadedSubs();
            SubmarineInfo.RefreshSavedSubs();

            TitleScreen.LoadState = 65.0f;
            yield return(CoroutineStatus.Running);

            GameScreen = new GameScreen(GraphicsDeviceManager.GraphicsDevice, Content);

            TitleScreen.LoadState = 68.0f;
            yield return(CoroutineStatus.Running);

            MainMenuScreen   = new MainMenuScreen(this);
            ServerListScreen = new ServerListScreen();

            TitleScreen.LoadState = 70.0f;
            yield return(CoroutineStatus.Running);

#if USE_STEAM
            SteamWorkshopScreen = new SteamWorkshopScreen();
            if (SteamManager.IsInitialized)
            {
                Steamworks.SteamFriends.OnGameRichPresenceJoinRequested += OnInvitedToGame;
                Steamworks.SteamFriends.OnGameLobbyJoinRequested        += OnLobbyJoinRequested;
            }
#endif

            SubEditorScreen = new SubEditorScreen();

            TitleScreen.LoadState = 75.0f;
            yield return(CoroutineStatus.Running);

            ParticleEditorScreen = new ParticleEditorScreen();

            TitleScreen.LoadState = 80.0f;
            yield return(CoroutineStatus.Running);

            LevelEditorScreen     = new LevelEditorScreen();
            SpriteEditorScreen    = new SpriteEditorScreen();
            EventEditorScreen     = new EventEditorScreen();
            CharacterEditorScreen = new CharacterEditor.CharacterEditorScreen();
            CampaignEndScreen     = new CampaignEndScreen();

            yield return(CoroutineStatus.Running);

            TitleScreen.LoadState = 85.0f;
            ParticleManager       = new ParticleManager(GameScreen.Cam);
            ParticleManager.LoadPrefabs();
            TitleScreen.LoadState = 88.0f;
            LevelObjectPrefab.LoadAll();

            TitleScreen.LoadState = 90.0f;
            yield return(CoroutineStatus.Running);

            DecalManager = new DecalManager();
            LocationType.Init();
            MainMenuScreen.Select();

            foreach (string steamError in SteamManager.InitializationErrors)
            {
                new GUIMessageBox(TextManager.Get("Error"), TextManager.Get(steamError));
            }

            TitleScreen.LoadState = 100.0f;
            hasLoaded             = true;
            if (GameSettings.VerboseLogging)
            {
                DebugConsole.NewMessage("LOADING COROUTINE FINISHED", Color.Lime);
            }
            yield return(CoroutineStatus.Success);
        }
Example #17
0
        public void PreloadContent(IEnumerable <ContentFile> contentFiles)
        {
            var filesToPreload = new List <ContentFile>(contentFiles);

            foreach (Submarine sub in Submarine.Loaded)
            {
                if (sub.WreckAI == null)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(sub.WreckAI.Config.DefensiveAgent))
                {
                    var prefab = CharacterPrefab.FindBySpeciesName(sub.WreckAI.Config.DefensiveAgent);
                    if (prefab != null && !filesToPreload.Any(f => f.Path == prefab.FilePath))
                    {
                        filesToPreload.Add(new ContentFile(prefab.FilePath, ContentType.Character));
                    }
                }
                foreach (Item item in Item.ItemList)
                {
                    if (item.Submarine != sub)
                    {
                        continue;
                    }
                    foreach (Items.Components.ItemComponent component in item.Components)
                    {
                        if (component.statusEffectLists == null)
                        {
                            continue;
                        }
                        foreach (var statusEffectList in component.statusEffectLists.Values)
                        {
                            foreach (StatusEffect statusEffect in statusEffectList)
                            {
                                foreach (var spawnInfo in statusEffect.SpawnCharacters)
                                {
                                    var prefab = CharacterPrefab.FindBySpeciesName(spawnInfo.SpeciesName);
                                    if (prefab != null && !filesToPreload.Any(f => f.Path == prefab.FilePath))
                                    {
                                        filesToPreload.Add(new ContentFile(prefab.FilePath, ContentType.Character));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach (ContentFile file in filesToPreload)
            {
                switch (file.Type)
                {
                case ContentType.Character:
#if CLIENT
                    CharacterPrefab characterPrefab = CharacterPrefab.FindByFilePath(file.Path);
                    if (characterPrefab?.XDocument == null)
                    {
                        throw new Exception($"Failed to load the character config file from {file.Path}!");
                    }
                    var doc         = characterPrefab.XDocument;
                    var rootElement = doc.Root;
                    var mainElement = rootElement.IsOverride() ? rootElement.FirstElement() : rootElement;

                    foreach (var soundElement in mainElement.GetChildElements("sound"))
                    {
                        var sound = Submarine.LoadRoundSound(soundElement);
                    }
                    string speciesName = mainElement.GetAttributeString("speciesname", null);
                    if (string.IsNullOrWhiteSpace(speciesName))
                    {
                        speciesName = mainElement.GetAttributeString("name", null);
                        if (!string.IsNullOrWhiteSpace(speciesName))
                        {
                            DebugConsole.NewMessage($"Error in {file.Path}: 'name' is deprecated! Use 'speciesname' instead.", Color.Orange);
                        }
                        else
                        {
                            throw new Exception($"Species name null in {file.Path}");
                        }
                    }

                    bool          humanoid = mainElement.GetAttributeBool("humanoid", false);
                    RagdollParams ragdollParams;
                    if (humanoid)
                    {
                        ragdollParams = RagdollParams.GetRagdollParams <HumanRagdollParams>(speciesName);
                    }
                    else
                    {
                        ragdollParams = RagdollParams.GetRagdollParams <FishRagdollParams>(speciesName);
                    }
                    if (ragdollParams != null)
                    {
                        HashSet <string> texturePaths = new HashSet <string>
                        {
                            ragdollParams.Texture
                        };
                        foreach (RagdollParams.LimbParams limb in ragdollParams.Limbs)
                        {
                            if (!string.IsNullOrEmpty(limb.normalSpriteParams?.Texture))
                            {
                                texturePaths.Add(limb.normalSpriteParams.Texture);
                            }
                            if (!string.IsNullOrEmpty(limb.deformSpriteParams?.Texture))
                            {
                                texturePaths.Add(limb.deformSpriteParams.Texture);
                            }
                            if (!string.IsNullOrEmpty(limb.damagedSpriteParams?.Texture))
                            {
                                texturePaths.Add(limb.damagedSpriteParams.Texture);
                            }
                            foreach (var decorativeSprite in limb.decorativeSpriteParams)
                            {
                                if (!string.IsNullOrEmpty(decorativeSprite.Texture))
                                {
                                    texturePaths.Add(decorativeSprite.Texture);
                                }
                            }
                        }
                        foreach (string texturePath in texturePaths)
                        {
                            preloadedSprites.Add(new Sprite(texturePath, Vector2.Zero));
                        }
                    }
#endif
                    break;
                }
            }
        }
Example #18
0
        public void PreloadContent(IEnumerable <ContentFile> contentFiles)
        {
            var filesToPreload = new List <ContentFile>(contentFiles);

            foreach (Submarine sub in Submarine.Loaded)
            {
                if (sub.WreckAI == null)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(sub.WreckAI.Config.DefensiveAgent))
                {
                    var prefab = CharacterPrefab.FindBySpeciesName(sub.WreckAI.Config.DefensiveAgent);
                    if (prefab != null && !filesToPreload.Any(f => f.Path == prefab.FilePath))
                    {
                        filesToPreload.Add(new ContentFile(prefab.FilePath, ContentType.Character));
                    }
                }
                foreach (Item item in Item.ItemList)
                {
                    if (item.Submarine != sub)
                    {
                        continue;
                    }
                    foreach (Items.Components.ItemComponent component in item.Components)
                    {
                        if (component.statusEffectLists == null)
                        {
                            continue;
                        }
                        foreach (var statusEffectList in component.statusEffectLists.Values)
                        {
                            foreach (StatusEffect statusEffect in statusEffectList)
                            {
                                foreach (var spawnInfo in statusEffect.SpawnCharacters)
                                {
                                    var prefab = CharacterPrefab.FindBySpeciesName(spawnInfo.SpeciesName);
                                    if (prefab != null && !filesToPreload.Any(f => f.Path == prefab.FilePath))
                                    {
                                        filesToPreload.Add(new ContentFile(prefab.FilePath, ContentType.Character));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach (ContentFile file in filesToPreload)
            {
                switch (file.Type)
                {
                case ContentType.Character:
#if CLIENT
                    CharacterPrefab characterPrefab = CharacterPrefab.FindByFilePath(file.Path);
                    if (characterPrefab?.XDocument == null)
                    {
                        throw new Exception($"Failed to load the character config file from {file.Path}!");
                    }
                    var doc         = characterPrefab.XDocument;
                    var rootElement = doc.Root;
                    var mainElement = rootElement.IsOverride() ? rootElement.FirstElement() : rootElement;
                    mainElement.GetChildElements("sound").ForEach(e => Submarine.LoadRoundSound(e));
                    if (!CharacterPrefab.CheckSpeciesName(mainElement, file.Path, out string speciesName))
                    {
                        continue;
                    }
                    bool            humanoid = mainElement.GetAttributeBool("humanoid", false);
                    CharacterPrefab originalCharacter;
                    if (characterPrefab.VariantOf != null)
                    {
                        originalCharacter = CharacterPrefab.FindBySpeciesName(characterPrefab.VariantOf);
                        var originalRoot        = originalCharacter.XDocument.Root;
                        var originalMainElement = originalRoot.IsOverride() ? originalRoot.FirstElement() : originalRoot;
                        originalMainElement.GetChildElements("sound").ForEach(e => Submarine.LoadRoundSound(e));
                        if (!CharacterPrefab.CheckSpeciesName(mainElement, file.Path, out string name))
                        {
                            continue;
                        }
                        speciesName = name;
                        if (mainElement.Attribute("humanoid") == null)
                        {
                            humanoid = originalMainElement.GetAttributeBool("humanoid", false);
                        }
                    }
                    RagdollParams ragdollParams;
                    try
                    {
                        if (humanoid)
                        {
                            ragdollParams = RagdollParams.GetRagdollParams <HumanRagdollParams>(characterPrefab.VariantOf ?? speciesName);
                        }
                        else
                        {
                            ragdollParams = RagdollParams.GetRagdollParams <FishRagdollParams>(characterPrefab.VariantOf ?? speciesName);
                        }
                    }
                    catch (Exception e)
                    {
                        DebugConsole.ThrowError($"Failed to preload a ragdoll file for the character \"{characterPrefab.Name}\"", e);
                        continue;
                    }

                    if (ragdollParams != null)
                    {
                        HashSet <string> texturePaths = new HashSet <string>
                        {
                            ragdollParams.Texture
                        };
                        foreach (RagdollParams.LimbParams limb in ragdollParams.Limbs)
                        {
                            if (!string.IsNullOrEmpty(limb.normalSpriteParams?.Texture))
                            {
                                texturePaths.Add(limb.normalSpriteParams.Texture);
                            }
                            if (!string.IsNullOrEmpty(limb.deformSpriteParams?.Texture))
                            {
                                texturePaths.Add(limb.deformSpriteParams.Texture);
                            }
                            if (!string.IsNullOrEmpty(limb.damagedSpriteParams?.Texture))
                            {
                                texturePaths.Add(limb.damagedSpriteParams.Texture);
                            }
                            foreach (var decorativeSprite in limb.decorativeSpriteParams)
                            {
                                if (!string.IsNullOrEmpty(decorativeSprite.Texture))
                                {
                                    texturePaths.Add(decorativeSprite.Texture);
                                }
                            }
                        }
                        foreach (string texturePath in texturePaths)
                        {
                            preloadedSprites.Add(new Sprite(texturePath, Vector2.Zero));
                        }
                    }
#endif
                    break;
                }
            }
        }
Example #19
0
        public static List <Limb> AttachHuskAppendage(Character character, string afflictionIdentifier, XElement appendageDefinition = null, Ragdoll ragdoll = null)
        {
            var appendage = new List <Limb>();

            if (!(AfflictionPrefab.List.FirstOrDefault(ap => ap.Identifier == afflictionIdentifier) is AfflictionPrefabHusk matchingAffliction))
            {
                DebugConsole.ThrowError($"Could not find an affliction of type 'huskinfection' that matches the affliction '{afflictionIdentifier}'!");
                return(appendage);
            }
            string          nonhuskedSpeciesName = GetNonHuskedSpeciesName(character.SpeciesName, matchingAffliction);
            string          huskedSpeciesName    = GetHuskedSpeciesName(nonhuskedSpeciesName, matchingAffliction);
            CharacterPrefab huskPrefab           = CharacterPrefab.FindBySpeciesName(huskedSpeciesName);

            if (huskPrefab?.XDocument == null)
            {
                DebugConsole.ThrowError($"Failed to find the config file for the husk infected species with the species name '{huskedSpeciesName}'!");
                return(appendage);
            }
            var mainElement = huskPrefab.XDocument.Root.IsOverride() ? huskPrefab.XDocument.Root.FirstElement() : huskPrefab.XDocument.Root;
            var element     = appendageDefinition;

            if (element == null)
            {
                element = mainElement.GetChildElements("huskappendage").FirstOrDefault(e => e.GetAttributeString("affliction", string.Empty).Equals(afflictionIdentifier));
            }
            if (element == null)
            {
                DebugConsole.ThrowError($"Error in '{huskPrefab.FilePath}': Failed to find a huskappendage that matches the affliction with an identifier '{afflictionIdentifier}'!");
                return(appendage);
            }
            string    pathToAppendage = element.GetAttributeString("path", string.Empty);
            XDocument doc             = XMLExtensions.TryLoadXml(pathToAppendage);

            if (doc == null)
            {
                return(appendage);
            }
            if (ragdoll == null)
            {
                ragdoll = character.AnimController;
            }
            if (ragdoll.Dir < 1.0f)
            {
                ragdoll.Flip();
            }
            var limbElements = doc.Root.Elements("limb").ToDictionary(e => e.GetAttributeString("id", null), e => e);

            foreach (var jointElement in doc.Root.Elements("joint"))
            {
                if (limbElements.TryGetValue(jointElement.GetAttributeString("limb2", null), out XElement limbElement))
                {
                    var  jointParams = new RagdollParams.JointParams(jointElement, ragdoll.RagdollParams);
                    Limb attachLimb  = null;
                    if (matchingAffliction.AttachLimbId > -1)
                    {
                        attachLimb = ragdoll.Limbs.FirstOrDefault(l => !l.IsSevered && l.Params.ID == matchingAffliction.AttachLimbId);
                    }
                    else if (matchingAffliction.AttachLimbName != null)
                    {
                        attachLimb = ragdoll.Limbs.FirstOrDefault(l => !l.IsSevered && l.Name == matchingAffliction.AttachLimbName);
                    }
                    else if (matchingAffliction.AttachLimbType != LimbType.None)
                    {
                        attachLimb = ragdoll.Limbs.FirstOrDefault(l => !l.IsSevered && l.type == matchingAffliction.AttachLimbType);
                    }
                    if (attachLimb == null)
                    {
                        attachLimb = ragdoll.Limbs.FirstOrDefault(l => !l.IsSevered && l.Params.ID == jointParams.Limb1);
                    }
                    if (attachLimb != null)
                    {
                        jointParams.Limb1 = attachLimb.Params.ID;
                        var appendageLimbParams = new RagdollParams.LimbParams(limbElement, ragdoll.RagdollParams)
                        {
                            // Ensure that we have a valid id for the new limb
                            ID = ragdoll.Limbs.Length
                        };
                        jointParams.Limb2 = appendageLimbParams.ID;
                        Limb huskAppendage = new Limb(ragdoll, character, appendageLimbParams);
                        huskAppendage.body.Submarine = character.Submarine;
                        huskAppendage.body.SetTransform(attachLimb.SimPosition, attachLimb.Rotation);
                        ragdoll.AddLimb(huskAppendage);
                        ragdoll.AddJoint(jointParams);
                        appendage.Add(huskAppendage);
                    }
                }
            }
            return(appendage);
        }
        protected override void StartMissionSpecific(Level level)
        {
            existingTargets.Clear();
            spawnedTargets.Clear();
            allTargets.Clear();
            if (IsClient)
            {
                return;
            }
            TargetRuin = Level.Loaded?.Ruins?.GetRandom(randSync: Rand.RandSync.Server);
            if (TargetRuin == null)
            {
                DebugConsole.ThrowError($"Failed to initialize an Alien Ruin mission (\"{Prefab.Identifier}\"): level contains no alien ruins");
                return;
            }
            if (targetItemIdentifiers.Length < 1 && targetEnemyIdentifiers.Length < 1)
            {
                DebugConsole.ThrowError($"Failed to initialize an Alien Ruin mission (\"{Prefab.Identifier}\"): no target identifiers set in the mission definition");
                return;
            }
            foreach (var item in Item.ItemList)
            {
                if (!targetItemIdentifiers.Contains(item.Prefab.Identifier))
                {
                    continue;
                }
                if (item.Submarine != TargetRuin.Submarine)
                {
                    continue;
                }
                existingTargets.Add(item);
                allTargets.Add(item);
            }
            int existingEnemyCount = 0;

            foreach (var character in Character.CharacterList)
            {
                if (string.IsNullOrEmpty(character.SpeciesName))
                {
                    continue;
                }
                if (!targetEnemyIdentifiers.Contains(character.SpeciesName.ToLowerInvariant()))
                {
                    continue;
                }
                if (character.Submarine != TargetRuin.Submarine)
                {
                    continue;
                }
                existingTargets.Add(character);
                allTargets.Add(character);
                existingEnemyCount++;
            }
            if (existingEnemyCount < minEnemyCount)
            {
                var enemyPrefabs = new HashSet <CharacterPrefab>();
                foreach (string identifier in targetEnemyIdentifiers)
                {
                    var prefab = CharacterPrefab.FindBySpeciesName(identifier);
                    if (prefab != null)
                    {
                        enemyPrefabs.Add(prefab);
                    }
                    else
                    {
                        DebugConsole.ThrowError($"Error in an Alien Ruin mission (\"{Prefab.Identifier}\"): could not find a character prefab with the species \"{identifier}\"");
                    }
                }
                if (enemyPrefabs.None())
                {
                    DebugConsole.ThrowError($"Error in an Alien Ruin mission (\"{Prefab.Identifier}\"): no enemy species defined that could be used to spawn more ({minEnemyCount - existingEnemyCount}) enemies");
                    return;
                }
                for (int i = 0; i < (minEnemyCount - existingEnemyCount); i++)
                {
                    var prefab   = enemyPrefabs.GetRandom();
                    var spawnPos = TargetRuin.Submarine.GetWaypoints(false).GetRandom(w => w.CurrentHull != null)?.WorldPosition;
                    if (!spawnPos.HasValue)
                    {
                        DebugConsole.ThrowError($"Error in an Alien Ruin mission (\"{Prefab.Identifier}\"): no valid spawn positions could be found for the additional ({minEnemyCount - existingEnemyCount}) enemies to be spawned");
                        return;
                    }
                    var newEnemy = Character.Create(prefab.Identifier, spawnPos.Value, ToolBox.RandomSeed(8), createNetworkEvent: false);
                    spawnedTargets.Add(newEnemy);
                    allTargets.Add(newEnemy);
                }
            }
#if DEBUG
            DebugConsole.NewMessage("********** CLEAR RUIN MISSION INFO **********");
            DebugConsole.NewMessage($"Existing item targets: {existingTargets.Count - existingEnemyCount}");
            DebugConsole.NewMessage($"Existing enemy targets: {existingEnemyCount}");
            DebugConsole.NewMessage($"Spawned enemy targets: {spawnedTargets.Count}");
#endif
        }
Example #21
0
 public AICharacter(CharacterPrefab prefab, string speciesName, Vector2 position, string seed, CharacterInfo characterInfo = null, bool isNetworkPlayer = false, RagdollParams ragdoll = null)
     : base(prefab, speciesName, position, seed, characterInfo, id: Entity.NullEntityID, isRemotePlayer: isNetworkPlayer, ragdollParams: ragdoll)
 {
     InitProjSpecific();
 }