"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostHolyMantleRemoved = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const ModCallbackCustom_1 = require("../../enums/ModCallbackCustom");
const frames_1 = require("../../functions/frames");
const playerDataStructures_1 = require("../../functions/playerDataStructures");
const shouldFire_1 = require("../../shouldFire");
const DefaultMap_1 = require("../DefaultMap");
const CustomCallback_1 = require("../private/CustomCallback");
const v = {
    run: {
        playersHolyMantleMap: new DefaultMap_1.DefaultMap(0),
    },
};
class PostHolyMantleRemoved extends CustomCallback_1.CustomCallback {
    v = v;
    constructor() {
        super();
        this.customCallbacksUsed = [
            [
                ModCallbackCustom_1.ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED,
                this.postPEffectUpdateReordered,
            ],
        ];
    }
    shouldFire = shouldFire_1.shouldFirePlayer;
    // ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED
    postPEffectUpdateReordered = (player) => {
        const effects = player.GetEffects();
        const newNumHolyMantles = effects.GetCollectibleEffectNum(isaac_typescript_definitions_1.CollectibleType.HOLY_MANTLE);
        const oldNumHolyMantles = (0, playerDataStructures_1.defaultMapGetPlayer)(v.run.playersHolyMantleMap, player);
        (0, playerDataStructures_1.mapSetPlayer)(v.run.playersHolyMantleMap, player, newNumHolyMantles);
        // We check for being after room frame 0 to prevent the callback from firing when the player
        // loses a lost curse from a white fire. (In this case, the player will have a Holy Mantle
        // effect from the lost curse, and then when losing the curse, they will also lose the Holy
        // Mantle.)
        if (newNumHolyMantles < oldNumHolyMantles && (0, frames_1.isAfterRoomFrame)(0)) {
            this.fire(player, oldNumHolyMantles, newNumHolyMantles);
        }
    };
}
exports.PostHolyMantleRemoved = PostHolyMantleRemoved;
