break alliance creates log

This commit is contained in:
evanpelle
2024-09-21 11:56:25 -07:00
parent 98bdf94bf6
commit dd5c357734
3 changed files with 31 additions and 3 deletions
+25 -1
View File
@@ -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);
}