core gameplay in! scavenging working!

This commit is contained in:
Tabby 2026-01-11 19:06:59 +11:00
parent c6a6171a81
commit b773e224c0
5 changed files with 38 additions and 4 deletions

5
crafting/rollableLoot.gd Normal file
View file

@ -0,0 +1,5 @@
extends Resource
class_name RollableLoot
@export var item : ItemData
@export var chance : int

View file

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

View file

@ -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

View file

@ -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"

View file

@ -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():