forge friendlier health and damage management

Removed knockback though
This commit is contained in:
2026-04-28 11:22:24 +02:00
parent dcfd937e53
commit ec44306d48
24 changed files with 776 additions and 490 deletions

View File

@@ -1,63 +0,0 @@
using Godot;
using System;
[GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_heart.png")]
public partial class Healthbar : ProgressBar
{
private Timer _damageCatchUpTimer = null!;
private ProgressBar _damagedHealth = null!;
[Export] public StyleBox? BarStyle;
private float _currentHealth;
public float CurrentHealth
{
get => _currentHealth;
set => SetHealth(value);
}
public override void _Ready()
{
_damageCatchUpTimer = GetNode<Timer>("DamageCatchUp");
_damagedHealth = GetNode<ProgressBar>("Damagebar");
_damageCatchUpTimer.Timeout += OnDamageCatchUp;
Visible = false;
if (BarStyle != null)
AddThemeStyleboxOverride("fill", BarStyle);
}
public void Initialize(float initialHealth)
{
_currentHealth = initialHealth;
MaxValue = initialHealth;
Value = initialHealth;
_damagedHealth.MaxValue = initialHealth;
_damagedHealth.Value = initialHealth;
}
public void SetHealth(float newHealth)
{
var previousHealth = _currentHealth;
_currentHealth = Mathf.Min(newHealth, (float) MaxValue);
_currentHealth = newHealth;
Value = _currentHealth;
Visible = _currentHealth < MaxValue;
if (_currentHealth < previousHealth)
{
_damageCatchUpTimer.Start();
}
else
{
_damagedHealth.Value = _currentHealth;
}
}
public void OnDamageCatchUp()
{
_damagedHealth.Value = _currentHealth;
}
}

View File

@@ -0,0 +1,92 @@
using Godot;
using System;
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Gamesmiths.Forge.Attributes;
using Gamesmiths.Forge.Core;
using Gamesmiths.Forge.Cues;
using Gamesmiths.Forge.Godot.Core;
using Gamesmiths.Forge.Tags;
[GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_heart.png"), Meta(typeof(IAutoOn), typeof(IAutoConnect))]
public partial class ResourceBar : ProgressBar, ICueHandler
{
public override void _Notification(int what) => this.Notify(what);
[Node("DamageCatchUp")] public required Timer DamageCatchUp { get; set; }
[Node("Damagebar")] public required ProgressBar DamageBar { get; set; }
[Export] public StyleBox? BarStyle;
private float _currentValue;
public float CurrentValue
{
get => _currentValue;
set => SetValue(value);
}
public void OnReady()
{
DamageCatchUp.Timeout += OnDamageCatchUp;
Visible = false;
if (BarStyle != null)
AddThemeStyleboxOverride("fill", BarStyle);
}
public void Initialize(EntityAttribute attribute, Tag cueTag)
{
_currentValue = attribute.BaseValue;
MaxValue = attribute.Max;
Value = attribute.BaseValue;
DamageBar.MaxValue = attribute.Max;
DamageBar.Value = attribute.BaseValue;
var cuesManager = ForgeManagers.Instance.CuesManager;
cuesManager.RegisterCue(cueTag, this);
}
public void SetValue(float newValue)
{
var previousValue = _currentValue;
_currentValue = Mathf.Min(newValue, (float) MaxValue);
_currentValue = newValue;
Value = _currentValue;
Visible = _currentValue < MaxValue;
if (_currentValue < previousValue)
{
DamageCatchUp.Start();
}
else
{
DamageBar.Value = _currentValue;
}
}
public void OnDamageCatchUp()
{
DamageBar.Value = _currentValue;
}
public void OnExecute(IForgeEntity? target, CueParameters? parameters)
{
if (target == null || !parameters.HasValue) return;
float magnitude = parameters.Value.Magnitude;
CurrentValue += magnitude;
}
public void OnApply(IForgeEntity? target, CueParameters? parameters)
{
}
public void OnRemove(IForgeEntity? target, bool interrupted)
{
}
public void OnUpdate(IForgeEntity? target, CueParameters? parameters)
{
}
}