33 lines
731 B
C#
33 lines
731 B
C#
using Godot;
|
|
using System;
|
|
using Movementtests.interfaces;
|
|
|
|
[GlobalClass]
|
|
public partial class CHealth : Node, IHealthable
|
|
{
|
|
public event Action<IHealthable, float> HealthChanged;
|
|
public event Action<IHealthable> HealthDepleted;
|
|
|
|
[Export]
|
|
public RHealth HealthResource;
|
|
|
|
public float CurrentHealth { get; set; }
|
|
|
|
public override void _Ready()
|
|
{
|
|
CurrentHealth = HealthResource.StartingHealth;
|
|
}
|
|
|
|
public void ReduceHealth(IDamageable source, float amount)
|
|
{
|
|
CurrentHealth -= amount;
|
|
HealthChanged?.Invoke(this, CurrentHealth);
|
|
|
|
if (CurrentHealth <= 0)
|
|
{
|
|
CurrentHealth = 0;
|
|
HealthDepleted?.Invoke(this);
|
|
}
|
|
}
|
|
}
|