Files
MovementTests/scenes/components/health/CHealth.cs
Minimata cd519e528f
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 55s
Create tag and build when new code gets to main / Test (push) Successful in 7m7s
Create tag and build when new code gets to main / Export (push) Successful in 9m56s
complete project reorganization
2026-02-04 11:20:00 +01:00

36 lines
1018 B
C#

using Godot;
using System;
using Movementtests.interfaces;
[GlobalClass, Icon("res://assets/ui/IconGodotNode/white/icon_heart.png")]
public partial class CHealth : Node, IHealthable
{
public event Action<IHealthable, HealthChangedRecord> 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 HealthChangedRecord ReduceHealth(IDamageable source, DamageRecord damageRecord)
{
var previousHealth = CurrentHealth;
CurrentHealth -= damageRecord.Damage.DamageDealt;
var record = new HealthChangedRecord(CurrentHealth, previousHealth, RHealth.StartingHealth);
HealthChanged?.Invoke(this, record);
if (CurrentHealth <= 0)
{
CurrentHealth = 0;
HealthDepleted?.Invoke(this);
}
return record;
}
}