Files
OpenFrontIO/src/core/execution/SAMMissileExecution.ts
T
Max Lundgren afd42d9b24 Add filters tabs to EvensDisplay to let users filter events (#1080)
## Description:
Big update to the EventsDisplay

- Style update for EventsDisplay, look & feel similar to other windows
- Component now hidden during spawn phase
- Adds new functionality for filtering events by category. Allows the
player to remove specific event types
- Displays latest gold amount, decays after 5 seconds

<img width="1147" alt="Screenshot 2025-06-07 at 20 18 55"
src="https://github.com/user-attachments/assets/11c39818-55ad-4ba1-a998-360057e2856c"
/>

<img width="422" alt="Screenshot 2025-06-07 at 19 01 55"
src="https://github.com/user-attachments/assets/09c0b998-6046-49fb-9fba-33b4f57f337b"
/>

<img width="444" alt="Screenshot 2025-06-07 at 20 20 25"
src="https://github.com/user-attachments/assets/022deadc-3a49-442a-85f5-f1cd128a5805"
/>

![Screen Shot 2025-06-07 at 20 32
07](https://github.com/user-attachments/assets/d8575ea0-109d-4841-b661-b233201a304a)



## 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:

maxion_


Fixes #1025 
Fixes #1034
2025-06-10 16:10:49 -07:00

94 lines
2.3 KiB
TypeScript

import {
Execution,
Game,
MessageType,
Player,
Unit,
UnitType,
} from "../game/Game";
import { TileRef } from "../game/GameMap";
import { AirPathFinder } from "../pathfinding/PathFinding";
import { PseudoRandom } from "../PseudoRandom";
import { NukeType } from "../StatsSchemas";
export class SAMMissileExecution implements Execution {
private active = true;
private pathFinder: AirPathFinder;
private SAMMissile: Unit | undefined;
private mg: Game;
constructor(
private spawn: TileRef,
private _owner: Player,
private ownerUnit: Unit,
private target: Unit,
private speed: number = 12,
) {}
init(mg: Game, ticks: number): void {
this.pathFinder = new AirPathFinder(mg, new PseudoRandom(mg.ticks()));
this.mg = mg;
}
tick(ticks: number): void {
if (this.SAMMissile === undefined) {
this.SAMMissile = this._owner.buildUnit(
UnitType.SAMMissile,
this.spawn,
{},
);
}
if (!this.SAMMissile.isActive()) {
this.active = false;
return;
}
// Mirv warheads are too fast, and mirv shouldn't be stopped ever
const nukesWhitelist = [UnitType.AtomBomb, UnitType.HydrogenBomb];
if (
!this.target.isActive() ||
!this.ownerUnit.isActive() ||
this.target.owner() === this.SAMMissile.owner() ||
!nukesWhitelist.includes(this.target.type())
) {
this.SAMMissile.delete(false);
this.active = false;
return;
}
for (let i = 0; i < this.speed; i++) {
const result = this.pathFinder.nextTile(
this.SAMMissile.tile(),
this.target.tile(),
);
if (result === true) {
this.mg.displayMessage(
`Missile intercepted ${this.target.type()}`,
MessageType.SAM_HIT,
this._owner.id(),
);
this.active = false;
this.target.delete(true, this._owner);
this.SAMMissile.delete(false);
// Record stats
this.mg
.stats()
.bombIntercept(
this._owner,
this.target.owner(),
this.target.type() as NukeType,
);
return;
} else {
this.SAMMissile.move(result);
}
}
}
isActive(): boolean {
return this.active;
}
activeDuringSpawnPhase(): boolean {
return false;
}
}