working on items and inventory
This commit is contained in:
72
ItemDatabase/ItemDatabase.gd
Normal file
72
ItemDatabase/ItemDatabase.gd
Normal file
@@ -0,0 +1,72 @@
|
||||
extends Node
|
||||
|
||||
var PU_objects:Dictionary = {}
|
||||
var Powerups:Dictionary = {}
|
||||
|
||||
# For random item drops
|
||||
var AllItems: Dictionary = {}
|
||||
var total_weight:float = 0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
PU_objects["Nail Gun"] = {
|
||||
"scene": "res://PickupableObjects/NailGun/NailGun.tscn",
|
||||
"spawn_chance": 0.8,
|
||||
"roll_weight": 0.0
|
||||
}
|
||||
PU_objects["Grappling Hook"] = {
|
||||
"scene": "res://pickupable_objects/grappling_hook/grappling_hook.tscn",
|
||||
"spawn_chance": 0.3,
|
||||
"roll_weight": 0.0
|
||||
}
|
||||
PU_objects["Bomb"] = {
|
||||
"scene": "res://PickupableObjects/Bomb/bomb.tscn",
|
||||
"spawn_chance": 0.7,
|
||||
"roll_weight": 0.0
|
||||
}
|
||||
PU_objects["Glue Patch"] = {
|
||||
"scene": "res://PickupableObjects/GluePatch/GluePatch.tscn",
|
||||
"spawn_chance": 1.0,
|
||||
"roll_weight": 0.0
|
||||
}
|
||||
PU_objects["Void Portal"] = {
|
||||
"scene": "res://pickupable_objects/void_portal/void_portal.tscn",
|
||||
"spawn_chance": 0.3,
|
||||
"roll_weight": 0.0
|
||||
}
|
||||
|
||||
Powerups["Speed Up"] = {
|
||||
"scene": "res://powerups/speed_up/speed_up.tscn",
|
||||
"spawn_chance": 1.0,
|
||||
"roll_weight": 0.0
|
||||
}
|
||||
|
||||
# Castable_objects["Nail Gun"] = "res://pickupable_objects/nail_gun/nail_shot.tscn"
|
||||
# Castable_objects["Grappling Hook"] = "res://pickupable_objects/grappling_hook/hook_shot.tscn"
|
||||
# Castable_objects["Bomb"] = "res://pickupable_objects/bomb/bomb_thrown.tscn"
|
||||
# Castable_objects["Glue Patch"] = "res://pickupable_objects/glue_patch/glue_patch_deployed.tscn"
|
||||
# Castable_objects["Void Portal"] = "res://pickupable_objects/void_portal/void_portal_thrown.tscn"
|
||||
create_all_items_dict()
|
||||
calculate_weights()
|
||||
|
||||
func create_all_items_dict():
|
||||
for key in PU_objects.keys():
|
||||
AllItems[key] = PU_objects[key]
|
||||
for key in Powerups.keys():
|
||||
AllItems[key] = Powerups[key]
|
||||
|
||||
func calculate_weights():
|
||||
total_weight = 0
|
||||
for item in AllItems.values():
|
||||
total_weight = total_weight + item.spawn_chance
|
||||
item.roll_weight = total_weight
|
||||
|
||||
func return_random_item() -> Dictionary:
|
||||
var roll: float = randf_range(-0.90, total_weight)
|
||||
if roll < 0:
|
||||
return {}
|
||||
for item in AllItems.values():
|
||||
if item.roll_weight > roll:
|
||||
return item
|
||||
return {}
|
||||
|
Reference in New Issue
Block a user