From 99e8c03870c5d1fa7953ce3c2e259eb37fc06c7b Mon Sep 17 00:00:00 2001 From: Ilan Schemoul Date: Tue, 11 Mar 2025 20:33:45 +0100 Subject: [PATCH] cancel trade if port is captured (no trade inside same country) (#194) If the port of destination and of source have same owner it means a player captures port of another player, we cease all trade that happens inside same country. Also added a check in the canTrade code to be more reliable and correct even outside of the specific case of capturing a port. --- src/core/execution/TradeShipExecution.ts | 8 ++++++++ src/core/game/PlayerImpl.ts | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/execution/TradeShipExecution.ts b/src/core/execution/TradeShipExecution.ts index 2e7f63476..c6587ec2a 100644 --- a/src/core/execution/TradeShipExecution.ts +++ b/src/core/execution/TradeShipExecution.ts @@ -65,6 +65,14 @@ export class TradeShipExecution implements Execution { this.wasCaptured = true; } + // If a player captures an other player's port while trading we should delete + // the ship. + if (this._dstPort.owner().id() == this.srcPort.owner().id()) { + this.tradeShip.delete(false); + this.active = false; + return; + } + if ( !this.wasCaptured && (!this._dstPort.isActive() || diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index 02341d4b9..c4c2b0cd0 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -539,7 +539,9 @@ export class PlayerImpl implements Player { } canTrade(other: Player): boolean { - return !other.hasEmbargoAgainst(this) && !this.hasEmbargoAgainst(other); + const embargo = + other.hasEmbargoAgainst(this) || this.hasEmbargoAgainst(other); + return !embargo && other.id() != this.id(); } addEmbargo(other: PlayerID): void {