local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local EntityFlag = ____isaac_2Dtypescript_2Ddefinitions.EntityFlag
local EntityType = ____isaac_2Dtypescript_2Ddefinitions.EntityType
local ProjectilesMode = ____isaac_2Dtypescript_2Ddefinitions.ProjectilesMode
local ____entities = require("functions.entities")
local getFilteredNewEntities = ____entities.getFilteredNewEntities
local ____entitiesSpecific = require("functions.entitiesSpecific")
local getProjectiles = ____entitiesSpecific.getProjectiles
local spawnNPC = ____entitiesSpecific.spawnNPC
--- Helper function to make an NPC fire one or more projectiles. Returns the fired projectile(s).
-- 
-- Use this function instead of the `EntityNPC.FireProjectiles` method if you need to modify or
-- access the `EntityProjectile` objects after they are fired, since this function returns the
-- objects in an array.
-- 
-- @param npc The NPC to fire the projectile(s) from. You can also pass undefined if you do not want
-- the projectile(s) to come from anything in particular.
-- @param position The staring position of the projectile(s).
-- @param velocity The starting velocity of the projectile(s).
-- @param projectilesMode Optional. The mode of the projectile(s). Default is
-- `ProjectilesMode.ONE_PROJECTILE`.
-- @param projectileParams Optional. The parameters of the projectile(s). Default is
-- `ProjectileParams()`.
-- @returns The fired projectile(s).
function ____exports.fireProjectiles(self, npc, position, velocity, projectilesMode, projectileParams)
    if projectilesMode == nil then
        projectilesMode = ProjectilesMode.ONE_PROJECTILE
    end
    if projectileParams == nil then
        projectileParams = ProjectileParams()
    end
    local oldProjectiles = getProjectiles(nil, projectileParams.Variant)
    local spawnedFly = false
    if npc == nil then
        spawnedFly = true
        npc = spawnNPC(
            nil,
            EntityType.FLY,
            0,
            0,
            position
        )
        npc.Visible = false
        npc:ClearEntityFlags(EntityFlag.APPEAR)
    end
    npc:FireProjectiles(position, velocity, projectilesMode, projectileParams)
    local newProjectiles = getProjectiles(nil, projectileParams.Variant)
    if spawnedFly then
        npc:Remove()
    end
    return getFilteredNewEntities(nil, oldProjectiles, newProjectiles)
end
--- Helper function to spawn projectiles in a circle around a position. Under the hood, this
-- leverages `ProjectileMode.N_PROJECTILES_IN_CIRCLE`.
-- 
-- @param npc The NPC to fire the projectile(s) from. You can also pass undefined if you do not want
-- the projectile(s) to come from anything in particular.
-- @param position The staring position of the projectile(s).
-- @param speed The speed of the projectile(s).
-- @param numProjectiles The amount of projectiles to spawn.
-- @returns The fired projectile(s).
function ____exports.fireProjectilesInCircle(self, npc, position, speed, numProjectiles)
    local velocity = Vector(speed, numProjectiles)
    return ____exports.fireProjectiles(
        nil,
        npc,
        position,
        velocity,
        ProjectilesMode.N_PROJECTILES_IN_CIRCLE
    )
end
return ____exports
