private static void AddCustomData(string classId, LootDistributionData.SrcData customSrcData, Dictionary <string, LootDistributionData.SrcData> srcDistribution, Dictionary <BiomeType, LootDistributionData.DstData> dstDistribution)
        {
            srcDistribution.Add(classId, customSrcData);

            List <LootDistributionData.BiomeData> distribution = customSrcData.distribution;

            if (distribution != null)
            {
                for (int i = 0; i < distribution.Count; i++)
                {
                    LootDistributionData.BiomeData biomeData = distribution[i];
                    BiomeType biome       = biomeData.biome;
                    int       count       = biomeData.count;
                    float     probability = biomeData.probability;

                    if (!dstDistribution.TryGetValue(biome, out LootDistributionData.DstData dstData))
                    {
                        dstData = new LootDistributionData.DstData
                        {
                            prefabs = new List <LootDistributionData.PrefabData>()
                        };
                        dstDistribution.Add(biome, dstData);
                    }

                    var prefabData = new LootDistributionData.PrefabData
                    {
                        classId     = classId,
                        count       = count,
                        probability = probability
                    };
                    dstData.prefabs.Add(prefabData);
                }
            }
        }
        public void Patch()
        {
            UnlockSprite = GetItemSprite();

            TechType = TechTypeHandler.Main.AddTechType(TechTypeName, FriendlyName, string.Empty, UnlockSprite, false);

            PrefabHandler.Main.RegisterPrefab(this);

            LootDistributionData.SrcData srcData = new LootDistributionData.SrcData()
            {
                prefabPath   = $"{ClassID}_Prefab",
                distribution = GetBiomeDatas()
            };

            LootDistributionHandler.Main.AddLootDistributionData(ClassID, srcData);

            WorldEntityInfo EntityInfo = new WorldEntityInfo()
            {
                classId    = ClassID,
                techType   = TechType,
                slotType   = SlotType,
                prefabZUp  = PrefabZUp,
                cellLevel  = CellLevel,
                localScale = LocalScale
            };

            WorldEntityDatabaseHandler.Main.AddCustomInfo(ClassID, EntityInfo);
        }
        private static void EditExistingData(string classId, LootDistributionData.SrcData existingData, LootDistributionData.SrcData changes, Dictionary <BiomeType, LootDistributionData.DstData> dstData)
        {
            foreach (LootDistributionData.BiomeData customBiomeDist in changes.distribution)
            {
                bool foundBiome = false;

                for (int i = 0; i < existingData.distribution.Count; i++)
                {
                    LootDistributionData.BiomeData biomeDist = existingData.distribution[i];

                    if (customBiomeDist.biome == biomeDist.biome)
                    {
                        biomeDist.count       = customBiomeDist.count;
                        biomeDist.probability = customBiomeDist.probability;

                        foundBiome = true;
                    }
                }

                if (!foundBiome)
                {
                    existingData.distribution.Add(customBiomeDist);
                }

                if (!dstData.TryGetValue(customBiomeDist.biome, out LootDistributionData.DstData biomeDistData))
                {
                    biomeDistData = new LootDistributionData.DstData
                    {
                        prefabs = new List <LootDistributionData.PrefabData>()
                    };
                    dstData.Add(customBiomeDist.biome, biomeDistData);
                }

                bool foundPrefab = false;

                for (int j = 0; j < biomeDistData.prefabs.Count; j++)
                {
                    LootDistributionData.PrefabData prefabData = biomeDistData.prefabs[j];

                    if (prefabData.classId == classId)
                    {
                        prefabData.count       = customBiomeDist.count;
                        prefabData.probability = customBiomeDist.probability;

                        foundPrefab = true;
                    }
                }

                if (!foundPrefab)
                {
                    biomeDistData.prefabs.Add(new LootDistributionData.PrefabData()
                    {
                        classId     = classId,
                        count       = customBiomeDist.count,
                        probability = customBiomeDist.probability
                    });
                }
            }
        }
Esempio n. 4
0
        void ILootDistributionHandler.AddLootDistributionData(string classId, LootDistributionData.SrcData data)
        {
            if (LootDistributionPatcher.CustomSrcData.ContainsKey(classId))
            {
                Logger.Log($"{classId}-{data.prefabPath} already has custom distribution data. Replacing with latest.", LogLevel.Debug);
            }

            LootDistributionPatcher.CustomSrcData[classId] = data;
        }
        private static void InitializePostfix(LootDistributionData __instance)
        {
            foreach (KeyValuePair <string, LootDistributionData.SrcData> entry in CustomSrcData)
            {
                LootDistributionData.SrcData customSrcData = entry.Value;
                string classId = entry.Key;

                if (__instance.srcDistribution.TryGetValue(entry.Key, out LootDistributionData.SrcData srcData))
                {
                    EditExistingData(classId, srcData, customSrcData, __instance.dstDistribution);
                }
                else
                {
                    AddCustomData(classId, customSrcData, __instance.srcDistribution, __instance.dstDistribution);
                }
            }
        }
        void ILootDistributionHandler.EditLootDistributionData(string classId, BiomeType biome, float probability, int count)
        {
            if (!LootDistributionPatcher.CustomSrcData.TryGetValue(classId, out LootDistributionData.SrcData srcData))
            {
                LootDistributionPatcher.CustomSrcData[classId] = (srcData = new LootDistributionData.SrcData());

                var biomeDistribution = new List <LootDistributionData.BiomeData>
                {
                    new LootDistributionData.BiomeData()
                    {
                        biome       = biome,
                        probability = probability,
                        count       = count
                    }
                };

                srcData.distribution = biomeDistribution;

                return;
            }

            for (int i = 0; i < srcData.distribution.Count; i++)
            {
                LootDistributionData.BiomeData distribution = srcData.distribution[i];

                if (distribution.biome == biome)
                {
                    distribution.count       = count;
                    distribution.probability = probability;

                    return;
                }
            }

            // If we reached this point, that means the srcData is present, but the biome in the distribution is not.
            // Lets add it manually.
            srcData.distribution.Add(new LootDistributionData.BiomeData()
            {
                biome       = biome,
                probability = probability,
                count       = count
            });
        }
Esempio n. 7
0
        private IEnumerator PatchAsync()
        {
            while (!SpriteManager.hasInitialized)
            {
                BZLogger.Debug($"{TechTypeName} : Spritemanager is not ready!");
                yield return(null);
            }

            BZLogger.Debug($"{TechTypeName} : Async patch started.");

            UnlockSprite = GetUnlockSprite();

            SpriteHandler.Main.RegisterSprite(TechType, UnlockSprite);

            PrefabHandler.Main.RegisterPrefab(this);

            LootDistributionData.SrcData srcData = new LootDistributionData.SrcData()
            {
                prefabPath   = VirtualPrefabFilename,
                distribution = GetBiomeDatas()
            };

            LootDistributionHandler.Main.AddLootDistributionData(ClassID, srcData);

            WorldEntityInfo EntityInfo = new WorldEntityInfo()
            {
                classId    = ClassID,
                techType   = TechType,
                slotType   = SlotType,
                prefabZUp  = PrefabZUp,
                cellLevel  = CellLevel,
                localScale = LocalScale
            };

            WorldEntityDatabaseHandler.Main.AddCustomInfo(ClassID, EntityInfo);
        }
 /// <summary>
 /// Adds in a custom entry into the Loot Distribution of the game.
 /// You must also add the <see cref="WorldEntityInfo"/> into the <see cref="WorldEntityDatabase"/> using <see cref="WorldEntityDatabaseHandler"/>.
 /// </summary>
 /// <param name="data">The <see cref="LootDistributionData.SrcData"/> that contains data related to the spawning of a prefab, also contains the path to the prefab.</param>
 /// <param name="classId">The classId of the prefab.</param>
 /// <param name="info">The WorldEntityInfo of the prefab. For more information on how to set this up, see <see cref="WorldEntityDatabaseHandler"/>.</param>
 public static void AddLootDistributionData(string classId, LootDistributionData.SrcData data, WorldEntityInfo info)
 {
     Main.AddLootDistributionData(classId, data, info);
 }
        }                                     // Hides constructor

        #region Static Methods

        /// <summary>
        /// Adds in a custom entry into the Loot Distribution of the game.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="classId"></param>
        public static void AddLootDistributionData(string classId, LootDistributionData.SrcData data)
        {
            Main.AddLootDistributionData(classId, data);
        }
 void ILootDistributionHandler.AddLootDistributionData(string classId, LootDistributionData.SrcData data)
 {
     LootDistributionPatcher.CustomSrcData.Add(classId, data);
 }
        /// <summary>
        /// Adds in a custom entry into the Loot Distribution of the game.
        /// You must also add the <see cref="WorldEntityInfo"/> into the <see cref="WorldEntityDatabase"/> using <see cref="WorldEntityDatabaseHandler"/>.
        /// </summary>
        /// <param name="data">The <see cref="LootDistributionData.SrcData"/> that contains data related to the spawning of a prefab, also contains the path to the prefab.</param>
        /// <param name="classId">The classId of the prefab.</param>
        /// <param name="info">The WorldEntityInfo of the prefab. For more information on how to set this up, see <see cref="WorldEntityDatabaseHandler"/>.</param>
        void ILootDistributionHandler.AddLootDistributionData(string classId, LootDistributionData.SrcData data, WorldEntityInfo info)
        {
            Main.AddLootDistributionData(classId, data);

            WorldEntityDatabaseHandler.AddCustomInfo(classId, info);
        }