extends LimboHSM

@onready var root: Normal = %Normal

func _setup() -> void:
	self.add_transition(root.idle_state,root.move_state,root.idle_state.EVENT_FINISHED)
	self.add_transition(root.move_state,root.idle_state,root.move_state.EVENT_FINISHED)
	
	self.add_event_handler(&"trigger_jump",_handler_trigger_jump)

func _enter() -> void:
	_land_from_air_check()
	
	get_root().blackboard.set_var(&"is_jumping",false)
	agent.locomotion_comp.full_recover_dash_count()

func _update(delta: float) -> void:
	if not agent.is_on_floor() : 
		dispatch(self.EVENT_FINISHED)

func _handler_trigger_jump() -> bool:
	get_root().blackboard.set_var(&"want_to_jump",true)
	self.dispatch(self.EVENT_FINISHED)
	return true

##无法在jump state 的时候进入grounded state
func _can_enter_grounded() -> bool:
	return not get_active_state() == root.jump_state

func _land_from_air_check() -> bool:
	var last_state = root.get_previous_active_state() as LimboState
	if last_state and last_state == root.airbone_state :
		agent.on_land_dust()
		return true
	
	return false
