diff --git a/src/combat/Hurtbox.cs b/src/combat/Hurtbox.cs new file mode 100644 index 0000000..779d581 --- /dev/null +++ b/src/combat/Hurtbox.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; + +namespace Dancer; + +[Meta(typeof(IAutoNode)), Tool] +public sealed partial class Hurtbox : Area2D, IAttackable +{ + public override void _Notification(int what) => this.Notify(what); + + [Dependency] + private IHurtboxOwner HurtboxOwner => this.DependOn(() => new DummyHurtboxOwner()); + + [Export(PropertyHint.None, "suffix:s")] + private float LocalImmunity { get; set; } + [Export] + private int LocalCountLimit { get; set; } = 1; + + public delegate void AttackedEventHandler(Hurtbox hurtbox, in Attack attack); + public event AttackedEventHandler? Attacked; + + public void OnReady() { } + + public void OnResolved() => HurtboxOwner.OnHurtboxAdded(this); + + public void OnExitTree() => HurtboxOwner.OnHurtboxRemoved(this); + + public void GetAttacked(in Attack attack) => Attacked?.Invoke(this, in attack); +} + +public interface IHurtboxOwner +{ + public void OnHurtboxAdded(Hurtbox hurtbox); + public void OnHurtboxRemoved(Hurtbox hurtbox); +} + +public class DummyHurtboxOwner : IHurtboxOwner +{ + public void OnHurtboxAdded(Hurtbox hurtbox) + { + } + + public void OnHurtboxRemoved(Hurtbox hurtbox) + { + } +} diff --git a/src/combat/Hurtbox.cs.uid b/src/combat/Hurtbox.cs.uid new file mode 100644 index 0000000..191de77 --- /dev/null +++ b/src/combat/Hurtbox.cs.uid @@ -0,0 +1 @@ +uid://b4k42r866lkut diff --git a/src/combat/hurtbox.tscn b/src/combat/hurtbox.tscn new file mode 100644 index 0000000..276a7fa --- /dev/null +++ b/src/combat/hurtbox.tscn @@ -0,0 +1,12 @@ +[gd_scene format=3 uid="uid://b02xxaidgagux"] + +[ext_resource type="Script" uid="uid://b4k42r866lkut" path="res://src/combat/Hitbox.cs" id="1_chyeu"] + +[node name="Hurtbox" type="Area2D" unique_id=1918418417] +collision_layer = 8 +collision_mask = 4 +script = ExtResource("1_chyeu") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=2048987579] +disabled = true +debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)