"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fireProjectilesInCircle = exports.fireProjectiles = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const entities_1 = require("./entities");
const entitiesSpecific_1 = require("./entitiesSpecific");
/**
 * 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 fireProjectiles(npc, position, velocity, projectilesMode = isaac_typescript_definitions_1.ProjectilesMode.ONE_PROJECTILE, projectileParams = ProjectileParams()) {
    const oldProjectiles = (0, entitiesSpecific_1.getProjectiles)(projectileParams.Variant);
    let spawnedFly = false;
    if (npc === undefined) {
        // Since the `EntityNPC.FireProjectiles` method is not static, we arbitrarily spawn a fly.
        spawnedFly = true;
        npc = (0, entitiesSpecific_1.spawnNPC)(isaac_typescript_definitions_1.EntityType.FLY, 0, 0, position);
        npc.Visible = false;
        npc.ClearEntityFlags(isaac_typescript_definitions_1.EntityFlag.APPEAR);
    }
    npc.FireProjectiles(position, velocity, projectilesMode, projectileParams);
    const newProjectiles = (0, entitiesSpecific_1.getProjectiles)(projectileParams.Variant);
    if (spawnedFly) {
        npc.Remove();
    }
    return (0, entities_1.getFilteredNewEntities)(oldProjectiles, newProjectiles);
}
exports.fireProjectiles = fireProjectiles;
/**
 * 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 fireProjectilesInCircle(npc, position, speed, numProjectiles) {
    const velocity = Vector(speed, numProjectiles);
    return fireProjectiles(npc, position, velocity, isaac_typescript_definitions_1.ProjectilesMode.N_PROJECTILES_IN_CIRCLE);
}
exports.fireProjectilesInCircle = fireProjectilesInCircle;
