mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-04 20:46:08 +00:00
afd42d9b24
## 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" />  ## 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
224 lines
5.6 KiB
TypeScript
224 lines
5.6 KiB
TypeScript
import {
|
|
Execution,
|
|
Game,
|
|
MessageType,
|
|
Player,
|
|
PlayerID,
|
|
TerraNullius,
|
|
Unit,
|
|
UnitType,
|
|
} from "../game/Game";
|
|
import { TileRef } from "../game/GameMap";
|
|
import { targetTransportTile } from "../game/TransportShipUtils";
|
|
import { PathFindResultType } from "../pathfinding/AStar";
|
|
import { PathFinder } from "../pathfinding/PathFinding";
|
|
import { AttackExecution } from "./AttackExecution";
|
|
|
|
export class TransportShipExecution implements Execution {
|
|
private lastMove: number;
|
|
|
|
// TODO: make this configurable
|
|
private ticksPerMove = 1;
|
|
|
|
private active = true;
|
|
|
|
private mg: Game;
|
|
private target: Player | TerraNullius;
|
|
|
|
// TODO make private
|
|
public path: TileRef[];
|
|
private dst: TileRef | null;
|
|
|
|
private boat: Unit;
|
|
|
|
private pathFinder: PathFinder;
|
|
|
|
constructor(
|
|
private attacker: Player,
|
|
private targetID: PlayerID | null,
|
|
private ref: TileRef,
|
|
private troops: number,
|
|
private src: TileRef | null,
|
|
) {}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
|
|
init(mg: Game, ticks: number) {
|
|
if (this.targetID !== null && !mg.hasPlayer(this.targetID)) {
|
|
console.warn(`TransportShipExecution: target ${this.targetID} not found`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
this.lastMove = ticks;
|
|
this.mg = mg;
|
|
this.pathFinder = PathFinder.Mini(mg, 10_000, 10);
|
|
|
|
if (
|
|
this.attacker.units(UnitType.TransportShip).length >=
|
|
mg.config().boatMaxNumber()
|
|
) {
|
|
mg.displayMessage(
|
|
`No boats available, max ${mg.config().boatMaxNumber()}`,
|
|
MessageType.ATTACK_FAILED,
|
|
this.attacker.id(),
|
|
);
|
|
this.active = false;
|
|
this.attacker.addTroops(this.troops);
|
|
return;
|
|
}
|
|
|
|
if (
|
|
this.targetID === null ||
|
|
this.targetID === this.mg.terraNullius().id()
|
|
) {
|
|
this.target = mg.terraNullius();
|
|
} else {
|
|
this.target = mg.player(this.targetID);
|
|
}
|
|
|
|
if (this.troops === null) {
|
|
this.troops = this.mg
|
|
.config()
|
|
.boatAttackAmount(this.attacker, this.target);
|
|
}
|
|
|
|
this.troops = Math.min(this.troops, this.attacker.troops());
|
|
|
|
this.dst = targetTransportTile(this.mg, this.ref);
|
|
if (this.dst === null) {
|
|
console.warn(
|
|
`${this.attacker} cannot send ship to ${this.target}, cannot find attack tile`,
|
|
);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
const closestTileSrc = this.attacker.canBuild(
|
|
UnitType.TransportShip,
|
|
this.dst,
|
|
);
|
|
if (closestTileSrc === false) {
|
|
console.warn(`can't build transport ship`);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
if (this.src === null) {
|
|
// Only update the src if it's not already set
|
|
// because we assume that the src is set to the best spawn tile
|
|
this.src = closestTileSrc;
|
|
} else {
|
|
if (
|
|
this.mg.owner(this.src) !== this.attacker ||
|
|
!this.mg.isShore(this.src)
|
|
) {
|
|
console.warn(
|
|
`src is not a shore tile or not owned by: ${this.attacker.name()}`,
|
|
);
|
|
this.src = closestTileSrc;
|
|
}
|
|
}
|
|
|
|
this.boat = this.attacker.buildUnit(UnitType.TransportShip, this.src, {
|
|
troops: this.troops,
|
|
});
|
|
|
|
// Notify the target player about the incoming naval invasion
|
|
if (this.targetID && this.targetID !== mg.terraNullius().id()) {
|
|
mg.displayIncomingUnit(
|
|
this.boat.id(),
|
|
// TODO TranslateText
|
|
`Naval invasion incoming from ${this.attacker.displayName()}`,
|
|
MessageType.NAVAL_INVASION_INBOUND,
|
|
this.targetID,
|
|
);
|
|
}
|
|
|
|
// Record stats
|
|
this.mg.stats().boatSendTroops(this.attacker, this.target, this.troops);
|
|
}
|
|
|
|
tick(ticks: number) {
|
|
if (this.dst === null) {
|
|
this.active = false;
|
|
return;
|
|
}
|
|
if (!this.active) {
|
|
return;
|
|
}
|
|
if (!this.boat.isActive()) {
|
|
this.active = false;
|
|
return;
|
|
}
|
|
if (ticks - this.lastMove < this.ticksPerMove) {
|
|
return;
|
|
}
|
|
this.lastMove = ticks;
|
|
|
|
if (this.boat.retreating()) {
|
|
this.dst = this.src!; // src is guaranteed to be set at this point
|
|
}
|
|
|
|
const result = this.pathFinder.nextTile(this.boat.tile(), this.dst);
|
|
switch (result.type) {
|
|
case PathFindResultType.Completed:
|
|
if (this.mg.owner(this.dst) === this.attacker) {
|
|
this.attacker.addTroops(this.boat.troops());
|
|
this.boat.delete(false);
|
|
this.active = false;
|
|
|
|
// Record stats
|
|
this.mg
|
|
.stats()
|
|
.boatArriveTroops(this.attacker, this.target, this.troops);
|
|
return;
|
|
}
|
|
this.attacker.conquer(this.dst);
|
|
if (this.target.isPlayer() && this.attacker.isFriendly(this.target)) {
|
|
this.attacker.addTroops(this.troops);
|
|
} else {
|
|
this.mg.addExecution(
|
|
new AttackExecution(
|
|
this.troops,
|
|
this.attacker,
|
|
this.targetID,
|
|
this.dst,
|
|
false,
|
|
),
|
|
);
|
|
}
|
|
this.boat.delete(false);
|
|
this.active = false;
|
|
|
|
// Record stats
|
|
this.mg
|
|
.stats()
|
|
.boatArriveTroops(this.attacker, this.target, this.troops);
|
|
return;
|
|
case PathFindResultType.NextTile:
|
|
this.boat.move(result.tile);
|
|
break;
|
|
case PathFindResultType.Pending:
|
|
break;
|
|
case PathFindResultType.PathNotFound:
|
|
// TODO: add to poisoned port list
|
|
console.warn(`path not found to dst`);
|
|
this.attacker.addTroops(this.troops);
|
|
this.boat.delete(false);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
owner(): Player {
|
|
return this.attacker;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
}
|