53 lines
1.4 KiB
GDScript
53 lines
1.4 KiB
GDScript
extends Spatial
|
|
signal item_dump_completed
|
|
signal item_dumped
|
|
|
|
# Godot is not configurable enough (without great pains)
|
|
# to make this look less dumb
|
|
export var item_type_0: Resource
|
|
export var item_count_0: int
|
|
export var item_type_1: Resource
|
|
export var item_count_1: int
|
|
export var item_type_2: Resource
|
|
export var item_count_2: int
|
|
|
|
var remaining := {}
|
|
export var enabled = true
|
|
|
|
func _ready():
|
|
reset()
|
|
|
|
func reset():
|
|
remaining.clear()
|
|
if item_type_0 and item_count_0 > 0:
|
|
remaining[item_type_0] = item_count_0
|
|
if item_type_1 and item_count_1 > 0:
|
|
remaining[item_type_1] = item_count_1
|
|
if item_type_2 and item_count_2 > 0:
|
|
remaining[item_type_2] = item_count_2
|
|
|
|
func on_player_interact(player) -> bool:
|
|
if not enabled:
|
|
return false
|
|
if remaining.empty():
|
|
return false
|
|
if not player.has_item():
|
|
return false
|
|
if not remaining.has(player.item_in_hand.item_type):
|
|
return false
|
|
assert(remaining[player.item_in_hand.item_type] > 0, "remaining dictionary should always erase keys with a value of 0")
|
|
|
|
# Remove the player's item and mark off the item on the remaining list
|
|
var item = player.drop_item_in_hand()
|
|
remaining[item.item_type] -= 1
|
|
if remaining[item.item_type] <= 0:
|
|
remaining.erase(item.item_type)
|
|
item.queue_free()
|
|
emit_signal("item_dumped")
|
|
|
|
# Check if everything's been checked off
|
|
if remaining.empty():
|
|
emit_signal("item_dump_completed")
|
|
|
|
return true
|