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 EntityType = ____isaac_2Dtypescript_2Ddefinitions.EntityType
local ModCallback = ____isaac_2Dtypescript_2Ddefinitions.ModCallback
local SuckerVariant = ____isaac_2Dtypescript_2Ddefinitions.SuckerVariant
local ____cachedEnumValues = require("arrays.cachedEnumValues")
local ACTIVE_SLOT_VALUES = ____cachedEnumValues.ACTIVE_SLOT_VALUES
local ____cachedClasses = require("core.cachedClasses")
local game = ____cachedClasses.game
local ____ModCallbackCustom = require("enums.ModCallbackCustom")
local ModCallbackCustom = ____ModCallbackCustom.ModCallbackCustom
local ____charge = require("functions.charge")
local getTotalCharge = ____charge.getTotalCharge
local ____playerDataStructures = require("functions.playerDataStructures")
local defaultMapGetPlayer = ____playerDataStructures.defaultMapGetPlayer
local mapGetPlayer = ____playerDataStructures.mapGetPlayer
local mapSetPlayer = ____playerDataStructures.mapSetPlayer
local ____types = require("functions.types")
local asNumber = ____types.asNumber
local ____DefaultMap = require("classes.DefaultMap")
local DefaultMap = ____DefaultMap.DefaultMap
local ____CustomCallback = require("classes.private.CustomCallback")
local CustomCallback = ____CustomCallback.CustomCallback
local v = {
    run = {
        playersActiveItemMap = __TS__New(
            DefaultMap,
            function() return __TS__New(Map) end
        ),
        playersActiveChargeMap = __TS__New(
            DefaultMap,
            function() return __TS__New(Map) end
        )
    },
    room = {playersBulbLastCollisionFrame = __TS__New(Map)}
}
____exports.PostItemDischarge = __TS__Class()
local PostItemDischarge = ____exports.PostItemDischarge
PostItemDischarge.name = "PostItemDischarge"
__TS__ClassExtends(PostItemDischarge, CustomCallback)
function PostItemDischarge.prototype.____constructor(self)
    CustomCallback.prototype.____constructor(self)
    self.v = v
    self.shouldFire = function(____, fireArgs, optionalArgs)
        local _player, collectibleType = table.unpack(fireArgs)
        local callbackCollectibleType = table.unpack(optionalArgs)
        return callbackCollectibleType == nil or callbackCollectibleType == collectibleType
    end
    self.preNPCCollisionSucker = function(____, npc, collider)
        if npc.Variant == asNumber(nil, SuckerVariant.BULB) then
            return self:preNPCCollisionBulb(npc, collider)
        end
        return nil
    end
    self.postPEffectUpdateReordered = function(____, player)
        local activeItemMap = defaultMapGetPlayer(nil, v.run.playersActiveItemMap, player)
        local chargeMap = defaultMapGetPlayer(nil, v.run.playersActiveChargeMap, player)
        for ____, activeSlot in ipairs(ACTIVE_SLOT_VALUES) do
            do
                local currentActiveItem = player:GetActiveItem()
                local previousActiveItem = activeItemMap:get(activeSlot)
                if previousActiveItem == nil then
                    previousActiveItem = currentActiveItem
                end
                activeItemMap:set(activeSlot, currentActiveItem)
                if currentActiveItem ~= previousActiveItem then
                    goto __continue9
                end
                local currentCharge = getTotalCharge(nil, player, activeSlot)
                local previousCharge = chargeMap:get(activeSlot)
                if previousCharge == nil then
                    previousCharge = currentCharge
                end
                chargeMap:set(activeSlot, currentCharge)
                if self:playerRecentlyCollidedWithBulb(player) then
                    goto __continue9
                end
                if currentCharge < previousCharge then
                    local collectibleType = player:GetActiveItem(activeSlot)
                    self:fire(player, collectibleType, activeSlot)
                end
            end
            ::__continue9::
        end
    end
    self.callbacksUsed = {{ModCallback.PRE_NPC_COLLISION, self.preNPCCollisionSucker, {EntityType.SUCKER}}}
    self.customCallbacksUsed = {{ModCallbackCustom.POST_PEFFECT_UPDATE_REORDERED, self.postPEffectUpdateReordered}}
end
function PostItemDischarge.prototype.preNPCCollisionBulb(self, _npc, collider)
    self:checkPlayerCollidedWithBulb(collider)
    return nil
end
function PostItemDischarge.prototype.checkPlayerCollidedWithBulb(self, collider)
    local player = collider:ToPlayer()
    if player == nil then
        return
    end
    local gameFrameCount = game:GetFrameCount()
    mapSetPlayer(nil, v.room.playersBulbLastCollisionFrame, player, gameFrameCount)
end
function PostItemDischarge.prototype.playerRecentlyCollidedWithBulb(self, player)
    local gameFrameCount = game:GetFrameCount()
    local bulbLastCollisionFrame = mapGetPlayer(nil, v.room.playersBulbLastCollisionFrame, player)
    local collidedOnThisFrame = gameFrameCount == bulbLastCollisionFrame
    local collidedOnLastFrame = gameFrameCount - 1 == bulbLastCollisionFrame
    return collidedOnThisFrame or collidedOnLastFrame
end
return ____exports
