mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-02 19:58:31 +00:00
moved attack config to separate config class
This commit is contained in:
@@ -90,6 +90,7 @@ export interface MutableBoat extends Boat {
|
||||
export interface TerraNullius {
|
||||
ownsTile(cell: Cell): boolean
|
||||
isPlayer(): false
|
||||
id(): PlayerID // always zero, maybe make it TerraNulliusID?
|
||||
}
|
||||
|
||||
export interface Player {
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
import {PlayerID, TerrainType, TerrainTypes} from "./Game";
|
||||
import {Colord, colord} from "colord";
|
||||
|
||||
export interface Settings {
|
||||
theme(): Theme;
|
||||
turnIntervalMs(): number
|
||||
tickIntervalMs(): number
|
||||
ticksPerTurn(): number
|
||||
lobbyCreationRate(): number
|
||||
lobbyLifetime(): number
|
||||
}
|
||||
|
||||
export interface Theme {
|
||||
playerInfoColor(id: PlayerID): Colord;
|
||||
territoryColor(id: PlayerID): Colord;
|
||||
borderColor(id: PlayerID): Colord;
|
||||
terrainColor(tile: TerrainType): Colord;
|
||||
backgroundColor(): Colord;
|
||||
font(): string;
|
||||
}
|
||||
|
||||
export const defaultSettings = new class implements Settings {
|
||||
ticksPerTurn(): number {
|
||||
return 1
|
||||
}
|
||||
turnIntervalMs(): number {
|
||||
return 100
|
||||
}
|
||||
lobbyCreationRate(): number {
|
||||
return 2 * 1000
|
||||
}
|
||||
lobbyLifetime(): number {
|
||||
return 3 * 1000
|
||||
}
|
||||
theme(): Theme {return pastelTheme;}
|
||||
|
||||
tickIntervalMs(): number {
|
||||
return 1000 / 20; // 50ms
|
||||
}
|
||||
}
|
||||
|
||||
const pastelTheme = new class implements Theme {
|
||||
private background = colord({r: 100, g: 100, b: 100});
|
||||
private land = colord({r: 244, g: 243, b: 198});
|
||||
private water = colord({r: 160, g: 203, b: 231});
|
||||
private territory = colord({r: 173, g: 216, b: 230});
|
||||
private territoryColors: Colord[] = [
|
||||
colord({r: 255, g: 179, b: 186}), // Vibrant Light Pink
|
||||
colord({r: 255, g: 223, b: 186}), // Vibrant Peach
|
||||
colord({r: 190, g: 255, b: 190}), // Vibrant Light Green
|
||||
colord({r: 173, g: 216, b: 255}), // Vibrant Light Blue
|
||||
colord({r: 224, g: 187, b: 255}), // Vibrant Light Purple
|
||||
colord({r: 255, g: 191, b: 230}), // Vibrant Pink
|
||||
colord({r: 210, g: 255, b: 210}), // Vibrant Mint Green
|
||||
colord({r: 255, g: 213, b: 179}), // Vibrant Light Orange
|
||||
colord({r: 198, g: 198, b: 255}), // Vibrant Lavender
|
||||
colord({r: 255, g: 255, b: 186}), // Vibrant Light Yellow
|
||||
colord({r: 186, g: 255, b: 201}), // Vibrant Seafoam Green
|
||||
colord({r: 255, g: 186, b: 255}), // Vibrant Light Magenta
|
||||
colord({r: 210, g: 255, b: 210}), // Vibrant Pale Green
|
||||
colord({r: 255, g: 202, b: 202}), // Vibrant Salmon Pink
|
||||
colord({r: 206, g: 206, b: 255}), // Vibrant Periwinkle
|
||||
colord({r: 255, g: 234, b: 186}), // Vibrant Cream
|
||||
colord({r: 186, g: 255, b: 255}), // Vibrant Light Cyan
|
||||
colord({r: 238, g: 210, b: 255}), // Vibrant Lilac
|
||||
colord({r: 206, g: 255, b: 238}), // Vibrant Pale Turquoise
|
||||
colord({r: 255, g: 209, b: 186}), // Vibrant Peach
|
||||
colord({r: 186, g: 216, b: 255}), // Vibrant Baby Blue
|
||||
colord({r: 246, g: 255, b: 186}), // Vibrant Pale Yellow
|
||||
colord({r: 220, g: 186, b: 255}), // Vibrant Light Violet
|
||||
colord({r: 255, g: 186, b: 213}), // Vibrant Rose
|
||||
colord({r: 186, g: 255, b: 226}), // Vibrant Honeydew
|
||||
colord({r: 206, g: 236, b: 255}), // Vibrant Sky Blue
|
||||
colord({r: 255, g: 232, b: 206}), // Vibrant Wheat
|
||||
colord({r: 206, g: 255, b: 255}), // Vibrant Pale Cyan
|
||||
colord({r: 255, g: 216, b: 216}), // Vibrant Misty Rose
|
||||
colord({r: 216, g: 216, b: 255}), // Vibrant Pale Lavender
|
||||
colord({r: 255, g: 250, b: 205}), // Vibrant Pale Goldenrod
|
||||
colord({r: 216, g: 255, b: 216}), // Vibrant Pale Mint
|
||||
colord({r: 255, g: 216, b: 255}), // Vibrant Pale Plum
|
||||
colord({r: 220, g: 255, b: 220}), // Vibrant Mint Cream
|
||||
colord({r: 255, g: 220, b: 220}), // Vibrant Pale Pink
|
||||
colord({r: 220, g: 220, b: 255}), // Vibrant Pale Blue
|
||||
colord({r: 255, g: 255, b: 220}), // Vibrant Light Goldenrod
|
||||
colord({r: 220, g: 255, b: 255}), // Vibrant Light Azure
|
||||
colord({r: 255, g: 220, b: 255}), // Vibrant Pale Magenta
|
||||
colord({r: 230, g: 255, b: 230}), // Vibrant Honeydew
|
||||
colord({r: 255, g: 230, b: 230}), // Vibrant Lavender Blush
|
||||
colord({r: 230, g: 230, b: 255}), // Vibrant Ghost White
|
||||
colord({r: 255, g: 239, b: 219}), // Vibrant Seashell
|
||||
colord({r: 219, g: 255, b: 239}), // Vibrant Mint Cream
|
||||
colord({r: 239, g: 219, b: 255}), // Vibrant Pale Lavender
|
||||
colord({r: 255, g: 250, b: 230}), // Vibrant Floral White
|
||||
colord({r: 230, g: 255, b: 250}), // Vibrant Azure Mist
|
||||
colord({r: 250, g: 230, b: 255}), // Vibrant Pale Purple
|
||||
colord({r: 250, g: 255, b: 230}), // Vibrant Ivory
|
||||
colord({r: 230, g: 250, b: 255}) // Vibrant Alice Blue
|
||||
];
|
||||
playerInfoColor(id: PlayerID): Colord {
|
||||
return colord({r: 0, g: 0, b: 0})
|
||||
}
|
||||
|
||||
territoryColor(id: PlayerID): Colord {
|
||||
return this.territoryColors[id % this.territoryColors.length]
|
||||
}
|
||||
|
||||
borderColor(id: PlayerID): Colord {
|
||||
const tc = this.territoryColor(id).rgba;
|
||||
return colord({
|
||||
r: Math.max(tc.r - 20, 0),
|
||||
g: Math.max(tc.g - 20, 0),
|
||||
b: Math.max(tc.b - 20, 0)
|
||||
})
|
||||
}
|
||||
|
||||
terrainColor(tile: TerrainType): Colord {
|
||||
if (tile == TerrainTypes.Land) {
|
||||
return this.land;
|
||||
}
|
||||
return this.water;
|
||||
}
|
||||
|
||||
backgroundColor(): Colord {
|
||||
return this.background;
|
||||
}
|
||||
|
||||
font(): string {
|
||||
return "Arial";
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import {EventBus, GameEvent} from "./EventBus";
|
||||
import {Settings} from "./Settings";
|
||||
import {Config} from "./configuration/Config";
|
||||
|
||||
export class TickEvent implements GameEvent {
|
||||
constructor(public readonly tickCount: number) { }
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import {Player, PlayerID, PlayerInfo, TerrainType, TerrainTypes, TerraNullius} from "../Game";
|
||||
import {Colord, colord} from "colord";
|
||||
import {pastelTheme} from "./PastelTheme";
|
||||
|
||||
export interface Config {
|
||||
theme(): Theme;
|
||||
player(): PlayerConfig
|
||||
turnIntervalMs(): number
|
||||
tickIntervalMs(): number
|
||||
ticksPerTurn(): number
|
||||
lobbyCreationRate(): number
|
||||
lobbyLifetime(): number
|
||||
}
|
||||
|
||||
export interface PlayerConfig {
|
||||
startTroops(playerInfo: PlayerInfo): number
|
||||
troopAdditionRate(player: Player): number
|
||||
attackLogic(attack: Player, defender: Player | TerraNullius): number
|
||||
attackAmount(attacker: Player, defender: Player | TerraNullius): number
|
||||
boatAttackAmount(attacker: Player, defender: Player | TerraNullius): number
|
||||
}
|
||||
|
||||
export interface Theme {
|
||||
playerInfoColor(id: PlayerID): Colord;
|
||||
territoryColor(id: PlayerID): Colord;
|
||||
borderColor(id: PlayerID): Colord;
|
||||
terrainColor(tile: TerrainType): Colord;
|
||||
backgroundColor(): Colord;
|
||||
font(): string;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import {Player, PlayerInfo, TerraNullius} from "../Game";
|
||||
import {Config, PlayerConfig, Theme} from "./Config";
|
||||
import {pastelTheme} from "./PastelTheme";
|
||||
|
||||
export const defaultConfig = new class implements Config {
|
||||
player(): PlayerConfig {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
ticksPerTurn(): number {
|
||||
return 1
|
||||
}
|
||||
turnIntervalMs(): number {
|
||||
return 100
|
||||
}
|
||||
lobbyCreationRate(): number {
|
||||
return 2 * 1000
|
||||
}
|
||||
lobbyLifetime(): number {
|
||||
return 3 * 1000
|
||||
}
|
||||
theme(): Theme {return pastelTheme;}
|
||||
|
||||
tickIntervalMs(): number {
|
||||
return 1000 / 20; // 50ms
|
||||
}
|
||||
}
|
||||
|
||||
export const defaultPlayerConfig = new class implements PlayerConfig {
|
||||
boatAttackAmount(attacker: Player, defender: Player | TerraNullius): number {
|
||||
return attacker.troops() / 5
|
||||
}
|
||||
attackAmount(attacker: Player, defender: Player | TerraNullius) {
|
||||
if (attacker.info().isBot) {
|
||||
return attacker.troops() / 20
|
||||
} else {
|
||||
return attacker.troops() / 5
|
||||
}
|
||||
}
|
||||
|
||||
startTroops(playerInfo: PlayerInfo): number {
|
||||
return 1000
|
||||
}
|
||||
|
||||
troopAdditionRate(player: Player): number {
|
||||
let toAdd = Math.sqrt(player.numTilesOwned() * player.troops()) / 5
|
||||
|
||||
const max = Math.sqrt(player.numTilesOwned()) * 100 + 1000
|
||||
const ratio = 1 - player.troops() / max
|
||||
toAdd *= ratio * ratio * ratio
|
||||
toAdd = Math.max(2, toAdd)
|
||||
return Math.min(player.troops(), max)
|
||||
}
|
||||
|
||||
attackLogic(attack: Player, defender: Player | TerraNullius): number {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import {Colord, colord} from "colord";
|
||||
import {PlayerID, TerrainType, TerrainTypes} from "../Game";
|
||||
import {Theme} from "./Config";
|
||||
|
||||
export const pastelTheme = new class implements Theme {
|
||||
private background = colord({r: 100, g: 100, b: 100});
|
||||
private land = colord({r: 244, g: 243, b: 198});
|
||||
private water = colord({r: 160, g: 203, b: 231});
|
||||
private territoryColors: Colord[] = [
|
||||
colord({r: 255, g: 179, b: 186}), // Vibrant Light Pink
|
||||
colord({r: 255, g: 223, b: 186}), // Vibrant Peach
|
||||
colord({r: 190, g: 255, b: 190}), // Vibrant Light Green
|
||||
colord({r: 173, g: 216, b: 255}), // Vibrant Light Blue
|
||||
colord({r: 224, g: 187, b: 255}), // Vibrant Light Purple
|
||||
colord({r: 255, g: 191, b: 230}), // Vibrant Pink
|
||||
colord({r: 210, g: 255, b: 210}), // Vibrant Mint Green
|
||||
colord({r: 255, g: 213, b: 179}), // Vibrant Light Orange
|
||||
colord({r: 198, g: 198, b: 255}), // Vibrant Lavender
|
||||
colord({r: 255, g: 255, b: 186}), // Vibrant Light Yellow
|
||||
colord({r: 186, g: 255, b: 201}), // Vibrant Seafoam Green
|
||||
colord({r: 255, g: 186, b: 255}), // Vibrant Light Magenta
|
||||
colord({r: 210, g: 255, b: 210}), // Vibrant Pale Green
|
||||
colord({r: 255, g: 202, b: 202}), // Vibrant Salmon Pink
|
||||
colord({r: 206, g: 206, b: 255}), // Vibrant Periwinkle
|
||||
colord({r: 255, g: 234, b: 186}), // Vibrant Cream
|
||||
colord({r: 186, g: 255, b: 255}), // Vibrant Light Cyan
|
||||
colord({r: 238, g: 210, b: 255}), // Vibrant Lilac
|
||||
colord({r: 206, g: 255, b: 238}), // Vibrant Pale Turquoise
|
||||
colord({r: 255, g: 209, b: 186}), // Vibrant Peach
|
||||
colord({r: 186, g: 216, b: 255}), // Vibrant Baby Blue
|
||||
colord({r: 246, g: 255, b: 186}), // Vibrant Pale Yellow
|
||||
colord({r: 220, g: 186, b: 255}), // Vibrant Light Violet
|
||||
colord({r: 255, g: 186, b: 213}), // Vibrant Rose
|
||||
colord({r: 186, g: 255, b: 226}), // Vibrant Honeydew
|
||||
colord({r: 206, g: 236, b: 255}), // Vibrant Sky Blue
|
||||
colord({r: 255, g: 232, b: 206}), // Vibrant Wheat
|
||||
colord({r: 206, g: 255, b: 255}), // Vibrant Pale Cyan
|
||||
colord({r: 255, g: 216, b: 216}), // Vibrant Misty Rose
|
||||
colord({r: 216, g: 216, b: 255}), // Vibrant Pale Lavender
|
||||
colord({r: 255, g: 250, b: 205}), // Vibrant Pale Goldenrod
|
||||
colord({r: 216, g: 255, b: 216}), // Vibrant Pale Mint
|
||||
colord({r: 255, g: 216, b: 255}), // Vibrant Pale Plum
|
||||
colord({r: 220, g: 255, b: 220}), // Vibrant Mint Cream
|
||||
colord({r: 255, g: 220, b: 220}), // Vibrant Pale Pink
|
||||
colord({r: 220, g: 220, b: 255}), // Vibrant Pale Blue
|
||||
colord({r: 255, g: 255, b: 220}), // Vibrant Light Goldenrod
|
||||
colord({r: 220, g: 255, b: 255}), // Vibrant Light Azure
|
||||
colord({r: 255, g: 220, b: 255}), // Vibrant Pale Magenta
|
||||
colord({r: 230, g: 255, b: 230}), // Vibrant Honeydew
|
||||
colord({r: 255, g: 230, b: 230}), // Vibrant Lavender Blush
|
||||
colord({r: 230, g: 230, b: 255}), // Vibrant Ghost White
|
||||
colord({r: 255, g: 239, b: 219}), // Vibrant Seashell
|
||||
colord({r: 219, g: 255, b: 239}), // Vibrant Mint Cream
|
||||
colord({r: 239, g: 219, b: 255}), // Vibrant Pale Lavender
|
||||
colord({r: 255, g: 250, b: 230}), // Vibrant Floral White
|
||||
colord({r: 230, g: 255, b: 250}), // Vibrant Azure Mist
|
||||
colord({r: 250, g: 230, b: 255}), // Vibrant Pale Purple
|
||||
colord({r: 250, g: 255, b: 230}), // Vibrant Ivory
|
||||
colord({r: 230, g: 250, b: 255}) // Vibrant Alice Blue
|
||||
];
|
||||
playerInfoColor(id: PlayerID): Colord {
|
||||
return colord({r: 0, g: 0, b: 0})
|
||||
}
|
||||
|
||||
territoryColor(id: PlayerID): Colord {
|
||||
return this.territoryColors[id % this.territoryColors.length]
|
||||
}
|
||||
|
||||
borderColor(id: PlayerID): Colord {
|
||||
const tc = this.territoryColor(id).rgba;
|
||||
return colord({
|
||||
r: Math.max(tc.r - 20, 0),
|
||||
g: Math.max(tc.g - 20, 0),
|
||||
b: Math.max(tc.b - 20, 0)
|
||||
})
|
||||
}
|
||||
|
||||
terrainColor(tile: TerrainType): Colord {
|
||||
if (tile == TerrainTypes.Land) {
|
||||
return this.land;
|
||||
}
|
||||
return this.water;
|
||||
}
|
||||
|
||||
backgroundColor(): Colord {
|
||||
return this.background;
|
||||
}
|
||||
|
||||
font(): string {
|
||||
return "Arial";
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,12 @@ import {AttackExecution} from "./AttackExecution";
|
||||
import {SpawnExecution} from "./SpawnExecution";
|
||||
import {BotSpawner} from "./BotSpawner";
|
||||
import {BoatAttackExecution} from "./BoatAttackExecution";
|
||||
import {PlayerConfig} from "../configuration/Config";
|
||||
|
||||
|
||||
export class Executor {
|
||||
|
||||
constructor(private gs: Game) {
|
||||
constructor(private gs: Game, private playerConfig: PlayerConfig) {
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +33,7 @@ export class Executor {
|
||||
new SpawnExecution(
|
||||
new PlayerInfo(intent.name, intent.isBot),
|
||||
new Cell(intent.x, intent.y),
|
||||
this.playerConfig
|
||||
)
|
||||
)
|
||||
} else if (intent.type == "boat") {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import {PlayerConfig} from "../configuration/Config"
|
||||
import {Execution, MutableGame, MutablePlayer, PlayerID} from "../Game"
|
||||
|
||||
export class PlayerExecution implements Execution {
|
||||
|
||||
private player: MutablePlayer
|
||||
|
||||
constructor(private playerID: PlayerID) {
|
||||
constructor(private playerID: PlayerID, private playerConfig: PlayerConfig) {
|
||||
}
|
||||
|
||||
init(gs: MutableGame, ticks: number) {
|
||||
@@ -12,15 +13,7 @@ export class PlayerExecution implements Execution {
|
||||
}
|
||||
|
||||
tick(ticks: number) {
|
||||
let toAdd = Math.sqrt(this.player.numTilesOwned() * this.player.troops()) / 5
|
||||
|
||||
const max = Math.sqrt(this.player.numTilesOwned()) * 100 + 1000
|
||||
const ratio = 1 - this.player.troops() / max
|
||||
toAdd *= ratio * ratio * ratio
|
||||
this.player.addTroops(
|
||||
Math.max(2, toAdd)
|
||||
);
|
||||
this.player.setTroops(Math.min(this.player.troops(), max))
|
||||
this.player.setTroops(this.playerConfig.troopAdditionRate(this.player))
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {PlayerConfig} from "../configuration/Config"
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, PlayerInfo} from "../Game"
|
||||
import {BotExecution} from "./BotExecution"
|
||||
import {PlayerExecution} from "./PlayerExecution"
|
||||
@@ -11,6 +12,7 @@ export class SpawnExecution implements Execution {
|
||||
constructor(
|
||||
private playerInfo: PlayerInfo,
|
||||
private cell: Cell,
|
||||
private playerConfig: PlayerConfig
|
||||
) { }
|
||||
|
||||
|
||||
@@ -22,12 +24,12 @@ export class SpawnExecution implements Execution {
|
||||
if (!this.isActive()) {
|
||||
return
|
||||
}
|
||||
const player = this.gs.addPlayer(this.playerInfo, 1000)
|
||||
const player = this.gs.addPlayer(this.playerInfo, this.playerConfig.startTroops(this.playerInfo))
|
||||
getSpawnCells(this.gs, this.cell).forEach(c => {
|
||||
console.log('conquering cell')
|
||||
player.conquer(this.gs.tile(c))
|
||||
})
|
||||
this.gs.addExecution(new PlayerExecution(player.id()))
|
||||
this.gs.addExecution(new PlayerExecution(player.id(), this.playerConfig))
|
||||
if (player.info().isBot) {
|
||||
this.gs.addExecution(new BotExecution(player))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user