Files
MovementTests/components/health/CHealth.cs
Minimata 98ed361546
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 17s
Create tag and build when new code gets to main / Export (push) Successful in 9m26s
reorganizing stuff
2026-01-18 17:04:28 +01:00

34 lines
801 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 RHealth { get; set; }
public float CurrentHealth { get; set; }
public override void _Ready()
{
CurrentHealth = RHealth.StartingHealth;
}
public void ReduceHealth(IDamageable source, DamageRecord damageRecord)
{
GD.Print(CurrentHealth);
CurrentHealth -= damageRecord.Damage.DamageDealt;
HealthChanged?.Invoke(this, CurrentHealth);
if (CurrentHealth <= 0)
{
CurrentHealth = 0;
HealthDepleted?.Invoke(this);
}
}
}