"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPlayerStats = exports.getPlayerStat = exports.getDefaultPlayerStat = exports.addPlayerStat = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const PlayerStat_1 = require("../enums/PlayerStat");
const defaultPlayerStatMap_1 = require("../maps/defaultPlayerStatMap");
const ReadonlySet_1 = require("../types/ReadonlySet");
const tears_1 = require("./tears");
const STAT_CACHE_FLAGS_SET = new ReadonlySet_1.ReadonlySet([
    isaac_typescript_definitions_1.CacheFlag.DAMAGE,
    isaac_typescript_definitions_1.CacheFlag.FIRE_DELAY,
    isaac_typescript_definitions_1.CacheFlag.SHOT_SPEED,
    isaac_typescript_definitions_1.CacheFlag.RANGE,
    isaac_typescript_definitions_1.CacheFlag.SPEED,
    isaac_typescript_definitions_1.CacheFlag.LUCK, // 1 << 10
]);
/**
 * Helper function to add a stat to a player based on the `CacheFlag` provided. Call this function
 * from the `EVALUATE_CACHE` callback.
 *
 * Note that for `CacheFlag.FIRE_DELAY`, the "amount" argument will be interpreted as the tear stat
 * to add (and not the amount to mutate `EntityPlayer.MaxFireDelay` by).
 *
 * This function supports the following cache flags:
 * - CacheFlag.DAMAGE (1 << 0)
 * - CacheFlag.FIRE_DELAY (1 << 1)
 * - CacheFlag.SHOT_SPEED (1 << 2)
 * - CacheFlag.RANGE (1 << 3)
 * - CacheFlag.SPEED (1 << 4)
 * - CacheFlag.LUCK (1 << 10)
 */
function addPlayerStat(player, cacheFlag, amount) {
    if (!STAT_CACHE_FLAGS_SET.has(cacheFlag)) {
        error(`You cannot add a stat to a player with the cache flag of: ${cacheFlag}`);
    }
    switch (cacheFlag) {
        // 1 << 0
        case isaac_typescript_definitions_1.CacheFlag.DAMAGE: {
            player.Damage += amount;
            break;
        }
        // 1 << 1
        case isaac_typescript_definitions_1.CacheFlag.FIRE_DELAY: {
            (0, tears_1.addTearsStat)(player, amount);
            break;
        }
        // 1 << 2
        case isaac_typescript_definitions_1.CacheFlag.SHOT_SPEED: {
            player.ShotSpeed += amount;
            break;
        }
        // 1 << 3
        case isaac_typescript_definitions_1.CacheFlag.RANGE: {
            player.TearHeight += amount;
            break;
        }
        // 1 << 4
        case isaac_typescript_definitions_1.CacheFlag.SPEED: {
            player.MoveSpeed += amount;
            break;
        }
        // 1 << 10
        case isaac_typescript_definitions_1.CacheFlag.LUCK: {
            player.Luck += amount;
            break;
        }
    }
}
exports.addPlayerStat = addPlayerStat;
/**
 * Returns the starting stat that Isaac (the default character) starts with. For example, if you
 * pass this function `CacheFlag.DAMAGE`, it will return 3.5.
 *
 * Note that the default fire delay is represented in the tear stat, not the `MaxFireDelay` value.
 */
function getDefaultPlayerStat(cacheFlag) {
    return defaultPlayerStatMap_1.DEFAULT_PLAYER_STAT_MAP.get(cacheFlag);
}
exports.getDefaultPlayerStat = getDefaultPlayerStat;
/** Helper function to get the stat for a player corresponding to the `StatType`. */
function getPlayerStat(player, playerStat) {
    const playerStats = getPlayerStats(player);
    return playerStats[playerStat];
}
exports.getPlayerStat = getPlayerStat;
/** Helper function to get all of the stat for a player. */
function getPlayerStats(player) {
    return {
        [PlayerStat_1.PlayerStat.DAMAGE]: player.Damage,
        [PlayerStat_1.PlayerStat.FIRE_DELAY]: player.MaxFireDelay,
        [PlayerStat_1.PlayerStat.SHOT_SPEED]: player.ShotSpeed,
        [PlayerStat_1.PlayerStat.TEAR_HEIGHT]: player.TearHeight,
        [PlayerStat_1.PlayerStat.TEAR_RANGE]: player.TearRange,
        [PlayerStat_1.PlayerStat.TEAR_FALLING_ACCELERATION]: player.TearFallingAcceleration,
        [PlayerStat_1.PlayerStat.TEAR_FALLING_SPEED]: player.TearFallingSpeed,
        [PlayerStat_1.PlayerStat.MOVE_SPEED]: player.MoveSpeed,
        [PlayerStat_1.PlayerStat.TEAR_FLAG]: player.TearFlags,
        [PlayerStat_1.PlayerStat.TEAR_COLOR]: player.TearColor,
        [PlayerStat_1.PlayerStat.FLYING]: player.CanFly,
        [PlayerStat_1.PlayerStat.LUCK]: player.Luck,
        [PlayerStat_1.PlayerStat.SIZE]: player.SpriteScale, // 1 << 11
    };
}
exports.getPlayerStats = getPlayerStats;
