mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:25:35 +00:00
75 lines
No EOL
1.9 KiB
C#
75 lines
No EOL
1.9 KiB
C#
using Cirno.Scripts.Components.FSM;
|
|
using Cirno.Scripts.Components.FSM.Enemy._3D;
|
|
using Cirno.Scripts.Enums;
|
|
using Cirno.Scripts.Resources;
|
|
using Godot;
|
|
|
|
namespace Cirno.Scripts.Components.Actors._3D;
|
|
|
|
public partial class EnemyDropModule3D : ModuleBase<EnemyState, CharacterBody3D>
|
|
{
|
|
|
|
[Export] public EnemyStorage3D StorageModule { get; private set; }
|
|
|
|
private bool _initialized = false;
|
|
private bool _enabled = false;
|
|
|
|
private RandomNumberGenerator _rng = new ();
|
|
|
|
public override void EnterState(EnemyState state)
|
|
{
|
|
_enabled = true;
|
|
|
|
foreach (var loot in StorageModule.EnemyData.LootDrops)
|
|
{
|
|
if (loot is not { Item: not null }) continue;
|
|
var roll = _rng.RandfRange(0f, 100f); // Generate a number between 0 and 100
|
|
if (roll <= loot.Chance) // Compare with drop chance
|
|
{
|
|
DropItem(loot.Item);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DropItem(LootItem item)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(item.DropScenePath3D))
|
|
{
|
|
item.Spawn3D(_machine.MainObject);
|
|
|
|
GD.Print($"Dropped item: {item.ItemName}");
|
|
//var scene = GD.Load<PackedScene>(item.DropScenePath3D);
|
|
//_actor.CreateSibling<Node3D>(scene);
|
|
}
|
|
else
|
|
{
|
|
GD.Print($"Skipping Item with missing path: {item.ItemName}");
|
|
}
|
|
}
|
|
|
|
public override void ExitState(EnemyState state)
|
|
{
|
|
_enabled = false;
|
|
}
|
|
|
|
private IStateMachine<EnemyState, CharacterBody3D> _machine;
|
|
|
|
public override void Init(IStateMachine<EnemyState, CharacterBody3D> machine)
|
|
{
|
|
if (_initialized) return;
|
|
|
|
_machine = machine;
|
|
|
|
|
|
}
|
|
|
|
public override void Process(double delta)
|
|
{
|
|
|
|
}
|
|
|
|
public override void PhysicsProcess(double delta)
|
|
{
|
|
|
|
}
|
|
} |