added fixed dash targets and can dash towards enemies to hit them, get a knockback or dash through if killed
This commit is contained in:
@@ -11,7 +11,8 @@ public partial class Enemy : CharacterBody3D,
|
||||
IMoveable,
|
||||
ISpawnable,
|
||||
IKnockbackable,
|
||||
ITargetable
|
||||
ITargetable,
|
||||
IStunnable
|
||||
{
|
||||
// Signals and events
|
||||
public event Action<IDamageable, DamageRecord> DamageTaken;
|
||||
@@ -44,10 +45,15 @@ public partial class Enemy : CharacterBody3D,
|
||||
public IMoveable CMovement { get; set; }
|
||||
|
||||
// Public stuff
|
||||
public float CurrentHealth { get; set; }
|
||||
public float CurrentHealth
|
||||
{
|
||||
get => CHealth.CurrentHealth;
|
||||
set => CHealth.CurrentHealth = value;
|
||||
}
|
||||
|
||||
// Private stuff
|
||||
private Area3D _damageBox;
|
||||
private Node3D _target;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -58,6 +64,7 @@ public partial class Enemy : CharacterBody3D,
|
||||
public void Initialize()
|
||||
{
|
||||
_damageBox = GetNode<Area3D>("DamageBox");
|
||||
_target = GetNode<Node3D>("CTarget");
|
||||
|
||||
CDamageable = GetNode<Node>("CDamageable") as IDamageable;
|
||||
CMovement = GetNode<Node>("CMovement") as IMoveable;
|
||||
@@ -106,6 +113,8 @@ public partial class Enemy : CharacterBody3D,
|
||||
|
||||
public void ProcessGameplay(double delta)
|
||||
{
|
||||
if (IsStunned) return;
|
||||
|
||||
var bodies = _damageBox.GetOverlappingBodies();
|
||||
foreach (var body in bodies)
|
||||
{
|
||||
@@ -130,6 +139,14 @@ public partial class Enemy : CharacterBody3D,
|
||||
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 void ReduceHealth(IDamageable source, DamageRecord damageRecord)
|
||||
{
|
||||
if (CHealth is null) return;
|
||||
@@ -160,8 +177,22 @@ public partial class Enemy : CharacterBody3D,
|
||||
|
||||
public Vector3 GetTargetGlobalPosition()
|
||||
{
|
||||
var target = GetNode<Node3D>("CTarget");
|
||||
if (target is null) return GlobalPosition;
|
||||
return target.GlobalPosition;
|
||||
if (_target is null) return GlobalPosition;
|
||||
return _target.GlobalPosition;
|
||||
}
|
||||
|
||||
// Stun management
|
||||
public bool IsStunned { get; set; } = false;
|
||||
|
||||
[Export(PropertyHint.Range, "0.1, 2, 0.1, or_greater")]
|
||||
public float StunDuration { get; set; } = 1f;
|
||||
public void Stun()
|
||||
{
|
||||
IsStunned = true;
|
||||
GetTree().CreateTimer(StunDuration).Timeout += Unstun;
|
||||
}
|
||||
public void Unstun()
|
||||
{
|
||||
IsStunned = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,19 +42,15 @@ albedo_color = Color(0.06469653, 0.06469653, 0.06469653, 1)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_4yfjf"]
|
||||
|
||||
[node name="FlyingEnemy" type="CharacterBody3D" node_paths=PackedStringArray("CHealth", "CDamage", "CKnockback", "CMovement")]
|
||||
[node name="FlyingEnemy" type="CharacterBody3D"]
|
||||
collision_layer = 16
|
||||
collision_mask = 273
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_q8l7o")
|
||||
CHealth = NodePath("CHealth")
|
||||
RHealth = ExtResource("2_ma2bq")
|
||||
DeathEffects = Array[Object]([])
|
||||
CDamage = NodePath("CDamageable")
|
||||
RDamage = ExtResource("2_on7rt")
|
||||
CKnockback = NodePath("CKnockback")
|
||||
RKnockback = ExtResource("11_mpa2u")
|
||||
CMovement = NodePath("CMovement")
|
||||
RMovement = ExtResource("4_dejyg")
|
||||
|
||||
[node name="CHealth" type="Node" parent="."]
|
||||
@@ -74,6 +70,8 @@ TerrainCollision = 256
|
||||
[node name="CKnockback" parent="." instance=ExtResource("10_dejyg")]
|
||||
RKnockback = ExtResource("11_mpa2u")
|
||||
|
||||
[node name="CTarget" type="Marker3D" parent="."]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_b46rq")
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
[sub_resource type="Resource" id="Resource_qj0ob"]
|
||||
script = ExtResource("2_r3cnf")
|
||||
Modifier = 3.0
|
||||
Modifier = 1.0
|
||||
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_6d4gl"]
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_h6jgd")
|
||||
StartingHealth = 10.0
|
||||
metadata/_custom_type_script = "uid://baiapod3csndf"
|
||||
|
||||
Reference in New Issue
Block a user