private void Recharge()
        {
            if (DayNightCycle.main == null || _mono.Manager == null || GetPowerSum() >= GetMaxPower())
            {
                return;
            }

            if (_mono.GetBaseDrainProtection())
            {
                if (GetBasePower() <= _mono.GetBasePowerProtectionGoal())
                {
                    return;
                }
            }

            _passedTime += DayNightCycle.main.deltaTime;

            if (_powerState != FCSPowerStates.Unpowered && _chargeMode == PowerToggleStates.ChargeMode && _passedTime >= 2f)
            {
                float num2 = 0f;
                _passedTime = num2;

                float num3 = DayNightCycle.main.deltaTime * LoadData.BatteryConfiguration.ChargeSpeed * LoadData.BatteryConfiguration.Capacity;
                if (_charge + num3 > LoadData.BatteryConfiguration.Capacity)
                {
                    num3 = LoadData.BatteryConfiguration.Capacity - _charge;
                }
                num2 += num3;

                float num4 = 0f;

                if (num2 > 0f && _connectedRelay.GetPower() > num2)
                {
                    _connectedRelay.ConsumeEnergy(num2, out num4);
                }

                if (num4 > 0f)
                {
                    ChargeBatteries(num4);
                }
            }
        }
Exemplo n.º 2
0
 public virtual void ConsumePower(float amount)
 {
     _connectedRelay.ConsumeEnergy(amount, out float amountConsumed);
     QuickLogger.Debug(amountConsumed.ToString());
 }
Exemplo n.º 3
0
        private void Update()
        {
            if (this.NotAllowToOperate)
            {
                return;
            }

            _energyToConsume = EnergyConsumptionPerSecond * DayNightCycle.main.deltaTime;
            var  batteryChargePull = DayNightCycle.main.deltaTime * chargeSpeed * _powercellData.GetCapacity();
            bool requiresEnergy    = GameModeUtils.RequiresPower();
            bool hasPowerToConsume = !requiresEnergy || (this.AvailablePower >= _energyToConsume);

            if (hasPowerToConsume && !_prevPowerState)
            {
                OnPowerResume?.Invoke();
                _prevPowerState = true;
            }
            else if (!hasPowerToConsume && _prevPowerState)
            {
                OnPowerOutage?.Invoke();
                _prevPowerState = false;
            }

            if (!hasPowerToConsume)
            {
                return;
            }


            if (requiresEnergy)
            {
                if (_connectedRelay.GetPower() <= _energyToConsume)
                {
                    _powercellData.RemoveCharge(_energyToConsume);
                    return;
                }

                if (!GetHasBreakerTripped())
                {
                    _connectedRelay.ConsumeEnergy(_energyToConsume, out float amountConsumed);
                }


                if (!_powercellData.IsFull())
                {
                    if (_connectedRelay.GetPower() >= batteryChargePull)
                    {
                        _chargeTimer -= Time.deltaTime;

                        if (_chargeTimer < 0)
                        {
                            _connectedRelay.ConsumeEnergy(batteryChargePull, out float amountPConsumed);
                            _powercellData.AddCharge(amountPConsumed);
                            QuickLogger.Debug($"Charging Battery: {amountPConsumed} units", true);
                            _chargeTimer = 5f;
                        }
                    }
                }
                //QuickLogger.Debug($"Power Consumed: {amountConsumed}");

                _mono.DisplayManager.UpdateVisuals(_powercellData);
            }
        }