Ejemplo n.º 1
0
        internal static float _CommonalityOfPlant(this BiomeDef _this, ThingDef plantDef)
        {
            var cachedPlantCommonalities = _this.cachedPlantCommonalities();

            if (cachedPlantCommonalities == null)
            {
                cachedPlantCommonalities = new Dictionary <ThingDef, float>();
                for (int i = 0; i < _this.wildPlants().Count; i++)
                {
                    cachedPlantCommonalities.Add(_this.wildPlants()[i].plant, _this.wildPlants()[i].commonality);
                }
                foreach (ThingDef current in DefDatabase <ThingDef> .AllDefs)
                {
                    if (current.plant != null && current.plant.wildBiomes != null)
                    {
                        for (int index = 0; index < current.plant.wildBiomes.Count; ++index)
                        {
                            if (current.plant.wildBiomes[index].biome.defName == _this.defName)
                            {
                                cachedPlantCommonalities.Add(current.plant.wildBiomes[index].plant, current.plant.wildBiomes[index].commonality);
                            }
                        }
                    }
                }
                _this.cachedPlantCommonalitiesSet(cachedPlantCommonalities);
            }
            float result;

            if (cachedPlantCommonalities.TryGetValue(plantDef, out result))
            {
                return(result);
            }
            return(0f);
        }