From bdbe1b759c50c9e6be0c61e32411c78ae5b6a7b5 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Wed, 18 Sep 2024 17:34:31 -0700 Subject: [PATCH] fixed bug: cannot request alliance multiple times or if already allied --- TODO.txt | 2 +- src/client/graphics/layers/UILayer.ts | 3 +++ src/core/game/Game.ts | 1 + src/core/game/PlayerImpl.ts | 6 ++++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/TODO.txt b/TODO.txt index 61668512e..6e11cac0a 100644 --- a/TODO.txt +++ b/TODO.txt @@ -114,7 +114,7 @@ * front page mobile friendly DONE 9/15/2024 * game mobile friendly DONE 9/16/2024 * UI: basic win condition & popup DONE 9/16/2024 -* right click popup alliance option +* right click popup alliance option DONE 9/17/2024 * BUG: can't ally same person twice * make fake humans easier * click alliance sends alliance request diff --git a/src/client/graphics/layers/UILayer.ts b/src/client/graphics/layers/UILayer.ts index 22cb0e443..9fe3560a7 100644 --- a/src/client/graphics/layers/UILayer.ts +++ b/src/client/graphics/layers/UILayer.ts @@ -253,6 +253,9 @@ export class UILayer implements Layer { console.warn('my player not found') return } + if (myPlayer.alliedWith(owner) || myPlayer.pendingAllianceRequestWith(owner)) { + return + } this.customMenu!.style.display = 'block'; this.customMenu!.style.left = `${e.x}px`; diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index c6a0da27f..a0a6078b6 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -139,6 +139,7 @@ export interface Player { outgoingAllianceRequests(): AllianceRequest[] alliances(): Alliance[] alliedWith(other: Player): boolean + pendingAllianceRequestWith(other: Player): boolean toString(): string } diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index 76675d8ee..f84966251 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -124,6 +124,12 @@ export class PlayerImpl implements MutablePlayer { return this.alliances().find(a => a.recipient() == other || a.requestor() == other) != null } + pendingAllianceRequestWith(other: Player): boolean { + return this.incomingAllianceRequests().find(ar => ar.requestor() == other) != null + || this.outgoingAllianceRequests().find(ar => ar.recipient() == other) != null + + } + hash(): number { return simpleHash(this.id()) * (this.troops() + this.numTilesOwned());