"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PreventChildEntities = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const decorators_1 = require("../../../decorators");
const Feature_1 = require("../../private/Feature");
const v = {
    room: {
        preventingEntities: new Set(),
    },
};
class PreventChildEntities extends Feature_1.Feature {
    /** @internal */
    v = v;
    /** @internal */
    constructor() {
        super();
        this.callbacksUsed = [
            // 27
            [isaac_typescript_definitions_1.ModCallback.POST_NPC_INIT, this.postNPCInit],
        ];
    }
    // ModCallback.POST_NPC_INIT (27)
    postNPCInit = (npc) => {
        const spawnerEntityMatch = npc.SpawnerEntity !== undefined &&
            v.room.preventingEntities.has(GetPtrHash(npc.SpawnerEntity));
        const parentMatch = npc.Parent !== undefined &&
            v.room.preventingEntities.has(GetPtrHash(npc.Parent));
        if (spawnerEntityMatch || parentMatch) {
            npc.Remove();
        }
    };
    /**
     * Helper function to prevent an entity from spawning any other entities. Meant to be used on NPCs
     * like Squirts. This behavior will only last for the current room.
     *
     * Under the hood, this function will remove any new NPCs spawned that have a
     * `Entity.SpawnerEntity` or `Entity.Parent` value that matches the provided entity. (They are
     * removed during the `POST_NPC_INIT` callback specifically.)
     *
     * In order to use this function, you must upgrade your mod with
     * `ISCFeature.PREVENT_CHILD_ENTITIES`.
     *
     * @public
     */
    preventChildEntities(entity) {
        const ptrHash = GetPtrHash(entity);
        v.room.preventingEntities.add(ptrHash);
    }
}
exports.PreventChildEntities = PreventChildEntities;
__decorate([
    decorators_1.Exported
], PreventChildEntities.prototype, "preventChildEntities", null);
