public override string GetDescription(Amount master, AmountInstance instance) { Growing component = instance.gameObject.GetComponent <Growing>(); if ((Object)component != (Object)null && component.IsGrowing()) { return(string.Format(CREATURES.STATS.MATURITY.AMOUNT_DESC_FMT, master.Name, formatter.GetFormattedValue(ToPercent(instance.value, instance), GameUtil.TimeSlice.None, null), GameUtil.GetFormattedCycles(component.TimeUntilNextHarvest(), "F1"))); } return(base.GetDescription(master, instance)); }
public void ConsumeMass(float mass_to_consume) { float max_maturity; HarvestDesignatable mostMatureBranch = GetMostMatureBranch(out max_maturity); if ((bool)mostMatureBranch) { Growing component = mostMatureBranch.GetComponent <Growing>(); if ((bool)component) { component.ConsumeMass(mass_to_consume); } } }
public override string GetTooltipDescription(Amount master, AmountInstance instance) { string tooltipDescription = base.GetTooltipDescription(master, instance); Growing component = instance.gameObject.GetComponent <Growing>(); if (!component.IsGrowing()) { if (!component.ReachedNextHarvest()) { return(tooltipDescription + CREATURES.STATS.MATURITY.TOOLTIP_STALLED); } return(tooltipDescription + CREATURES.STATS.MATURITY.TOOLTIP_GROWN); } float num = instance.GetMax() - instance.value; float seconds = num / instance.GetDelta(); if ((Object)component != (Object)null && component.IsGrowing()) { return(tooltipDescription + string.Format(CREATURES.STATS.MATURITY.TOOLTIP_GROWING_CROP, GameUtil.GetFormattedCycles(seconds, "F1"), GameUtil.GetFormattedCycles(component.TimeUntilNextHarvest(), "F1"))); } return(tooltipDescription + string.Format(CREATURES.STATS.MATURITY.TOOLTIP_GROWING, GameUtil.GetFormattedCycles(seconds, "F1"))); }
private static bool IsNotNeedTending(Growing growing) { if (growing == null) { return(true); } // todo: сделать опционально if (growing.HasTag(ForestTreeBranchConfig.ID)) // не нужно убобрять отдельные ветки { return(true); } if (growing.HasTag(ForestTreeConfig.ID)) // дерево { if (growing.IsGrown()) { // не нужно убобрять дерево если все ветки выросли // todo: проверить можно ли упростить var buddingTrunk = growing.GetComponent <BuddingTrunk>(); if (buddingTrunk != null) { for (int i = 0; i < ForestTreeConfig.NUM_BRANCHES; i++) { var growingBranch = buddingTrunk.GetBranchAtPosition(i)?.GetComponent <Growing>(); if (growingBranch != null && !growingBranch.IsGrown()) { return(false); } } } return(true); } else { return(false); } } // остальные растения не нужно убобрять если выросли return(growing.IsGrown()); }
/// <summary> /// Applied after OnPrefabInit runs. /// </summary> internal static void Postfix(Growing __instance) { __instance.gameObject.AddOrGet <InstantGrowable>(); }
/// <summary> /// Applied after OnPrefabInit runs. /// </summary> internal static void Postfix(Growing __instance) { __instance.gameObject.AddOrGet <HarvestTrackerComponent>(); }
}; //wilt1, grow_seed public static void ProcessPlant(GameObject plant) { PlantData setting = CustomizePlantsState.StateManager.State.PlantSettings?.FirstOrDefault(t => t.id == plant.name); if (setting == null) { return; } #region decor plant fixes if (setting.fruitId != null) //decor plant fixes { PrickleGrass grass = plant.GetComponent <PrickleGrass>(); if (grass != null || plant.name == ColdBreatherConfig.ID || plant.name == EvilFlowerConfig.ID) { UnityEngine.Object.DestroyImmediate(grass); //what happens if this is null? plant.AddOrGet <StandardCropPlant>(); KPrefabID prefab = plant.GetComponent <KPrefabID>(); prefab.prefabInitFn += (inst => { StandardCropPlant stdcrop2 = inst.GetComponent <StandardCropPlant>(); stdcrop2.anims = PlantHelper.DecorAnim; }); //KBatchedAnimController kbatchedAnimController = plant.AddOrGet<KBatchedAnimController>(); //kbatchedAnimController.AnimFiles = new KAnimFile[1] //{ // Assets.GetAnim("bristleblossom_kanim") //}; //kbatchedAnimController.initialAnim = "idle_empty"; } SeedProducer seed = plant.GetComponent <SeedProducer>(); if (seed != null) { seed.seedInfo.productionType = SeedProducer.ProductionType.Harvest; seed.seedInfo.newSeedsProduced = 1; } } #endregion #region fruitId if (setting.fruitId != null || setting.fruit_grow_time != null || setting.fruit_amount != null) //actual setting fruit { Crop crop = plant.AddOrGet <Crop>(); Crop.CropVal cropval = crop.cropVal; //this is a copy if (setting.fruitId != null) { cropval.cropId = setting.fruitId; } if (cropval.cropId == "") { cropval.cropId = "WoodLog"; } if (setting.fruit_grow_time != null) { cropval.cropDuration = (float)setting.fruit_grow_time; } if (cropval.cropDuration < 1f) { cropval.cropDuration = 1f; } if (setting.fruit_amount != null) { cropval.numProduced = (int)setting.fruit_amount; } if (cropval.numProduced < 1) { cropval.numProduced = 1; } crop.Configure(cropval); KPrefabID prefab = plant.GetComponent <KPrefabID>(); GeneratedBuildings.RegisterWithOverlay(OverlayScreen.HarvestableIDs, prefab.PrefabID().ToString()); Growing growing = plant.AddOrGet <Growing>(); growing.growthTime = cropval.cropDuration; if (setting.id != ForestTreeConfig.ID) // don't harvest arbor trees directly { plant.AddOrGet <Harvestable>(); } plant.AddOrGet <HarvestDesignatable>(); plant.AddOrGet <StandardCropPlant>(); } #endregion #region irrigation if (setting.irrigation != null) { RemoveIrrigation(plant); List <PlantElementAbsorber.ConsumeInfo> irrigation = new List <PlantElementAbsorber.ConsumeInfo>(3); List <PlantElementAbsorber.ConsumeInfo> fertilization = new List <PlantElementAbsorber.ConsumeInfo>(3); foreach (KeyValuePair <string, float> entry in setting.irrigation) { if (GameTags.LiquidElements.Contains(entry.Key)) { irrigation.Add(new PlantElementAbsorber.ConsumeInfo(entry.Key, entry.Value / 600f)); } else if (GameTags.SolidElements.Contains(entry.Key)) { fertilization.Add(new PlantElementAbsorber.ConsumeInfo(entry.Key, entry.Value / 600f)); } else { Debug.Log(ToDialog("Irrigation for " + setting.id + " defines bad element: " + entry.Key)); } } if (irrigation.Count > 0) { EntityTemplates.ExtendPlantToIrrigated(plant, irrigation.ToArray()); } if (fertilization.Count > 0) { EntityTemplates.ExtendPlantToFertilizable(plant, fertilization.ToArray()); } } #endregion #region illumination if (setting.illumination != null) { IlluminationVulnerable illumination = plant.GetComponent <IlluminationVulnerable>(); CropSleepingMonitor.Def cropSleep = plant.GetDef <CropSleepingMonitor.Def>(); if (setting.illumination == 0f) { if (illumination != null) { UnityEngine.Object.DestroyImmediate(illumination); } if (cropSleep != null) { FumLib.FumTools.RemoveDef(plant, cropSleep); } } else if (setting.illumination < 0f) { if (illumination == null) { illumination = plant.AddOrGet <IlluminationVulnerable>(); } if (cropSleep != null) { FumLib.FumTools.RemoveDef(plant, cropSleep); } illumination.SetPrefersDarkness(true); } else if (setting.illumination == 1f) { if (illumination == null) { illumination = plant.AddOrGet <IlluminationVulnerable>(); } if (cropSleep != null) { FumLib.FumTools.RemoveDef(plant, cropSleep); } illumination.SetPrefersDarkness(false); } else { if (illumination != null) { UnityEngine.Object.DestroyImmediate(illumination); } if (cropSleep == null) { cropSleep = plant.AddOrGetDef <CropSleepingMonitor.Def>(); } cropSleep.lightIntensityThreshold = (float)setting.illumination; cropSleep.prefersDarkness = false; } } #endregion #region safe_elements if (setting.safe_elements != null) { plant.GetComponent <KPrefabID>().prefabInitFn += (inst => { PressureVulnerable pressure = inst.GetComponent <PressureVulnerable>(); pressure.safe_atmospheres.Clear(); foreach (string safe_element in setting.safe_elements) { pressure.safe_atmospheres.Add(ElementLoader.FindElementByName(safe_element)); } }); } #endregion #region pressure if (setting.pressures != null) { PressureVulnerable pressure = plant.AddOrGet <PressureVulnerable>(); pressure.pressureLethal_Low = 0f; pressure.pressureWarning_Low = 0f; pressure.pressureWarning_High = float.MaxValue; pressure.pressureLethal_High = float.MaxValue; pressure.pressure_sensitive = false; for (int i = 0; i < setting.pressures.Length; i++) { switch (i) { case 0: pressure.pressureLethal_Low = setting.pressures[i]; pressure.pressure_sensitive = true; break; case 1: pressure.pressureWarning_Low = setting.pressures[i]; break; case 2: pressure.pressureWarning_High = setting.pressures[i]; break; case 3: pressure.pressureLethal_High = setting.pressures[i]; break; } } } #endregion #region decor try { if (setting.decor_value != null) { plant.GetComponent <DecorProvider>().baseDecor = (float)setting.decor_value; } if (setting.decor_radius != null) { plant.GetComponent <DecorProvider>().baseRadius = (float)setting.decor_radius; } } catch (Exception) { Debug.LogWarning("[CustomizePlants] For some weird reason " + plant.name + " has no DecorProvider."); } #endregion #region temperatures if (setting.temperatures != null) { TemperatureVulnerable temperature = plant.AddOrGet <TemperatureVulnerable>(); for (int i = 0; i < setting.temperatures.Length; i++) { switch (i) { case 0: temperature.internalTemperatureLethal_Low = setting.temperatures[i]; break; case 1: temperature.internalTemperatureWarning_Low = setting.temperatures[i]; break; case 2: temperature.internalTemperatureWarning_High = setting.temperatures[i]; break; case 3: temperature.internalTemperatureLethal_High = setting.temperatures[i]; break; } } } #endregion #region submerged_threshold if (setting.submerged_threshold != null) { DrowningMonitor drowning = plant.AddOrGet <DrowningMonitor>(); if (setting.submerged_threshold == 0f) //doesn't care about water { UnityEngine.Object.DestroyImmediate(drowning); } else if (setting.submerged_threshold < 0f) //needs water { drowning.livesUnderWater = true; drowning.canDrownToDeath = false; } else //if(setting.submerged_threshold > 0f) //hates water { drowning.livesUnderWater = false; drowning.canDrownToDeath = false; } } #endregion #region can_tinker if (setting.can_tinker != null) { if (setting.can_tinker == true) { Tinkerable.MakeFarmTinkerable(plant); } } #endregion #region require_solid_tile if (setting.require_solid_tile != null) { UprootedMonitor uproot = plant.AddOrGet <UprootedMonitor>(); if (setting.require_solid_tile == false) { UnityEngine.Object.DestroyImmediate(uproot); } } #endregion #region max_age if (setting.max_age != null && plant.GetComponent <StandardCropPlant>() != null) //only if plant has fruit { Growing growing = plant.AddOrGet <Growing>(); if (setting.max_age <= 0) { growing.shouldGrowOld = false; } else { growing.shouldGrowOld = true; growing.maxAge = (float)setting.max_age; } } #endregion #region disease if (setting.disease != null || setting.disease_amount != null) { DiseaseDropper.Def def = plant.AddOrGetDef <DiseaseDropper.Def>(); if (setting.disease != null) { def.diseaseIdx = Db.Get().Diseases.GetIndex(setting.disease); } if (setting.disease_amount != null) { def.singleEmitQuantity = (int)setting.disease_amount; } if (def.diseaseIdx == byte.MaxValue || def.singleEmitQuantity == 0) { FumLib.FumTools.RemoveDef(plant, def); } } #endregion #region input_element if (setting.input_element != null) { ElementConsumer consumer = plant.AddOrGet <ElementConsumer>(); Element element = ElementLoader.FindElementByName(setting.input_element); if (element == null || element.IsSolid) //invalid element { Debug.Log(ToDialog("input_element is bad element: " + setting.input_element)); UnityEngine.Object.DestroyImmediate(consumer); } else if (setting.input_rate <= 0f) //delete consumer { UnityEngine.Object.DestroyImmediate(consumer); } else { consumer.configuration = ElementConsumer.Configuration.Element; consumer.consumptionRadius = 2; consumer.sampleCellOffset = new Vector3(0f, 0f); consumer.EnableConsumption(true); consumer.showInStatusPanel = true; consumer.storeOnConsume = false; //consumer deletes elements; output_element might overrides this consumer.consumptionRate = (float)setting.input_rate; consumer.elementToConsume = element.id; consumer.capacityKG = (float)setting.input_rate * 10; plant.AddOrGet <Storage>().capacityKg = consumer.capacityKG; plant.AddOrGet <SaltPlant>(); } } #endregion #region output_element if (setting.output_element != null) { ElementConsumer consumer = plant.GetComponent <ElementConsumer>(); ElementConverter converter = plant.AddOrGet <ElementConverter>(); Element element = ElementLoader.FindElementByName(setting.output_element); if (element == null) //invalid element { Debug.Log(ToDialog("output_element is bad element: " + setting.output_element)); UnityEngine.Object.DestroyImmediate(converter); } else if (setting.output_rate <= 0f) //delete converter { UnityEngine.Object.DestroyImmediate(converter); if (consumer != null) { consumer.storeOnConsume = false; } } else { if (consumer != null) //transform elements { consumer.storeOnConsume = true; converter.consumedElements = new ElementConverter.ConsumedElement[1] { new ElementConverter.ConsumedElement(consumer.elementToConsume.CreateTag(), consumer.consumptionRate) }; converter.OutputMultiplier = (float)setting.output_rate / consumer.consumptionRate; //Debug.Log("TAG is: " + consumer.elementToConsume.CreateTag().Name + " SimHash is: " + consumer.elementToConsume.ToString()); } else //create from nothing { converter.consumedElements = new ElementConverter.ConsumedElement[0]; converter.OutputMultiplier = 1f; } converter.outputElements = new ElementConverter.OutputElement[1] { new ElementConverter.OutputElement((float)setting.output_rate, element.id, 0f, true, false, 0f, 1f) }; plant.AddOrGet <Storage>(); plant.AddOrGet <SaltPlant>(); } } #endregion }
public void Refresh() { if (!((UnityEngine.Object)selectedEntity == (UnityEngine.Object)null) && !((UnityEngine.Object)selectedEntity.gameObject == (UnityEngine.Object)null)) { Amounts amounts = selectedEntity.GetAmounts(); Attributes attributes = selectedEntity.GetAttributes(); if (amounts != null && attributes != null) { WiltCondition component = selectedEntity.GetComponent <WiltCondition>(); if ((UnityEngine.Object)component == (UnityEngine.Object)null) { conditionsContainerNormal.gameObject.SetActive(false); conditionsContainerAdditional.gameObject.SetActive(false); foreach (AmountLine amountsLine in amountsLines) { AmountLine current = amountsLine; bool flag = current.TryUpdate(amounts); if (current.go.activeSelf != flag) { current.go.SetActive(flag); } } foreach (AttributeLine attributesLine in attributesLines) { AttributeLine current2 = attributesLine; bool flag2 = current2.TryUpdate(attributes); if (current2.go.activeSelf != flag2) { current2.go.SetActive(flag2); } } } bool flag3 = false; for (int i = 0; i < checkboxLines.Count; i++) { CheckboxLine checkboxLine = checkboxLines[i]; CheckboxLineDisplayType checkboxLineDisplayType = CheckboxLineDisplayType.Hidden; CheckboxLine checkboxLine2 = checkboxLines[i]; if (checkboxLine2.amount != null) { for (int j = 0; j < amounts.Count; j++) { AmountInstance amountInstance = amounts[j]; if (checkboxLine.amount == amountInstance.amount) { checkboxLineDisplayType = checkboxLine.display_condition(selectedEntity.gameObject); break; } } } else { checkboxLineDisplayType = checkboxLine.display_condition(selectedEntity.gameObject); } if (checkboxLineDisplayType != CheckboxLineDisplayType.Hidden) { checkboxLine.locText.SetText(checkboxLine.label_text_func(selectedEntity.gameObject)); if (!checkboxLine.go.activeSelf) { checkboxLine.go.SetActive(true); } GameObject gameObject = checkboxLine.go.GetComponent <HierarchyReferences>().GetReference("Check").gameObject; gameObject.SetActive(checkboxLine.get_value(selectedEntity.gameObject)); if ((UnityEngine.Object)checkboxLine.go.transform.parent != (UnityEngine.Object)checkboxLine.parentContainer) { checkboxLine.go.transform.SetParent(checkboxLine.parentContainer); checkboxLine.go.transform.localScale = Vector3.one; } if ((UnityEngine.Object)checkboxLine.parentContainer == (UnityEngine.Object)conditionsContainerAdditional) { flag3 = true; } if (checkboxLineDisplayType == CheckboxLineDisplayType.Normal) { if (checkboxLine.get_value(selectedEntity.gameObject)) { checkboxLine.locText.color = Color.black; gameObject.transform.parent.GetComponent <Image>().color = Color.black; } else { Color color = new Color(0.992156863f, 0f, 0.101960786f); checkboxLine.locText.color = color; gameObject.transform.parent.GetComponent <Image>().color = color; } } else { checkboxLine.locText.color = Color.grey; gameObject.transform.parent.GetComponent <Image>().color = Color.grey; } } else if (checkboxLine.go.activeSelf) { checkboxLine.go.SetActive(false); } } if ((UnityEngine.Object)component != (UnityEngine.Object)null) { Growing component2 = component.GetComponent <Growing>(); bool flag4 = component.HasTag(GameTags.Decoration); conditionsContainerNormal.gameObject.SetActive(true); conditionsContainerAdditional.gameObject.SetActive(!flag4); if ((UnityEngine.Object)component2 == (UnityEngine.Object)null) { float num = 1f; LocText reference = conditionsContainerNormal.GetComponent <HierarchyReferences>().GetReference <LocText>("Label"); reference.text = string.Empty; reference.text = ((!flag4) ? string.Format(UI.VITALSSCREEN.CONDITIONS_GROWING.WILD_INSTANT.BASE, Util.FormatTwoDecimalPlace(num * 0.25f * 100f)) : string.Format(UI.VITALSSCREEN.CONDITIONS_GROWING.WILD_DECOR.BASE)); reference.GetComponent <ToolTip>().SetSimpleTooltip(string.Format(UI.VITALSSCREEN.CONDITIONS_GROWING.WILD_INSTANT.TOOLTIP)); reference = conditionsContainerAdditional.GetComponent <HierarchyReferences>().GetReference <LocText>("Label"); reference.color = ((!selectedEntity.GetComponent <ReceptacleMonitor>().Replanted) ? Color.grey : Color.black); reference.text = string.Empty; reference.text = string.Format(UI.VITALSSCREEN.CONDITIONS_GROWING.ADDITIONAL_DOMESTIC_INSTANT.BASE, Util.FormatTwoDecimalPlace(num * 100f)); reference.GetComponent <ToolTip>().SetSimpleTooltip(string.Format(UI.VITALSSCREEN.CONDITIONS_GROWING.ADDITIONAL_DOMESTIC_INSTANT.TOOLTIP)); } else { LocText reference = conditionsContainerNormal.GetComponent <HierarchyReferences>().GetReference <LocText>("Label"); reference.text = string.Empty; reference.text = string.Format(UI.VITALSSCREEN.CONDITIONS_GROWING.WILD.BASE, GameUtil.GetFormattedCycles(component.GetComponent <Growing>().WildGrowthTime(), "F1")); reference.GetComponent <ToolTip>().SetSimpleTooltip(string.Format(UI.VITALSSCREEN.CONDITIONS_GROWING.WILD.TOOLTIP, GameUtil.GetFormattedCycles(component.GetComponent <Growing>().WildGrowthTime(), "F1"))); reference = conditionsContainerAdditional.GetComponent <HierarchyReferences>().GetReference <LocText>("Label"); reference.color = ((!selectedEntity.GetComponent <ReceptacleMonitor>().Replanted) ? Color.grey : Color.black); reference.text = string.Empty; reference.text = ((!flag3) ? string.Format(UI.VITALSSCREEN.CONDITIONS_GROWING.DOMESTIC.BASE, GameUtil.GetFormattedCycles(component.GetComponent <Growing>().DomesticGrowthTime(), "F1")) : string.Format(UI.VITALSSCREEN.CONDITIONS_GROWING.ADDITIONAL_DOMESTIC.BASE, GameUtil.GetFormattedCycles(component.GetComponent <Growing>().DomesticGrowthTime(), "F1"))); reference.GetComponent <ToolTip>().SetSimpleTooltip(string.Format(UI.VITALSSCREEN.CONDITIONS_GROWING.ADDITIONAL_DOMESTIC.TOOLTIP, GameUtil.GetFormattedCycles(component.GetComponent <Growing>().DomesticGrowthTime(), "F1"))); } foreach (AmountLine amountsLine2 in amountsLines) { AmountLine current3 = amountsLine2; current3.go.SetActive(false); } foreach (AttributeLine attributesLine2 in attributesLines) { AttributeLine current4 = attributesLine2; current4.go.SetActive(false); } } } } }
public static GameObject ExtendEntityToBasicPlant(GameObject template, float temperature_lethal_low = 218.15f, float temperature_warning_low = 283.15f, float temperature_warning_high = 303.15f, float temperature_lethal_high = 398.15f, SimHashes[] safe_elements = null, bool pressure_sensitive = true, float pressure_lethal_low = 0f, float pressure_warning_low = 0.15f, string crop_id = null, bool can_drown = true, bool can_tinker = true, bool require_solid_tile = true, bool should_grow_old = true, float max_age = 2400f) { template.AddOrGet <EntombVulnerable>(); PressureVulnerable pressureVulnerable = template.AddOrGet <PressureVulnerable>(); if (pressure_sensitive) { PressureVulnerable pressureVulnerable2 = pressureVulnerable; SimHashes[] safeAtmospheres = safe_elements; pressureVulnerable2.Configure(pressure_warning_low, pressure_lethal_low, 10f, 30f, safeAtmospheres); } else { pressureVulnerable.Configure(safe_elements); } template.AddOrGet <WiltCondition>(); template.AddOrGet <Prioritizable>(); template.AddOrGet <Uprootable>(); if (require_solid_tile) { template.AddOrGet <UprootedMonitor>(); } template.AddOrGet <ReceptacleMonitor>(); template.AddOrGet <Notifier>(); if (can_drown) { template.AddOrGet <DrowningMonitor>(); } TemperatureVulnerable temperatureVulnerable = template.AddOrGet <TemperatureVulnerable>(); temperatureVulnerable.Configure(temperature_warning_low, temperature_lethal_low, temperature_warning_high, temperature_lethal_high); template.AddOrGet <OccupyArea>().objectLayers = new ObjectLayer[1] { ObjectLayer.Building }; KPrefabID component = template.GetComponent <KPrefabID>(); if (crop_id != null) { GeneratedBuildings.RegisterWithOverlay(OverlayScreen.HarvestableIDs, component.PrefabID().ToString()); Crop.CropVal cropval = CROPS.CROP_TYPES.Find((Crop.CropVal m) => m.cropId == crop_id); Crop crop = template.AddOrGet <Crop>(); crop.Configure(cropval); Growing growing = template.AddOrGet <Growing>(); growing.growthTime = cropval.cropDuration; growing.shouldGrowOld = should_grow_old; growing.maxAge = max_age; template.AddOrGet <Harvestable>(); template.AddOrGet <HarvestDesignatable>(); } component.prefabInitFn += delegate(GameObject inst) { PressureVulnerable component2 = inst.GetComponent <PressureVulnerable>(); if (safe_elements != null) { SimHashes[] array = safe_elements; foreach (SimHashes hash in array) { component2.safe_atmospheres.Add(ElementLoader.FindElementByHash(hash)); } } }; if (can_tinker) { Tinkerable.MakeFarmTinkerable(template); } return(template); }