Skip to content

Commit e533ed8

Browse files
committed
Add game event logging for ordnance launches, combat results, and game over
1 parent 55f5960 commit e533ed8

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/client/main.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -333,18 +333,18 @@ class GameClient {
333333
}
334334
break;
335335

336-
case 'gameOver':
336+
case 'gameOver': {
337337
this.setState('gameOver');
338-
this.ui.showGameOver(
339-
msg.winner === this.playerId,
340-
msg.reason,
341-
);
342-
if (msg.winner === this.playerId) {
338+
const won = msg.winner === this.playerId;
339+
this.ui.showGameOver(won, msg.reason);
340+
this.ui.logText(`${won ? 'VICTORY' : 'DEFEAT'}: ${msg.reason}`, won ? 'log-landed' : 'log-eliminated');
341+
if (won) {
343342
playVictory();
344343
} else {
345344
playDefeat();
346345
}
347346
break;
347+
}
348348

349349
case 'rematchPending':
350350
this.ui.showRematchPending();
@@ -502,6 +502,9 @@ class GameClient {
502502
launch.torpedoAccel = this.renderer.planningState.torpedoAccel ?? null;
503503
}
504504

505+
const shipName = SHIP_STATS[ship.type]?.name ?? ship.type;
506+
this.ui.logText(`${shipName} launched ${ordType}`);
507+
505508
if (this.isLocalGame) {
506509
this.localProcessOrdnance([launch]);
507510
} else {
@@ -631,11 +634,11 @@ class GameClient {
631634
private localCheckGameEnd() {
632635
if (!this.gameState || this.gameState.phase !== 'gameOver') return;
633636
this.setState('gameOver');
634-
this.ui.showGameOver(
635-
this.gameState.winner === this.playerId,
636-
this.gameState.winReason ?? '',
637-
);
638-
if (this.gameState.winner === this.playerId) {
637+
const won = this.gameState.winner === this.playerId;
638+
const reason = this.gameState.winReason ?? '';
639+
this.ui.showGameOver(won, reason);
640+
this.ui.logText(`${won ? 'VICTORY' : 'DEFEAT'}: ${reason}`, won ? 'log-landed' : 'log-eliminated');
641+
if (won) {
639642
playVictory();
640643
} else {
641644
playDefeat();
@@ -691,6 +694,11 @@ class GameClient {
691694
if (this.gameState.phase === 'ordnance' && this.gameState.activePlayer === aiPlayer) {
692695
const launches = aiOrdnance(this.gameState, aiPlayer, this.map, this.aiDifficulty);
693696
if (launches.length > 0) {
697+
for (const l of launches) {
698+
const ship = this.gameState.ships.find(s => s.id === l.shipId);
699+
const name = ship ? (SHIP_STATS[ship.type]?.name ?? ship.type) : l.shipId;
700+
this.ui.logText(`AI: ${name} launched ${l.ordnanceType}`);
701+
}
694702
const result = processOrdnance(this.gameState, aiPlayer, launches, this.map);
695703
if (!('error' in result)) {
696704
this.gameState = result.state;

0 commit comments

Comments
 (0)