extends Node

@export var KatanaSlash: PackedScene
@export var max_range = 50
@export var min_range = 50
@export var max_ammo = 20
var ammo = max_ammo

func activate(world, activator):
	var katana = KatanaSlash.instantiate()
	var target = activator.get_target_pos()
	katana.position = activator.position
	katana.position += katana.position.direction_to(target) \
		* clamp(katana.position.distance_to(target), min_range, max_range)
	katana.look_at(target)
	if activator.get_collision_layer_value(1): # player object
		katana.get_node("Area2D").set_collision_layer_value(1, false)
		katana.get_node("Area2D").set_collision_layer_value(2, true)
	elif activator.get_collision_layer_value(2): # enemy object
		katana.get_node("Area2D").set_collision_layer_value(1, true)
		katana.get_node("Area2D").set_collision_layer_value(2, false)
	else:
		assert(false, "who are you, activator?")
	world.add_child(katana)
	

func discard(world, activator):
	pass
