From fc562533e183f7328d9eefd761e5c8a288e8be01 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Mon, 12 Aug 2024 17:05:02 -0700 Subject: [PATCH] fix boat bug --- TODO.txt | 2 +- src/client/ClientGame.ts | 2 +- src/core/configuration/DefaultConfig.ts | 4 ++-- src/core/execution/AttackExecution.ts | 1 + src/core/execution/BoatAttackExecution.ts | 11 ++++++++++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/TODO.txt b/TODO.txt index 04beeddf7..a7e263603 100644 --- a/TODO.txt +++ b/TODO.txt @@ -9,7 +9,7 @@ * harder to expand on other players (defense) DONE 8/12/2024 * lose troops when attacked DONE 8/12/2024 * slower to attack stronger players DONE 8/12/2024 -* move all attack related config to Settings +* move all attack related config to Settings DONE 8/12/2024 * fix boat bugs * add username in front page * improve front page diff --git a/src/client/ClientGame.ts b/src/client/ClientGame.ts index bb9942df7..ca9b3bd28 100644 --- a/src/client/ClientGame.ts +++ b/src/client/ClientGame.ts @@ -163,7 +163,7 @@ export class ClientGame { if (tile.owner() != this.myPlayer && tile.terrain() == TerrainTypes.Land) { if (this.myPlayer.sharesBorderWith(tile.owner())) { this.sendAttackIntent(targetID, cell, this.config.player().attackAmount(this.myPlayer, owner)) - } else { + } else if (owner.isPlayer()) { // TODO verify on ocean console.log('going to send boat') this.sendBoatAttackIntent(targetID, cell, this.config.player().boatAttackAmount(this.myPlayer, owner)) diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index feadd5356..40829a4a4 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -4,7 +4,7 @@ import {pastelTheme} from "./PastelTheme"; export const defaultConfig = new class implements Config { player(): PlayerConfig { - throw new Error("Method not implemented."); + return defaultPlayerConfig } ticksPerTurn(): number { @@ -49,7 +49,7 @@ export const defaultPlayerConfig = new class implements PlayerConfig { const ratio = 1 - player.troops() / max toAdd *= ratio * ratio * ratio toAdd = Math.max(2, toAdd) - return Math.min(player.troops(), max) + return Math.min(player.troops() + toAdd, max) } attackLogic(attack: Player, defender: Player | TerraNullius): number { diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index 41618be98..5fd3f4079 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -64,6 +64,7 @@ export class AttackExecution implements Execution { badTiles++ continue } + // TODO: move this to configs this._owner.conquer(tileToConquer) if (this.target.isPlayer()) { this.troops -= Math.max(this.target.troops() / this._owner.troops(), 1) diff --git a/src/core/execution/BoatAttackExecution.ts b/src/core/execution/BoatAttackExecution.ts index c00bb0f55..ddadc7565 100644 --- a/src/core/execution/BoatAttackExecution.ts +++ b/src/core/execution/BoatAttackExecution.ts @@ -47,6 +47,12 @@ export class BoatAttackExecution implements Execution { this.src = this.closestShoreTileToTarget(this.attacker, this.cell) this.dst = this.closestShoreTileToTarget(this.target, this.cell) + + if(this.src == null || this.dst == null) { + this.active = false + return + } + this.path = this.computePath(this.src, this.dst) if (this.path != null) { console.log(`got path ${this.path.map(t => t.cell().toString())}`) @@ -91,8 +97,11 @@ export class BoatAttackExecution implements Execution { return this.active } - private closestShoreTileToTarget(player: Player, target: Cell): Tile { + private closestShoreTileToTarget(player: Player, target: Cell): Tile | null { const shoreTiles = Array.from(player.borderTiles()).filter(t => t.onShore()) + if (shoreTiles.length == 0) { + return null + } return shoreTiles.reduce((closest, current) => { const closestDistance = manhattanDist(target, closest.cell());