mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:50:43 +00:00
added local build, improved spawnexec
This commit is contained in:
+2
-1
@@ -8,6 +8,7 @@
|
||||
"start:server": "GAME_ENV=prod node --loader ts-node/esm --experimental-specifier-resolution=node src/server/Server.ts",
|
||||
"start:server-dev": "GAME_ENV=dev node --loader ts-node/esm --experimental-specifier-resolution=node src/server/Server.ts",
|
||||
"dev": "GAME_ENV=dev concurrently \"npm run start:client\" \"npm run start:server-dev\"",
|
||||
"tunnel": "npm run build-prod && npm run start:server",
|
||||
"test": "jest"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -72,4 +73,4 @@
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,11 @@ import {Colord, colord} from "colord";
|
||||
import {devConfig} from "./DevConfig";
|
||||
import {defaultConfig} from "./DefaultConfig";
|
||||
|
||||
export enum GameEnv {
|
||||
Dev,
|
||||
Prod
|
||||
}
|
||||
|
||||
export function getConfig(): Config {
|
||||
// TODO: 'prod' not found in prod env
|
||||
if (process.env.GAME_ENV == 'dev') {
|
||||
@@ -14,6 +19,10 @@ export function getConfig(): Config {
|
||||
}
|
||||
}
|
||||
|
||||
export function getGameEnv(): GameEnv {
|
||||
return GameEnv.Prod
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
theme(): Theme;
|
||||
turnIntervalMs(): number
|
||||
|
||||
@@ -35,15 +35,15 @@ export class DefaultConfig implements Config {
|
||||
switch (tileToConquer.terrain()) {
|
||||
case TerrainType.Plains:
|
||||
mag = 5
|
||||
speed = 5
|
||||
speed = 3
|
||||
break
|
||||
case TerrainType.Highland:
|
||||
mag = 15
|
||||
speed = 10
|
||||
speed = 5
|
||||
break
|
||||
case TerrainType.Mountain:
|
||||
mag = 45
|
||||
speed = 15
|
||||
speed = 10
|
||||
break
|
||||
}
|
||||
if (defender.isPlayer()) {
|
||||
@@ -99,7 +99,7 @@ export class DefaultConfig implements Config {
|
||||
// console.log(`to add ${toAdd}`)
|
||||
|
||||
if (player.type() == PlayerType.Bot) {
|
||||
toAdd *= .5
|
||||
toAdd *= .7
|
||||
}
|
||||
|
||||
return Math.min(player.troops() + toAdd, max)
|
||||
|
||||
@@ -9,14 +9,14 @@ export const devConfig = new class extends DefaultConfig {
|
||||
return 2 * 1000
|
||||
}
|
||||
lobbyLifetime(): number {
|
||||
return 4 * 1000
|
||||
return 2 * 1000
|
||||
}
|
||||
turnIntervalMs(): number {
|
||||
return 100
|
||||
}
|
||||
|
||||
numBots(): number {
|
||||
return 400
|
||||
return 0
|
||||
}
|
||||
|
||||
// startTroops(playerInfo: PlayerInfo): number {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {BotSpawner} from "./BotSpawner";
|
||||
import {BoatAttackExecution} from "./BoatAttackExecution";
|
||||
import {PseudoRandom} from "../PseudoRandom";
|
||||
import {UpdateNameExecution} from "./UpdateNameExecution";
|
||||
import {FakeHumanExecution} from "./FakeHumanExecution";
|
||||
|
||||
|
||||
export class Executor {
|
||||
@@ -57,4 +58,9 @@ export class Executor {
|
||||
spawnBots(numBots: number): Execution[] {
|
||||
return new BotSpawner(this.gs).spawnBots(numBots).map(i => this.createExec(i))
|
||||
}
|
||||
|
||||
fakeHumanExecutions(numFakes: number): Execution[] {
|
||||
return [new FakeHumanExecution(null)]
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, TerraNullius} from "../Game"
|
||||
import {PseudoRandom} from "../PseudoRandom"
|
||||
import {simpleHash} from "../Util";
|
||||
import {AttackExecution} from "./AttackExecution";
|
||||
import {SpawnExecution} from "./SpawnExecution";
|
||||
|
||||
export class FakeHumanExecution implements Execution {
|
||||
|
||||
private active = true
|
||||
private random: PseudoRandom;
|
||||
private attackRate: number
|
||||
private mg: MutableGame
|
||||
private neighborsTerraNullius = true
|
||||
|
||||
|
||||
constructor(private bot: MutablePlayer) {
|
||||
this.random = new PseudoRandom(simpleHash(bot.id()))
|
||||
this.attackRate = this.random.nextInt(10, 50)
|
||||
}
|
||||
activeDuringSpawnPhase(): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
init(mg: MutableGame, ticks: number) {
|
||||
this.mg = mg
|
||||
}
|
||||
|
||||
tick(ticks: number) {
|
||||
|
||||
if (ticks < this.mg.config().numSpawnPhaseTurns()) {
|
||||
if(ticks % 10 == 0) {
|
||||
this.mg.addExecution(new SpawnExecution(
|
||||
null, null
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.bot.isAlive()) {
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
|
||||
if (ticks % this.attackRate != 0) {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.neighborsTerraNullius) {
|
||||
for (const b of this.bot.borderTiles()) {
|
||||
for (const n of b.neighbors()) {
|
||||
if (n.owner() == this.mg.terraNullius() && n.isLand()) {
|
||||
this.sendAttack(this.mg.terraNullius())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
this.neighborsTerraNullius = false
|
||||
}
|
||||
|
||||
const border = Array.from(this.bot.borderTiles()).flatMap(t => t.neighbors()).filter(t => t.hasOwner() && t.owner() != this.bot)
|
||||
|
||||
if (border.length == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const toAttack = border[this.random.nextInt(0, border.length)]
|
||||
this.sendAttack(toAttack.owner())
|
||||
}
|
||||
|
||||
sendAttack(toAttack: Player | TerraNullius) {
|
||||
this.mg.addExecution(new AttackExecution(
|
||||
this.bot.troops() / 20,
|
||||
this.bot.id(),
|
||||
toAttack.isPlayer() ? toAttack.id() : null,
|
||||
null,
|
||||
null
|
||||
))
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
return this.bot
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
return this.active
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,9 @@ export class SpawnExecution implements Execution {
|
||||
}
|
||||
|
||||
tick(ticks: number) {
|
||||
if (!this.isActive()) {
|
||||
return
|
||||
}
|
||||
this.active = false
|
||||
|
||||
if (ticks >= this.mg.config().numSpawnPhaseTurns()) {
|
||||
this.active = false
|
||||
if (!this.mg.inSpawnPhase()) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -44,8 +41,8 @@ export class SpawnExecution implements Execution {
|
||||
if (player.type() == PlayerType.Bot) {
|
||||
this.mg.addExecution(new BotExecution(player))
|
||||
}
|
||||
this.active = false
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user