示例#1
0
        internal static void AddGearSpawnInfo(string sceneName, GearSpawnInfo gearSpawnInfo)
        {
            string normalizedSceneName = GetNormalizedSceneName(sceneName);

            if (!gearSpawnInfos.ContainsKey(normalizedSceneName))
            {
                gearSpawnInfos.Add(normalizedSceneName, new List <GearSpawnInfo>());
            }

            List <GearSpawnInfo> sceneGearSpawnInfos = gearSpawnInfos[normalizedSceneName];

            sceneGearSpawnInfos.Add(gearSpawnInfo);
        }
示例#2
0
        internal static float GetAdjustedProbability(GearSpawnInfo gearSpawnInfo)
        {
            if (ModComponentMain.Settings.instance.alwaysSpawnItems)
            {
                return(100f);                                                                 //overrides everything else
            }
            DifficultyLevel     difficultyLevel     = GetDifficultyLevel();
            FirearmAvailability firearmAvailability = GetFirearmAvailability();

            if (SpawnTagManager.ContainsTag(gearSpawnInfo.tag))
            {
                return(SpawnTagManager.GetTaggedFunction(gearSpawnInfo.tag).Invoke(difficultyLevel, firearmAvailability, gearSpawnInfo));
            }
            else
            {
                return(GetAdjustedProbability(difficultyLevel, gearSpawnInfo.SpawnChance));
            }
        }
示例#3
0
        internal static void ProcessLines(string[] lines, string path)
        {
            Logger.Log("Processing spawn file '" + path + "'.");
            string scene     = null;
            string loottable = null;
            string tag       = "none";

            foreach (string eachLine in lines)
            {
                var trimmedLine = GetTrimmedLine(eachLine);
                if (trimmedLine.Length == 0 || trimmedLine.StartsWith("#"))
                {
                    continue;
                }

                var match = SCENE_REGEX.Match(trimmedLine);
                if (match.Success)
                {
                    scene     = match.Groups[1].Value;
                    loottable = null;
                    continue;
                }

                match = TAG_REGEX.Match(trimmedLine);
                if (match.Success)
                {
                    tag = match.Groups[1].Value;
                    Logger.Log("Tag found while reading spawn file. '{0}'", tag);
                    continue;
                }

                match = SPAWN_REGEX.Match(trimmedLine);
                if (match.Success)
                {
                    if (string.IsNullOrEmpty(scene))
                    {
                        PageManager.SetItemPackNotWorking(path, $"No scene name defined before line '{eachLine}' from '{path}'. Did you forget a 'scene = <SceneName>'?");
                        return;
                    }

                    GearSpawnInfo info = new GearSpawnInfo();
                    info.PrefabName = match.Groups[1].Value;

                    info.SpawnChance = ParseFloat(match.Groups[4].Value, 100, eachLine, path);

                    info.Position = ParseVector(match.Groups[2].Value, eachLine, path);
                    info.Rotation = Quaternion.Euler(ParseVector(match.Groups[3].Value, eachLine, path));

                    info.tag = tag + "";

                    GearSpawner.AddGearSpawnInfo(scene, info);
                    continue;
                }

                match = LOOTTABLE_REGEX.Match(trimmedLine);
                if (match.Success)
                {
                    loottable = match.Groups[1].Value;
                    scene     = null;
                    continue;
                }

                match = LOOTTABLE_ENTRY_REGEX.Match(trimmedLine);
                if (match.Success)
                {
                    if (string.IsNullOrEmpty(loottable))
                    {
                        PageManager.SetItemPackNotWorking(path, $"No loottable name defined before line '{eachLine}' from '{path}'. Did you forget a 'loottable = <LootTableName>'?");
                        return;
                    }

                    LootTableEntry entry = new LootTableEntry();
                    entry.PrefabName = match.Groups[1].Value;
                    entry.Weight     = ParseInt(match.Groups[2].Value, 0, eachLine, path);
                    GearSpawner.AddLootTableEntry(loottable, entry);
                    continue;
                }

                //Only runs if nothing matches
                PageManager.SetItemPackNotWorking(path, $"Unrecognized line '{eachLine}' in '{path}'.");
                return;
            }
        }
        private static void ProcessFile(string path)
        {
            string scene     = null;
            string loottable = null;

            string[] lines = File.ReadAllLines(path);
            foreach (string eachLine in lines)
            {
                var trimmedLine = GetTrimmedLine(eachLine);
                if (trimmedLine.Length == 0 || trimmedLine.StartsWith("#"))
                {
                    continue;
                }

                var match = SCENE_REGEX.Match(trimmedLine);
                if (match.Success)
                {
                    scene     = match.Groups[1].Value;
                    loottable = null;
                    continue;
                }

                match = SPAWN_REGEX.Match(trimmedLine);
                if (match.Success)
                {
                    if (string.IsNullOrEmpty(scene))
                    {
                        throw new System.ArgumentException("No scene name defined before line '" + eachLine + "' from '" + path + "'. Did you forget a 'scene = <SceneName>'?");
                    }

                    GearSpawnInfo info = new GearSpawnInfo();
                    info.PrefabName  = match.Groups[1].Value;
                    info.SpawnChance = ParseFloat(match.Groups[4].Value, 100, eachLine, path);
                    info.Position    = ParseVector(match.Groups[2].Value, eachLine, path);
                    info.Rotation    = Quaternion.Euler(ParseVector(match.Groups[3].Value, eachLine, path));

                    GearSpawner.AddGearSpawnInfo(scene, info);
                    continue;
                }

                match = LOOTTABLE_REGEX.Match(trimmedLine);
                if (match.Success)
                {
                    loottable = match.Groups[1].Value;
                    scene     = null;
                    continue;
                }

                match = LOOTTABLE_ENTRY_REGEX.Match(trimmedLine);
                if (match.Success)
                {
                    if (string.IsNullOrEmpty(loottable))
                    {
                        throw new System.ArgumentException("No loottable name defined before line '" + eachLine + "' from '" + path + "'. Did you forget a 'loottable = <LootTableName>'?");
                    }

                    LootTableEntry entry = new LootTableEntry();
                    entry.PrefabName = match.Groups[1].Value;
                    entry.Weight     = ParseInt(match.Groups[2].Value, 0, eachLine, path);
                    GearSpawner.AddLootTableEntry(loottable, entry);
                    continue;
                }

                throw new System.ArgumentException("Unrecognized line '" + eachLine + "' in '" + path + "'.");
            }
        }