mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-10 00:38:08 +00:00
alliances expire after 1000 ticks (~1.5 minutes)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {Player, PlayerID, PlayerInfo, TerraNullius, Tile} from "../game/Game";
|
||||
import {Player, PlayerID, PlayerInfo, TerraNullius, Tick, Tile} from "../game/Game";
|
||||
import {Colord, colord} from "colord";
|
||||
import {devConfig} from "./DevConfig";
|
||||
import {defaultConfig} from "./DefaultConfig";
|
||||
@@ -47,6 +47,7 @@ export interface Config {
|
||||
boatAttackAmount(attacker: Player, defender: Player | TerraNullius): number
|
||||
boatMaxDistance(): number
|
||||
boatMaxNumber(): number
|
||||
allianceDuration(): Tick
|
||||
}
|
||||
|
||||
export interface Theme {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Player, PlayerInfo, PlayerType, TerrainType, TerraNullius, Tile} from "../game/Game";
|
||||
import {Player, PlayerInfo, PlayerType, TerrainType, TerraNullius, Tick, Tile} from "../game/Game";
|
||||
import {GameID} from "../Schemas";
|
||||
import {simpleHash, within} from "../Util";
|
||||
import {Config, Theme} from "./Config";
|
||||
@@ -7,6 +7,9 @@ import {pastelTheme} from "./PastelTheme";
|
||||
|
||||
|
||||
export class DefaultConfig implements Config {
|
||||
allianceDuration(): Tick {
|
||||
return 10 * 100
|
||||
}
|
||||
percentageTilesOwnedToWin(): number {
|
||||
return 95
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import {Tick} from "../game/Game";
|
||||
import {GameID} from "../Schemas";
|
||||
import {DefaultConfig} from "./DefaultConfig";
|
||||
|
||||
export const devConfig = new class extends DefaultConfig {
|
||||
percentageTilesOwnedToWin(): number {
|
||||
return 80
|
||||
return 95
|
||||
}
|
||||
numSpawnPhaseTurns(): number {
|
||||
return 80
|
||||
@@ -22,6 +23,9 @@ export const devConfig = new class extends DefaultConfig {
|
||||
return 0
|
||||
}
|
||||
|
||||
// allianceDuration(): Tick {
|
||||
// return 10 * 10
|
||||
// }
|
||||
|
||||
numFakeHumans(gameID: GameID): number {
|
||||
return 0
|
||||
|
||||
@@ -32,6 +32,13 @@ export class PlayerExecution implements Execution {
|
||||
}
|
||||
this.player.setTroops(this.config.troopAdditionRate(this.player))
|
||||
|
||||
const alliances = Array.from(this.player.alliances())
|
||||
for (const alliance of alliances) {
|
||||
if (this.mg.ticks() - alliance.createdAt() > this.mg.config().allianceDuration()) {
|
||||
alliance.expire()
|
||||
}
|
||||
}
|
||||
|
||||
if (ticks - this.lastCalc > this.ticksPerClusterCalc) {
|
||||
this.lastCalc = ticks
|
||||
const start = performance.now()
|
||||
|
||||
@@ -23,7 +23,7 @@ export class AllianceImpl implements MutableAlliance {
|
||||
}
|
||||
|
||||
expire(): void {
|
||||
|
||||
this.mg.expireAlliance(this)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -183,7 +183,7 @@ export interface Game {
|
||||
executions(): ExecutionView[]
|
||||
terraNullius(): TerraNullius
|
||||
executeNextTick(): void
|
||||
ticks(): number
|
||||
ticks(): Tick
|
||||
inSpawnPhase(): boolean
|
||||
addExecution(...exec: Execution[]): void
|
||||
config(): Config
|
||||
@@ -220,4 +220,8 @@ export class AllianceRequestReplyEvent implements GameEvent {
|
||||
|
||||
export class BrokeAllianceEvent implements GameEvent {
|
||||
constructor(public readonly traitor: Player, public readonly betrayed: Player) { }
|
||||
}
|
||||
|
||||
export class AllianceExpiredEvent implements GameEvent {
|
||||
constructor(public readonly player1: Player, public readonly player2: Player) { }
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import {info} from "console";
|
||||
import {Config} from "../configuration/Config";
|
||||
import {EventBus} from "../EventBus";
|
||||
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, BoatEvent, PlayerType, MutableAllianceRequest, AllianceRequestReplyEvent, AllianceRequestEvent, BrokeAllianceEvent, MutableAlliance, Alliance} from "./Game";
|
||||
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, BoatEvent, PlayerType, MutableAllianceRequest, AllianceRequestReplyEvent, AllianceRequestEvent, BrokeAllianceEvent, MutableAlliance, Alliance, AllianceExpiredEvent} from "./Game";
|
||||
import {TerrainMap} from "./TerrainMapLoader";
|
||||
import {PlayerImpl} from "./PlayerImpl";
|
||||
import {TerraNulliusImpl} from "./TerraNulliusImpl";
|
||||
@@ -366,6 +366,16 @@ export class GameImpl implements MutableGame {
|
||||
this.eventBus.emit(new BrokeAllianceEvent(breaker, other))
|
||||
}
|
||||
|
||||
public expireAlliance(alliance: Alliance) {
|
||||
const p1Set = new Set(alliance.recipient().alliances())
|
||||
const alliances = alliance.requestor().alliances().filter(a => p1Set.has(a))
|
||||
if (alliances.length != 1) {
|
||||
throw new Error(`cannot expire alliance: must have exactly one alliance, have ${alliances.length}`)
|
||||
}
|
||||
this.alliances_ = this.alliances_.filter(a => a != alliances[0])
|
||||
this.eventBus.emit(new AllianceExpiredEvent(alliance.requestor(), alliance.recipient()))
|
||||
}
|
||||
|
||||
displayMessage(message: string, type: MessageType, playerID: PlayerID | null): void {
|
||||
this.eventBus.emit(new DisplayMessageEvent(message, type, playerID))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user