protected override bool HasAmbientEnergy(ref float ambientEnergyStatus)
        {
            ambientEnergyStatus = 0f;

            if (Cyclops.transform.position.y < -MaxSolarDepth)
            {
                return(false);
            }

            depthRatio = Mathf.Clamp01((MaxSolarDepth + Cyclops.transform.position.y) / MaxSolarDepth);

            DayNightCycle daynightCycle = DayNightCycle.main;

            if (daynightCycle == null)
            {
                return(false);
            }

            lightRatio = daynightCycle.GetLocalLightScalar();

            bool hasEnergy = lightRatio > 0.05f;

            rechargeRatio = depthRatio * lightRatio;

            if (hasEnergy)
            {
                ambientEnergyStatus = rechargeRatio * PercentageMaker;
            }

            return(hasEnergy);
        }
        private void UpdateRecharge()
        {
            if (solarCount > 0)
            {
                DayNightCycle daynight = DayNightCycle.main;
                if (daynight == null)
                {
                    return;
                }
                float num = Mathf.Clamp01((Constants.kMaxSolarChargeDepth + parentVehicle.transform.position.y) / Constants.kMaxSolarChargeDepth);
                float localLightScalar = daynight.GetLocalLightScalar();
                float amount           = Constants.kSeamothSolarChargePerSecond * localLightScalar * num * (float)solarCount;
                parentVehicle.relay.ModifyPower(amount, out float modified);
            }

            if (thermalCount > 0)
            {
                WaterTemperatureSimulation waterSim = WaterTemperatureSimulation.main;
                if (waterSim != null)
                {
                    float temperature = waterSim.GetTemperature(parentVehicle.transform.position);
                    float num         = thermalReactorCharge.Evaluate(temperature) * thermalCount;
                    parentVehicle.relay.ModifyPower(num * Time.deltaTime, out float modified);
                }
            }
        }
        private bool HasAmbientEnergy()
        {
            if (base.Cyclops.transform.position.y < -MaxSolarDepth)
            {
                energyStatus = 0f;
                return(false);
            }

            depthRatio = Mathf.Clamp01((MaxSolarDepth + Cyclops.transform.position.y) / MaxSolarDepth);

            DayNightCycle daynightCycle = DayNightCycle.main;

            if (daynightCycle == null)
            {
                energyStatus = 0f;
                return(false);
            }

            lightRatio = daynightCycle.GetLocalLightScalar();

            bool hasEnergy = lightRatio > MinRequiredLight;

            rechargeRatio = depthRatio * lightRatio;

            if (hasEnergy)
            {
                energyStatus = rechargeRatio * PercentageMaker;
            }

            return(hasEnergy);
        }
Esempio n. 4
0
        private void Update()
        {
            if (!bInitialised)
            {
                return;
            }

            float delta = Time.deltaTime;

            if (delta <= 0f)
            {
                return;
            }

            float power = this.powerSource.GetPower();

            if (power >= this.regenerationThreshhold)
            {
                return;
            }

            DayNightCycle main = DayNightCycle.main;

            if (main == null)
            {
                return;
            }
            //int count = base.modules.GetCount(TechType.SeamothSolarCharge);
            float depthScalar      = Mathf.Clamp01((Constants.kMaxSolarChargeDepth + gameObject.transform.position.y) / Constants.kMaxSolarChargeDepth);
            float localLightScalar = main.GetLocalLightScalar();
            float rechargeAmount   = this.regenerationRate * delta * localLightScalar * depthScalar;

            //Log.LogDebug($"Adding rechargeAmount {rechargeAmount} to solar cell; delta = {delta}, regenerationRate = {this.regenerationRate}, localLightScalar = {localLightScalar}, depthScalar = {depthScalar}");
            this.powerSource.SetPower(Mathf.Min(power + rechargeAmount, this.regenerationThreshhold));
        }
        /// <summary>
        /// Gets the amount of available energy provided by the currently available sunlight.
        /// </summary>
        /// <param name="cyclops">The cyclops.</param>
        /// <returns>The currently available solar energy.</returns>
        private static float GetSolarChargeAmount(ref SubRoot cyclops)
        {
            // The code here mostly replicates what the UpdateSolarRecharge() method does from the SeaMoth class.
            // Consessions were made for the differences between the Seamoth and Cyclops upgrade modules.
            DayNightCycle main = DayNightCycle.main;

            if (main == null)
            {
                return(0f); // Safety check
            }
            // This is 1-to-1 the same way the Seamoth calculates its solar charging rate.
            float proximityToSurface = Mathf.Clamp01((MaxSolarDepth + cyclops.transform.position.y) / MaxSolarDepth);
            float localLightScalar   = main.GetLocalLightScalar();

            return(SolarChargingFactor * localLightScalar * proximityToSurface);
        }
        internal virtual void PreUpdateEnergy(Hoverbike instance = null)
        {
            float deltaTime = Time.deltaTime;

            if (parentHoverbike == null)
            {
                if (instance != null)
                {
                    parentHoverbike = instance;
                }
                else
                {
                    return;
                }
            }

            if (GetModuleCount(techTypeSolarCharger) > 0)
            {
                //if (Main.bVerboseLogging)
                //	Log.LogDebug("Solar charger found in Hoverbike");

                DayNightCycle dayNightCycle = DayNightCycle.main;
                if (dayNightCycle == null)
                {
                    return;
                }

                float depthMultiplier = Mathf.Clamp01((fMaxSolarDepth + parentHoverbike.transform.position.y) / fMaxSolarDepth);
                float lightScalar     = dayNightCycle.GetLocalLightScalar();

                //Log.LogDebug($"Charging Hoverbike battery with depthMultiplier of {depthMultiplier}, lightScalar = {lightScalar}, fSolarChargeMultiplier = {fSolarChargeMultiplier}, and deltaTime of {deltaTime}");
                parentHoverbike.energyMixin.AddEnergy(deltaTime * fSolarChargeMultiplier * depthMultiplier * lightScalar);
            }
            if (bHasSelfRepair)
            {
                if (parentHoverbike.liveMixin.GetHealthFraction() < 1f && parentHoverbike.energyMixin.GetEnergyScalar() > SelfRepairDisableThreshold)
                {
                    parentHoverbike.energyMixin.ConsumeEnergy(SelfRepairEnergyConsumption * deltaTime);
                    parentHoverbike.liveMixin.AddHealth(SelfRepairRate * deltaTime);
                }
            }
        }
Esempio n. 7
0
        private void Update()
        {
            TechType tankSlot = Inventory.main.equipment.GetTechTypeInSlot("Tank");

            if (Player.main.IsSwimming() && GameModeUtils.RequiresOxygen())
            {
                float playerDepth = Ocean.main.GetDepthOf(Player.main.gameObject);
                if ((tankSlot == O2TanksCore.PhotosynthesisSmallID || tankSlot == O2TanksCore.PhotosynthesisTankID) && playerDepth < 200f)
                {
                    if (cachedDayNight == null) // Safety check
                    {
                        cachedDayNight = DayNightCycle.main;
                        return;
                    }
                    float lightScalar = cachedDayNight.GetLocalLightScalar();
                    if (lightScalar > 0.9f)
                    {
                        lightScalar = 0.9f;
                    }
                    float percentage = (200f - playerDepth) / 200f;
                    cachedOxygenManager.AddOxygen(Time.deltaTime * lightScalar * percentage);
                }

                if (tankSlot == O2TanksCore.ChemosynthesisTankID)
                {
                    if (cachedTemp == null) // Safety check
                    {
                        cachedTemp = WaterTemperatureSimulation.main;
                        return;
                    }
                    else
                    {
                        float waterTemp = cachedTemp.GetTemperature(Player.main.transform.position);
                        if (waterTemp > 30f)
                        {
                            float oxygenAdded = waterTemp * Time.deltaTime * .01f;
                            cachedOxygenManager.AddOxygen(oxygenAdded);
                        }
                    }
                }
            }
        }