local ____lualib = require("lualib_bundle")
local __TS__ArrayEntries = ____lualib.__TS__ArrayEntries
local __TS__Iterator = ____lualib.__TS__Iterator
local ____exports = {}
local movePlayerAndTheirFamiliars
local ____isaac_2Dtypescript_2Ddefinitions = require("isaac-typescript-definitions")
local Direction = ____isaac_2Dtypescript_2Ddefinitions.Direction
local ____cachedClasses = require("core.cachedClasses")
local game = ____cachedClasses.game
local ____constants = require("core.constants")
local NEW_FLOOR_STARTING_POSITION_GREED_MODE = ____constants.NEW_FLOOR_STARTING_POSITION_GREED_MODE
local NEW_FLOOR_STARTING_POSITION_NORMAL_MODE = ____constants.NEW_FLOOR_STARTING_POSITION_NORMAL_MODE
local ____familiars = require("functions.familiars")
local getPlayerFamiliars = ____familiars.getPlayerFamiliars
local ____math = require("functions.math")
local getCircleDiscretizedPoints = ____math.getCircleDiscretizedPoints
local ____playerIndex = require("functions.playerIndex")
local getAllPlayers = ____playerIndex.getAllPlayers
function movePlayerAndTheirFamiliars(self, player, position)
    player.Position = position
    local familiars = getPlayerFamiliars(nil, player)
    for ____, familiar in ipairs(familiars) do
        familiar.Position = position
    end
end
--- Helper function to move all of the players to where they would normally go when arriving at a new
-- floor. (In normal mode, this is the center of the room. In Greed Mode, this is below the top
-- door.)
-- 
-- If there is more than one player, they will be distributed around the center in a circle.
-- 
-- This function emulates what happens in the vanilla game when you travel to a new floor.
-- 
-- @param radius Optional. The radius of the circle. Default is 10.
function ____exports.movePlayersToCenter(self, radius)
    if radius == nil then
        radius = 10
    end
    local isGreedMode = game:IsGreedMode()
    local startingPosition = isGreedMode and NEW_FLOOR_STARTING_POSITION_GREED_MODE or NEW_FLOOR_STARTING_POSITION_NORMAL_MODE
    local players = getAllPlayers(nil)
    local firstPlayer = players[1]
    if firstPlayer == nil then
        return
    end
    if #players == 1 then
        movePlayerAndTheirFamiliars(nil, firstPlayer, startingPosition)
        return
    end
    local circlePoints = getCircleDiscretizedPoints(
        nil,
        startingPosition,
        radius,
        #players,
        1,
        1,
        Direction.LEFT
    )
    for ____, ____value in __TS__Iterator(__TS__ArrayEntries(players)) do
        local i = ____value[1]
        local player = ____value[2]
        local circlePosition = circlePoints[i + 1]
        if circlePosition ~= nil then
            player.Position = circlePosition
        end
    end
end
return ____exports
