local no_cooldown = true

for _, ch in ipairs(EntityGetAllChildren(EntityGetParent(GetUpdatedEntityID())) or {}) do
	if EntityGetName(ch) == "ln_sex_cooldown" then
		no_cooldown = false
		break
	end
end

SetRandomSeed(GameGetFrameNum(), GetUpdatedEntityID())

if no_cooldown == true then
	local kobold_id = EntityGetParent(GetUpdatedEntityID())

	local birth_scene = EntityCreateNew("birth")

	EntityAddComponent2(birth_scene, "VariableStorageComponent", {
		value_string=ComponentGetValue2(EntityGetFirstComponent(GetUpdatedEntityID(), "VariableStorageComponent"), "value_string"),
	})

	local kobold_x, kobold_y = EntityGetTransform(kobold_id)

	if Random(0, 1) == 1 then
		EntitySetTransform(birth_scene, kobold_x, kobold_y, 0, 1, 1)
	else
		EntitySetTransform(birth_scene, kobold_x, kobold_y, 0, -1, 1)
	end

	EntityAddChild(birth_scene, kobold_id)

	EntityAddComponent2(birth_scene, "LuaComponent", {
		script_source_file="mods/lewd_noita/files/sex_logic/sex_scene.lua"
	})

	EntityKill(GetUpdatedEntityID())
else
	-- delay birth if it triggers during another scene
	EntityAddComponent2(GetUpdatedEntityID(), "LuaComponent", {
		script_source_file="mods/lewd_noita/files/sex_logic/start_birth.lua",
		execute_every_n_frame=Random(10, 15) * 60,
		remove_after_executed=true,
	})
end