mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 11:23:25 +00:00
742a544a69
Part of [#2661](https://github.com/openfrontio/OpenFrontIO/issues/2661) (split into 3 PRs so they are not too large..) ## Description: Part 3/3 of [#2661](https://github.com/openfrontio/OpenFrontIO/issues/2661). This PR adds the retreat control and override behavior for warships: - Manual override: moving a warship manually cancels retreat and suppresses auto-retreat for 5 seconds - Aggro override: a retreating warship will aggro a nearby enemy transport or warship before continuing retreat - Heal-at-port command for sending a warship to a friendly port manually - Friendly-port validation for HealAtPortExecution - Regression tests for manual override, aggro override, and heal-at-port behavior ## 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 ## Please put your Discord username so you can be contacted if a bug or regression is found: zixer._ --------- Co-authored-by: iamlewis <lewismmmm@gmail.com> Co-authored-by: evanpelle <evanpelle@gmail.com>
94 lines
2.1 KiB
TypeScript
94 lines
2.1 KiB
TypeScript
import { Execution, Game, MessageType, Player, Unit } from "../game/Game";
|
|
|
|
export class DeleteUnitExecution implements Execution {
|
|
private active: boolean = true;
|
|
private mg: Game;
|
|
private unit: Unit | null = null;
|
|
|
|
constructor(
|
|
private player: Player,
|
|
private unitId: number,
|
|
) {}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
|
|
init(mg: Game, ticks: number) {
|
|
if (!this.active) {
|
|
return;
|
|
}
|
|
this.mg = mg;
|
|
|
|
const unit = this.mg.unit(this.unitId);
|
|
if (!unit || unit.owner() !== this.player) {
|
|
console.warn(
|
|
`SECURITY: unit ${this.unitId} not found or not owned by player ${this.player.displayName()}`,
|
|
);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
if (!unit.isActive()) {
|
|
console.warn(`SECURITY: unit ${this.unitId} is not active`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
this.unit = unit;
|
|
|
|
const tileOwner = mg.owner(unit.tile());
|
|
if (!tileOwner.isPlayer() || tileOwner.id() !== this.player.id()) {
|
|
console.warn(
|
|
`SECURITY: unit ${this.unitId} is not on player's territory`,
|
|
);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
if (!mg.isLand(unit.tile())) {
|
|
console.warn(`SECURITY: unit ${this.unitId} is not on land`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
if (mg.inSpawnPhase()) {
|
|
console.warn(`SECURITY: cannot delete units during spawn phase`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
if (!this.player.canDeleteUnit()) {
|
|
console.warn(`SECURITY: delete unit cooldown not expired`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
this.player.recordDeleteUnit();
|
|
unit.markForDeletion();
|
|
}
|
|
|
|
tick(ticks: number) {
|
|
if (!this.active || !this.unit) {
|
|
return;
|
|
}
|
|
if (!this.unit.isActive()) {
|
|
this.active = false;
|
|
return;
|
|
}
|
|
if (this.unit.isOverdueDeletion()) {
|
|
this.unit.delete(false);
|
|
|
|
this.mg.displayMessage(
|
|
`events_display.unit_voluntarily_deleted`,
|
|
MessageType.UNIT_DESTROYED,
|
|
this.player.id(),
|
|
);
|
|
this.active = false;
|
|
}
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
}
|