dofile_once("data/scripts/lib/utilities.lua")

local no_cooldown = true

for _, ch in ipairs(EntityGetAllChildren(EntityGetWithTag("player_unit")[1])) do
	if EntityGetName(ch) == "ln_sex_cooldown" then
		no_cooldown = false
		break
	end
end

local entity_id = GetUpdatedEntityID()
local puller_x, puller_y = EntityGetTransform(entity_id)
local player_x, player_y = EntityGetTransform(EntityGetWithTag("player_unit")[1])

-- will shoot if player is close to entity and only if no other tentacle was shot
if no_cooldown == true and
math.abs(puller_x - player_x) < 50 and
math.abs(puller_y - player_y) < 50 and
EntityGetWithName("ln_pulling_tentacle") == 0 then
	local angle = get_direction(puller_x, puller_y, player_x, player_y)
	local length = 3000

	local vel_x = 0 - math.cos(angle) * length
	local vel_y =  math.sin(angle) * length

	shoot_projectile(entity_id, "mods/lewd_noita/files/enemies/pulling_tentacle.xml", puller_x, puller_y, vel_x, vel_y)
end