From b773e224c0e304a3be5d111a4757fd9e248d7965 Mon Sep 17 00:00:00 2001 From: Tabby <41929769+tabby-cat-nya@users.noreply.github.com> Date: Sun, 11 Jan 2026 19:06:59 +1100 Subject: [PATCH] core gameplay in! scavenging working! --- crafting/rollableLoot.gd | 5 +++++ crafting/rollableLoot.gd.uid | 1 + crafting/scavenge_recipe.gd | 15 ++++++++++++++- crafting/scavenges/testScavenge.tres | 13 +++++++++++-- inv_system/crafting_panel.gd | 8 +++++++- 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 crafting/rollableLoot.gd create mode 100644 crafting/rollableLoot.gd.uid diff --git a/crafting/rollableLoot.gd b/crafting/rollableLoot.gd new file mode 100644 index 0000000..1050877 --- /dev/null +++ b/crafting/rollableLoot.gd @@ -0,0 +1,5 @@ +extends Resource +class_name RollableLoot + +@export var item : ItemData +@export var chance : int diff --git a/crafting/rollableLoot.gd.uid b/crafting/rollableLoot.gd.uid new file mode 100644 index 0000000..9e855b9 --- /dev/null +++ b/crafting/rollableLoot.gd.uid @@ -0,0 +1 @@ +uid://oa5rlx6ttwuj diff --git a/crafting/scavenge_recipe.gd b/crafting/scavenge_recipe.gd index 91d98aa..d239f0d 100644 --- a/crafting/scavenge_recipe.gd +++ b/crafting/scavenge_recipe.gd @@ -3,4 +3,17 @@ class_name ScavengeRecipe @export var input : ItemData @export var rolls : int = 3 -@export var loot_pool : Dictionary[int, ItemData] +@export var loot_pool : Array[RollableLoot] + +func roll() -> ItemData: + var selected : ItemData + var total_chance : int = 0 + for loot in loot_pool: + total_chance += loot.chance + var sel_chance : int = randi() % total_chance + for loot in loot_pool: + if sel_chance >= 0: + selected = loot.item + sel_chance -= loot.chance + + return selected diff --git a/crafting/scavenges/testScavenge.tres b/crafting/scavenges/testScavenge.tres index a21857f..fac0af4 100644 --- a/crafting/scavenges/testScavenge.tres +++ b/crafting/scavenges/testScavenge.tres @@ -1,10 +1,19 @@ -[gd_resource type="Resource" script_class="ScavengeRecipe" load_steps=4 format=3 uid="uid://deohei5avmspt"] +[gd_resource type="Resource" script_class="ScavengeRecipe" load_steps=6 format=3 uid="uid://deohei5avmspt"] [ext_resource type="Resource" uid="uid://88v5bcyrgpob" path="res://items/large_psu_item.tres" id="1_20hhf"] -[ext_resource type="Script" uid="uid://dccraom7a7e8d" path="res://inv_system/item_data.gd" id="1_o2l1m"] [ext_resource type="Script" uid="uid://boqr1fowaqmt0" path="res://crafting/scavenge_recipe.gd" id="2_20hhf"] +[ext_resource type="Script" uid="uid://oa5rlx6ttwuj" path="res://crafting/rollableLoot.gd" id="2_i5wfm"] +[ext_resource type="Resource" uid="uid://swd1m0hvep4c" path="res://items/small_psu_item.tres" id="3_svciw"] + +[sub_resource type="Resource" id="Resource_rhaxb"] +script = ExtResource("2_i5wfm") +item = ExtResource("3_svciw") +chance = 1 +metadata/_custom_type_script = "uid://oa5rlx6ttwuj" [resource] script = ExtResource("2_20hhf") input = ExtResource("1_20hhf") +rolls = 2 +loot_pool = Array[ExtResource("2_i5wfm")]([SubResource("Resource_rhaxb")]) metadata/_custom_type_script = "uid://boqr1fowaqmt0" diff --git a/inv_system/crafting_panel.gd b/inv_system/crafting_panel.gd index 0c1c4cb..2650e98 100644 --- a/inv_system/crafting_panel.gd +++ b/inv_system/crafting_panel.gd @@ -94,10 +94,16 @@ func style_none(): func _on_action_button_pressed() -> void: if not matched_recipe: return - if matched_recipe is CraftRecipe: + elif matched_recipe is CraftRecipe: var crafting : CraftRecipe = matched_recipe empty_grid() add_item(crafting.output) + check_recipes() + elif matched_recipe is ScavengeRecipe: + empty_grid() + for x in range(matched_recipe.rolls): + add_item(matched_recipe.roll()) + check_recipes() pass # Replace with function body. func empty_grid():