Loot Drops

This commit is contained in:
Marco 2025-03-04 09:43:05 +01:00
commit b7d241bf11
16 changed files with 129 additions and 6 deletions

View file

@ -9,6 +9,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnemy_005FScriptProperties_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fd6739058209280d46591ab296d6b49dfcf7ecd2_003FEnemy_005FScriptProperties_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGameManager_005FScriptMethods_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003F642294f86639b2f8d4cb4d14e791d697e55369_003FGameManager_005FScriptMethods_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fbb1b701f3c7411227a9d2e09f965d857ff3e771557650c4f513e427d77c_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Ff1d69ec2da76ccf9bc8a75c8e0fdca9a7ba1adf8c8c9d5047e2fa5991c02eca_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlayerMovement_005FScriptMethods_002Egenerated_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003F4af4702ac4bbb9ab7299554c41beea2bf703b4a_003FPlayerMovement_005FScriptMethods_002Egenerated_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AScriptManagerBridge_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FDecompilerCache_003Fdecompiler_003F4fd22cd129a84c16b5d8004b467c426f518800_003F3a_003Fc456f450_003FScriptManagerBridge_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelpers_002Ecs_002Fl_003AC_0021_003FUsers_003FMaddo_003FAppData_003FLocal_003FJetBrains_003FShared_003FvAny_003FSourcesCache_003Fbb2a94dce7ca55a596694df58d3ca91c6d9c9c9c9813775e4d1abd0f91dc59_003FThrowHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>

View file

@ -21,3 +21,4 @@ UiType = 2
Selectable = false
InventorySprite = SubResource("AtlasTexture_3y0hf")
HudItemScene = ExtResource("1_qkp4b")
DropScenePath = &"res://Scenes/Items/Ammo1.tscn"

View file

@ -20,3 +20,4 @@ ConsumeOnUse = false
UiType = 1
Selectable = false
InventorySprite = SubResource("AtlasTexture_ebbst")
DropScenePath = &"res://Scenes/Items/Blue_Keycard.tscn"

View file

@ -20,3 +20,4 @@ ConsumeOnUse = false
UiType = 1
Selectable = false
InventorySprite = SubResource("AtlasTexture_iasoh")
DropScenePath = &"res://Scenes/Items/Green_Keycard.tscn"

View file

@ -16,3 +16,4 @@ ConsumeOnUse = true
UiType = 2
Selectable = true
InventorySprite = ExtResource("1_cang8")
DropScenePath = &"res://Scenes/Items/Power_Pickup.tscn"

View file

@ -20,3 +20,4 @@ Selectable = false
InventorySprite = ExtResource("1_glhfu")
WorldSprite = ExtResource("1_1j6xs")
HudItemScene = ExtResource("1_30txj")
DropScenePath = &"res://Scenes/Items/Red_Keycard.tscn"

View file

@ -40,4 +40,5 @@ ConsumeOnUse = false
UiType = 0
Selectable = true
InventorySprite = SubResource("AtlasTexture_gpot4")
DropScenePath = &"res://Scenes/Items/SpiderBomb_Pickup.tscn"
metadata/_custom_type_script = "uid://epnwjptvks3t"

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=3 uid="uid://bc054js8ep2b"]
[gd_scene load_steps=29 format=3 uid="uid://bc054js8ep2b"]
[ext_resource type="Script" uid="uid://c2mo5hc1qb6kf" path="res://Scripts/Components/Actors/Actor.cs" id="1_ugrra"]
[ext_resource type="SpriteFrames" uid="uid://ch2ll1on8im2p" path="res://Resources/Sprites/FairyGuard.tres" id="2_i2plx"]
@ -15,6 +15,12 @@
[ext_resource type="Script" uid="uid://m0ag88kn0c40" path="res://Scripts/Components/Actors/DeathAnimationHandler.cs" id="13_e2vvk"]
[ext_resource type="Resource" uid="uid://dk2rbf88a5irh" path="res://Resources/Bullets/Explosion_Harmless.tres" id="14_881we"]
[ext_resource type="Script" uid="uid://7g3luecewcp5" path="res://Scripts/Components/Actors/ActorDefeatScriptHandler.cs" id="15_17yce"]
[ext_resource type="Script" uid="uid://dwbh55rqi0x5e" path="res://Scripts/Components/Actors/EnemyDropModule.cs" id="16_76vwd"]
[ext_resource type="Script" uid="uid://cq65aed620ijo" path="res://Scripts/Resources/Loot/LootDrop.cs" id="17_gsthm"]
[ext_resource type="Resource" uid="uid://ct1fa2huvy34n" path="res://Resources/Items/Ammo1.tres" id="18_hwppe"]
[ext_resource type="Resource" uid="uid://dodwpect0ldjf" path="res://Resources/Items/Heart_Pickup.tres" id="19_swk2c"]
[ext_resource type="Resource" uid="uid://clr1gln7nxa1o" path="res://Resources/Items/Power_Pickup.tres" id="20_evv7k"]
[ext_resource type="Resource" uid="uid://dhbltvgsa3g88" path="res://Resources/Items/Spider_Bomb_Pickup.tres" id="21_y1chq"]
[sub_resource type="CircleShape2D" id="CircleShape2D_2b36v"]
radius = 5.0
@ -25,6 +31,30 @@ radius = 85.0529
[sub_resource type="CircleShape2D" id="CircleShape2D_0tkae"]
radius = 5.09902
[sub_resource type="Resource" id="Resource_lh4qp"]
script = ExtResource("17_gsthm")
Item = ExtResource("18_hwppe")
Chance = 40.0
metadata/_custom_type_script = "uid://cq65aed620ijo"
[sub_resource type="Resource" id="Resource_fmqd5"]
script = ExtResource("17_gsthm")
Item = ExtResource("19_swk2c")
Chance = 20.0
metadata/_custom_type_script = "uid://cq65aed620ijo"
[sub_resource type="Resource" id="Resource_gry1a"]
script = ExtResource("17_gsthm")
Item = ExtResource("20_evv7k")
Chance = 20.0
metadata/_custom_type_script = "uid://cq65aed620ijo"
[sub_resource type="Resource" id="Resource_6b6qx"]
script = ExtResource("17_gsthm")
Item = ExtResource("21_y1chq")
Chance = 10.0
metadata/_custom_type_script = "uid://cq65aed620ijo"
[node name="FairyGuard" type="CharacterBody2D"]
collision_layer = 16
collision_mask = 113
@ -103,6 +133,10 @@ ExplosionData = ExtResource("14_881we")
[node name="DefeatScriptHandler" type="Node2D" parent="."]
script = ExtResource("15_17yce")
[node name="LootDrops" type="Node2D" parent="."]
script = ExtResource("16_76vwd")
LootDrops = Array[ExtResource("17_gsthm")]([SubResource("Resource_lh4qp"), SubResource("Resource_fmqd5"), SubResource("Resource_gry1a"), SubResource("Resource_6b6qx")])
[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="velocity_computed" from="NavigationAgent2D" to="NavigationMovementProvider" method="_on_navigation_agent_2d_velocity_computed"]

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=8 format=3 uid="uid://r25rq6ijgm6m"]
[gd_scene load_steps=9 format=3 uid="uid://r25rq6ijgm6m"]
[ext_resource type="Script" uid="uid://b3h7b30kerf60" path="res://Scripts/Interactables/ItemPickup.cs" id="1_kb5vg"]
[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="2_k08wy"]
[ext_resource type="Resource" uid="uid://cspcgkr0tane2" path="res://Resources/Items/Green_Keycard.tres" id="2_kb5vg"]
[ext_resource type="Texture2D" uid="uid://bvkjnc3ggp7ba" path="res://Sprites/Items/GreenKeycard_Small.png" id="2_lts72"]
@ -32,7 +33,7 @@ animations = [{
collision_layer = 4
collision_mask = 2
script = ExtResource("1_kb5vg")
LootTable = [ExtResource("2_kb5vg")]
LootTable = Array[ExtResource("2_k08wy")]([ExtResource("2_kb5vg")])
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_6vv2s")

View file

@ -57,7 +57,7 @@ PlayerTemplate = ExtResource("8_c3v4x")
SpawnMarkers = Dictionary[int, NodePath]({
0: NodePath("PlayerStartPosition")
})
StartingEquipment = [ExtResource("3_6314l"), ExtResource("4_yyg8m")]
StartingEquipment = Array[ExtResource("5_u1i8n")]([ExtResource("3_6314l"), ExtResource("4_yyg8m")])
MapStartData = SubResource("Resource_6wo78")
[node name="Tilemaps" type="Node2D" parent="."]

View file

@ -207,7 +207,7 @@ SpawnMarkers = Dictionary[int, NodePath]({
2: NodePath("Factory Tilemaps/LevelProps/BossDebugTeleporterDestination"),
255: NodePath("Factory Tilemaps/Debug Room/DebugRoomStartPosition")
})
StartingEquipment = [ExtResource("4_swym2"), ExtResource("5_nqier")]
StartingEquipment = Array[ExtResource("6_8tdlb")]([ExtResource("4_swym2"), ExtResource("5_nqier")])
MapStartData = SubResource("Resource_6sau4")
metadata/_edit_lock_ = true

View file

@ -0,0 +1,66 @@
using Cirno.Scripts.Resources;
using Cirno.Scripts.Resources.Loot;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Components.Actors;
public partial class EnemyDropModule : ActorModule
{
[Export] public Array<LootDrop> LootDrops { get; private set; } = [];
private RandomNumberGenerator _rng = new ();
private Actor _actor;
public override void Init(Actor actor)
{
_actor = actor;
actor.OnDeath += ActorOnDeath;
}
private void DropLoot()
{
foreach (var loot in 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);
_actor.CreateSibling<Node2D>(scene);
}
else
{
GD.Print($"Skipping Item with missing path: {item.ItemName}");
}
}
private void ActorOnDeath()
{
DropLoot();
_actor.OnDeath -= ActorOnDeath;
}
public override void Update(double delta)
{
}
public override void PhysicsUpdate(double delta)
{
}
}

View file

@ -0,0 +1 @@
uid://dwbh55rqi0x5e

View file

@ -0,0 +1,13 @@
using Godot;
namespace Cirno.Scripts.Resources.Loot;
[GlobalClass]
public partial class LootDrop : Resource
{
[Export]
public LootItem Item { get; private set; }
[Export(PropertyHint.None, "suffix:%")]
public float Chance { get; private set; }
}

View file

@ -0,0 +1 @@
uid://cq65aed620ijo

View file

@ -19,7 +19,7 @@ public partial class LootItem : Resource
[Export] public Texture2D InventorySprite;
[Export] public SpriteFrames WorldSprite;
[Export] public PackedScene HudItemScene;
[Export(PropertyHint.File)] public StringName DropScenePath { get; private set; } // Has to be a string path to avoid recursion issues
}
public enum UiItemType