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,10 @@
using Godot;
using System;
using System.Diagnostics;
using System.Linq;
using Cirno.Scripts;
using Cirno.Scripts.Resources;
using Godot.Collections;
public partial class Barrel : Area2D, IDestructible
{
@ -19,6 +21,7 @@ public partial class Barrel : Area2D, IDestructible
[Export] public BulletResource ExplosionData { get; set; }
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.None;
[Export] public Array<DamageResistance> DamageResistances { get; set; } = [];
[ExportCategory("On Death Activation")]
[Export]
@ -136,7 +139,9 @@ public partial class Barrel : Area2D, IDestructible
{
if (_isDestroyed || Indestructible) return;
_currentHealth -= damage;
var dmg = DamageResistances.Aggregate(damage, (current, resistance) => current * resistance.CalculateDamage(current, damageType));
_currentHealth -= dmg;
if (_currentHealth > 0) return;
_isDestroyed = true;
Explode();