Add item_dump
This commit is contained in:
1 parent
9fc5043c7b
commit
b215e201e0
2 files changed
+63
No files matched your search
@@ -0,0 +1,52 @@
|
||||
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
|
||||
Reference in new issue
Block a user