mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
69 lines
No EOL
1.6 KiB
C#
69 lines
No EOL
1.6 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] public BulletOwner BulletGroup { get; set; } = BulletOwner.None;
|
|
|
|
public override void Init(Actor actor)
|
|
{
|
|
_actor = actor;
|
|
|
|
this.HealthProvider.MaxResource = actor.Health;
|
|
|
|
HealthProvider.FillResource();
|
|
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;
|
|
_actor.TriggerDeath();
|
|
}
|
|
} |