Enhanced loot drops system

This commit is contained in:
MaddoScientisto 2026-03-01 19:14:34 +01:00
commit acc61f9a0e
12 changed files with 661 additions and 443 deletions

View file

@ -2,6 +2,7 @@
using System.Linq;
using Cirno.Scripts.Controllers;
using Cirno.Scripts.Resources;
using Cirno.Scripts.Resources.Loot;
using Cirno.Scripts.Utils;
using Cirno.Scripts.Weapons;
using Godot;
@ -30,12 +31,19 @@ public partial class Destructible3D : StaticBody3D, IDestructible
[Export] public Node Target { get; private set; }
[Export] public string TargetGroup { get; protected set; }
[ExportCategory("Loot Drops")]
[Export] public Array<LootDrop> LootDrops { get; set; } = [];
/// <summary>Radius of the circle in which dropped items are scattered uniformly.</summary>
[Export] public float LootScatterRadius { get; set; } = 1.0f;
/// <summary>Initial upward speed applied to each dropped item so it pops up before falling.</summary>
[Export] public float LootLaunchUpSpeed { get; set; } = 3.0f;
[Signal]
public delegate void ExplodedEventHandler();
private float _currentHealth = 0f;
private bool _isDestroyed = false;
private readonly RandomNumberGenerator _rng = new();
public override void _Ready()
{
@ -86,6 +94,7 @@ public partial class Destructible3D : StaticBody3D, IDestructible
CreateExplosion();
CreateParticles();
CreateDebris();
DropLoot();
QueueFree();
@ -137,6 +146,11 @@ public partial class Destructible3D : StaticBody3D, IDestructible
particle.Emitting = true;
}
private void DropLoot()
{
LootDropHelper.SpawnDrops(LootDrops, this, GlobalPosition, LootScatterRadius, LootLaunchUpSpeed, _rng);
}
public void Hit(float damage, DamageType damageType = DamageType.Neutral)
{