added boat events

This commit is contained in:
evanpelle
2024-09-21 12:06:01 -07:00
parent dd5c357734
commit 7799e76ef8
5 changed files with 14 additions and 4 deletions
+2 -2
View File
@@ -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
+4 -2
View File
@@ -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
}
+1
View File
@@ -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";
+2
View File
@@ -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 {
+5
View File
@@ -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))
}
}