using AsteroidGame.Interfaces; using UnityEngine; namespace AsteroidGame.Entities { public class StructureBase : EntityBase, IBuildable, IPowerSystem { [Header("BuildParameters")] [SerializeField] protected int _cost; [SerializeField] private bool _buildPlacementBlocked; [SerializeField] protected float _buildTimer; [Header("Power")] [SerializeField] protected bool _isGenerator; [SerializeField] protected bool _isConsumer; [SerializeField] protected int _maxPower; [SerializeField] protected int _currentPower; #region Private #endregion #region Publics public bool IsGenerator => _isGenerator; public bool IsConsumer => _isConsumer; public bool BuildPlacementBlocked => _buildPlacementBlocked; #endregion private void OnEnable() { if (!_isConsumer && !_isGenerator) { Debug.LogWarning("Power consumer/generator not set!"); } } private void OnTriggerStay(Collider other) { if (other.name == "BuildCollider") { _buildPlacementBlocked = true; } } private void OnTriggerExit(Collider other) { if (other.name == "BuildCollider") { _buildPlacementBlocked = false; } } #region Setters public void SetMaxPower(int newValue) => _maxPower = newValue; public int SetCost(int newCost) => _cost = newCost; #endregion #region Getters public int GetMaxPower() => _maxPower; public int GetCurrentPower() => _currentPower; public float GetPowerFactor() => (float)_currentPower / _maxPower; public int GetCost() => _cost; #endregion } }