extends BaseState

signal PlayerBeganDrawingBow

@export var strafing_speed := 35
@export var movement_componenent: MovementComponent
@export var body: CharacterBody2D

var used_item_action: String
var animation_finished := false

func GetStateEnum() -> PlayerStateMachine.States:
	return PlayerStateMachine.States.DRAWING_BOW


func Enter(extra_parameters: Dictionary) -> void:
	animation_finished = false
	used_item_action = extra_parameters.action_name
	PlayerBeganDrawingBow.emit()


func Update(_delta: float) -> void:
	if !animation_finished:
		return
	
	if !Input.is_action_pressed(used_item_action):
		state_machine.QueueStateChange(PlayerStateMachine.States.FIRING_ARROW)
		return
	
	var movement_vector := movement_componenent.movement_vector
	if movement_vector != Vector2.ZERO:
		body.velocity = movement_vector * strafing_speed
		body.move_and_slide()


func OnDrawingBowAnimationFinished() -> void:
	animation_finished = true
