extends WeaponState

const active_bomb: StringName = "uid://dtbpyfdawb02b"

func enter():
	machine.animation_player.play(machine.animation_prefix+"plant")
	machine.animation_player.animation_finished.connect(on_animation_finished)
	machine.speed_modifier = 0.0
	machine.player.get_node("PlantAudio").multiplayer_play()

func exit():
	machine.animation_player.animation_finished.disconnect(on_animation_finished)
	machine.speed_modifier = 1.0

func on_animation_finished(animation: StringName):
	if is_multiplayer_authority() == false:
		return
	if animation == machine.animation_prefix + "plant":
		
		Session.spawn({"scene": active_bomb, "position": machine.player_camera.get_parent().global_position,"plant": Session.get_site().name})
		
		machine.ammo -= 1
		return_to_previous.emit()

func state_input(event: InputEvent) -> void:
	if is_multiplayer_authority() == false:
		return
	if event.is_action_released("plr_bomb"):
		transition.emit("Idle")
		machine.player.get_node("PlantAudio").multiplayer_stop()
