diff --git a/src/client/graphics/layers/EventsDisplay.ts b/src/client/graphics/layers/EventsDisplay.ts index 12854d5a3..cbe8f334e 100644 --- a/src/client/graphics/layers/EventsDisplay.ts +++ b/src/client/graphics/layers/EventsDisplay.ts @@ -1,6 +1,6 @@ import {nullable} from "zod"; import {EventBus, GameEvent} from "../../../core/EventBus"; -import {AllianceRequest, AllianceRequestEvent, AllianceRequestReplyEvent, Game} from "../../../core/game/Game"; +import {AllianceRequest, AllianceRequestEvent, AllianceRequestReplyEvent, BrokeAllianceEvent as BrokenAllianceEvent, Game} from "../../../core/game/Game"; import {ClientID} from "../../../core/Schemas"; import {Layer} from "./Layer"; @@ -52,6 +52,7 @@ export class EventsDisplay implements Layer { this.eventBus.on(AllianceRequestEvent, a => this.onAllianceRequestEvent(a)) this.eventBus.on(AllianceRequestReplyEvent, a => this.onAllianceRequestReplyEvent(a)) this.eventBus.on(DisplayMessageEvent, e => this.onDisplayMessageEvent(e)) + this.eventBus.on(BrokenAllianceEvent, e => this.onBrokenAllianceEvent(e)) this.renderTable() } @@ -147,6 +148,29 @@ export class EventsDisplay implements Layer { this.renderTable() } + onBrokenAllianceEvent(event: BrokenAllianceEvent) { + const myPlayer = this.game.playerByClientID(this.clientID) + if (myPlayer == null) { + return + } + if (event.traitor == myPlayer) { + this.addEvent({ + description: `You broke your alliance with ${event.betrayed.name()}, making you a TRAITOR`, + type: MessageType.ERROR, + highlight: true, + createdAt: this.game.ticks(), + }) + } + if (event.betrayed == myPlayer) { + this.addEvent({ + description: `${event.traitor.name()}, broke their alliance with you`, + type: MessageType.ERROR, + highlight: true, + createdAt: this.game.ticks(), + }) + } + } + addEvent(event: Event): void { this.events.push(event); } diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index 0627216d7..4ab1b0f97 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -210,3 +210,7 @@ export class AllianceRequestEvent implements GameEvent { export class AllianceRequestReplyEvent implements GameEvent { constructor(public readonly allianceRequest: AllianceRequest, public readonly accepted: boolean) { } } + +export class BrokeAllianceEvent implements GameEvent { + constructor(public readonly traitor: Player, public readonly betrayed: Player) { } +} \ No newline at end of file diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts index 7cb0a5565..f6ca227e5 100644 --- a/src/core/game/GameImpl.ts +++ b/src/core/game/GameImpl.ts @@ -1,7 +1,7 @@ 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, AllianceRequestEvent} from "./Game"; +import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, BoatEvent, PlayerType, MutableAllianceRequest, AllianceRequestReplyEvent, AllianceRequestEvent, BrokeAllianceEvent} from "./Game"; import {TerrainMap} from "./TerrainMapLoader"; import {PlayerImpl} from "./PlayerImpl"; import {TerraNulliusImpl} from "./TerraNulliusImpl"; @@ -335,7 +335,7 @@ export class GameImpl implements MutableGame { throw new Error('must have exactly one alliance') } this.alliances_ = this.alliances_.filter(a => a != alliances[0]) - // TODO emit event. + this.eventBus.emit(new BrokeAllianceEvent(breaker, other)) } } \ No newline at end of file