isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
53 lines (52 loc) • 2.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.movePlayersToCenter = movePlayersToCenter;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedClasses_1 = require("../core/cachedClasses");
const constants_1 = require("../core/constants");
const familiars_1 = require("./familiars");
const math_1 = require("./math");
const playerIndex_1 = require("./playerIndex");
/**
* 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 movePlayersToCenter(radius = 10) {
const isGreedMode = cachedClasses_1.game.IsGreedMode();
const startingPosition = isGreedMode
? constants_1.NEW_FLOOR_STARTING_POSITION_GREED_MODE
: constants_1.NEW_FLOOR_STARTING_POSITION_NORMAL_MODE;
const players = (0, playerIndex_1.getAllPlayers)();
const firstPlayer = players[0];
if (firstPlayer === undefined) {
return;
}
// If there is only one player, we can move them exactly to the center of the room.
if (players.length === 1) {
movePlayerAndTheirFamiliars(firstPlayer, startingPosition);
return;
}
// If there is more than one player, spread them out in a circle around the center of the room.
// (This is what happens in vanilla.)
const circlePoints = (0, math_1.getCircleDiscretizedPoints)(startingPosition, radius, players.length, 1, 1, isaac_typescript_definitions_1.Direction.LEFT);
for (const [i, player] of players.entries()) {
const circlePosition = circlePoints[i];
if (circlePosition !== undefined) {
player.Position = circlePosition;
}
}
}
function movePlayerAndTheirFamiliars(player, position) {
player.Position = position;
const familiars = (0, familiars_1.getPlayerFamiliars)(player);
for (const familiar of familiars) {
familiar.Position = position;
}
}