mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 09:18:11 +00:00
e8834e15e6
## Description: https://github.com/user-attachments/assets/b46f949a-eb50-4656-8492-216cf820ac46 Add a couple animations for naval combat: - shell hit - ship explosion - ship sinking Added a simple `Timeline` class to spread FX animations over time. Added a `ColoredAnimatedSprite` similar to the existing `ColoredSprite`. Refactored the latter to avoid code duplication. ## Please complete the following: - [x] I have added screenshots for all UI updates - [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: IngloriousTom
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import { Execution, Game, Player, Unit, UnitType } from "../game/Game";
|
|
import { TileRef } from "../game/GameMap";
|
|
import { AirPathFinder } from "../pathfinding/PathFinding";
|
|
import { PseudoRandom } from "../PseudoRandom";
|
|
|
|
export class ShellExecution implements Execution {
|
|
private active = true;
|
|
private pathFinder: AirPathFinder;
|
|
private shell: Unit | undefined;
|
|
private mg: Game;
|
|
private destroyAtTick: number = -1;
|
|
|
|
constructor(
|
|
private spawn: TileRef,
|
|
private _owner: Player,
|
|
private ownerUnit: Unit,
|
|
private target: Unit,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
this.pathFinder = new AirPathFinder(mg, new PseudoRandom(mg.ticks()));
|
|
this.mg = mg;
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (this.shell === undefined) {
|
|
this.shell = this._owner.buildUnit(UnitType.Shell, this.spawn, {});
|
|
}
|
|
if (!this.shell.isActive()) {
|
|
this.active = false;
|
|
return;
|
|
}
|
|
if (
|
|
!this.target.isActive() ||
|
|
this.target.owner() === this.shell.owner() ||
|
|
(this.destroyAtTick !== -1 && this.mg.ticks() >= this.destroyAtTick)
|
|
) {
|
|
this.shell.delete(false);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
if (this.destroyAtTick === -1 && !this.ownerUnit.isActive()) {
|
|
this.destroyAtTick = this.mg.ticks() + this.mg.config().shellLifetime();
|
|
}
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
const result = this.pathFinder.nextTile(
|
|
this.shell.tile(),
|
|
this.target.tile(),
|
|
);
|
|
if (result === true) {
|
|
this.active = false;
|
|
this.target.modifyHealth(-this.effectOnTarget(), this._owner);
|
|
this.shell.setReachedTarget();
|
|
this.shell.delete(false);
|
|
return;
|
|
} else {
|
|
this.shell.move(result);
|
|
}
|
|
}
|
|
}
|
|
|
|
private effectOnTarget(): number {
|
|
const { damage } = this.mg.config().unitInfo(UnitType.Shell);
|
|
return damage ?? 0;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|