From 7799e76ef8695eebe2699bf96ca977f6a6cea718 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Sat, 21 Sep 2024 12:06:01 -0700 Subject: [PATCH] added boat events --- TODO.txt | 4 ++-- src/core/execution/BoatAttackExecution.ts | 6 ++++-- src/core/execution/FakeHumanExecution.ts | 1 + src/core/game/Game.ts | 2 ++ src/core/game/GameImpl.ts | 5 +++++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/TODO.txt b/TODO.txt index 3043dfd36..2f0a68eac 100644 --- a/TODO.txt +++ b/TODO.txt @@ -131,10 +131,10 @@ * eventbox events dissapear after timeout DONE 9/20/2024 * auto reject alliance when event dissapears DONE 9/20/2024 * first place has crown DONE 9/20/2024 -* can't attack ally +* can't attack ally DONE 9/20/2024 +* add updates to eventbox: boats (max count, too far) * make alliances expire * color code events -* add updates to eventbox: boats (max count, too far) * broken alliances * BUG: FakeHuman don't be enemy if don't share border * BUG: when send boat only captures one pixel diff --git a/src/core/execution/BoatAttackExecution.ts b/src/core/execution/BoatAttackExecution.ts index 4f17ca175..77ca3a593 100644 --- a/src/core/execution/BoatAttackExecution.ts +++ b/src/core/execution/BoatAttackExecution.ts @@ -3,6 +3,8 @@ import {Boat, Cell, Execution, MutableBoat, MutableGame, MutablePlayer, Player, import {manhattanDist, manhattanDistWrapped} from "../Util"; import {AttackExecution} from "./AttackExecution"; import {Config} from "../configuration/Config"; +import {EventBus} from "../EventBus"; +import {DisplayMessageEvent, MessageType} from "../../client/graphics/layers/EventsDisplay"; export class BoatAttackExecution implements Execution { @@ -49,7 +51,7 @@ export class BoatAttackExecution implements Execution { this.attacker = mg.player(this.attackerID) if (this.attacker.boats().length >= mg.config().boatMaxNumber()) { - console.log('too many boats') + mg.displayMessage(`No boats available, max ${mg.config().boatMaxNumber()}`, MessageType.WARN) this.active = false this.attacker.addTroops(this.troops) return @@ -76,7 +78,7 @@ export class BoatAttackExecution implements Execution { return } if (manhattanDistWrapped(this.src.cell(), this.dst.cell(), mg.width()) > mg.config().boatMaxDistance()) { - console.log(`boat attack distance too large, dist ${manhattanDist(this.src.cell(), this.dst.cell())} max: ${mg.config().boatMaxDistance()}`) + mg.displayMessage(`Cannot send boat: destination is too far away`, MessageType.WARN) this.active = false return } diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index c6fd866e5..c2a69c6a4 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -1,3 +1,4 @@ +import {EventBus} from "../EventBus"; import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, PlayerType, TerrainType, TerraNullius, Tile} from "../game/Game" import {PseudoRandom} from "../PseudoRandom" import {and, bfs, dist, simpleHash} from "../Util"; diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index 4ab1b0f97..c648cfe93 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -2,6 +2,7 @@ import {info} from "console" import {Config} from "../configuration/Config" import {GameEvent} from "../EventBus" import {ClientID, GameID} from "../Schemas" +import {DisplayMessageEvent, MessageType} from "../../client/graphics/layers/EventsDisplay" export type PlayerID = string @@ -181,6 +182,7 @@ export interface Game { inSpawnPhase(): boolean addExecution(...exec: Execution[]): void config(): Config + displayMessage(message: string, type: MessageType): void } export interface MutableGame extends Game { diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts index f6ca227e5..1b3ac110c 100644 --- a/src/core/game/GameImpl.ts +++ b/src/core/game/GameImpl.ts @@ -9,6 +9,7 @@ import {TileImpl} from "./TileImpl"; import {AllianceRequestImpl} from "./AllianceRequestImpl"; import {AllianceImpl} from "./AllianceImpl"; import {ClientID} from "../Schemas"; +import {DisplayMessageEvent, MessageType} from "../../client/graphics/layers/EventsDisplay"; export function createGame(terrainMap: TerrainMap, eventBus: EventBus, config: Config): Game { return new GameImpl(terrainMap, eventBus, config) @@ -338,4 +339,8 @@ export class GameImpl implements MutableGame { this.eventBus.emit(new BrokeAllianceEvent(breaker, other)) } + displayMessage(message: string, type: MessageType): void { + this.eventBus.emit(new DisplayMessageEvent(message, type)) + } + } \ No newline at end of file