Damage dealing through meta attribute and custom exec
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 30s
Create tag and build when new code gets to main / Export (push) Successful in 6m8s

This commit is contained in:
2026-05-03 10:47:56 +02:00
parent 631935fdc8
commit 99f383be00
29 changed files with 453 additions and 143 deletions

View File

@@ -15,6 +15,7 @@ using Godot;
using Movementtests.interfaces;
using Movementtests.systems;
using Movementtests.tools;
using Movementtests.tools.calculators;
using Node = Godot.Node;
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_beetle.png"), Meta(typeof(IAutoNode))]
@@ -132,7 +133,6 @@ public partial class Enemy : CharacterBody3D,
[Node("ForgeEntityNode")] public required ForgeEntityNode ForgeEntity { get; set;}
private AbilityHandle? _hitAbilityHandle;
private EntityAttribute _healthAttribute;
public void OnReady()
{
@@ -144,11 +144,10 @@ public partial class Enemy : CharacterBody3D,
{
CMovement = GetNode<Node>("CMovement") as IMoveable ?? throw new Exception("Movement component not found");
CMovement.RMovement = RMovement;
_healthAttribute = Attributes["EnemyAttributeSet.Health"];
CDamageable = (GetNode<Node>("CDamageable") as IDamageable)!;
CHealth = (GetNode<Node>("CHealth") as IHealthable)!;
CKnockback = (GetNode<Node>("CKnockback") as IKnockbackable)!;
CDamageable = GetNode<Node>("CDamageable") as IDamageable ?? throw new Exception("Damageable component not found");
CHealth = GetNode<Node>("CHealth") as IHealthable ?? throw new Exception("Health component not found");
CKnockback = GetNode<Node>("CKnockback") as IKnockbackable ?? throw new Exception("Knockback component not found");
CHealth.RHealth = RHealth;
CHealth.CurrentHealth = RHealth.StartingHealth;
@@ -156,15 +155,16 @@ public partial class Enemy : CharacterBody3D,
_hitAbilityHandle = Abilities.GrantAbilityPermanently(HitAbility.GetAbilityData(), 1, LevelComparison.None, this);
}
public void OnResolved()
{
HealthBarWrapper.ResourceBar.Init(_healthAttribute);
// CuesManager.RegisterCue(Tag.RequestTag(TagsManager, "cues.enemy.health"), HealthBarWrapper.ResourceBar);
var healthAttribute = Attributes["CharacterAttributeSet.Health"];
HealthBarWrapper.ResourceBar.Init(healthAttribute);
healthAttribute.OnValueChanged += OnHealthChanged;
Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.hit"),
data => {GD.Print("Hit!");});
Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.damage"), OnDamageReceived);
Events.Subscribe<DamageDone>(Tag.RequestTag(TagsManager, "events.combat.damage"), OnDamageReceived);
Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.death"), OnDeath);
}
@@ -216,19 +216,25 @@ public partial class Enemy : CharacterBody3D,
return CMovement is null ? Vector3.Zero : CMovement.ComputeVelocity(inputs);
}
public void OnDamageReceived(EventData data)
public void OnDamageReceived(EventData<DamageDone> data)
{
var newHealth = _healthAttribute.CurrentValue + data.EventMagnitude;
if (newHealth > _healthAttribute.Min) return;
var source = data.Source as Node;
var sourceName = source?.Name ?? "unknown damage dealer";
GD.Print($"Ouch! Fuck you {sourceName}!");
if (data.Payload.OverkillDamage > 0) GD.Print($"Overkill! {data.Payload.OverkillDamage} damage");
}
private void OnHealthChanged(EntityAttribute healthAttribute, int i)
{
if (healthAttribute.CurrentValue > healthAttribute.Min) return;
Events.Raise(new EventData
{
EventTags = Tag.RequestTag(TagsManager, "events.combat.death").GetSingleTagContainer()!,
Source = data.Source,
Target = data.Target
EventTags = Tag.RequestTag(TagsManager, "events.combat.death").GetSingleTagContainer()!
});
}
public void OnDeath(EventData data)
{
// Remove weapon that might be planted there