mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-19 07:25:02 +00:00
Create ranked type enum, last person not afk wins in 1v1 (#2892)
## Description: * Add RankedType enum, for now it's just 1v1 * Add new method to MapPlaylist to create 1v1 game config * Update WinCheck so the last player is declared a winner on 1v1. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
This commit is contained in:
+3
-2
@@ -16,6 +16,7 @@ import {
|
||||
GameType,
|
||||
HumansVsNations,
|
||||
Quads,
|
||||
RankedType,
|
||||
Trios,
|
||||
UnitType,
|
||||
} from "./game/Game";
|
||||
@@ -183,6 +184,7 @@ export const GameConfigSchema = z.object({
|
||||
donateTroops: z.boolean(), // Configures donations to humans only
|
||||
gameType: z.enum(GameType),
|
||||
gameMode: z.enum(GameMode),
|
||||
rankedType: z.enum(RankedType).optional(), // Only set for ranked games.
|
||||
gameMapSize: z.enum(GameMapSize),
|
||||
publicGameModifiers: z
|
||||
.object({
|
||||
@@ -198,11 +200,10 @@ export const GameConfigSchema = z.object({
|
||||
disableNavMesh: z.boolean().optional(),
|
||||
randomSpawn: z.boolean(),
|
||||
maxPlayers: z.number().optional(),
|
||||
maxTimerValue: z.number().int().min(1).max(120).optional(),
|
||||
maxTimerValue: z.number().int().min(1).max(120).optional(), // In minutes
|
||||
spawnImmunityDuration: z.number().int().min(0).optional(), // In ticks
|
||||
disabledUnits: z.enum(UnitType).array().optional(),
|
||||
playerTeams: TeamCountConfigSchema.optional(),
|
||||
isOneVOne: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const TeamSchema = z.string();
|
||||
|
||||
@@ -5,6 +5,8 @@ import {
|
||||
Game,
|
||||
GameMode,
|
||||
Player,
|
||||
PlayerType,
|
||||
RankedType,
|
||||
Team,
|
||||
} from "../game/Game";
|
||||
|
||||
@@ -44,6 +46,19 @@ export class WinCheckExecution implements Execution {
|
||||
if (sorted.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.mg.config().gameConfig().rankedType === RankedType.OneVOne) {
|
||||
const humans = sorted.filter(
|
||||
(p) => p.type() === PlayerType.Human && !p.isDisconnected(),
|
||||
);
|
||||
if (humans.length === 1) {
|
||||
this.mg.setWinner(humans[0], this.mg.stats().stats());
|
||||
console.log(`${humans[0].name()} has won the game`);
|
||||
this.active = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const max = sorted[0];
|
||||
const timeElapsed =
|
||||
(this.mg.ticks() - this.mg.config().numSpawnPhaseTurns()) / 10;
|
||||
|
||||
@@ -195,6 +195,11 @@ export enum GameMode {
|
||||
FFA = "Free For All",
|
||||
Team = "Team",
|
||||
}
|
||||
|
||||
export enum RankedType {
|
||||
OneVOne = "1v1",
|
||||
}
|
||||
|
||||
export const isGameMode = (value: unknown): value is GameMode =>
|
||||
isEnumValue(GameMode, value);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
HumansVsNations,
|
||||
PublicGameModifiers,
|
||||
Quads,
|
||||
RankedType,
|
||||
Trios,
|
||||
} from "../core/game/Game";
|
||||
import { PseudoRandom } from "../core/PseudoRandom";
|
||||
@@ -140,6 +141,40 @@ export class MapPlaylist {
|
||||
} satisfies GameConfig;
|
||||
}
|
||||
|
||||
public get1v1Config(): GameConfig {
|
||||
const ffaMaps = [
|
||||
GameMapType.Iceland,
|
||||
GameMapType.World,
|
||||
GameMapType.EuropeClassic,
|
||||
GameMapType.Australia,
|
||||
GameMapType.FaroeIslands,
|
||||
GameMapType.Pangaea,
|
||||
GameMapType.Italia,
|
||||
GameMapType.FalklandIslands,
|
||||
GameMapType.Sierpinski,
|
||||
];
|
||||
return {
|
||||
donateGold: false,
|
||||
donateTroops: false,
|
||||
gameMap: ffaMaps[Math.floor(Math.random() * ffaMaps.length)],
|
||||
maxPlayers: 2,
|
||||
gameType: GameType.Public,
|
||||
gameMapSize: GameMapSize.Compact,
|
||||
difficulty: Difficulty.Easy,
|
||||
rankedType: RankedType.OneVOne,
|
||||
infiniteGold: false,
|
||||
infiniteTroops: false,
|
||||
maxTimerValue: 10, // 10 minutes
|
||||
instantBuild: false,
|
||||
randomSpawn: false,
|
||||
disableNations: false,
|
||||
gameMode: GameMode.FFA,
|
||||
bots: 100,
|
||||
spawnImmunityDuration: 5 * 10,
|
||||
disabledUnits: [],
|
||||
} satisfies GameConfig;
|
||||
}
|
||||
|
||||
private getNextMap(): MapWithMode {
|
||||
if (this.mapsPlaylist.length === 0) {
|
||||
const numAttempts = 10000;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { fileURLToPath } from "url";
|
||||
import { WebSocket, WebSocketServer } from "ws";
|
||||
import { z } from "zod";
|
||||
import { getServerConfigFromServer } from "../core/configuration/ConfigLoader";
|
||||
import { GameMapSize, GameType } from "../core/game/Game";
|
||||
import { GameType } from "../core/game/Game";
|
||||
import {
|
||||
ClientMessageSchema,
|
||||
GameID,
|
||||
@@ -522,8 +522,7 @@ async function pollLobby(gm: GameManager) {
|
||||
log.info(`Lobby poll successful:`, data);
|
||||
|
||||
if (data.assignment) {
|
||||
const gameConfig = await playlist.gameConfig();
|
||||
gameConfig.gameMapSize = GameMapSize.Compact;
|
||||
const gameConfig = playlist.get1v1Config();
|
||||
const game = gm.createGame(gameId, gameConfig);
|
||||
setTimeout(() => {
|
||||
// Wait a few seconds to allow clients to connect.
|
||||
|
||||
Reference in New Issue
Block a user