mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:25:35 +00:00
66 lines
No EOL
1.5 KiB
C#
66 lines
No EOL
1.5 KiB
C#
using Godot;
|
|
|
|
namespace Cirno.Scripts.Components.Actors;
|
|
|
|
public partial class DamageReceiverActorModule : ActorModule
|
|
{
|
|
protected Actor _actor;
|
|
|
|
[Export]
|
|
public ActorResourceProvider HealthProvider { get; private set; }
|
|
|
|
[Export]
|
|
public bool Invulnerable { get; private set; } = false;
|
|
|
|
[Export] protected BulletOwner BulletGroup { get; set; } = BulletOwner.None;
|
|
|
|
public override void Init(Actor actor)
|
|
{
|
|
_actor = actor;
|
|
|
|
HealthProvider.ResourceDepleted += OnDeath;
|
|
}
|
|
|
|
public override void Update(double delta)
|
|
{
|
|
|
|
}
|
|
|
|
public override void PhysicsUpdate(double delta)
|
|
{
|
|
|
|
}
|
|
|
|
private void _on_damage_hitbox_area_entered(Area2D area)
|
|
{
|
|
if (_actor.IsDestroyed) return;
|
|
if (Invulnerable) return;
|
|
if (area is not Bullet bullet) return;
|
|
|
|
if (BulletGroup is BulletOwner.None)
|
|
{
|
|
this.Hit(bullet.Damage);
|
|
bullet.RequestCollisionDestruction();
|
|
return;
|
|
}
|
|
|
|
if (bullet.BulletInfo.Owner == BulletGroup) return;
|
|
|
|
this.Hit(bullet.Damage);
|
|
bullet.RequestCollisionDestruction();
|
|
}
|
|
|
|
public void Hit(float damage, DamageType damageType = DamageType.Neutral)
|
|
{
|
|
if (_actor.IsDestroyed) return;
|
|
if (Invulnerable) return;
|
|
|
|
HealthProvider.CurrentResource -= damage;
|
|
}
|
|
|
|
protected void OnDeath()
|
|
{
|
|
_actor.IsDestroyed = true;
|
|
GD.Print("Actor dead");
|
|
}
|
|
} |