mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-14 14:14:39 +00:00
add logic break alliance. break alliance makes you traitor
This commit is contained in:
@@ -128,7 +128,6 @@ export interface Player {
|
||||
boats(): Boat[]
|
||||
ownsTile(cell: Cell): boolean
|
||||
isAlive(): boolean
|
||||
executions(): ExecutionView[]
|
||||
borderTiles(): ReadonlySet<Tile>
|
||||
isPlayer(): this is Player
|
||||
neighbors(): (Player | TerraNullius)[]
|
||||
@@ -140,6 +139,7 @@ export interface Player {
|
||||
alliances(): Alliance[]
|
||||
alliedWith(other: Player): boolean
|
||||
pendingAllianceRequestWith(other: Player): boolean
|
||||
isTraitor(): boolean
|
||||
toString(): string
|
||||
}
|
||||
|
||||
@@ -156,6 +156,7 @@ export interface MutablePlayer extends Player {
|
||||
incomingAllianceRequests(): MutableAllianceRequest[]
|
||||
outgoingAllianceRequests(): MutableAllianceRequest[]
|
||||
alliances(): MutableAlliance[]
|
||||
breakAllianceWith(other: Player): void
|
||||
addBoat(troops: number, tile: Tile, target: Player | TerraNullius): MutableBoat
|
||||
}
|
||||
|
||||
@@ -185,8 +186,7 @@ export interface MutableGame extends Game {
|
||||
players(): MutablePlayer[]
|
||||
addPlayer(playerInfo: PlayerInfo, troops: number): MutablePlayer
|
||||
executions(): Execution[]
|
||||
removeInactiveExecutions(): void
|
||||
removeExecution(exec: Execution): void
|
||||
// todo move to player.
|
||||
createAllianceRequest(requestor: Player, recipient: Player): MutableAllianceRequest
|
||||
}
|
||||
|
||||
|
||||
@@ -316,4 +316,14 @@ export class GameImpl implements MutableGame {
|
||||
this.eventBus.emit(new BoatEvent(boat, oldTile))
|
||||
}
|
||||
|
||||
public breakAlliance(breaker: Player, other: Player) {
|
||||
const breakerSet = new Set(breaker.alliances())
|
||||
const alliances = other.alliances().filter(a => breakerSet.has(a))
|
||||
if (alliances.length != 1) {
|
||||
throw new Error('must have exactly one alliance')
|
||||
}
|
||||
this.alliances_ = this.alliances_.filter(a => a != alliances[0])
|
||||
// TODO emit event.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,9 +5,12 @@ import {CellString, GameImpl} from "./GameImpl";
|
||||
import {BoatImpl} from "./BoatImpl";
|
||||
import {TileImpl} from "./TileImpl";
|
||||
import {TerraNulliusImpl} from "./TerraNulliusImpl";
|
||||
import {threadId} from "worker_threads";
|
||||
|
||||
|
||||
export class PlayerImpl implements MutablePlayer {
|
||||
private isTraitor_ = false
|
||||
|
||||
public _borderTiles: Set<Tile> = new Set();
|
||||
|
||||
public _boats: BoatImpl[] = [];
|
||||
@@ -130,6 +133,17 @@ export class PlayerImpl implements MutablePlayer {
|
||||
|
||||
}
|
||||
|
||||
isTraitor(): boolean {
|
||||
return this.isTraitor_
|
||||
}
|
||||
|
||||
breakAllianceWith(other: Player): void {
|
||||
if (!this.alliedWith(other)) {
|
||||
throw new Error('cannot break alliance, already allied')
|
||||
}
|
||||
this.isTraitor_ = true
|
||||
this.gs.breakAlliance(this, other)
|
||||
}
|
||||
|
||||
hash(): number {
|
||||
return simpleHash(this.id()) * (this.troops() + this.numTilesOwned());
|
||||
|
||||
Reference in New Issue
Block a user