local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local __TS__DecorateLegacy = ____lualib.__TS__DecorateLegacy
local ____exports = {}
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local CardType = ____isaac_2Dtypescript_2Ddefinitions.CardType
local CoinSubType = ____isaac_2Dtypescript_2Ddefinitions.CoinSubType
local CollectibleType = ____isaac_2Dtypescript_2Ddefinitions.CollectibleType
local EffectVariant = ____isaac_2Dtypescript_2Ddefinitions.EffectVariant
local EntityType = ____isaac_2Dtypescript_2Ddefinitions.EntityType
local HeartSubType = ____isaac_2Dtypescript_2Ddefinitions.HeartSubType
local ItemPoolType = ____isaac_2Dtypescript_2Ddefinitions.ItemPoolType
local PillColor = ____isaac_2Dtypescript_2Ddefinitions.PillColor
local RoomType = ____isaac_2Dtypescript_2Ddefinitions.RoomType
local TrinketType = ____isaac_2Dtypescript_2Ddefinitions.TrinketType
local ____cachedClasses = require("core.cachedClasses")
local game = ____cachedClasses.game
local ____constants = require("core.constants")
local DISTANCE_OF_GRID_TILE = ____constants.DISTANCE_OF_GRID_TILE
local ____decorators = require("decorators")
local Exported = ____decorators.Exported
local ____ISCFeature = require("enums.ISCFeature")
local ISCFeature = ____ISCFeature.ISCFeature
local ____RockAltType = require("enums.RockAltType")
local RockAltType = ____RockAltType.RockAltType
local ____entitiesSpecific = require("functions.entitiesSpecific")
local spawnEffectWithSeed = ____entitiesSpecific.spawnEffectWithSeed
local spawnNPCWithSeed = ____entitiesSpecific.spawnNPCWithSeed
local ____pickupsSpecific = require("functions.pickupsSpecific")
local spawnCardWithSeed = ____pickupsSpecific.spawnCardWithSeed
local spawnCoinWithSeed = ____pickupsSpecific.spawnCoinWithSeed
local spawnHeartWithSeed = ____pickupsSpecific.spawnHeartWithSeed
local spawnPillWithSeed = ____pickupsSpecific.spawnPillWithSeed
local spawnTrinketWithSeed = ____pickupsSpecific.spawnTrinketWithSeed
local ____projectiles = require("functions.projectiles")
local fireProjectilesInCircle = ____projectiles.fireProjectilesInCircle
local ____random = require("functions.random")
local getRandom = ____random.getRandom
local ____rng = require("functions.rng")
local isRNG = ____rng.isRNG
local newRNG = ____rng.newRNG
local ____spawnCollectible = require("functions.spawnCollectible")
local spawnCollectible = ____spawnCollectible.spawnCollectible
local ____utils = require("functions.utils")
local ____repeat = ____utils["repeat"]
local ____vector = require("functions.vector")
local getRandomVector = ____vector.getRandomVector
local isVector = ____vector.isVector
local ____Feature = require("classes.private.Feature")
local Feature = ____Feature.Feature
local ROCK_ALT_CHANCES = {NOTHING = 0.68, BASIC_DROP = 0.0967, TRINKET = 0.025, COLLECTIBLE = 0.005}
local COIN_VELOCITY_MULTIPLIER = 2
--- Matches the vanilla value, according to Fly's decompilation.
local FIND_FREE_INITIAL_STEP = 70
--- Matches the vanilla value, according to Fly's decompilation.
local FART_RADIUS = DISTANCE_OF_GRID_TILE * 3
local POLYP_PROJECTILE_SPEED = 10
local POLYP_NUM_PROJECTILES = 6
____exports.SpawnRockAltRewards = __TS__Class()
local SpawnRockAltRewards = ____exports.SpawnRockAltRewards
SpawnRockAltRewards.name = "SpawnRockAltRewards"
__TS__ClassExtends(SpawnRockAltRewards, Feature)
function SpawnRockAltRewards.prototype.____constructor(self, itemPoolDetection)
    Feature.prototype.____constructor(self)
    self.featuresUsed = {ISCFeature.ITEM_POOL_DETECTION}
    self.itemPoolDetection = itemPoolDetection
end
function SpawnRockAltRewards.prototype.spawnRockAltReward(self, positionOrGridIndex, rockAltType, seedOrRNG)
    local room = game:GetRoom()
    local position = isVector(nil, positionOrGridIndex) and positionOrGridIndex or room:GetGridPosition(positionOrGridIndex)
    local rng = isRNG(nil, seedOrRNG) and seedOrRNG or newRNG(nil, seedOrRNG)
    repeat
        local ____switch4 = rockAltType
        local ____cond4 = ____switch4 == RockAltType.URN
        if ____cond4 then
            do
                return self:spawnRockAltRewardUrn(position, rng)
            end
        end
        ____cond4 = ____cond4 or ____switch4 == RockAltType.MUSHROOM
        if ____cond4 then
            do
                return self:spawnRockAltRewardMushroom(position, rng)
            end
        end
        ____cond4 = ____cond4 or ____switch4 == RockAltType.SKULL
        if ____cond4 then
            do
                return self:spawnRockAltRewardSkull(position, rng)
            end
        end
        ____cond4 = ____cond4 or ____switch4 == RockAltType.POLYP
        if ____cond4 then
            do
                return self:spawnRockAltRewardPolyp(position, rng)
            end
        end
        ____cond4 = ____cond4 or ____switch4 == RockAltType.BUCKET_DOWNPOUR
        if ____cond4 then
            do
                return self:spawnRockAltRewardBucketDownpour(position, rng)
            end
        end
        ____cond4 = ____cond4 or ____switch4 == RockAltType.BUCKET_DROSS
        if ____cond4 then
            do
                return self:spawnRockAltRewardBucketDross(position, rng)
            end
        end
    until true
end
__TS__DecorateLegacy({Exported}, SpawnRockAltRewards.prototype, "spawnRockAltReward", true)
function SpawnRockAltRewards.prototype.spawnRockAltRewardUrn(self, position, rng)
    local room = game:GetRoom()
    local chance = getRandom(nil, rng)
    local totalChance = 0
    totalChance = totalChance + ROCK_ALT_CHANCES.NOTHING
    if chance < totalChance then
        return false
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.BASIC_DROP
    if chance < totalChance then
        local numCoinsChance = getRandom(nil, rng)
        local numCoins = numCoinsChance < 0.5 and 1 or 2
        ____repeat(
            nil,
            numCoins,
            function()
                local randomVector = getRandomVector(nil, rng)
                local velocity = randomVector * COIN_VELOCITY_MULTIPLIER
                spawnCoinWithSeed(
                    nil,
                    CoinSubType.NULL,
                    position,
                    rng,
                    velocity
                )
            end
        )
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.TRINKET
    if chance < totalChance then
        spawnTrinketWithSeed(nil, TrinketType.SWALLOWED_PENNY, position, rng)
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.COLLECTIBLE
    if chance < totalChance then
        local stillInPools = self.itemPoolDetection:isCollectibleInItemPool(CollectibleType.QUARTER, ItemPoolType.DEVIL)
        if stillInPools then
            spawnCollectible(nil, CollectibleType.QUARTER, position, rng)
            return true
        end
        return false
    end
    local numEnemiesChance = getRandom(nil, rng)
    local numEnemies = numEnemiesChance < 0.5 and 1 or 2
    ____repeat(
        nil,
        numEnemies,
        function()
            local targetPos = room:FindFreePickupSpawnPosition(position, FIND_FREE_INITIAL_STEP)
            EntityNPC.ThrowSpider(
                position,
                nil,
                targetPos,
                false,
                0
            )
        end
    )
    return true
end
__TS__DecorateLegacy({Exported}, SpawnRockAltRewards.prototype, "spawnRockAltRewardUrn", true)
function SpawnRockAltRewards.prototype.spawnRockAltRewardMushroom(self, position, rng)
    local room = game:GetRoom()
    local roomType = room:GetType()
    local chance = getRandom(nil, rng)
    local totalChance = 0
    totalChance = totalChance + ROCK_ALT_CHANCES.NOTHING
    if chance < totalChance then
        return false
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.BASIC_DROP
    if chance < totalChance then
        spawnPillWithSeed(nil, PillColor.NULL, position, rng)
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.TRINKET
    if chance < totalChance then
        spawnTrinketWithSeed(nil, TrinketType.LIBERTY_CAP, position, rng)
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.COLLECTIBLE
    if chance < totalChance then
        if roomType == RoomType.SECRET then
            local wavyCapChance = getRandom(nil, rng)
            if wavyCapChance < 0.0272 then
                local stillInPools = self.itemPoolDetection:isCollectibleInItemPool(CollectibleType.WAVY_CAP, ItemPoolType.SECRET)
                if stillInPools then
                    spawnCollectible(nil, CollectibleType.WAVY_CAP, position, rng)
                    return true
                end
            end
        end
        local magicMushroomStillInPools = self.itemPoolDetection:isCollectibleInItemPool(CollectibleType.MAGIC_MUSHROOM, ItemPoolType.TREASURE)
        local miniMushStillInPools = self.itemPoolDetection:isCollectibleInItemPool(CollectibleType.MINI_MUSH, ItemPoolType.TREASURE)
        if magicMushroomStillInPools and miniMushStillInPools then
            local collectibleChance = getRandom(nil, rng)
            local collectibleType = collectibleChance < 0.5 and CollectibleType.MAGIC_MUSHROOM or CollectibleType.MINI_MUSH
            spawnCollectible(nil, collectibleType, position, rng)
            return true
        end
        if magicMushroomStillInPools then
            spawnCollectible(nil, CollectibleType.MINI_MUSH, position, rng)
            return true
        end
        if miniMushStillInPools then
            spawnCollectible(nil, CollectibleType.MAGIC_MUSHROOM, position, rng)
            return true
        end
        return false
    end
    game:Fart(position)
    game:ButterBeanFart(position, FART_RADIUS, nil)
    return true
end
__TS__DecorateLegacy({Exported}, SpawnRockAltRewards.prototype, "spawnRockAltRewardMushroom", true)
function SpawnRockAltRewards.prototype.spawnRockAltRewardSkull(self, position, rng)
    local chance = getRandom(nil, rng)
    local totalChance = 0
    totalChance = totalChance + ROCK_ALT_CHANCES.NOTHING
    if chance < totalChance then
        return false
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.BASIC_DROP
    if chance < totalChance then
        spawnCardWithSeed(nil, CardType.NULL, position, rng)
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.TRINKET
    if chance < totalChance then
        spawnHeartWithSeed(nil, HeartSubType.BLACK, position, rng)
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.COLLECTIBLE
    if chance < totalChance then
        local ghostBabyStillInPools = self.itemPoolDetection:isCollectibleInItemPool(CollectibleType.GHOST_BABY, ItemPoolType.TREASURE)
        local dryBabyStillInPools = self.itemPoolDetection:isCollectibleInItemPool(CollectibleType.DRY_BABY, ItemPoolType.TREASURE)
        if ghostBabyStillInPools and dryBabyStillInPools then
            local collectibleChance = getRandom(nil, rng)
            local collectibleType = collectibleChance < 0.5 and CollectibleType.GHOST_BABY or CollectibleType.DRY_BABY
            spawnCollectible(nil, collectibleType, position, rng)
            return true
        end
        if ghostBabyStillInPools then
            spawnCollectible(nil, CollectibleType.DRY_BABY, position, rng)
            return true
        end
        if dryBabyStillInPools then
            spawnCollectible(nil, CollectibleType.GHOST_BABY, position, rng)
            return true
        end
        return false
    end
    spawnNPCWithSeed(
        nil,
        EntityType.HOST,
        0,
        0,
        position,
        rng
    )
    return true
end
__TS__DecorateLegacy({Exported}, SpawnRockAltRewards.prototype, "spawnRockAltRewardSkull", true)
function SpawnRockAltRewards.prototype.spawnRockAltRewardPolyp(self, position, rng)
    local chance = getRandom(nil, rng)
    local totalChance = 0
    totalChance = totalChance + ROCK_ALT_CHANCES.NOTHING
    if chance < totalChance then
        return false
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.BASIC_DROP
    if chance < totalChance then
        spawnHeartWithSeed(nil, HeartSubType.NULL, position, rng)
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.TRINKET
    if chance < totalChance then
        spawnTrinketWithSeed(nil, TrinketType.UMBILICAL_CORD, position, rng)
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.COLLECTIBLE
    if chance < totalChance then
        local placentaStillInPools = self.itemPoolDetection:isCollectibleInItemPool(CollectibleType.PLACENTA, ItemPoolType.BOSS)
        local bloodClotStillInPools = self.itemPoolDetection:isCollectibleInItemPool(CollectibleType.BLOOD_CLOT, ItemPoolType.BOSS)
        if placentaStillInPools and bloodClotStillInPools then
            local collectibleChance = getRandom(nil, rng)
            local collectibleType = collectibleChance < 0.5 and CollectibleType.PLACENTA or CollectibleType.BLOOD_CLOT
            spawnCollectible(nil, collectibleType, position, rng)
            return true
        end
        if placentaStillInPools then
            spawnCollectible(nil, CollectibleType.PLACENTA, position, rng)
            return true
        end
        if bloodClotStillInPools then
            spawnCollectible(nil, CollectibleType.BLOOD_CLOT, position, rng)
            return true
        end
        return false
    end
    spawnEffectWithSeed(
        nil,
        EffectVariant.CREEP_RED,
        0,
        position,
        rng
    )
    fireProjectilesInCircle(
        nil,
        nil,
        position,
        POLYP_PROJECTILE_SPEED,
        POLYP_NUM_PROJECTILES
    )
    return true
end
__TS__DecorateLegacy({Exported}, SpawnRockAltRewards.prototype, "spawnRockAltRewardPolyp", true)
function SpawnRockAltRewards.prototype.spawnRockAltRewardBucketDownpour(self, position, rng)
    local room = game:GetRoom()
    local chance = getRandom(nil, rng)
    local totalChance = 0
    totalChance = totalChance + ROCK_ALT_CHANCES.NOTHING
    if chance < totalChance then
        return false
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.BASIC_DROP
    if chance < totalChance then
        local numCoinsChance = getRandom(nil, rng)
        local numCoins = numCoinsChance < 0.5 and 1 or 2
        ____repeat(
            nil,
            numCoins,
            function()
                local randomVector = getRandomVector(nil, rng)
                local velocity = randomVector * COIN_VELOCITY_MULTIPLIER
                spawnCoinWithSeed(
                    nil,
                    CoinSubType.NULL,
                    position,
                    rng,
                    velocity
                )
            end
        )
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.TRINKET
    if chance < totalChance then
        spawnTrinketWithSeed(nil, TrinketType.SWALLOWED_PENNY, position, rng)
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.COLLECTIBLE
    if chance < totalChance then
        local stillInPools = self.itemPoolDetection:isCollectibleInItemPool(CollectibleType.LEECH, ItemPoolType.TREASURE)
        if stillInPools then
            spawnCollectible(nil, CollectibleType.LEECH, position, rng)
            return true
        end
        return false
    end
    local enemiesChance = getRandom(nil, rng)
    local entityType = enemiesChance < 0.5 and EntityType.SPIDER or EntityType.SMALL_LEECH
    local numEnemiesChance = getRandom(nil, rng)
    local numEnemies = numEnemiesChance < 0.5 and 1 or 2
    ____repeat(
        nil,
        numEnemies,
        function()
            local targetPos = room:FindFreePickupSpawnPosition(position, FIND_FREE_INITIAL_STEP)
            local spider = EntityNPC.ThrowSpider(
                position,
                nil,
                targetPos,
                false,
                0
            )
            if entityType == EntityType.SMALL_LEECH and spider.Type ~= entityType then
                spider:Morph(entityType, 0, 0, -1)
            end
        end
    )
    return true
end
__TS__DecorateLegacy({Exported}, SpawnRockAltRewards.prototype, "spawnRockAltRewardBucketDownpour", true)
function SpawnRockAltRewards.prototype.spawnRockAltRewardBucketDross(self, position, rng)
    local room = game:GetRoom()
    local chance = getRandom(nil, rng)
    local totalChance = 0
    totalChance = totalChance + ROCK_ALT_CHANCES.NOTHING
    if chance < totalChance then
        return false
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.BASIC_DROP
    if chance < totalChance then
        local numCoinsChance = getRandom(nil, rng)
        local numCoins = numCoinsChance < 0.5 and 1 or 2
        ____repeat(
            nil,
            numCoins,
            function()
                local randomVector = getRandomVector(nil, rng)
                local velocity = randomVector * COIN_VELOCITY_MULTIPLIER
                spawnCoinWithSeed(
                    nil,
                    CoinSubType.NULL,
                    position,
                    rng,
                    velocity
                )
            end
        )
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.TRINKET
    if chance < totalChance then
        spawnTrinketWithSeed(nil, TrinketType.BUTT_PENNY, position, rng)
        return true
    end
    totalChance = totalChance + ROCK_ALT_CHANCES.COLLECTIBLE
    if chance < totalChance then
        local stillInPools = self.itemPoolDetection:isCollectibleInItemPool(CollectibleType.POOP, ItemPoolType.TREASURE)
        if stillInPools then
            spawnCollectible(nil, CollectibleType.POOP, position, rng)
            return true
        end
        return false
    end
    local enemiesChance = getRandom(nil, rng)
    local entityType = enemiesChance < 0.5 and EntityType.DRIP or EntityType.SMALL_LEECH
    local numEnemiesChance = getRandom(nil, rng)
    local numEnemies = numEnemiesChance < 0.5 and 1 or 2
    ____repeat(
        nil,
        numEnemies,
        function()
            local targetPos = room:FindFreePickupSpawnPosition(position, FIND_FREE_INITIAL_STEP)
            local spider = EntityNPC.ThrowSpider(
                position,
                nil,
                targetPos,
                false,
                0
            )
            spider:Morph(entityType, 0, 0, -1)
        end
    )
    return true
end
__TS__DecorateLegacy({Exported}, SpawnRockAltRewards.prototype, "spawnRockAltRewardBucketDross", true)
return ____exports
