mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 14:33:25 +00:00
game start delay 5 seconds
This commit is contained in:
@@ -2,7 +2,7 @@ import PriorityQueue from "priority-queue-typescript";
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, PlayerID, Player, TerrainTypes, TerraNullius, Tile} from "../Game";
|
||||
import {PseudoRandom} from "../PseudoRandom";
|
||||
import {manhattanDist} from "../Util";
|
||||
import {PlayerConfig} from "../configuration/Config";
|
||||
import {Config, PlayerConfig} from "../configuration/Config";
|
||||
|
||||
export class AttackExecution implements Execution {
|
||||
private active: boolean = true;
|
||||
@@ -22,7 +22,7 @@ export class AttackExecution implements Execution {
|
||||
private _ownerID: PlayerID,
|
||||
private targetID: PlayerID | null,
|
||||
private targetCell: Cell | null,
|
||||
private playerConfig: PlayerConfig
|
||||
private config: Config
|
||||
) { }
|
||||
|
||||
init(mg: MutableGame, ticks: number) {
|
||||
@@ -68,8 +68,11 @@ export class AttackExecution implements Execution {
|
||||
if (!this.active) {
|
||||
return
|
||||
}
|
||||
if (ticks < this.config.turnsUntilGameStart()) {
|
||||
return
|
||||
}
|
||||
|
||||
let numTilesPerTick = this.playerConfig.attackTilesPerTick(this._owner, this.target, this.numTilesWithEnemy)
|
||||
let numTilesPerTick = this.config.player().attackTilesPerTick(this._owner, this.target, this.numTilesWithEnemy)
|
||||
if (this.targetCell != null) {
|
||||
numTilesPerTick /= 2
|
||||
}
|
||||
@@ -104,7 +107,7 @@ export class AttackExecution implements Execution {
|
||||
badTiles++
|
||||
continue
|
||||
}
|
||||
const {attackerTroopLoss, defenderTroopLoss, tilesPerTickUsed} = this.playerConfig.attackLogic(this._owner, this.target, tileToConquer)
|
||||
const {attackerTroopLoss, defenderTroopLoss, tilesPerTickUsed} = this.config.player().attackLogic(this._owner, this.target, tileToConquer)
|
||||
numTilesPerTick -= tilesPerTickUsed
|
||||
this.troops -= attackerTroopLoss
|
||||
if (this.target.isPlayer()) {
|
||||
|
||||
@@ -2,7 +2,7 @@ import PriorityQueue from "priority-queue-typescript";
|
||||
import {Boat, Cell, Execution, MutableBoat, MutableGame, MutablePlayer, Player, PlayerID, Tile} from "../Game";
|
||||
import {manhattanDist} from "../Util";
|
||||
import {AttackExecution} from "./AttackExecution";
|
||||
import {PlayerConfig} from "../configuration/Config";
|
||||
import {Config, PlayerConfig} from "../configuration/Config";
|
||||
|
||||
export class BoatAttackExecution implements Execution {
|
||||
|
||||
@@ -31,7 +31,7 @@ export class BoatAttackExecution implements Execution {
|
||||
private targetID: PlayerID | null,
|
||||
private cell: Cell,
|
||||
private troops: number,
|
||||
private playerConfig: PlayerConfig
|
||||
private config: Config
|
||||
) { }
|
||||
|
||||
init(mg: MutableGame, ticks: number) {
|
||||
@@ -82,7 +82,7 @@ export class BoatAttackExecution implements Execution {
|
||||
return
|
||||
}
|
||||
this.attacker.conquer(this.dst)
|
||||
this.mg.addExecution(new AttackExecution(this.troops, this.attacker.id(), this.targetID, null, this.playerConfig))
|
||||
this.mg.addExecution(new AttackExecution(this.troops, this.attacker.id(), this.targetID, null, this.config))
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {PlayerConfig} from "../configuration/Config";
|
||||
import {Config, PlayerConfig} from "../configuration/Config";
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, TerrainTypes, TerraNullius} from "../Game"
|
||||
import {PseudoRandom} from "../PseudoRandom"
|
||||
import {AttackExecution} from "./AttackExecution";
|
||||
@@ -11,9 +11,8 @@ export class BotExecution implements Execution {
|
||||
private gs: MutableGame
|
||||
private neighborsTerra = true
|
||||
|
||||
private ticksUntilStart = 50
|
||||
|
||||
constructor(private bot: MutablePlayer, private playerConfig: PlayerConfig) {
|
||||
constructor(private bot: MutablePlayer, private config: Config) {
|
||||
|
||||
this.random = new PseudoRandom(bot.id())
|
||||
this.attackRate = this.random.nextInt(10, 50)
|
||||
@@ -26,10 +25,9 @@ export class BotExecution implements Execution {
|
||||
|
||||
tick(ticks: number) {
|
||||
|
||||
if (ticks < this.ticksUntilStart) {
|
||||
if (ticks < this.config.turnsUntilGameStart()) {
|
||||
return
|
||||
}
|
||||
return
|
||||
|
||||
if (!this.bot.isAlive()) {
|
||||
this.active = false
|
||||
@@ -64,7 +62,7 @@ export class BotExecution implements Execution {
|
||||
this.bot.id(),
|
||||
toAttack.isPlayer() ? toAttack.id() : null,
|
||||
null,
|
||||
this.playerConfig
|
||||
this.config
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@ import {AttackExecution} from "./AttackExecution";
|
||||
import {SpawnExecution} from "./SpawnExecution";
|
||||
import {BotSpawner} from "./BotSpawner";
|
||||
import {BoatAttackExecution} from "./BoatAttackExecution";
|
||||
import {PlayerConfig} from "../configuration/Config";
|
||||
import {Config, PlayerConfig} from "../configuration/Config";
|
||||
|
||||
|
||||
export class Executor {
|
||||
|
||||
constructor(private gs: Game, private playerConfig: PlayerConfig) {
|
||||
constructor(private gs: Game, private config: Config) {
|
||||
|
||||
}
|
||||
|
||||
@@ -18,20 +18,20 @@ export class Executor {
|
||||
return turn.intents.map(i => this.createExec(i))
|
||||
}
|
||||
|
||||
createExec(intent: Intent) {
|
||||
createExec(intent: Intent): Execution {
|
||||
if (intent.type == "attack") {
|
||||
return new AttackExecution(
|
||||
intent.troops,
|
||||
intent.attackerID,
|
||||
intent.targetID,
|
||||
new Cell(intent.targetX, intent.targetY),
|
||||
this.playerConfig
|
||||
this.config
|
||||
)
|
||||
} else if (intent.type == "spawn") {
|
||||
return new SpawnExecution(
|
||||
new PlayerInfo(intent.name, intent.isBot, intent.clientID),
|
||||
new Cell(intent.x, intent.y),
|
||||
this.playerConfig
|
||||
this.config
|
||||
)
|
||||
} else if (intent.type == "boat") {
|
||||
return new BoatAttackExecution(
|
||||
@@ -39,7 +39,7 @@ export class Executor {
|
||||
intent.targetID,
|
||||
new Cell(intent.x, intent.y),
|
||||
intent.troops,
|
||||
this.playerConfig
|
||||
this.config
|
||||
)
|
||||
} else {
|
||||
throw new Error(`intent type ${intent} not found`)
|
||||
@@ -47,7 +47,7 @@ export class Executor {
|
||||
}
|
||||
|
||||
|
||||
spawnBots(numBots: number): void {
|
||||
new BotSpawner(this.gs).spawnBots(numBots).forEach(i => this.createExec(i))
|
||||
spawnBots(numBots: number): Execution[] {
|
||||
return new BotSpawner(this.gs).spawnBots(numBots).map(i => this.createExec(i))
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import {PlayerConfig} from "../configuration/Config"
|
||||
import {Config, PlayerConfig} from "../configuration/Config"
|
||||
import {Execution, MutableGame, MutablePlayer, PlayerID} from "../Game"
|
||||
|
||||
export class PlayerExecution implements Execution {
|
||||
|
||||
private player: MutablePlayer
|
||||
|
||||
constructor(private playerID: PlayerID, private playerConfig: PlayerConfig) {
|
||||
constructor(private playerID: PlayerID, private config: Config) {
|
||||
}
|
||||
|
||||
init(gs: MutableGame, ticks: number) {
|
||||
@@ -13,7 +13,10 @@ export class PlayerExecution implements Execution {
|
||||
}
|
||||
|
||||
tick(ticks: number) {
|
||||
this.player.setTroops(this.playerConfig.troopAdditionRate(this.player))
|
||||
if (ticks < this.config.turnsUntilGameStart()) {
|
||||
return
|
||||
}
|
||||
this.player.setTroops(this.config.player().troopAdditionRate(this.player))
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {PlayerConfig} from "../configuration/Config"
|
||||
import {Config, PlayerConfig} from "../configuration/Config"
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, PlayerInfo} from "../Game"
|
||||
import {BotExecution} from "./BotExecution"
|
||||
import {PlayerExecution} from "./PlayerExecution"
|
||||
@@ -12,7 +12,7 @@ export class SpawnExecution implements Execution {
|
||||
constructor(
|
||||
private playerInfo: PlayerInfo,
|
||||
private cell: Cell,
|
||||
private playerConfig: PlayerConfig
|
||||
private config: Config
|
||||
) { }
|
||||
|
||||
|
||||
@@ -24,13 +24,13 @@ export class SpawnExecution implements Execution {
|
||||
if (!this.isActive()) {
|
||||
return
|
||||
}
|
||||
const player = this.gs.addPlayer(this.playerInfo, this.playerConfig.startTroops(this.playerInfo))
|
||||
const player = this.gs.addPlayer(this.playerInfo, this.config.player().startTroops(this.playerInfo))
|
||||
getSpawnCells(this.gs, this.cell).forEach(c => {
|
||||
player.conquer(this.gs.tile(c))
|
||||
})
|
||||
this.gs.addExecution(new PlayerExecution(player.id(), this.playerConfig))
|
||||
this.gs.addExecution(new PlayerExecution(player.id(), this.config))
|
||||
if (player.info().isBot) {
|
||||
this.gs.addExecution(new BotExecution(player, this.playerConfig))
|
||||
this.gs.addExecution(new BotExecution(player, this.config))
|
||||
}
|
||||
this.active = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user