AsteroidGame/Assets/Entities/Structures/Scripts/StructureBase.cs

86 lines
2.2 KiB
C#

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;
[Header("Configuration")]
[SerializeField] private SStructureBaseRuntimeSet _structureBaseSet;
#region Private
#endregion
#region Publics
public bool IsGenerator => _isGenerator;
public bool IsConsumer => _isConsumer;
public bool BuildPlacementBlocked => _buildPlacementBlocked;
#endregion
protected override void OnEnable()
{
base.OnEnable();
if (!_isConsumer && !_isGenerator)
{
Debug.LogWarning("Power consumer/generator not set!");
}
_structureBaseSet.Add(this);
}
protected override void OnDisable()
{
base.OnDisable();
_structureBaseSet.Remove(this);
}
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
}
}