mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-28 07:24:51 +00:00
create EventsDisplay file
This commit is contained in:
@@ -6,13 +6,13 @@ export const devConfig = new class extends DefaultConfig {
|
||||
return 80
|
||||
}
|
||||
numSpawnPhaseTurns(): number {
|
||||
return 40
|
||||
return 80
|
||||
}
|
||||
gameCreationRate(): number {
|
||||
return 2 * 1000
|
||||
return 10 * 1000
|
||||
}
|
||||
lobbyLifetime(): number {
|
||||
return 2 * 1000
|
||||
return 10 * 1000
|
||||
}
|
||||
turnIntervalMs(): number {
|
||||
return 100
|
||||
|
||||
@@ -3,8 +3,8 @@ import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID
|
||||
export class AllianceRequestExecution implements Execution {
|
||||
private active = true
|
||||
private mg: MutableGame = null
|
||||
private requestor: Player;
|
||||
private recipient: Player
|
||||
private requestor: MutablePlayer;
|
||||
private recipient: MutablePlayer
|
||||
|
||||
constructor(private requestorID: PlayerID, private recipientID: PlayerID) { }
|
||||
|
||||
@@ -18,7 +18,7 @@ export class AllianceRequestExecution implements Execution {
|
||||
if (this.requestor.alliedWith(this.recipient)) {
|
||||
console.warn('already allied')
|
||||
} else {
|
||||
this.mg.createAllianceRequest(this.requestor, this.recipient)
|
||||
this.requestor.createAllianceRequest(this.recipient)
|
||||
}
|
||||
this.active = false
|
||||
}
|
||||
|
||||
@@ -157,12 +157,14 @@ export interface MutablePlayer extends Player {
|
||||
outgoingAllianceRequests(): MutableAllianceRequest[]
|
||||
alliances(): MutableAlliance[]
|
||||
breakAllianceWith(other: Player): void
|
||||
createAllianceRequest(recipient: Player): MutableAllianceRequest
|
||||
addBoat(troops: number, tile: Tile, target: Player | TerraNullius): MutableBoat
|
||||
}
|
||||
|
||||
export interface Game {
|
||||
// Throws exception is player not found
|
||||
player(id: PlayerID): Player
|
||||
playerByClientID(id: ClientID): Player | null
|
||||
hasPlayer(id: PlayerID): boolean
|
||||
players(): Player[]
|
||||
tile(cell: Cell): Tile
|
||||
@@ -183,11 +185,10 @@ export interface Game {
|
||||
|
||||
export interface MutableGame extends Game {
|
||||
player(id: PlayerID): MutablePlayer
|
||||
playerByClientID(id: ClientID): MutablePlayer | null
|
||||
players(): MutablePlayer[]
|
||||
addPlayer(playerInfo: PlayerInfo, troops: number): MutablePlayer
|
||||
executions(): Execution[]
|
||||
// todo move to player.
|
||||
createAllianceRequest(requestor: Player, recipient: Player): MutableAllianceRequest
|
||||
}
|
||||
|
||||
export class TileEvent implements GameEvent {
|
||||
@@ -202,6 +203,10 @@ export class BoatEvent implements GameEvent {
|
||||
constructor(public readonly boat: Boat, public oldTile: Tile) { }
|
||||
}
|
||||
|
||||
export class AllianceRequestEvent implements GameEvent {
|
||||
constructor(public readonly allianceRequest: AllianceRequest) { }
|
||||
}
|
||||
|
||||
export class AllianceRequestReplyEvent implements GameEvent {
|
||||
constructor(public readonly allianceRequest: AllianceRequest, public readonly accepted: boolean) { }
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import {info} from "console";
|
||||
import {Config} from "../configuration/Config";
|
||||
import {EventBus} from "../EventBus";
|
||||
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, BoatEvent, PlayerType, MutableAllianceRequest, AllianceRequestReplyEvent} from "./Game";
|
||||
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, BoatEvent, PlayerType, MutableAllianceRequest, AllianceRequestReplyEvent, AllianceRequestEvent} from "./Game";
|
||||
import {TerrainMap} from "./TerrainMapLoader";
|
||||
import {PlayerImpl} from "./PlayerImpl";
|
||||
import {TerraNulliusImpl} from "./TerraNulliusImpl";
|
||||
import {TileImpl} from "./TileImpl";
|
||||
import {AllianceRequestImpl} from "./AllianceRequestImpl";
|
||||
import {AllianceImpl} from "./AllianceImpl";
|
||||
import {ClientID} from "../Schemas";
|
||||
|
||||
export function createGame(terrainMap: TerrainMap, eventBus: EventBus, config: Config): Game {
|
||||
return new GameImpl(terrainMap, eventBus, config)
|
||||
@@ -50,6 +51,7 @@ export class GameImpl implements MutableGame {
|
||||
createAllianceRequest(requestor: Player, recipient: Player): MutableAllianceRequest {
|
||||
const ar = new AllianceRequestImpl(requestor, recipient, this._ticks, this)
|
||||
this.allianceRequests.push(ar)
|
||||
this.eventBus.emit(new AllianceRequestEvent(ar))
|
||||
return ar
|
||||
}
|
||||
|
||||
@@ -192,6 +194,16 @@ export class GameImpl implements MutableGame {
|
||||
return this._players.get(id)
|
||||
}
|
||||
|
||||
playerByClientID(id: ClientID): MutablePlayer | null {
|
||||
for (const [pID, player] of this._players) {
|
||||
if (player.clientID() == id) {
|
||||
return player
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
tile(cell: Cell): Tile {
|
||||
this.assertIsOnMap(cell)
|
||||
return this.map[cell.x][cell.y]
|
||||
|
||||
@@ -150,6 +150,10 @@ export class PlayerImpl implements MutablePlayer {
|
||||
this.gs.breakAlliance(this, other)
|
||||
}
|
||||
|
||||
createAllianceRequest(recipient: Player): MutableAllianceRequest {
|
||||
return this.gs.createAllianceRequest(this, recipient)
|
||||
}
|
||||
|
||||
hash(): number {
|
||||
return simpleHash(this.id()) * (this.troops() + this.numTilesOwned());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user