Destroyable chests

This commit is contained in:
MaddoScientisto 2025-03-12 22:01:45 +01:00
commit 80e0eda977
14 changed files with 253 additions and 27 deletions

View file

@ -1,8 +1,11 @@
using Godot;
using System.Linq;
using Cirno.Scripts.Resources;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Components.Actors;
public partial class DamageReceiverActorModule : ActorModule
public partial class DamageReceiverActorModule : ActorModule, IHittable
{
protected Actor _actor;
@ -14,6 +17,8 @@ public partial class DamageReceiverActorModule : ActorModule
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.None;
[Export] public Array<DamageResistance> DamageResistances { get; set; } = [];
public override void Init(Actor actor)
{
_actor = actor;
@ -42,14 +47,14 @@ public partial class DamageReceiverActorModule : ActorModule
if (BulletGroup is BulletOwner.None)
{
this.Hit(bullet.Damage);
this.Hit(bullet.Damage, bullet.DamageType);
bullet.RequestCollisionDestruction();
return;
}
if (bullet.BulletInfo.Owner == BulletGroup) return;
this.Hit(bullet.Damage);
this.Hit(bullet.Damage, bullet.DamageType);
bullet.RequestCollisionDestruction();
}
@ -58,7 +63,9 @@ public partial class DamageReceiverActorModule : ActorModule
if (_actor.IsDestroyed) return;
if (Invulnerable) return;
HealthProvider.CurrentResource -= damage;
var dmg = DamageResistances.Aggregate(damage, (current, resistance) => current * resistance.CalculateDamage(current, damageType));
HealthProvider.CurrentResource -= dmg;
}
protected void OnDeath()