extends LimboHSM

@onready var root: Normal = %Normal

@export var jump_grace_time: float = .13

var _jump_grace_timer: float

func _setup() -> void:
	self.add_transition(
		root.hook_shooting_state,
		root.grapping_state,
		root.hook_shooting_state.EVENT_FINISHED,
		_can_enter_grapping_state
	)
	self.add_event_handler(&"trigger_jump",_handle_trigger_jump)

func _enter() -> void:
	_jump_grace_timer = 0
	get_root().blackboard.set_var(&"is_hooking",true) ##BB里锁住Dash状态

func _update(delta: float) -> void:
	if _jump_grace_timer > 0:
		_jump_grace_timer -= delta

func _exit() -> void:
	get_root().blackboard.set_var(&"is_hooking",false) ##BB里锁住Dash状态
	
	agent.locomotion_comp.enable_movement()

func _handle_trigger_jump() -> bool:
	_jump_grace_timer = jump_grace_time
	return false

func _can_enter_grapping_state() -> bool:
	return agent.spawn_hook_comp.has_hook_anchor()
