mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-15 08:03:04 +00:00
moved attack logic to config
This commit is contained in:
@@ -2,6 +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";
|
||||
|
||||
export class AttackExecution implements Execution {
|
||||
private active: boolean = true;
|
||||
@@ -20,7 +21,8 @@ export class AttackExecution implements Execution {
|
||||
private troops: number,
|
||||
private _ownerID: PlayerID,
|
||||
private targetID: PlayerID | null,
|
||||
private targetCell: Cell | null
|
||||
private targetCell: Cell | null,
|
||||
private playerConfig: PlayerConfig
|
||||
) { }
|
||||
|
||||
init(mg: MutableGame, ticks: number) {
|
||||
@@ -61,7 +63,7 @@ export class AttackExecution implements Execution {
|
||||
return
|
||||
}
|
||||
|
||||
let numTilesPerTick = this.numTilesWithEnemy / 4
|
||||
let numTilesPerTick = this.playerConfig.attackTilesPerTick(this._owner, this.target, this.numTilesWithEnemy)
|
||||
if (this.targetCell != null) {
|
||||
numTilesPerTick /= 2
|
||||
}
|
||||
@@ -88,15 +90,13 @@ export class AttackExecution implements Execution {
|
||||
badTiles++
|
||||
continue
|
||||
}
|
||||
// TODO: move this to configs
|
||||
this._owner.conquer(tileToConquer)
|
||||
const {attackerTroopLoss, defenderTroopLoss, tilesPerTickUsed} = this.playerConfig.attackLogic(this._owner, this.target, tileToConquer)
|
||||
numTilesPerTick -= tilesPerTickUsed
|
||||
this.troops -= attackerTroopLoss
|
||||
if (this.target.isPlayer()) {
|
||||
this.troops -= Math.max(this.target.troops() / this._owner.troops(), 1)
|
||||
numTilesPerTick -= Math.max(this.target.troops() / this._owner.troops(), .25)
|
||||
} else {
|
||||
this.troops -= 1
|
||||
numTilesPerTick -= 1
|
||||
this.target.removeTroops(defenderTroopLoss)
|
||||
}
|
||||
this._owner.conquer(tileToConquer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +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";
|
||||
|
||||
export class BoatAttackExecution implements Execution {
|
||||
|
||||
@@ -29,7 +30,8 @@ export class BoatAttackExecution implements Execution {
|
||||
private attackerID: PlayerID,
|
||||
private targetID: PlayerID | null,
|
||||
private cell: Cell,
|
||||
private troops: number
|
||||
private troops: number,
|
||||
private playerConfig: PlayerConfig
|
||||
) { }
|
||||
|
||||
init(mg: MutableGame, ticks: number) {
|
||||
@@ -48,7 +50,7 @@ export class BoatAttackExecution implements Execution {
|
||||
this.src = this.closestShoreTileToTarget(this.attacker, this.cell)
|
||||
this.dst = this.closestShoreTileToTarget(this.target, this.cell)
|
||||
|
||||
if(this.src == null || this.dst == null) {
|
||||
if (this.src == null || this.dst == null) {
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
@@ -80,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.mg.addExecution(new AttackExecution(this.troops, this.attacker.id(), this.targetID, null, this.playerConfig))
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {PlayerConfig} from "../configuration/Config";
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, TerraNullius} from "../Game"
|
||||
import {PseudoRandom} from "../PseudoRandom"
|
||||
import {AttackExecution} from "./AttackExecution";
|
||||
@@ -10,7 +11,7 @@ export class BotExecution implements Execution {
|
||||
private gs: MutableGame
|
||||
private neighborsTerra = true
|
||||
|
||||
constructor(private bot: MutablePlayer) {
|
||||
constructor(private bot: MutablePlayer, private playerConfig: PlayerConfig) {
|
||||
|
||||
this.random = new PseudoRandom(bot.id())
|
||||
this.attackRate = this.random.nextInt(10, 50)
|
||||
@@ -57,7 +58,8 @@ export class BotExecution implements Execution {
|
||||
this.bot.troops() / 20,
|
||||
this.bot.id(),
|
||||
toAttack.isPlayer() ? toAttack.id() : null,
|
||||
null
|
||||
null,
|
||||
this.playerConfig
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ export class Executor {
|
||||
intent.troops,
|
||||
intent.attackerID,
|
||||
intent.targetID,
|
||||
new Cell(intent.targetX, intent.targetY)
|
||||
new Cell(intent.targetX, intent.targetY),
|
||||
this.playerConfig
|
||||
)
|
||||
)
|
||||
} else if (intent.type == "spawn") {
|
||||
@@ -43,6 +44,7 @@ export class Executor {
|
||||
intent.targetID,
|
||||
new Cell(intent.x, intent.y),
|
||||
intent.troops,
|
||||
this.playerConfig
|
||||
)
|
||||
)
|
||||
} else {
|
||||
|
||||
@@ -30,7 +30,7 @@ export class SpawnExecution implements Execution {
|
||||
})
|
||||
this.gs.addExecution(new PlayerExecution(player.id(), this.playerConfig))
|
||||
if (player.info().isBot) {
|
||||
this.gs.addExecution(new BotExecution(player))
|
||||
this.gs.addExecution(new BotExecution(player, this.playerConfig))
|
||||
}
|
||||
this.active = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user