Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/PlantGrowthSystem.cs
2026-02-21 16:45:37 +08:00

260 lines
5.9 KiB
C#

using UnityEngine;
public class PlantGrowthSystem : MonoBehaviour
{
private UniStormWeatherSystem_C uniStormSystem;
private GameObject uniStormObject;
public GameObject plantObject;
public int UpdateTime;
public float growthAmountX = 0.1f;
public float growthAmountY = 0.1f;
public float growthAmountZ = 0.1f;
public float maxGrowthAmountX = 2f;
public float maxGrowthAmountY = 2f;
public float maxGrowthAmountZ = 2f;
public bool isFullyGrown;
public bool canGrowUsingPrec;
public bool isWaitingUsingPrec;
public bool canGrowUsingSun;
public bool isWaitingUsingSun;
public bool canGrowUsingTemp;
public bool isWaitingUsingTemp;
public int usePrecipitation;
public int rainNeededToGrow = 100;
public int useTemperature;
public int temperatureNeededToGrow = 70;
public int useSunLight;
public float sunLightNeededToGrow = 0.5f;
public int tempRoll;
public int precRoll;
public int sunRoll;
public int seasonInhibitor;
public bool isSeasonallyInhibited;
public bool isTemperatureInhibited;
public int temperatureInhibitor;
public int minTemperature;
public int currentTemperature;
private void Start()
{
uniStormObject = GameObject.Find("UniStormSystemEditor");
uniStormSystem = uniStormObject.GetComponent<UniStormWeatherSystem_C>();
base.transform.rotation = Quaternion.Euler(0f, Random.Range(5, 350), 0f);
}
private void Update()
{
if (!isSeasonallyInhibited && !isFullyGrown && !isTemperatureInhibited)
{
if (usePrecipitation != 11)
{
UsePrecipitation();
}
if (useSunLight != 11)
{
UseSunLight();
}
if (useTemperature != 11)
{
UseTemperature();
}
}
}
private void UseSunLight()
{
if (isFullyGrown)
{
return;
}
if (!isWaitingUsingSun && !canGrowUsingSun && uniStormSystem.sun.intensity >= sunLightNeededToGrow)
{
canGrowUsingSun = true;
}
if (canGrowUsingSun && !isWaitingUsingSun && uniStormSystem.minuteCounter >= 59)
{
CheckSize();
sunRoll = Random.Range(useSunLight, 11);
if (sunRoll == useSunLight)
{
base.transform.localScale = new Vector3(base.transform.localScale.x + growthAmountX, base.transform.localScale.y + growthAmountY, base.transform.localScale.z + growthAmountZ);
isWaitingUsingSun = true;
canGrowUsingSun = false;
sunRoll = 0;
}
}
if (uniStormSystem.minuteCounter <= 1 && isWaitingUsingSun)
{
isWaitingUsingSun = false;
}
if (uniStormSystem.minuteCounter >= 59 && canGrowUsingSun)
{
canGrowUsingSun = false;
}
}
private void UseTemperature()
{
if (isFullyGrown)
{
return;
}
if (!isWaitingUsingTemp && !canGrowUsingTemp && uniStormSystem.temperature >= temperatureNeededToGrow)
{
canGrowUsingTemp = true;
}
if (canGrowUsingTemp && !isWaitingUsingTemp && uniStormSystem.minuteCounter >= 59)
{
CheckSize();
tempRoll = Random.Range(useTemperature, 11);
if (tempRoll == useTemperature)
{
base.transform.localScale = new Vector3(base.transform.localScale.x + growthAmountX, base.transform.localScale.y + growthAmountY, base.transform.localScale.z + growthAmountZ);
isWaitingUsingTemp = true;
canGrowUsingTemp = false;
tempRoll = 0;
}
}
if (uniStormSystem.minuteCounter <= 1 && isWaitingUsingTemp)
{
isWaitingUsingTemp = false;
}
if (uniStormSystem.minuteCounter >= 59 && canGrowUsingTemp)
{
canGrowUsingTemp = false;
}
}
private void UsePrecipitation()
{
if (isFullyGrown)
{
return;
}
if (!isWaitingUsingPrec && !canGrowUsingPrec && uniStormSystem.minRainIntensity >= (float)rainNeededToGrow)
{
canGrowUsingPrec = true;
}
if (canGrowUsingPrec && !isWaitingUsingPrec && uniStormSystem.minuteCounter >= 59)
{
CheckSize();
precRoll = Random.Range(usePrecipitation, 11);
if (precRoll == usePrecipitation)
{
base.transform.localScale = new Vector3(base.transform.localScale.x + growthAmountX, base.transform.localScale.y + growthAmountY, base.transform.localScale.z + growthAmountZ);
isWaitingUsingPrec = true;
canGrowUsingPrec = false;
precRoll = 0;
}
}
if (uniStormSystem.minuteCounter <= 1 && isWaitingUsingPrec)
{
isWaitingUsingPrec = false;
}
if (uniStormSystem.minuteCounter >= 59 && canGrowUsingPrec)
{
canGrowUsingPrec = false;
}
}
private void CheckUniStorm()
{
if (temperatureInhibitor == 0)
{
currentTemperature = uniStormSystem.temperature;
if (currentTemperature < minTemperature)
{
isTemperatureInhibited = true;
}
if (currentTemperature >= minTemperature)
{
isTemperatureInhibited = false;
}
}
if (seasonInhibitor == 0)
{
isSeasonallyInhibited = uniStormSystem.isSpring;
if (!uniStormSystem.isSpring)
{
isSeasonallyInhibited = false;
}
}
if (seasonInhibitor == 1)
{
isSeasonallyInhibited = uniStormSystem.isSummer;
if (!uniStormSystem.isSummer)
{
isSeasonallyInhibited = false;
}
}
if (seasonInhibitor == 2)
{
isSeasonallyInhibited = uniStormSystem.isFall;
if (!uniStormSystem.isFall)
{
isSeasonallyInhibited = false;
}
}
if (seasonInhibitor == 3)
{
isSeasonallyInhibited = uniStormSystem.isWinter;
if (!uniStormSystem.isWinter)
{
isSeasonallyInhibited = false;
}
}
}
private void CheckSize()
{
CheckUniStorm();
if (base.transform.localScale.x >= maxGrowthAmountX)
{
base.transform.localScale = new Vector3(maxGrowthAmountX, base.transform.localScale.y, base.transform.localScale.z);
}
if (base.transform.localScale.y >= maxGrowthAmountY)
{
base.transform.localScale = new Vector3(base.transform.localScale.x, maxGrowthAmountY, base.transform.localScale.z);
}
if (base.transform.localScale.z >= maxGrowthAmountZ)
{
base.transform.localScale = new Vector3(base.transform.localScale.x, base.transform.localScale.y, maxGrowthAmountZ);
}
if (!isFullyGrown && base.transform.localScale.x >= maxGrowthAmountX && base.transform.localScale.y >= maxGrowthAmountY && base.transform.localScale.z >= maxGrowthAmountZ)
{
isFullyGrown = true;
}
}
}