mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 16:30:16 +00:00
665a8c3823
when an building is taken over by another player the execution for it doesnt change its owner this makes it so when a sam is captured it tries to intercept your own nukes and doesnt intercept the ones by the previous player this change makes executions of buildings automaticly switch their owner
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import { Execution, Game, Player, 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: Unit;
|
|
|
|
constructor(
|
|
private spawn: TileRef,
|
|
private _owner: Player,
|
|
private ownerUnit: Unit,
|
|
private target: Unit,
|
|
) {}
|
|
|
|
init(mg: Game, 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;
|
|
}
|
|
}
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|