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

View File

@@ -1,12 +1,8 @@
[gd_scene format=3 uid="uid://cmlud1hwkd6sv"]
[ext_resource type="Script" uid="uid://bn7sc6id7n166" path="res://scenes/enemies/Enemy.cs" id="1_q8l7o"]
[ext_resource type="Script" uid="uid://b6y3ugfydvch0" path="res://scenes/components/damage/RDamageModifier.cs" id="2_1bsgx"]
[ext_resource type="Resource" uid="uid://qpdw62ubaclc" path="res://forge/resources/ability_datas/grounded_enemy_hit.tres" id="2_46wn3"]
[ext_resource type="Resource" uid="uid://dg1xbjhyhgnnk" path="res://scenes/enemies/flying_enemy/flying_enemy_health.tres" id="2_ma2bq"]
[ext_resource type="Resource" uid="uid://dgo65k2ceqfvy" path="res://scenes/enemies/flying_enemy/flying_enemy_damage.tres" id="2_on7rt"]
[ext_resource type="Resource" uid="uid://bwqjaom4k7rc3" path="res://scenes/enemies/flying_enemy/flying_enemy_movement.tres" id="4_dejyg"]
[ext_resource type="Script" uid="uid://bjwrpv3jpsc1e" path="res://scenes/components/health/CHealth.cs" id="4_ys4jv"]
[ext_resource type="Script" uid="uid://cxihb42t2mfqi" path="res://addons/forge/nodes/ForgeAttributeSet.cs" id="7_2digf"]
[ext_resource type="Script" uid="uid://rpcbb54q4atx" path="res://forge/ForgeEntityNode.cs" id="7_46wn3"]
[ext_resource type="PackedScene" uid="uid://dmw5ibwrb483f" path="res://scenes/components/movement/CFlyingMovement.tscn" id="7_vaeds"]
@@ -14,7 +10,6 @@
[ext_resource type="Script" uid="uid://ccovd5i0wr3kk" path="res://addons/forge/editor/attributes/AttributeValues.cs" id="8_46wn3"]
[ext_resource type="Resource" uid="uid://bocsykxbh8l0g" path="res://forge/resources/tag_containers/enemy_base_tags.tres" id="8_oj1ws"]
[ext_resource type="Script" uid="uid://dtpxijlnb2c5" path="res://scenes/components/movement/RMovement.cs" id="8_on7rt"]
[ext_resource type="Script" uid="uid://b0u23nkpaimyc" path="res://scenes/components/damage/CDamageable.cs" id="8_uotso"]
[ext_resource type="PackedScene" uid="uid://bctpe34ddamg5" path="res://scenes/components/knockback/CKnockback.tscn" id="10_dejyg"]
[ext_resource type="Resource" uid="uid://dt7a1io5o0b8s" path="res://scenes/enemies/flying_enemy/flying_enemy_knockback.tres" id="11_mpa2u"]
@@ -30,19 +25,9 @@ Default = 1
Min = 1
Max = 100
[sub_resource type="ViewportTexture" id="ViewportTexture_46wn3"]
[sub_resource type="ViewportTexture" id="ViewportTexture_ykkxn"]
viewport_path = NodePath("SubViewport")
[sub_resource type="Resource" id="Resource_jnv07"]
script = ExtResource("2_1bsgx")
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
[sub_resource type="Resource" id="Resource_53j1c"]
script = ExtResource("2_1bsgx")
DamageType = 3
Modifier = 1.0
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
[sub_resource type="Resource" id="Resource_on7rt"]
script = ExtResource("8_on7rt")
Speed = 3.0
@@ -74,9 +59,6 @@ motion_mode = 1
script = ExtResource("1_q8l7o")
HitAbility = ExtResource("2_46wn3")
EnemyHeight = 0.5
RHealth = ExtResource("2_ma2bq")
DeathEffects = Array[Object]([])
RDamage = ExtResource("2_on7rt")
RKnockback = ExtResource("11_mpa2u")
RMovement = ExtResource("4_dejyg")
@@ -114,19 +96,9 @@ InitialAttributeValues = Dictionary[String, ExtResource("8_46wn3")]({
})
metadata/_custom_type_script = "uid://cxihb42t2mfqi"
[node name="CHealth" type="Node" parent="." unique_id=1717035166]
script = ExtResource("4_ys4jv")
RHealth = ExtResource("2_ma2bq")
metadata/_custom_type_script = "uid://bjwrpv3jpsc1e"
[node name="CHealthBar" parent="." unique_id=1635725931 instance=ExtResource("7_ykkxn")]
transform = Transform3D(0.3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.70000005, 0)
texture = SubResource("ViewportTexture_46wn3")
[node name="CDamageable" type="Node" parent="." unique_id=1785297232]
script = ExtResource("8_uotso")
DamageModifiers = Array[Object]([SubResource("Resource_jnv07"), SubResource("Resource_53j1c")])
metadata/_custom_type_script = "uid://b0u23nkpaimyc"
texture = SubResource("ViewportTexture_ykkxn")
[node name="CMovement" parent="." unique_id=1699571730 instance=ExtResource("7_vaeds")]
RMovement = SubResource("Resource_on7rt")

View File

@@ -1,14 +1,9 @@
[gd_scene format=3 uid="uid://dxt0e2ugmttqq"]
[ext_resource type="Script" uid="uid://bn7sc6id7n166" path="res://scenes/enemies/Enemy.cs" id="1_r6506"]
[ext_resource type="Resource" uid="uid://otfc2snh8umc" path="res://scenes/enemies/grounded_enemy/grounded_enemy_damage.tres" id="2_bn56u"]
[ext_resource type="Script" uid="uid://bjwrpv3jpsc1e" path="res://scenes/components/health/CHealth.cs" id="2_gsmti"]
[ext_resource type="Script" uid="uid://b6y3ugfydvch0" path="res://scenes/components/damage/RDamageModifier.cs" id="2_r3cnf"]
[ext_resource type="Resource" uid="uid://bohbojc68j7y1" path="res://scenes/enemies/grounded_enemy/grounded_enemy_health.tres" id="2_w4lm8"]
[ext_resource type="Resource" uid="uid://bqq6uukbdfysr" path="res://scenes/enemies/grounded_enemy/grounded_enemy_movement.tres" id="4_na24f"]
[ext_resource type="Resource" uid="uid://qpdw62ubaclc" path="res://forge/resources/ability_datas/grounded_enemy_hit.tres" id="6_4jf2q"]
[ext_resource type="Script" uid="uid://cxihb42t2mfqi" path="res://addons/forge/nodes/ForgeAttributeSet.cs" id="6_yk4hc"]
[ext_resource type="Script" uid="uid://b0u23nkpaimyc" path="res://scenes/components/damage/CDamageable.cs" id="7_1tw73"]
[ext_resource type="PackedScene" uid="uid://bwx2um43k0ou4" path="res://scenes/components/health/CHealthbar.tscn" id="7_18xwy"]
[ext_resource type="Script" uid="uid://rpcbb54q4atx" path="res://forge/ForgeEntityNode.cs" id="7_f22p3"]
[ext_resource type="PackedScene" uid="uid://dbr7ioio158ew" path="res://scenes/components/movement/CGroundedMovement.tscn" id="7_qyswd"]
@@ -30,20 +25,9 @@ Default = 1
Min = 1
Max = 100
[sub_resource type="ViewportTexture" id="ViewportTexture_4jf2q"]
[sub_resource type="ViewportTexture" id="ViewportTexture_18xwy"]
viewport_path = NodePath("SubViewport")
[sub_resource type="Resource" id="Resource_qj0ob"]
script = ExtResource("2_r3cnf")
Modifier = 1.0
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
[sub_resource type="Resource" id="Resource_18xwy"]
script = ExtResource("2_r3cnf")
DamageType = 3
Modifier = 1.0
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
[sub_resource type="Resource" id="Resource_6d4gl"]
script = ExtResource("8_6d4gl")
Speed = 5.0
@@ -74,9 +58,6 @@ collision_mask = 273
script = ExtResource("1_r6506")
HitAbility = ExtResource("6_4jf2q")
EnemyHeight = 2.0
RHealth = ExtResource("2_w4lm8")
DeathEffects = Array[Object]([])
RDamage = ExtResource("2_bn56u")
RKnockback = ExtResource("11_8k3xb")
RMovement = ExtResource("4_na24f")
@@ -114,19 +95,9 @@ InitialAttributeValues = Dictionary[String, ExtResource("7_x50ya")]({
})
metadata/_custom_type_script = "uid://cxihb42t2mfqi"
[node name="CHealth" type="Node" parent="." unique_id=188153645]
script = ExtResource("2_gsmti")
RHealth = ExtResource("2_w4lm8")
metadata/_custom_type_script = "uid://bjwrpv3jpsc1e"
[node name="CHealthBar" parent="." unique_id=1278247727 instance=ExtResource("7_18xwy")]
transform = Transform3D(0.4, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.2, 0)
texture = SubResource("ViewportTexture_4jf2q")
[node name="CDamageable" type="Node" parent="." unique_id=1601518000]
script = ExtResource("7_1tw73")
DamageModifiers = Array[Object]([SubResource("Resource_qj0ob"), SubResource("Resource_18xwy")])
metadata/_custom_type_script = "uid://b0u23nkpaimyc"
texture = SubResource("ViewportTexture_18xwy")
[node name="CMovement" parent="." unique_id=1080640834 node_paths=PackedStringArray("WallInFrontRayCast") instance=ExtResource("7_qyswd")]
RMovement = SubResource("Resource_6d4gl")