Example #1
0
        public static void Prefix(WaterParkCreature __instance)
        {
            if ((__instance.GetComponent <LiveMixin>()?.IsAlive() ?? false) && Main.config.CreaturePowerGeneration.TryGetValue(__instance?.pickupable?.GetTechType() ?? TechType.None, out float powerValue))
            {
                if (!timeLastGenerated.TryGetValue(__instance, out float time))
                {
                    time = DayNightCycle.main.timePassedAsFloat;
                }

                float       power       = powerValue * (DayNightCycle.main.timePassedAsFloat - time) * Main.config.PowerGenSpeed;
                PowerSource powerSource = __instance?.GetWaterPark()?.itemsRoot?.gameObject?.GetComponent <PowerSource>();

                if (powerSource != null)
                {
                    if (!powerSource.AddEnergy(power, out float amountStored))
                    {
                        powerSource.connectedRelay?.AddEnergy(power - amountStored, out _);
                    }
                }

                timeLastGenerated[__instance] = DayNightCycle.main.timePassedAsFloat;
            }
        }