extends WeaponState

@export var emptyable: bool

func enter() -> void:
	machine.animation_player.play(with_morphems("idle"))

func exit() -> void:
	pass

func state_input(event: InputEvent) -> void:
	if not machine.is_multiplayer_authority() or Input.mouse_mode != Input.MouseMode.MOUSE_MODE_CAPTURED: return
	
	if event.is_action_pressed("plr_reload"):
		init_reload.rpc()

func use_begin() -> void:
	if machine.ammo > 0:
		transition.emit("Shoot")

@rpc("authority","call_local","reliable")
func init_reload():
	if machine.ammo == machine.max_ammo or machine.remaining_ammo <= 0:
		return
	transition.emit("Reload")

func with_morphems(animation):
	return machine.animation_prefix + ((animation+"_empty") if emptyable and machine.ammo == 0 else animation)
