mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-03 00:27:58 +00:00
add difficulties
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import {Config} from "../core/configuration/Config";
|
||||
import {ClientID, GameConfig, GameID} from "../core/Schemas";
|
||||
import {v4 as uuidv4} from 'uuid';
|
||||
import {Client} from "./Client";
|
||||
import {GamePhase, GameServer} from "./GameServer";
|
||||
import {GameMap} from "../core/game/Game";
|
||||
import { Config } from "../core/configuration/Config";
|
||||
import { ClientID, GameConfig, GameID } from "../core/Schemas";
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { Client } from "./Client";
|
||||
import { GamePhase, GameServer } from "./GameServer";
|
||||
import { Difficulty, GameMap } from "../core/game/Game";
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ export class GameManager {
|
||||
|
||||
createPrivateGame(): string {
|
||||
const id = genSmallGameID()
|
||||
this.games.push(new GameServer(id, Date.now(), false, this.config, {gameMap: GameMap.World}))
|
||||
this.games.push(new GameServer(id, Date.now(), false, this.config, { gameMap: GameMap.World, difficulty: Difficulty.Medium }))
|
||||
return id
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ export class GameManager {
|
||||
if (now > this.lastNewLobby + this.config.gameCreationRate()) {
|
||||
this.lastNewLobby = now
|
||||
const id = uuidv4()
|
||||
lobbies.push(new GameServer(id, now, true, this.config, {gameMap: GameMap.World}))
|
||||
lobbies.push(new GameServer(id, now, true, this.config, { gameMap: GameMap.World, difficulty: Difficulty.Medium }))
|
||||
}
|
||||
|
||||
active.filter(g => !g.hasStarted() && g.isPublic).forEach(g => {
|
||||
|
||||
@@ -30,12 +30,16 @@ export class GameServer {
|
||||
public readonly isPublic: boolean,
|
||||
private config: Config,
|
||||
private gameConfig: GameConfig,
|
||||
|
||||
) { }
|
||||
|
||||
public updateGameConfig(gameConfig: GameConfig): void {
|
||||
if (gameConfig.gameMap != null) {
|
||||
this.gameConfig.gameMap = gameConfig.gameMap
|
||||
}
|
||||
if(gameConfig.difficulty != null) {
|
||||
this.gameConfig.difficulty = gameConfig.difficulty
|
||||
}
|
||||
}
|
||||
|
||||
public addClient(client: Client, lastTurn: number) {
|
||||
|
||||
@@ -49,7 +49,7 @@ app.post('/start_private_lobby/:id', (req, res) => {
|
||||
|
||||
app.put('/private_lobby/:id', (req, res) => {
|
||||
const lobbyID = req.params.id
|
||||
gm.updateGameConfig(lobbyID, {gameMap: req.body.gameMap})
|
||||
gm.updateGameConfig(lobbyID, {gameMap: req.body.gameMap, difficulty: req.body.difficulty})
|
||||
});
|
||||
|
||||
app.get('/lobby/:id/exists', (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user