mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-03 14:00:47 +00:00
moved attack config to separate config class
This commit is contained in:
@@ -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