moved attack config to separate config class

This commit is contained in:
evanpelle
2024-08-12 16:31:32 -07:00
parent ca546919bb
commit a4799a3c21
16 changed files with 222 additions and 169 deletions
+3 -1
View File
@@ -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") {
+3 -10
View File
@@ -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 {
+4 -2
View File
@@ -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))
}