extends State

@export var max_speed: float = 2.5
@export var acceleration: float = 1.0
@export var deceleration: float = 100.0
@export var JUMP_VELOCITY: float = 4.5
@export var player: Player
@export var player_movement: PlayerMovement
@export var player_input: PlayerInput
@export var weapon_system: WeaponSystem

func enter() -> void:
	player_input.crouch_begin.connect(begin_crouch)
	player_input.walk_end.connect(end_walk)
	player_input.jumped.connect(on_jumped)

func exit() -> void:
	player_input.crouch_begin.disconnect(begin_crouch)
	player_input.walk_end.disconnect(end_walk)
	player_input.jumped.disconnect(on_jumped)

func physics_update(delta: float) -> void:
	if not is_multiplayer_authority():
		return
	
	if not player.is_on_floor():
		transition.emit("Fall")
		return
	
	player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta)

func on_jumped() -> void:
	if player.is_on_floor():
		player_movement.jump()
		transition.emit("Fall")

func end_walk() -> void:
	transition.emit("Stand")

func begin_crouch() -> void:
	transition.emit("Crouch")
