diff --git a/resources/lang/en.json b/resources/lang/en.json index 92fcb3a16..8b62a1fb2 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -423,6 +423,7 @@ "sent_emoji": "Sent {name}: {emoji}", "sent_gold_to_player": "Sent {gold} gold to {name}", "sent_troops_to_player": "Sent {troops} troops to {name}", + "trade_ship_captured": "Your trade ship was captured by {name}", "unit_destroyed": "Your {unit} was destroyed", "unit_voluntarily_deleted": "Unit voluntarily deleted", "wants_to_renew_alliance": "{name} wants to renew your alliance" diff --git a/src/core/execution/TradeShipExecution.ts b/src/core/execution/TradeShipExecution.ts index 01519fe40..baaff6f51 100644 --- a/src/core/execution/TradeShipExecution.ts +++ b/src/core/execution/TradeShipExecution.ts @@ -69,6 +69,14 @@ export class TradeShipExecution implements Execution { if (this.wasCaptured !== true && this.origOwner !== tradeShipOwner) { // Store as variable in case ship is recaptured by previous owner this.wasCaptured = true; + this.mg.displayMessage( + "events_display.trade_ship_captured", + MessageType.UNIT_DESTROYED, + this.origOwner.id(), + undefined, + { name: tradeShipOwner.displayName() }, + this.tradeShip.id(), + ); } // If a player captures another player's port while trading we should delete diff --git a/tests/core/executions/TradeShipExecution.test.ts b/tests/core/executions/TradeShipExecution.test.ts index b05986cb4..36b9860cc 100644 --- a/tests/core/executions/TradeShipExecution.test.ts +++ b/tests/core/executions/TradeShipExecution.test.ts @@ -1,5 +1,5 @@ import { TradeShipExecution } from "../../../src/core/execution/TradeShipExecution"; -import { Game, Player, Unit } from "../../../src/core/game/Game"; +import { Game, MessageType, Player, Unit } from "../../../src/core/game/Game"; import { PathStatus } from "../../../src/core/pathfinding/types"; import { setup } from "../../util/Setup"; @@ -135,6 +135,26 @@ describe("TradeShipExecution", () => { expect(tradeShip.setTargetUnit).toHaveBeenCalledWith(piratePort); }); + it("should notify the original owner when the ship is captured", () => { + tradeShip.owner = vi.fn(() => pirate); + tradeShipExecution.tick(1); + expect(game.displayMessage).toHaveBeenCalledWith( + "events_display.trade_ship_captured", + MessageType.UNIT_DESTROYED, + origOwner.id(), + undefined, + { name: pirate.displayName() }, + tradeShip.id(), + ); + }); + + it("should only notify the original owner once across ticks", () => { + tradeShip.owner = vi.fn(() => pirate); + tradeShipExecution.tick(1); + tradeShipExecution.tick(2); + expect(game.displayMessage).toHaveBeenCalledTimes(1); + }); + it("should complete trade and award gold", () => { tradeShipExecution["pathFinder"] = { next: vi.fn(() => ({ status: PathStatus.COMPLETE, node: 32 })),