"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostPlayerInitFirst = void 0;
const ModCallbackCustom_1 = require("../../enums/ModCallbackCustom");
const playerIndex_1 = require("../../functions/playerIndex");
const rooms_1 = require("../../functions/rooms");
const shouldFire_1 = require("../../shouldFire");
const CustomCallback_1 = require("../private/CustomCallback");
class PostPlayerInitFirst extends CustomCallback_1.CustomCallback {
    constructor() {
        super();
        this.customCallbacksUsed = [
            [ModCallbackCustom_1.ModCallbackCustom.POST_NEW_ROOM_REORDERED, this.postNewRoomReordered],
            [ModCallbackCustom_1.ModCallbackCustom.POST_PLAYER_INIT_LATE, this.postPlayerInitLate],
        ];
    }
    shouldFire = shouldFire_1.shouldFirePlayer;
    // ModCallbackCustom.POST_NEW_ROOM_REORDERED
    postNewRoomReordered = () => {
        // When a player uses the Genesis collectible, they will lose all of their collectibles,
        // trinkets, pocket items, and stats, so they will need to be re-initialized like they would be
        // at the beginning of a run. However, in this case, the `POST_PLAYER_INIT_FIRST` callback will
        // not fire, because that only fires once per run. Thus, we explicitly handle this special case.
        // Note that whichever player uses Genesis, items will be removed from all players (at least in
        // the case of Jacob & Esau).
        if ((0, rooms_1.inGenesisRoom)()) {
            for (const player of (0, playerIndex_1.getPlayers)()) {
                this.fire(player);
            }
        }
    };
    // ModCallbackCustom.POST_PLAYER_INIT_LATE
    postPlayerInitLate = (player) => {
        // We want to exclude non-real players like the Strawman keeper.
        if ((0, playerIndex_1.isChildPlayer)(player)) {
            return;
        }
        this.fire(player);
    };
}
exports.PostPlayerInitFirst = PostPlayerInitFirst;
