From d21dcd457b5fc390e193f304c7fbfbbccadd04e2 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Fri, 20 Sep 2024 13:24:55 -0700 Subject: [PATCH] create alliance request reply execution --- .../AllianceRequestReplyExecution.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/core/execution/AllianceRequestReplyExecution.ts diff --git a/src/core/execution/AllianceRequestReplyExecution.ts b/src/core/execution/AllianceRequestReplyExecution.ts new file mode 100644 index 000000000..f5e90af31 --- /dev/null +++ b/src/core/execution/AllianceRequestReplyExecution.ts @@ -0,0 +1,46 @@ +import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../game/Game"; + +export class AllianceRequestExecutionReply implements Execution { + private active = true + private mg: MutableGame = null + private requestor: MutablePlayer; + private recipient: MutablePlayer + + constructor(private requestorID: PlayerID, private recipientID: PlayerID, private accept: boolean) { } + + init(mg: MutableGame, ticks: number): void { + this.mg = mg + this.requestor = mg.player(this.requestorID) + this.recipient = mg.player(this.recipientID) + } + + tick(ticks: number): void { + if (this.requestor.alliedWith(this.recipient)) { + console.warn('already allied') + } else { + const request = this.requestor.outgoingAllianceRequests().find(ar => ar.recipient() == this.recipient) + if (request == null) { + console.warn('no alliance request found') + } else { + if (this.accept) { + request.accept() + } else { + request.reject() + } + } + } + this.active = false + } + + owner(): MutablePlayer { + return null + } + + isActive(): boolean { + return this.active + } + + activeDuringSpawnPhase(): boolean { + return false + } +} \ No newline at end of file