"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostDiceRoomActivated = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const effects_1 = require("../../functions/effects");
const players_1 = require("../../functions/players");
const CustomCallback_1 = require("../private/CustomCallback");
const v = {
    room: {
        diceRoomActivated: false,
    },
};
class PostDiceRoomActivated extends CustomCallback_1.CustomCallback {
    v = v;
    constructor() {
        super();
        this.callbacksUsed = [
            // 55
            [
                isaac_typescript_definitions_1.ModCallback.POST_EFFECT_UPDATE,
                this.postEffectUpdateDiceFloor,
                [isaac_typescript_definitions_1.EffectVariant.DICE_FLOOR],
            ],
        ];
    }
    shouldFire = (fireArgs, optionalArgs) => {
        const [_player, diceFloorSubType] = fireArgs;
        const [callbackDiceFloorSubType] = optionalArgs;
        return (callbackDiceFloorSubType === undefined ||
            diceFloorSubType === callbackDiceFloorSubType);
    };
    // ModCallback.POST_EFFECT_UPDATE (55)
    // EffectVariant.DICE_FLOOR (76)
    postEffectUpdateDiceFloor = (effect) => {
        if (v.room.diceRoomActivated) {
            return;
        }
        // When using the debug console to go to a dice room, the player can appear on top of the dice
        // floor before they snap to the door.
        if (effect.FrameCount === 0) {
            return;
        }
        const closestPlayer = (0, players_1.getClosestPlayer)(effect.Position);
        if ((0, effects_1.isCloseEnoughToTriggerDiceFloor)(closestPlayer, effect)) {
            v.room.diceRoomActivated = true;
            this.fire(closestPlayer, effect.SubType);
        }
    };
}
exports.PostDiceRoomActivated = PostDiceRoomActivated;
