using System; using System.Collections.Generic; using AsteroidGame.Entities; using UnityEngine; namespace AsteroidGame.Handlers { public class PowerHandler : HandlerBase { [Header("State")] [SerializeField] private int _powerConsumption; [SerializeField] private int _powerCapacity; [SerializeField] private float _powerFactor; [Header("Connections")] [SerializeField] private BuildingHandler _buildingHandler; #region Private [SerializeField] private List _activeStructures = new(); #endregion protected override void OnEnable() { base.OnEnable(); _buildingHandler = FindObjectOfType(); _activeStructures = _buildingHandler.GetActiveStructures(); } private void Update() { _powerConsumption = 0; _powerCapacity = 0; foreach (var structure in _activeStructures) { if (structure.IsConsumer) { _powerConsumption += 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() { throw new NotImplementedException(); } public float GetPowerFactor() { throw new NotImplementedException(); } } }