mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:40:44 +00:00
break alliance creates log
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) { }
|
||||
}
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user