Compare commits

..

2 Commits

Author SHA1 Message Date
Stedd 87e455827c Fixed weapon debug ray 2024-10-05 19:38:26 +02:00
Stedd bee2db1354 Added simple power loss mechanic
Also added two UI texts to see power consumption and generation
2024-10-05 19:24:11 +02:00
2 changed files with 44 additions and 2 deletions

View File

@ -2,18 +2,59 @@ namespace GameDev.CoreSystems
{
public interface IPowerSystem
{
/// <summary>
/// This entity generates power
/// </summary>
public bool IsGenerator { get; }
/// <summary>
/// This entity consumes power
/// </summary>
public bool IsConsumer { get; }
public void SetMaxPower(int newValue);
/// <summary>
/// True if consumer demand exceed generator capacity
/// </summary>
public bool PowerLost { get; set; }
/// <summary>
/// Initialize the power configuration of the entity with the <see cref="SoPowerConfig"/>
/// </summary>
/// <param name="config">Power config for the entity</param>
public void Initialize(SoPowerConfig config);
/// <summary>
/// Max power for the entity
/// Generator capacity or max consumption depending on
/// the set type <see cref="IsGenerator"/> or <see cref="IsConsumer"/>
/// </summary>
/// <param name="newMaxPowerValue"></param>
public void SetMaxPower(int newMaxPowerValue);
/// <summary>
/// Current power for the entity
/// </summary>
/// <param name="newCurrentPowerValue">current power generated/consumed power for this entity [W]</param>
public void SetCurrentPower(int newCurrentPowerValue);
/// <summary>
/// Get Max power for the entity
/// Generator capacity or max consumption depending on
/// the set type <see cref="IsGenerator"/> or <see cref="IsConsumer"/>
/// </summary>
/// <returns>The max power that can be generated/consumed by this entity [W]</returns>
public int GetMaxPower();
/// <summary>
/// Get current power for the entity.
/// </summary>
/// <returns>The power generated/consumed by this entity right now [W]</returns>
public int GetCurrentPower();
/// <summary>
/// Get the power factor for the entity
/// </summary>
/// <returns>The ratio between current power and max power [factor]</returns>
public float GetPowerFactor();
}
}

View File

@ -27,12 +27,13 @@ namespace GameDev.CoreSystems
var position = BarrelEndPoint.position;
var forward = BarrelEndPoint.forward;
var ray = new Ray(position, forward);
Debug.DrawRay(position, forward * 10, Color.green);
if (Physics.Raycast(ray, out RaycastHit hitInfo))
{
if (hitInfo.transform.TryGetComponent(out Targetable target))
{
Debug.DrawRay(position, forward * Vector3.Distance(position, target.GetCenterPosition()),
Color.red, 0.1f);
target.Damageable.ModifyHealth(Mathf.RoundToInt(-Damage));
}
}