local ____lualib = require("lualib_bundle")
local __TS__New = ____lualib.__TS__New
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local CacheFlag = ____isaac_2Dtypescript_2Ddefinitions.CacheFlag
local ____PlayerStat = require("enums.PlayerStat")
local PlayerStat = ____PlayerStat.PlayerStat
local ____defaultPlayerStatMap = require("maps.defaultPlayerStatMap")
local DEFAULT_PLAYER_STAT_MAP = ____defaultPlayerStatMap.DEFAULT_PLAYER_STAT_MAP
local ____ReadonlySet = require("types.ReadonlySet")
local ReadonlySet = ____ReadonlySet.ReadonlySet
local ____tears = require("functions.tears")
local addTearsStat = ____tears.addTearsStat
--- Helper function to get all of the stat for a player.
function ____exports.getPlayerStats(self, player)
    return {
        [PlayerStat.DAMAGE] = player.Damage,
        [PlayerStat.FIRE_DELAY] = player.MaxFireDelay,
        [PlayerStat.SHOT_SPEED] = player.ShotSpeed,
        [PlayerStat.TEAR_HEIGHT] = player.TearHeight,
        [PlayerStat.TEAR_RANGE] = player.TearRange,
        [PlayerStat.TEAR_FALLING_ACCELERATION] = player.TearFallingAcceleration,
        [PlayerStat.TEAR_FALLING_SPEED] = player.TearFallingSpeed,
        [PlayerStat.MOVE_SPEED] = player.MoveSpeed,
        [PlayerStat.TEAR_FLAG] = player.TearFlags,
        [PlayerStat.TEAR_COLOR] = player.TearColor,
        [PlayerStat.FLYING] = player.CanFly,
        [PlayerStat.LUCK] = player.Luck,
        [PlayerStat.SIZE] = player.SpriteScale
    }
end
local STAT_CACHE_FLAGS_SET = __TS__New(ReadonlySet, {
    CacheFlag.DAMAGE,
    CacheFlag.FIRE_DELAY,
    CacheFlag.SHOT_SPEED,
    CacheFlag.RANGE,
    CacheFlag.SPEED,
    CacheFlag.LUCK
})
--- 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 ____exports.addPlayerStat(self, player, cacheFlag, amount)
    if not STAT_CACHE_FLAGS_SET:has(cacheFlag) then
        error("You cannot add a stat to a player with the cache flag of: " .. tostring(cacheFlag))
    end
    repeat
        local ____switch4 = cacheFlag
        local ____cond4 = ____switch4 == CacheFlag.DAMAGE
        if ____cond4 then
            do
                player.Damage = player.Damage + amount
                break
            end
        end
        ____cond4 = ____cond4 or ____switch4 == CacheFlag.FIRE_DELAY
        if ____cond4 then
            do
                addTearsStat(nil, player, amount)
                break
            end
        end
        ____cond4 = ____cond4 or ____switch4 == CacheFlag.SHOT_SPEED
        if ____cond4 then
            do
                player.ShotSpeed = player.ShotSpeed + amount
                break
            end
        end
        ____cond4 = ____cond4 or ____switch4 == CacheFlag.RANGE
        if ____cond4 then
            do
                player.TearHeight = player.TearHeight + amount
                break
            end
        end
        ____cond4 = ____cond4 or ____switch4 == CacheFlag.SPEED
        if ____cond4 then
            do
                player.MoveSpeed = player.MoveSpeed + amount
                break
            end
        end
        ____cond4 = ____cond4 or ____switch4 == CacheFlag.LUCK
        if ____cond4 then
            do
                player.Luck = player.Luck + amount
                break
            end
        end
    until true
end
--- 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 ____exports.getDefaultPlayerStat(self, cacheFlag)
    return DEFAULT_PLAYER_STAT_MAP:get(cacheFlag)
end
--- Helper function to get the stat for a player corresponding to the `StatType`.
function ____exports.getPlayerStat(self, player, playerStat)
    local playerStats = ____exports.getPlayerStats(nil, player)
    return playerStats[playerStat]
end
return ____exports
