items added to recipie manager, loot system improved
This commit is contained in:
parent
54d072c843
commit
9588dfe559
5 changed files with 32 additions and 13 deletions
|
|
@ -5,6 +5,8 @@ var craft_recipes : Array[CraftRecipe]
|
|||
var crafts_dir : String = "res://crafting/crafts/"
|
||||
var scavenge_recipes : Array[ScavengeRecipe]
|
||||
var scavenges_dir : String = "res://crafting/scavenges/"
|
||||
var items : Array[ItemData]
|
||||
var items_dir : String = "res://items/"
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
|
@ -46,4 +48,16 @@ func load_recipes():
|
|||
scavenge_recipes.append(load(scavenges_dir + file_name) as ScavengeRecipe)
|
||||
file_name = dir.get_next()
|
||||
|
||||
## ITEMS
|
||||
dir = DirAccess.open(items_dir)
|
||||
if dir:
|
||||
dir.list_dir_begin()
|
||||
var file_name = dir.get_next()
|
||||
while file_name != "":
|
||||
if (file_name.get_extension() == "remap"):
|
||||
file_name = file_name.replace('.remap', '')
|
||||
print(items_dir+file_name)
|
||||
items.append(load(items_dir + file_name) as ItemData)
|
||||
file_name = dir.get_next()
|
||||
|
||||
recipes_loaded.emit()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ extends Control
|
|||
|
||||
@export var bin_inventory : Inventory
|
||||
@export var loot_button : Button
|
||||
@export var loot_pool : Array[ItemData]
|
||||
#@export var loot_pool : Array[ItemData]
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
|
@ -32,8 +32,20 @@ func _on_loot_button_pressed() -> void:
|
|||
#bin_inventory.add_item(pick_random_item())
|
||||
|
||||
func pick_random_item() -> ItemData:
|
||||
var icount = loot_pool.size()
|
||||
return loot_pool[randi() % icount]
|
||||
#var icount = loot_pool.size()
|
||||
#return loot_pool[randi() % icount]
|
||||
|
||||
var selected : ItemData
|
||||
var total_chance : int = 0
|
||||
for loot in RecipeManager.items :
|
||||
total_chance += loot.bin_chance
|
||||
var sel_chance : int = randi() % total_chance
|
||||
for loot in RecipeManager.items:
|
||||
if sel_chance >= 0:
|
||||
selected = loot
|
||||
sel_chance -= loot.bin_chance
|
||||
|
||||
return selected
|
||||
|
||||
|
||||
func _on_return_button_pressed() -> void:
|
||||
|
|
|
|||
|
|
@ -5,3 +5,4 @@ class_name ItemData
|
|||
@export var icon : Texture2D
|
||||
@export var value : String
|
||||
@export var custom_panel_style : StyleBox
|
||||
@export var bin_chance : int = 5
|
||||
|
|
|
|||
|
|
@ -9,4 +9,5 @@ script = ExtResource("2_x7wm3")
|
|||
item_name = "Computer"
|
||||
icon = ExtResource("1_e0dbh")
|
||||
custom_panel_style = ExtResource("1_x7wm3")
|
||||
bin_chance = 0
|
||||
metadata/_custom_type_script = "uid://dccraom7a7e8d"
|
||||
|
|
|
|||
|
|
@ -1,17 +1,9 @@
|
|||
[gd_scene load_steps=14 format=3 uid="uid://dsfal3m4siap2"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://dsfal3m4siap2"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c6oycdae5wvjf" path="res://inv_system/inventory.gd" id="1_6uqi0"]
|
||||
[ext_resource type="Texture2D" uid="uid://dj487wauiay6i" path="res://assets/ewase bins.png" id="1_g14j6"]
|
||||
[ext_resource type="Script" uid="uid://dal8g1ce37r3w" path="res://demo_scene.gd" id="1_vbegm"]
|
||||
[ext_resource type="Script" uid="uid://dccraom7a7e8d" path="res://inv_system/item_data.gd" id="2_ehkex"]
|
||||
[ext_resource type="Resource" uid="uid://bepkdyf7dn1y0" path="res://items/hdd_item.tres" id="3_ykrsh"]
|
||||
[ext_resource type="Resource" uid="uid://bcteljob51wfj" path="res://items/battery_item.tres" id="5_00tp4"]
|
||||
[ext_resource type="Resource" uid="uid://c2wbqelme8vy1" path="res://items/ram_item.tres" id="5_g14j6"]
|
||||
[ext_resource type="Resource" uid="uid://88v5bcyrgpob" path="res://items/large_psu_item.tres" id="6_77dp3"]
|
||||
[ext_resource type="Resource" uid="uid://swd1m0hvep4c" path="res://items/small_psu_item.tres" id="7_5tkv4"]
|
||||
[ext_resource type="PackedScene" uid="uid://dgqs20xf7l8c" path="res://inv_system/item_slot.tscn" id="7_xersf"]
|
||||
[ext_resource type="Resource" uid="uid://bufa63unuppu5" path="res://items/cpu.tres" id="8_6pgwd"]
|
||||
[ext_resource type="Resource" uid="uid://oc57emfpcnm0" path="res://items/gpu.tres" id="9_p1n6o"]
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_00tp4"]
|
||||
font_color = Color(1, 0, 0, 0.5764706)
|
||||
|
|
@ -27,7 +19,6 @@ mouse_filter = 2
|
|||
script = ExtResource("1_vbegm")
|
||||
bin_inventory = NodePath("BinPanel")
|
||||
loot_button = NodePath("LootButton")
|
||||
loot_pool = Array[ExtResource("2_ehkex")]([ExtResource("3_ykrsh"), ExtResource("5_g14j6"), ExtResource("5_00tp4"), ExtResource("6_77dp3"), ExtResource("7_5tkv4"), ExtResource("8_6pgwd"), ExtResource("9_p1n6o")])
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
z_index = -3
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue