Exemplo n.º 1
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
                    }
                }
            }
        }
Exemplo n.º 2
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
                    }
                }
            }
        }
Exemplo n.º 3
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
                    }
                }
            }
        }
Exemplo n.º 4
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)));
        }
Exemplo n.º 5
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;
                }
            }
        }
Exemplo n.º 6
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;
                }
            }
        }
Exemplo n.º 7
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;
                }
            }
        }