"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.CharacterStats = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const decorators_1 = require("../../../decorators");
const stats_1 = require("../../../functions/stats");
const Feature_1 = require("../../private/Feature");
/** Easily create custom characters that have base stats different from that of Isaac. */
class CharacterStats extends Feature_1.Feature {
    charactersStatMap = new Map();
    /** @internal */
    constructor() {
        super();
        this.callbacksUsed = [
            // 8
            [isaac_typescript_definitions_1.ModCallback.EVALUATE_CACHE, this.evaluateCache],
        ];
    }
    // ModCallback.EVALUATE_CACHE (8)
    evaluateCache = (player, cacheFlag) => {
        const character = player.GetPlayerType();
        const statMap = this.charactersStatMap.get(character);
        if (statMap === undefined) {
            return;
        }
        const stat = statMap.get(cacheFlag);
        const defaultStat = (0, stats_1.getDefaultPlayerStat)(cacheFlag);
        if (stat === undefined || defaultStat === undefined) {
            return;
        }
        const delta = stat - defaultStat;
        (0, stats_1.addPlayerStat)(player, cacheFlag, delta);
    };
    /**
     * Helper function to manage the stats for a vanilla or custom character. Call this function once
     * at the beginning of your mod to declare the starting stats.
     *
     * You must provide this function with a map of CacheFlag to the default stat amount. For example,
     * the default amount of damage is 3.5. To make a custom character start with 4.5 damage:
     *
     * ```ts
     * const fooDefaultStats = new Map<CacheFlag, number>([
     *   [CacheFlag.DAMAGE, 4.5],
     * ])
     * registerCharacterStats(PlayerTypeCustom.FOO, fooDefaultStats);
     * ```
     *
     * Note that the format for the `CacheFlag.FIRE_DELAY` value should be in the tears stat format,
     * not the `MaxFireDelay` format.
     *
     * In order to use this function, you must upgrade your mod with `ISCFeature.CHARACTER_STATS`.
     *
     * @public
     */
    registerCharacterStats(playerType, statMap) {
        this.charactersStatMap.set(playerType, statMap);
    }
}
exports.CharacterStats = CharacterStats;
__decorate([
    decorators_1.Exported
], CharacterStats.prototype, "registerCharacterStats", null);
