mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 00:45:53 +00:00
Enemy sounds
This commit is contained in:
parent
585befb932
commit
a11e61b2c2
15 changed files with 224 additions and 38 deletions
|
|
@ -7,7 +7,7 @@ using Godot.Collections;
|
|||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class DamageReceiver3D : Area3D, IHittable
|
||||
public partial class DamageReceiver3D : Area3D, IHittable
|
||||
{
|
||||
[Export] public ActorResourceProvider HealthProvider { get; private set; }
|
||||
|
||||
|
|
@ -16,22 +16,23 @@ public partial class DamageReceiver3D : Area3D, IHittable
|
|||
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.None;
|
||||
|
||||
[Export] public PackedScene Debris { get; set; }
|
||||
|
||||
|
||||
[Export] public Array<DamageResistance> DamageResistances { get; set; } = [];
|
||||
|
||||
[Export] public bool DeleteParentOnDeath { get; private set; } = true;
|
||||
|
||||
[Signal]
|
||||
public delegate void ShieldHitEventHandler();
|
||||
|
||||
[Signal] public delegate void BulletHitEventHandler(Bullet3D bullet, Vector3 position, Vector3 direction);
|
||||
|
||||
|
||||
[Signal]
|
||||
public delegate void BulletHitEventHandler(Bullet3D bullet, Vector3 position, Vector3 direction);
|
||||
|
||||
//[Signal] public delegate void DeathEventHandler();
|
||||
|
||||
|
||||
private Node3D _parent;
|
||||
|
||||
|
||||
public bool Enabled { get; private set; } = true;
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_parent = GetParent<Node3D>();
|
||||
|
|
@ -43,7 +44,7 @@ public partial class DamageReceiver3D : Area3D, IHittable
|
|||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
|
||||
|
||||
private void _on_damage_hitbox_area_entered(Area3D area)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
|
|
@ -52,50 +53,53 @@ public partial class DamageReceiver3D : Area3D, IHittable
|
|||
{
|
||||
EmitSignalShieldHit();
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
if (BulletGroup is BulletOwner.None)
|
||||
{
|
||||
this.Hit(bullet.Damage, bullet.DamageType);
|
||||
|
||||
|
||||
EmitSignalBulletHit(bullet, area.GlobalPosition, (this.GlobalPosition - area.GlobalPosition).Normalized());
|
||||
|
||||
|
||||
bullet.RequestCollisionDestruction();
|
||||
return;
|
||||
}
|
||||
|
||||
if (bullet.BulletInfo.Owner == BulletGroup) return;
|
||||
|
||||
if (bullet.BulletInfo.Owner == BulletGroup) return;
|
||||
|
||||
this.Hit(bullet.Damage, bullet.DamageType);
|
||||
|
||||
|
||||
EmitSignalBulletHit(bullet, area.GlobalPosition, (this.GlobalPosition - area.GlobalPosition).Normalized());
|
||||
|
||||
|
||||
bullet.RequestCollisionDestruction();
|
||||
}
|
||||
|
||||
|
||||
public void Hit(float damage, DamageType damageType = DamageType.Neutral)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
if (Invulnerable) return;
|
||||
|
||||
|
||||
// Change value based on difficulty
|
||||
float difficultyReducedDmg = damage * GlobalState.Instance.SessionSettings.DifficultyDamageMultiplier;
|
||||
|
||||
var dmg = DamageResistances.Aggregate(difficultyReducedDmg, (current, resistance) => current * resistance.CalculateDamage(current, damageType));
|
||||
var dmg = DamageResistances.Aggregate(difficultyReducedDmg,
|
||||
(current, resistance) => current * resistance.CalculateDamage(current, damageType));
|
||||
|
||||
HealthProvider.CurrentResource -= dmg;
|
||||
}
|
||||
|
||||
|
||||
private void OnDeath()
|
||||
{
|
||||
if (Debris is not null)
|
||||
{
|
||||
_parent.CreateSibling<Node3D>(Debris);
|
||||
}
|
||||
|
||||
|
||||
// Not needed because the health provider is accessible
|
||||
//EmitSignal(SignalName.Death);
|
||||
|
||||
|
||||
if (DeleteParentOnDeath)
|
||||
{
|
||||
_parent.QueueFree();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue