mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-16 05:23:48 +00:00
Loot drops provider
This commit is contained in:
parent
cc85cd4b54
commit
cf4b11d157
9 changed files with 117 additions and 19 deletions
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=26 format=3 uid="uid://clieeuln36a7a"]
|
||||
[gd_scene load_steps=27 format=3 uid="uid://clieeuln36a7a"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dn6dbog1s2818" path="res://Scripts/Components/FSM/Enemy/EnemyStateMachine.cs" id="1_27djw"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://bcc5mlwwnkvri" path="res://Resources/Sprites/Fairy.tres" id="1_ho0th"]
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
[ext_resource type="Script" uid="uid://bo5sgbv1t8ril" path="res://Scripts/Components/Actors/PlayerAnimationProvider.cs" id="19_km3yo"]
|
||||
[ext_resource type="Material" uid="uid://dnvwgyt2tbqmr" path="res://Resources/Materials/Player_Blink_Teleport_Material.tres" id="20_8kl2e"]
|
||||
[ext_resource type="Script" uid="uid://dncdgq843sj2f" path="res://Scripts/Components/FSM/Enemy/AnimationModule.cs" id="21_8kl2e"]
|
||||
[ext_resource type="Script" uid="uid://bw4t2clyr6lib" path="res://Scripts/Components/FSM/Enemy/EnemyDropsProvider.cs" id="22_poxpj"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_pnkma"]
|
||||
|
||||
|
|
@ -80,9 +81,10 @@ DamageReceiver = NodePath("../../DamageReceiver")
|
|||
EquippedWeapon = NodePath("../../EnemyWeapon")
|
||||
_moduleNodes = [NodePath("../../AnimationModule")]
|
||||
|
||||
[node name="Dead" type="Node2D" parent="StateMachine" node_paths=PackedStringArray("StorageModule")]
|
||||
[node name="Dead" type="Node2D" parent="StateMachine" node_paths=PackedStringArray("StorageModule", "DropsProvider")]
|
||||
script = ExtResource("8_pi7ab")
|
||||
StorageModule = NodePath("../../Storage")
|
||||
DropsProvider = NodePath("../../DropsProvider")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
sprite_frames = ExtResource("1_ho0th")
|
||||
|
|
@ -159,6 +161,10 @@ script = ExtResource("21_8kl2e")
|
|||
AnimationProvider = NodePath("../AnimationProvider")
|
||||
StorageModule = NodePath("../Storage")
|
||||
|
||||
[node name="DropsProvider" type="Node2D" parent="." node_paths=PackedStringArray("StorageModule")]
|
||||
script = ExtResource("22_poxpj")
|
||||
StorageModule = NodePath("../Storage")
|
||||
|
||||
[connection signal="area_entered" from="PlayerDetection" to="PlayerDetection" method="_on_area_entered"]
|
||||
[connection signal="area_exited" from="PlayerDetection" to="PlayerDetection" method="_on_area_exited"]
|
||||
[connection signal="area_entered" from="DamageReceiver" to="DamageReceiver" method="_on_damage_hitbox_area_entered"]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=75 format=4 uid="uid://dqyfnby0t7gu1"]
|
||||
[gd_scene load_steps=78 format=4 uid="uid://dqyfnby0t7gu1"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_c3v4x"]
|
||||
[ext_resource type="Resource" uid="uid://cs3ihltcn2166" path="res://Resources/Items/IcicleGun.tres" id="3_6314l"]
|
||||
|
|
@ -18,10 +18,12 @@
|
|||
[ext_resource type="Script" uid="uid://bdshph801ac2i" path="res://Scenes/CameraTarget.gd" id="12_8to53"]
|
||||
[ext_resource type="PackedScene" uid="uid://clieeuln36a7a" path="res://Scenes/Actors/Fairy_FSM.tscn" id="12_64bae"]
|
||||
[ext_resource type="Script" uid="uid://cnkipcolyj61w" path="res://Scripts/AlarmManager.cs" id="13_8fnge"]
|
||||
[ext_resource type="Script" uid="uid://cq65aed620ijo" path="res://Scripts/Resources/Loot/LootDrop.cs" id="13_b3y78"]
|
||||
[ext_resource type="PackedScene" uid="uid://b0gpbkxdfbnjh" path="res://Scenes/Actors/ForceField_Horizontal.tscn" id="13_mljl7"]
|
||||
[ext_resource type="PackedScene" uid="uid://d0yes7huiyisw" path="res://Scenes/Items/Blue_Keycard.tscn" id="14_0knpf"]
|
||||
[ext_resource type="PackedScene" uid="uid://b3tyacxxw88lx" path="res://Scenes/Utils/StreamPlayerWithName.tscn" id="14_q7rh4"]
|
||||
[ext_resource type="PackedScene" uid="uid://cd36ch65jijg0" path="res://Scenes/Activable/BulletEmitter.tscn" id="15_b3hxm"]
|
||||
[ext_resource type="Resource" uid="uid://cspcgkr0tane2" path="res://Resources/Items/Green_Keycard.tres" id="15_suuav"]
|
||||
[ext_resource type="PackedScene" uid="uid://r25rq6ijgm6m" path="res://Scenes/Items/Green_Keycard.tscn" id="16_dj0ui"]
|
||||
[ext_resource type="PackedScene" uid="uid://byms2dhliyux0" path="res://Scenes/Actors/teleporter.tscn" id="16_qmakk"]
|
||||
[ext_resource type="Resource" uid="uid://bj331rcsq65es" path="res://Resources/Bullets/EmitterTestBullet.tres" id="16_u1i8n"]
|
||||
|
|
@ -54,7 +56,6 @@
|
|||
[ext_resource type="Script" uid="uid://c1gu44a1kkmt1" path="res://Scripts/Actors/ScriptableBulletsEmitter.cs" id="38_m2f1m"]
|
||||
[ext_resource type="Script" uid="uid://bngko08ho85p6" path="res://Scripts/Resources/BulletScript.cs" id="39_83jc5"]
|
||||
[ext_resource type="Resource" uid="uid://dqnvesdj0dk3v" path="res://Resources/Bullets/simple_enemy_bullet.tres" id="39_b0wyy"]
|
||||
[ext_resource type="Script" uid="uid://b5s5mjuk1rng5" path="res://Scripts/Resources/TimeModifier.cs" id="40_4mkc6"]
|
||||
[ext_resource type="Script" uid="uid://c0ndqalsc4jve" path="res://Scripts/AttackPatterns/SpiralPattern.cs" id="40_o56je"]
|
||||
[ext_resource type="Script" uid="uid://c6467d6yx50qh" path="res://Scripts/Components/BulletSpawner.cs" id="43_b8ffn"]
|
||||
[ext_resource type="PackedScene" uid="uid://b7gkxlll3b1eg" path="res://Scenes/Activable/FloorEmitter.tscn" id="44_b8ffn"]
|
||||
|
|
@ -82,6 +83,18 @@ colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 1)
|
|||
[sub_resource type="GradientTexture1D" id="GradientTexture1D_4gtx8"]
|
||||
gradient = SubResource("Gradient_2vu2h")
|
||||
|
||||
[sub_resource type="Resource" id="Resource_w8nwr"]
|
||||
script = ExtResource("13_b3y78")
|
||||
Item = ExtResource("20_rff8l")
|
||||
Chance = 100.0
|
||||
metadata/_custom_type_script = "uid://cq65aed620ijo"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_awjkl"]
|
||||
script = ExtResource("13_b3y78")
|
||||
Item = ExtResource("15_suuav")
|
||||
Chance = 100.0
|
||||
metadata/_custom_type_script = "uid://cq65aed620ijo"
|
||||
|
||||
[sub_resource type="Curve2D" id="Curve2D_16ubp"]
|
||||
_data = {
|
||||
"points": PackedVector2Array(0, 0, 0, 0, 0, -80, 0, 0, 0, 0, 0, 0)
|
||||
|
|
@ -107,7 +120,7 @@ DamageType = 0
|
|||
OverrideControllable = false
|
||||
Controllable = false
|
||||
OverrideCreationModifier = false
|
||||
TimeModifiers = Array[ExtResource("40_4mkc6")]([])
|
||||
TimeModifiers = []
|
||||
WaitForCompletion = true
|
||||
metadata/_custom_type_script = "uid://c0ndqalsc4jve"
|
||||
|
||||
|
|
@ -135,11 +148,11 @@ DamageType = 0
|
|||
OverrideControllable = false
|
||||
Controllable = false
|
||||
OverrideCreationModifier = false
|
||||
TimeModifiers = Array[ExtResource("40_4mkc6")]([])
|
||||
TimeModifiers = []
|
||||
WaitForCompletion = true
|
||||
metadata/_custom_type_script = "uid://c0ndqalsc4jve"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_5nxem"]
|
||||
[sub_resource type="Resource" id="Resource_r562v"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("39_83jc5")
|
||||
Patterns = Array[Object]([SubResource("Resource_kuo18")])
|
||||
|
|
@ -231,6 +244,22 @@ scale = Vector2(0.66, 2.04)
|
|||
|
||||
[node name="FairyFsm" parent="Tilemaps/AcidHitboxes" node_paths=PackedStringArray("DefeatScript") instance=ExtResource("12_64bae")]
|
||||
position = Vector2(776, -56)
|
||||
ExtraLoot = Array[ExtResource("13_b3y78")]([SubResource("Resource_w8nwr"), SubResource("Resource_awjkl")])
|
||||
DefeatScript = NodePath("../../Actors/HorizontalForceField2")
|
||||
ActivationType = 2
|
||||
|
||||
[node name="FairyFsm2" parent="Tilemaps/AcidHitboxes" node_paths=PackedStringArray("DefeatScript") instance=ExtResource("12_64bae")]
|
||||
position = Vector2(854.636, -127.371)
|
||||
DefeatScript = NodePath("../../Actors/HorizontalForceField2")
|
||||
ActivationType = 2
|
||||
|
||||
[node name="FairyFsm3" parent="Tilemaps/AcidHitboxes" node_paths=PackedStringArray("DefeatScript") instance=ExtResource("12_64bae")]
|
||||
position = Vector2(945.965, -83.9098)
|
||||
DefeatScript = NodePath("../../Actors/HorizontalForceField2")
|
||||
ActivationType = 2
|
||||
|
||||
[node name="FairyFsm4" parent="Tilemaps/AcidHitboxes" node_paths=PackedStringArray("DefeatScript") instance=ExtResource("12_64bae")]
|
||||
position = Vector2(852.633, -14.8125)
|
||||
DefeatScript = NodePath("../../Actors/HorizontalForceField2")
|
||||
ActivationType = 2
|
||||
|
||||
|
|
@ -382,7 +411,7 @@ InvertSignal = true
|
|||
|
||||
[node name="FloorEmitter2" parent="Tilemaps/Actors" instance=ExtResource("44_b8ffn")]
|
||||
position = Vector2(601, 147)
|
||||
Script = SubResource("Resource_5nxem")
|
||||
Script = SubResource("Resource_r562v")
|
||||
InvertSignal = true
|
||||
|
||||
[node name="Camera" parent="Tilemaps/Actors" instance=ExtResource("48_r562v")]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=141 format=4 uid="uid://bv451a8wgty4u"]
|
||||
[gd_scene load_steps=140 format=4 uid="uid://bv451a8wgty4u"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
|
||||
[ext_resource type="PackedScene" uid="uid://c4pr2707hbeph" path="res://Scenes/Actors/fsm_player.tscn" id="2_ksslq"]
|
||||
|
|
@ -104,7 +104,6 @@
|
|||
[ext_resource type="Resource" uid="uid://cmra7n6so1x4u" path="res://Resources/BulletScripts/Basic_Enemy_Emitter_Spiral_Bullets.tres" id="95_7m6n7"]
|
||||
[ext_resource type="Resource" uid="uid://dodwpect0ldjf" path="res://Resources/Items/Heart_Pickup.tres" id="95_srv0g"]
|
||||
[ext_resource type="PackedScene" uid="uid://nupd3pg74vua" path="res://Scenes/Activable/ScriptableInvisibleEmitter.tscn" id="96_ygp23"]
|
||||
[ext_resource type="Script" uid="uid://b5s5mjuk1rng5" path="res://Scripts/Resources/TimeModifier.cs" id="97_gvbi8"]
|
||||
[ext_resource type="Resource" uid="uid://dtkti2rjlcp3u" path="res://Resources/Bullets/Fire_Emitter_Bullet.tres" id="97_xwjvv"]
|
||||
[ext_resource type="Script" uid="uid://c0ndqalsc4jve" path="res://Scripts/AttackPatterns/SpiralPattern.cs" id="98_gvbi8"]
|
||||
[ext_resource type="Script" uid="uid://bngko08ho85p6" path="res://Scripts/Resources/BulletScript.cs" id="99_j6vrf"]
|
||||
|
|
@ -255,7 +254,7 @@ DamageType = 0
|
|||
OverrideControllable = false
|
||||
Controllable = false
|
||||
OverrideCreationModifier = false
|
||||
TimeModifiers = Array[ExtResource("97_gvbi8")]([])
|
||||
TimeModifiers = []
|
||||
WaitForCompletion = true
|
||||
metadata/_custom_type_script = "uid://c0ndqalsc4jve"
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ public partial class Dead : EnemyStateBase
|
|||
|
||||
[Export]
|
||||
public EnemyStorageModule StorageModule { get; private set; }
|
||||
|
||||
[Export]
|
||||
public EnemyDropsProvider DropsProvider { get; private set; }
|
||||
|
||||
// public override void Init(IStateMachine<EnemyState, CharacterBody2D> machine)
|
||||
// {
|
||||
|
|
@ -27,7 +30,8 @@ public partial class Dead : EnemyStateBase
|
|||
activatable.Activate(StorageModule.Root.ActivationType);
|
||||
}
|
||||
|
||||
StorageModule.Root.QueueFree();
|
||||
DropsProvider.DropLoot();
|
||||
|
||||
StorageModule.Root.QueueFree();
|
||||
}
|
||||
}
|
||||
55
Scripts/Components/FSM/Enemy/EnemyDropsProvider.cs
Normal file
55
Scripts/Components/FSM/Enemy/EnemyDropsProvider.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Enemy;
|
||||
|
||||
public partial class EnemyDropsProvider : Node2D
|
||||
{
|
||||
private RandomNumberGenerator _rng = new();
|
||||
|
||||
[Export] public float DropRadius { get; private set; } = 8f;
|
||||
|
||||
[Export]
|
||||
public EnemyStorageModule StorageModule { get; private set; }
|
||||
|
||||
public void DropLoot()
|
||||
{
|
||||
foreach (var loot in StorageModule.LootDrops)
|
||||
{
|
||||
if (loot is { Item: not null })
|
||||
{
|
||||
float 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.DropScenePath))
|
||||
{
|
||||
GD.Print($"Dropped item: {item.ItemName}");
|
||||
var scene = GD.Load<PackedScene>(item.DropScenePath);
|
||||
var droppedItem = StorageModule.Root.CreateSibling<Node2D>(scene);
|
||||
|
||||
// Generate random point within DropRadius
|
||||
float angle = _rng.RandfRange(0, Mathf.Tau); // Random angle (0 to 2π)
|
||||
float radius = _rng.RandfRange(0, DropRadius); // Random radius within range
|
||||
|
||||
// Convert polar to cartesian coordinates
|
||||
float xOffset = radius * Mathf.Cos(angle);
|
||||
float yOffset = radius * Mathf.Sin(angle);
|
||||
|
||||
Vector2 spawnPosition = StorageModule.Root.GlobalPosition + new Vector2(xOffset, yOffset);
|
||||
|
||||
droppedItem.GlobalPosition = spawnPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print($"Skipping Item with missing path: {item.ItemName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/Enemy/EnemyDropsProvider.cs.uid
Normal file
1
Scripts/Components/FSM/Enemy/EnemyDropsProvider.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bw4t2clyr6lib
|
||||
|
|
@ -11,8 +11,8 @@ public partial class EnemyFSMProxy : CharacterBody2D
|
|||
[Export] public EnemyStateMachine EnemyFSM { get; private set; }
|
||||
|
||||
[Export] public EnemyResource EnemyResource { get; private set; }
|
||||
|
||||
[Export] public Array<LootDrop> ExtraLoot { get; private set; }
|
||||
|
||||
[Export] public Array<LootDrop> ExtraLoot { get; private set; } = [];
|
||||
|
||||
[Export]
|
||||
public AiState StartingAiState { get; private set; }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Resources.Loot;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Enemy;
|
||||
|
||||
|
|
@ -11,8 +15,8 @@ public partial class EnemyStorageModule : Node2D
|
|||
public Vector2 FacingDirection { get; set; }
|
||||
|
||||
public float MovementSpeed => Root.EnemyResource.MovementSpeed;
|
||||
|
||||
|
||||
|
||||
public IEnumerable<LootDrop> LootDrops => Root.EnemyResource.LootDrops.Concat(Root.ExtraLoot);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ public partial class EnemyResource : Resource
|
|||
[Export] public float MovementSpeed { get; private set; } = 20f;
|
||||
[Export] public DamageResistance Resistances { get; private set; }
|
||||
[Export] public WeaponResource Weapon { get; private set; }
|
||||
|
||||
[Export] public Array<LootDrop> LootDrops { get; private set; }
|
||||
|
||||
[Export] public Array<LootDrop> LootDrops { get; private set; } = [];
|
||||
|
||||
[ExportCategory("AI")] [Export] public float PlayerDetectionRange { get; private set; } = 90f;
|
||||
[Export] public float ViewRange { get; private set; } = 120f;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue