UNPKG

slp-enforcer

Version:

Finds violations of the Melee Controller Ruleset by inspecting SLP files

63 lines (62 loc) 2.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const types_1 = require("../types"); const exists_1 = require("./exists"); function getWinners(gameEnd, settings, finalPostFrameUpdates) { var _a, _b, _c; const { placements, gameEndMethod, lrasInitiatorIndex } = gameEnd; const { players, isTeams } = settings; if (gameEndMethod === types_1.GameEndMethod.NO_CONTEST || gameEndMethod === types_1.GameEndMethod.UNRESOLVED) { // The winner is the person who didn't LRAS if (exists_1.exists(lrasInitiatorIndex) && players.length === 2) { const winnerIndex = (_a = players.find(({ playerIndex }) => playerIndex !== lrasInitiatorIndex)) === null || _a === void 0 ? void 0 : _a.playerIndex; if (exists_1.exists(winnerIndex)) { return [ { playerIndex: winnerIndex, position: 0, }, ]; } } return []; } if (gameEndMethod === types_1.GameEndMethod.TIME && players.length === 2) { const nonFollowerUpdates = finalPostFrameUpdates.filter((pfu) => !pfu.isFollower); if (nonFollowerUpdates.length !== players.length) { return []; } const p1 = nonFollowerUpdates[0]; const p2 = nonFollowerUpdates[1]; if (p1.stocksRemaining > p2.stocksRemaining) { return [{ playerIndex: p1.playerIndex, position: 0 }]; } else if (p2.stocksRemaining > p1.stocksRemaining) { return [{ playerIndex: p2.playerIndex, position: 0 }]; } const p1Health = Math.trunc(p1.percent); const p2Health = Math.trunc(p2.percent); if (p1Health < p2Health) { return [{ playerIndex: p1.playerIndex, position: 0 }]; } else if (p2Health < p1Health) { return [{ playerIndex: p2.playerIndex, position: 0 }]; } // If stocks and percents were tied, no winner return []; } const firstPosition = placements.find((placement) => placement.position === 0); if (!firstPosition) { return []; } const winningTeam = (_c = (_b = players.find(({ playerIndex }) => playerIndex === firstPosition.playerIndex)) === null || _b === void 0 ? void 0 : _b.teamId) !== null && _c !== void 0 ? _c : null; if (isTeams && exists_1.exists(winningTeam)) { return placements.filter((placement) => { var _a, _b; const teamId = (_b = (_a = players.find(({ playerIndex }) => playerIndex === placement.playerIndex)) === null || _a === void 0 ? void 0 : _a.teamId) !== null && _b !== void 0 ? _b : null; return teamId === winningTeam; }); } return [firstPosition]; } exports.getWinners = getWinners;