Files
OpenFrontIO/src/core/execution/alliance/AllianceRequestExecution.ts
T
falc 07916d46bf Changed consolex to console logging (#1036)
## Description:
Changed from consolex to console
## 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:

@qqkedsi
2025-06-05 16:14:27 +02:00

55 lines
1.4 KiB
TypeScript

import { Execution, Game, Player, PlayerID } from "../../game/Game";
export class AllianceRequestExecution implements Execution {
private active = true;
private requestor: Player | null = null;
private recipient: Player | null = null;
constructor(
private requestorID: PlayerID,
private recipientID: PlayerID,
) {}
init(mg: Game, ticks: number): void {
if (!mg.hasPlayer(this.requestorID)) {
console.warn(
`AllianceRequestExecution requester ${this.requestorID} not found`,
);
this.active = false;
return;
}
if (!mg.hasPlayer(this.recipientID)) {
console.warn(
`AllianceRequestExecution recipient ${this.recipientID} not found`,
);
this.active = false;
return;
}
this.requestor = mg.player(this.requestorID);
this.recipient = mg.player(this.recipientID);
}
tick(ticks: number): void {
if (this.requestor === null || this.recipient === null) {
throw new Error("Not initialized");
}
if (this.requestor.isFriendly(this.recipient)) {
console.warn("already allied");
} else if (!this.requestor.canSendAllianceRequest(this.recipient)) {
console.warn("recent or pending alliance request");
} else {
this.requestor.createAllianceRequest(this.recipient);
}
this.active = false;
}
isActive(): boolean {
return this.active;
}
activeDuringSpawnPhase(): boolean {
return false;
}
}