mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:05:34 +00:00
Readded loot drops
This commit is contained in:
parent
265f5ecfca
commit
3a7fd66193
3 changed files with 84 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=39 format=3 uid="uid://bh3vxmqflijgj"]
|
||||
[gd_scene load_steps=40 format=3 uid="uid://bh3vxmqflijgj"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dwregubt4iila" path="res://Scripts/Components/FSM/Enemy/3D/EnemyProxy3D.cs" id="1_a3crc"]
|
||||
[ext_resource type="Resource" uid="uid://ccym6mcq4fbul" path="res://Resources/Enemies/Fairy_Guard_3D.tres" id="2_jgarc"]
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
[ext_resource type="Script" uid="uid://qrdor3gk6x37" path="res://Scripts/Components/FSM/Enemy/3D/GravityProvider.cs" id="25_qg061"]
|
||||
[ext_resource type="Script" uid="uid://khph8rethll7" path="res://Scripts/Components/Actors/3D/EnemySoundModule3D.cs" id="26_ojvcb"]
|
||||
[ext_resource type="Texture2D" uid="uid://bf37ce6jskdel" path="res://Sprites/SmallHitbox.png" id="27_bh48e"]
|
||||
[ext_resource type="Script" uid="uid://buvtqwl5fvwxk" path="res://Scripts/Components/Actors/3D/EnemyDropModule3D.cs" id="28_2ut2v"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_jgarc"]
|
||||
radius = 0.343
|
||||
|
|
@ -143,9 +144,10 @@ NavigationModule = NodePath("../../NavigationProvider")
|
|||
GravityProvider = NodePath("../../GravityProvider")
|
||||
_moduleNodes = [NodePath("../../DamageModule"), NodePath("../../AnimationModule"), NodePath("../../SoundModule")]
|
||||
|
||||
[node name="Dead" type="Node" parent="StateMachine" node_paths=PackedStringArray("Storage")]
|
||||
[node name="Dead" type="Node" parent="StateMachine" node_paths=PackedStringArray("Storage", "_moduleNodes")]
|
||||
script = ExtResource("8_5j04l")
|
||||
Storage = NodePath("../../Storage")
|
||||
_moduleNodes = [NodePath("../../LootModule")]
|
||||
|
||||
[node name="Controlled" type="Node" parent="StateMachine" node_paths=PackedStringArray("Storage", "_moduleNodes")]
|
||||
script = ExtResource("9_dm2sd")
|
||||
|
|
@ -268,6 +270,10 @@ texture_filter = 0
|
|||
render_priority = -1
|
||||
sprite_frames = SubResource("SpriteFrames_t121s")
|
||||
|
||||
[node name="LootModule" type="Node" parent="." node_paths=PackedStringArray("StorageModule")]
|
||||
script = ExtResource("28_2ut2v")
|
||||
StorageModule = NodePath("../Storage")
|
||||
|
||||
[connection signal="body_entered" from="PlayerDetectionProvider" to="PlayerDetectionProvider" method="_on_body_entered"]
|
||||
[connection signal="body_exited" from="PlayerDetectionProvider" to="PlayerDetectionProvider" method="_on_body_exited"]
|
||||
[connection signal="velocity_computed" from="NavigationAgent3D" to="NavigationProvider" method="_on_navigation_agent_3d_velocity_computed"]
|
||||
|
|
|
|||
75
Scripts/Components/Actors/3D/EnemyDropModule3D.cs
Normal file
75
Scripts/Components/Actors/3D/EnemyDropModule3D.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/Actors/3D/EnemyDropModule3D.cs.uid
Normal file
1
Scripts/Components/Actors/3D/EnemyDropModule3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://buvtqwl5fvwxk
|
||||
Loading…
Add table
Add a link
Reference in a new issue