mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 16:36:36 +00:00
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { Execution, MutableGame, Player, MutableUnit, Unit, UnitType } from "../game/Game";
|
|
import { PathFinder } from "../pathfinding/PathFinding";
|
|
import { PathFindResultType } from "../pathfinding/AStar";
|
|
import { consolex } from "../Consolex";
|
|
import { TileRef } from "../game/GameMap";
|
|
|
|
export class ShellExecution implements Execution {
|
|
|
|
private active = true
|
|
private pathFinder: PathFinder
|
|
private shell: MutableUnit
|
|
|
|
constructor(private spawn: TileRef, private _owner: Player, private ownerUnit: Unit, private target: MutableUnit) {
|
|
|
|
}
|
|
|
|
init(mg: MutableGame, ticks: number): void {
|
|
this.pathFinder = PathFinder.Mini(mg, 2000, true, 10)
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (this.shell == null) {
|
|
this.shell = this._owner.buildUnit(UnitType.Shell, 0, this.spawn)
|
|
}
|
|
if (!this.shell.isActive()) {
|
|
this.active = false
|
|
return
|
|
}
|
|
if (!this.target.isActive() || !this.ownerUnit.isActive() || this.target.owner() == this.shell.owner()) {
|
|
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(), 3)
|
|
switch (result.type) {
|
|
case PathFindResultType.Completed:
|
|
this.active = false
|
|
this.target.modifyHealth(-this.shell.info().damage)
|
|
this.shell.delete(false)
|
|
return
|
|
case PathFindResultType.NextTile:
|
|
this.shell.move(result.tile)
|
|
break
|
|
case PathFindResultType.Pending:
|
|
return
|
|
case PathFindResultType.PathNotFound:
|
|
consolex.log(`Shell ${this.shell} could not find target`)
|
|
this.active = false
|
|
this.shell.delete(false)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
owner(): Player {
|
|
return null
|
|
}
|
|
isActive(): boolean {
|
|
return this.active
|
|
}
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false
|
|
}
|
|
|
|
} |