local ____lualib = require("lualib_bundle")
local Map = ____lualib.Map
local __TS__New = ____lualib.__TS__New
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local BossID = ____isaac_2Dtypescript_2Ddefinitions.BossID
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
local DamageFlag = ____isaac_2Dtypescript_2Ddefinitions.DamageFlag
local DamageFlagZero = ____isaac_2Dtypescript_2Ddefinitions.DamageFlagZero
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
local ____cachedClasses = require("core.cachedClasses")
local game = ____cachedClasses.game
local ____ModCallbackCustom = require("enums.ModCallbackCustom")
local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
local ____flag = require("functions.flag")
local hasFlag = ____flag.hasFlag
local ____playerDataStructures = require("functions.playerDataStructures")
local mapGetPlayer = ____playerDataStructures.mapGetPlayer
local mapSetPlayer = ____playerDataStructures.mapSetPlayer
local ____playerIndex = require("functions.playerIndex")
local isChildPlayer = ____playerIndex.isChildPlayer
local ____revive = require("functions.revive")
local isDamageToPlayerFatal = ____revive.isDamageToPlayerFatal
local willPlayerRevive = ____revive.willPlayerRevive
local ____rooms = require("functions.rooms")
local inBossRoomOf = ____rooms.inBossRoomOf
local ____shouldFire = require("shouldFire")
local shouldFirePlayer = ____shouldFire.shouldFirePlayer
local ____CustomCallback = require("classes.private.CustomCallback")
local CustomCallback = ____CustomCallback.CustomCallback
local v = {run = {playersLastDamageGameFrame = __TS__New(Map)}}
____exports.PostPlayerFatalDamage = __TS__Class()
local PostPlayerFatalDamage = ____exports.PostPlayerFatalDamage
PostPlayerFatalDamage.name = "PostPlayerFatalDamage"
__TS__ClassExtends(PostPlayerFatalDamage, CustomCallback)
function PostPlayerFatalDamage.prototype.____constructor(self)
    CustomCallback.prototype.____constructor(self)
    self.v = v
    self.shouldFire = shouldFirePlayer
    self.preUseItemBible = function(____, _collectibleType, _rng, player, _useFlags, _activeSlot, _customVarData)
        if not inBossRoomOf(nil, BossID.SATAN) then
            return nil
        end
        if willPlayerRevive(nil, player) then
            return nil
        end
        local shouldSustainDeath = self:fire(
            player,
            0,
            DamageFlagZero,
            EntityRef(player),
            0
        )
        if shouldSustainDeath ~= nil then
            return not shouldSustainDeath
        end
        return nil
    end
    self.entityTakeDmgPlayer = function(____, player, amount, damageFlags, source, countdownFrames)
        if isChildPlayer(nil, player) then
            return nil
        end
        local gameFrameCount = game:GetFrameCount()
        local lastDamageGameFrame = mapGetPlayer(nil, v.run.playersLastDamageGameFrame, player)
        mapSetPlayer(nil, v.run.playersLastDamageGameFrame, player, gameFrameCount)
        if hasFlag(nil, damageFlags, DamageFlag.NO_KILL) then
            return nil
        end
        if willPlayerRevive(nil, player) then
            return nil
        end
        if not isDamageToPlayerFatal(
            nil,
            player,
            amount,
            source,
            lastDamageGameFrame
        ) then
            return nil
        end
        local shouldSustainDeath = self:fire(
            player,
            amount,
            damageFlags,
            source,
            countdownFrames
        )
        if shouldSustainDeath ~= nil then
            return shouldSustainDeath
        end
        return nil
    end
    self.callbacksUsed = {{ModCallback.PRE_USE_ITEM, self.preUseItemBible, {CollectibleType.BIBLE}}}
    self.customCallbacksUsed = {{ModCallbackCustom.ENTITY_TAKE_DMG_PLAYER, self.entityTakeDmgPlayer}}
end
return ____exports
