|
|
|
|
@ -1,17 +1,13 @@
|
|
|
|
|
class_name Chest
|
|
|
|
|
extends ItemInteractable
|
|
|
|
|
|
|
|
|
|
# Aktionstexte
|
|
|
|
|
const ACTION_OPEN_CHEST: StringName = &"open chest"
|
|
|
|
|
const ACTION_CLOSE_CHEST: StringName = &"close chest"
|
|
|
|
|
const ACTION_COLLECT: StringName = &"collect gold"
|
|
|
|
|
# Animationsnamen
|
|
|
|
|
const ANIM_TAKE_GOLD: StringName = &"take_gold"
|
|
|
|
|
# Action texts
|
|
|
|
|
const ACTION_COLLECT: StringName = &"collect gold"
|
|
|
|
|
# Animation names
|
|
|
|
|
const ANIM_TAKE_GOLD: StringName = &"take_gold"
|
|
|
|
|
|
|
|
|
|
@export var gold_amount: int = 10
|
|
|
|
|
|
|
|
|
|
var has_gold: bool = false
|
|
|
|
|
|
|
|
|
|
var has_gold: bool = false
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
state_changed.connect(_on_state_changed)
|
|
|
|
|
@ -20,7 +16,6 @@ func _ready() -> void:
|
|
|
|
|
state = States.closed
|
|
|
|
|
update_action_name()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_interact() -> void:
|
|
|
|
|
match state:
|
|
|
|
|
States.closed:
|
|
|
|
|
@ -35,7 +30,6 @@ func _on_interact() -> void:
|
|
|
|
|
state = States.closed
|
|
|
|
|
update_action_name()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_state_changed(new_state: States) -> void:
|
|
|
|
|
match new_state:
|
|
|
|
|
States.opened:
|
|
|
|
|
@ -44,30 +38,18 @@ func _on_state_changed(new_state: States) -> void:
|
|
|
|
|
animation_player.play(ANIM_CLOSE)
|
|
|
|
|
States.looted:
|
|
|
|
|
animation_player.play(ANIM_TAKE_GOLD)
|
|
|
|
|
|
|
|
|
|
States.destroyed:
|
|
|
|
|
pass
|
|
|
|
|
States.hidden:
|
|
|
|
|
pass
|
|
|
|
|
States.idle:
|
|
|
|
|
pass
|
|
|
|
|
_:
|
|
|
|
|
pass # Other states: destroyed, hidden, idle
|
|
|
|
|
|
|
|
|
|
func update_action_name() -> void:
|
|
|
|
|
match state:
|
|
|
|
|
States.closed:
|
|
|
|
|
States.closed, States.looted:
|
|
|
|
|
interaction_area.action_name = ACTION_OPEN
|
|
|
|
|
States.opened:
|
|
|
|
|
interaction_area.action_name = ACTION_COLLECT if has_gold else ACTION_CLOSE
|
|
|
|
|
States.looted:
|
|
|
|
|
interaction_area.action_name = ACTION_OPEN
|
|
|
|
|
_:
|
|
|
|
|
pass # Other states
|
|
|
|
|
|
|
|
|
|
States.destroyed:
|
|
|
|
|
pass
|
|
|
|
|
States.hidden:
|
|
|
|
|
pass
|
|
|
|
|
States.idle:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
func collect_gold() -> void:
|
|
|
|
|
GameManager.player.gold += gold_amount
|
|
|
|
|
has_gold = false
|
|
|
|
|
has_gold = false
|
|
|
|
|
|