mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-28 23:54:15 +00:00
give Battleships & Destroyers health, make shells more frequent & larger
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, TerrainType, Tile, UnitType } from "../game/Game";
|
||||
import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, TerrainType, Tile, Unit, UnitType } from "../game/Game";
|
||||
import { PathFinder } from "../pathfinding/PathFinding";
|
||||
import { PathFindResultType } from "../pathfinding/AStar";
|
||||
import { SerialAStar } from "../pathfinding/SerialAStar";
|
||||
@@ -22,9 +22,11 @@ export class BattleshipExecution implements Execution {
|
||||
|
||||
// TODO: put in config
|
||||
private searchRange = 100
|
||||
private attackRate = 20
|
||||
private attackRate = 5
|
||||
private lastAttack = 0
|
||||
|
||||
private alreadyTargeted = new Set<Unit>()
|
||||
|
||||
constructor(
|
||||
private playerID: PlayerID,
|
||||
private cell: Cell,
|
||||
@@ -41,6 +43,11 @@ export class BattleshipExecution implements Execution {
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
this.alreadyTargeted.forEach(u => {
|
||||
if (!u.isActive()) {
|
||||
this.alreadyTargeted.delete(u)
|
||||
}
|
||||
})
|
||||
if (this.battleship == null) {
|
||||
const spawn = this._owner.canBuild(UnitType.Battleship, this.patrolTile)
|
||||
if (spawn == false) {
|
||||
@@ -82,11 +89,17 @@ export class BattleshipExecution implements Execution {
|
||||
.filter(u => u.owner() != this.battleship.owner())
|
||||
.filter(u => u != this.battleship)
|
||||
.filter(u => !u.owner().isAlliedWith(this.battleship.owner()))
|
||||
.filter(u => !this.alreadyTargeted.has(u))
|
||||
.sort(distSortUnit(this.battleship));
|
||||
|
||||
if (ships.length > 0) {
|
||||
const toAttack = ships[0]
|
||||
if (!toAttack.hasHealth()) {
|
||||
// Don't send multiple shells to target if it can be one-shotted.
|
||||
this.alreadyTargeted.add(toAttack)
|
||||
}
|
||||
this.lastAttack = this.mg.ticks()
|
||||
this.mg.addExecution(new ShellExecution(this.battleship.tile(), this.battleship.owner(), ships[0]))
|
||||
this.mg.addExecution(new ShellExecution(this.battleship.tile(), this.battleship.owner(), this.battleship, toAttack))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ export class DestroyerExecution implements Execution {
|
||||
if (this.target == null) {
|
||||
const ships = this.mg.units(UnitType.TransportShip, UnitType.Destroyer, UnitType.TradeShip, UnitType.Battleship)
|
||||
.filter(u => manhattanDist(u.tile().cell(), this.destroyer.tile().cell()) < 100)
|
||||
.filter(u => u.type() != UnitType.Destroyer || u.health() < this.destroyer.health()) // only attack Destroyers weaker than it.
|
||||
.filter(u => u.owner() != this.destroyer.owner())
|
||||
.filter(u => u != this.destroyer)
|
||||
.filter(u => !u.owner().isAlliedWith(this.destroyer.owner()))
|
||||
@@ -93,14 +94,16 @@ export class DestroyerExecution implements Execution {
|
||||
case PathFindResultType.Completed:
|
||||
switch (this.target.type()) {
|
||||
case UnitType.TransportShip:
|
||||
case UnitType.Battleship:
|
||||
this.target.delete()
|
||||
break
|
||||
case UnitType.TradeShip:
|
||||
this.owner().captureUnit(this.target)
|
||||
break
|
||||
case UnitType.Destroyer:
|
||||
this.target.delete()
|
||||
this.destroyer.delete()
|
||||
const health = this.target.health()
|
||||
this.target.modifyHealth(-this.destroyer.health())
|
||||
this.destroyer.modifyHealth(-health)
|
||||
break
|
||||
}
|
||||
this.target = null
|
||||
|
||||
@@ -30,6 +30,11 @@ export class PlayerExecution implements Execution {
|
||||
|
||||
tick(ticks: number) {
|
||||
this.player.units().forEach(u => {
|
||||
if (u.health() <= 0) {
|
||||
u.delete()
|
||||
return
|
||||
}
|
||||
u.modifyHealth(1)
|
||||
const tileOwner = u.tile().owner()
|
||||
if (u.info().territoryBound) {
|
||||
if (tileOwner.isPlayer()) {
|
||||
|
||||
@@ -9,7 +9,7 @@ export class ShellExecution implements Execution {
|
||||
private pathFinder: PathFinder
|
||||
private shell: MutableUnit
|
||||
|
||||
constructor(private spawn: Tile, private _owner: MutablePlayer, private target: MutableUnit) {
|
||||
constructor(private spawn: Tile, private _owner: MutablePlayer, private ownerUnit: Unit, private target: MutableUnit) {
|
||||
|
||||
}
|
||||
|
||||
@@ -25,17 +25,17 @@ export class ShellExecution implements Execution {
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
if (!this.target.isActive()) {
|
||||
if (!this.target.isActive() || !this.ownerUnit.isActive()) {
|
||||
this.shell.delete(false)
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const result = this.pathFinder.nextTile(this.shell.tile(), this.target.tile())
|
||||
const result = this.pathFinder.nextTile(this.shell.tile(), this.target.tile(), 3)
|
||||
switch (result.type) {
|
||||
case PathFindResultType.Completed:
|
||||
this.active = false
|
||||
this.target.delete()
|
||||
this.target.modifyHealth(-this.shell.info().damage)
|
||||
this.shell.delete(false)
|
||||
return
|
||||
case PathFindResultType.NextTile:
|
||||
|
||||
Reference in New Issue
Block a user