58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using System;
|
|
using AsteroidGame.Entities;
|
|
using UnityEngine;
|
|
|
|
namespace AsteroidGame.Handlers
|
|
{
|
|
public class PowerHandler : HandlerBase
|
|
{
|
|
[Header("State")]
|
|
[SerializeField] private int _powerConsumption;
|
|
[SerializeField] private int _powerConsumptionPeak;
|
|
[SerializeField] private int _powerCapacity;
|
|
[SerializeField] private float _powerFactor;
|
|
|
|
[Header("Connections")]
|
|
[SerializeField] private SPowerBaseRuntimeSet _activePowerStructures;
|
|
|
|
|
|
private void Update()
|
|
{
|
|
_powerConsumption = 0;
|
|
_powerConsumptionPeak = 0;
|
|
_powerCapacity = 0;
|
|
foreach (var structure in _activePowerStructures._list)
|
|
{
|
|
if (structure.IsConsumer)
|
|
{
|
|
_powerConsumption += structure.GetCurrentPower();
|
|
_powerConsumptionPeak += structure.GetMaxPower();
|
|
}
|
|
|
|
if (structure.IsGenerator)
|
|
{
|
|
_powerCapacity += structure.GetMaxPower();
|
|
}
|
|
}
|
|
|
|
if (_powerCapacity > 0)
|
|
{
|
|
_powerFactor = (float)_powerConsumption / _powerCapacity;
|
|
}
|
|
else
|
|
{
|
|
_powerFactor = 0;
|
|
}
|
|
}
|
|
|
|
public int GetMaxPower()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public int GetCurrentPower() => _powerConsumption;
|
|
|
|
public float GetPowerFactor() => _powerFactor;
|
|
|
|
}
|
|
} |