38 lines
947 B
GDScript
38 lines
947 B
GDScript
class_name Chest
|
|
extends Item
|
|
|
|
@onready var chest_lid: StaticBody3D = $chest/chest_lid
|
|
@onready var interaction_area: InteractionArea = $InteractionArea
|
|
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
|
|
|
@export var gold_amount := 10
|
|
var is_empty := false
|
|
|
|
func _ready() -> void:
|
|
state_changed.connect(_on_state_changed)
|
|
interaction_area.interact = Callable(self, "_on_interact")
|
|
if gold_amount == 0: is_empty = true
|
|
|
|
func _on_interact() -> void:
|
|
match state:
|
|
States.closed:
|
|
state = States.opened
|
|
States.opened:
|
|
if is_empty:
|
|
state = States.closed
|
|
else:
|
|
is_empty = true
|
|
GameManager.player.gold += gold_amount
|
|
state = States.looted
|
|
States.looted:
|
|
state = States.closed
|
|
|
|
func _on_state_changed(new_state: States) -> void:
|
|
match new_state:
|
|
States.opened:
|
|
animation_player.play("open")
|
|
States.closed:
|
|
animation_player.play("close")
|
|
States.looted:
|
|
animation_player.play("take_gold")
|