removed obsolete interfaces for health and damage
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 27s
Create tag and build when new code gets to main / Export (push) Successful in 5m25s

This commit is contained in:
2026-05-05 11:51:35 +02:00
parent 33f55d04f3
commit 68e36742af
41 changed files with 37 additions and 703 deletions

View File

@@ -21,8 +21,6 @@ using Node = Godot.Node;
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_beetle.png"), Meta(typeof(IAutoNode))]
public partial class Enemy : CharacterBody3D,
IDamageable,
IHealthable,
IKillable,
IMoveable,
ISpawnable,
@@ -40,15 +38,6 @@ public partial class Enemy : CharacterBody3D,
[Dependency]
public CuesManager CuesManager => this.DependOn<CuesManager>();
#endregion
#region Signals
// Signals and events
public event Action<IDamageable, DamageRecord> DamageTaken = null!;
public event Action<IHealthable, HealthChangedRecord> HealthChanged = null!;
public event Action<IHealthable> HealthDepleted = null!;
#endregion
#region Inspector
@@ -57,25 +46,14 @@ public partial class Enemy : CharacterBody3D,
[Export]
public Node3D? Target { get; set; }
[Export] public required ForgeAbilityData HitAbility { get; set; }
[Export]
public float EnemyHeight { get; set; } = 1f;
[ExportGroup("Health")]
[Export]
public RHealth RHealth { get; set; } = null!;
[Export]
public RDeathEffect[] DeathEffects { get; set; } = null!;
public IHealthable CHealth { get; set; } = null!;
[ExportGroup("Damage")]
[Export]
public RDamage? RDamage { get; set; }
public IDamageable CDamageable { get; set; } = null!;
public RDeathEffect[] DeathEffects { get; set; } = [];
[Export]
public RKnockback? RKnockback { get; set; }
public IKnockbackable CKnockback { get; set; } = null!;
public IKnockbackable? CKnockback { get; set; }
[ExportGroup("Movement")]
[Export]
@@ -84,13 +62,6 @@ public partial class Enemy : CharacterBody3D,
#endregion
// Public stuff
public float CurrentHealth
{
get => CHealth.CurrentHealth;
set => CHealth.CurrentHealth = value;
}
#region IForgeEntity
// Perfectly forward the IForgeEntity interface to the ForgeEntity component
@@ -145,13 +116,7 @@ public partial class Enemy : CharacterBody3D,
{
CMovement = GetNode<Node>("CMovement") as IMoveable ?? throw new Exception("Movement component not found");
CMovement.RMovement = RMovement;
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;
CKnockback.RKnockback = RKnockback;
_hitAbilityHandle = Abilities.GrantAbilityPermanently(HitAbility.GetAbilityData(), 1, LevelComparison.None, this);
@@ -177,10 +142,6 @@ public partial class Enemy : CharacterBody3D,
public void SetupSignals()
{
// Anonymous function call to erase return values of ReduceHealth
// CDamageable.DamageTaken += (source, record) => ReduceHealth(source, record);
// CDamageable.DamageTaken += (_, record) => RegisterKnockback(new KnockbackRecord(record));
// CHealth.HealthDepleted += Kill;
}
public override void _PhysicsProcess(double delta)
@@ -220,7 +181,7 @@ public partial class Enemy : CharacterBody3D,
public Vector3 ComputeVelocity(MovementInputs inputs)
{
return CMovement is null ? Vector3.Zero : CMovement.ComputeVelocity(inputs);
return CMovement.ComputeVelocity(inputs);
}
public void OnDamageReceived(EventData<DamageDone> data)
@@ -244,46 +205,10 @@ public partial class Enemy : CharacterBody3D,
public void OnDeath(EventData data)
{
// Remove weapon that might be planted there
foreach (var child in GetChildren())
{
if (child is not WeaponSystem system) continue;
CallDeferred(Node.MethodName.RemoveChild, system);
GetTree().GetRoot().CallDeferred(Node.MethodName.AddChild, system);
system.CallDeferred(Node3D.MethodName.SetGlobalPosition, GlobalPosition + Vector3.Up*EnemyHeight);
system.CallDeferred(WeaponSystem.MethodName.RethrowWeapon);
}
CallDeferred(Node.MethodName.QueueFree);
Kill();
}
public DamageRecord TakeDamage(DamageRecord damageRecord)
{
if (CDamageable is null)
return damageRecord with { Damage = new RDamage(0, damageRecord.Damage.DamageType) };
var finalDamage = CDamageable.TakeDamage(damageRecord);
DamageTaken?.Invoke(this, finalDamage);
return finalDamage;
}
public DamageRecord ComputeDamage(DamageRecord damageRecord)
{
if (CDamageable is null)
return damageRecord with { Damage = new RDamage(0, damageRecord.Damage.DamageType) };
return CDamageable.ComputeDamage(damageRecord);
}
public HealthChangedRecord ReduceHealth(IDamageable source, DamageRecord damageRecord)
{
if (CHealth is null) return new HealthChangedRecord(0, 0, 0);
var record = CHealth.ReduceHealth(source, damageRecord);
HealthChanged?.Invoke(this, record);
return record;
}
public void Kill(IHealthable source)
public void Kill()
{
// Remove weapon that might be planted there
foreach (var child in GetChildren())
@@ -299,24 +224,24 @@ public partial class Enemy : CharacterBody3D,
foreach (var killable in DeathEffects.ToIKillables())
{
killable.Kill(source);
killable.Kill();
}
CallDeferred(Node.MethodName.QueueFree);
}
public void RegisterKnockback(KnockbackRecord knockbackRecord)
{
CKnockback.RegisterKnockback(knockbackRecord);
CKnockback!.RegisterKnockback(knockbackRecord);
}
public Vector3 ComputeKnockback()
{
return CKnockback.ComputeKnockback();
return CKnockback!.ComputeKnockback();
}
public Vector3 GetTargetGlobalPosition()
{
return TargetComponent == null ? GlobalPosition : TargetComponent.GlobalPosition;
return TargetComponent.GlobalPosition;
}
// Stun management