mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 03:53:49 +00:00
9ae544595b
## Description: Sending invalid coords can cause game to crash. Make sure to validate tile ref. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import { Execution, Game, Player, UnitType } from "../game/Game";
|
|
import { TileRef } from "../game/GameMap";
|
|
|
|
export class MoveWarshipExecution implements Execution {
|
|
constructor(
|
|
private readonly owner: Player,
|
|
private readonly unitId: number,
|
|
private readonly position: TileRef,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
if (!mg.isValidRef(this.position)) {
|
|
console.warn(`MoveWarshipExecution: position ${this.position} not valid`);
|
|
return;
|
|
}
|
|
const warship = this.owner
|
|
.units(UnitType.Warship)
|
|
.find((u) => u.id() === this.unitId);
|
|
if (!warship) {
|
|
console.warn("MoveWarshipExecution: warship not found");
|
|
return;
|
|
}
|
|
if (!warship.isActive()) {
|
|
console.warn("MoveWarshipExecution: warship is not active");
|
|
return;
|
|
}
|
|
warship.setPatrolTile(this.position);
|
|
warship.setTargetTile(undefined);
|
|
}
|
|
|
|
tick(ticks: number): void {}
|
|
|
|
isActive(): boolean {
|
|
return false;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|