extends Node

@export var Mine: PackedScene
@export var max_range = 1500
@export var min_range = 15
@export var max_ammo = 5
var ammo = max_ammo

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

func discard(world, activator):
	pass
