mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-30 09:42:13 +00:00
f362e47413
Resolves #3154 ## Description: #2716 introduced nuke cancellation logic on alliance acceptance via `AllianceRequestReplyExecution`. The radial menu action, though, calls `AllianceRequestExecution` instead, which accepts the alliance if a request has already been made by the other player. This PR moves the nuke cancellation logic to `GameImpl`, hooking into the `acceptAllianceRequest` method, therefore accounting for every alliance acceptance, regardless of the specific action that brought to that. ## 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: deshack_82603
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { Execution, Game, Player, PlayerID } from "../../game/Game";
|
|
|
|
export class AllianceRejectExecution implements Execution {
|
|
private active = true;
|
|
|
|
constructor(
|
|
private requestorID: PlayerID,
|
|
private recipient: Player,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
if (!mg.hasPlayer(this.requestorID)) {
|
|
console.warn(
|
|
`[AllianceRejectExecution] Requestor ${this.requestorID} not found`,
|
|
);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
const requestor = mg.player(this.requestorID);
|
|
|
|
if (requestor.isFriendly(this.recipient)) {
|
|
console.warn(
|
|
`[AllianceRejectExecution] Player ${this.requestorID} cannot reject alliance with ${this.recipient.id}, already allied`,
|
|
);
|
|
} else {
|
|
const request = requestor
|
|
.outgoingAllianceRequests()
|
|
.find((ar) => ar.recipient() === this.recipient);
|
|
if (request === undefined) {
|
|
console.warn(
|
|
`[AllianceRejectExecution] Player ${this.requestorID} cannot reject alliance with ${this.recipient.id}, no alliance request found`,
|
|
);
|
|
} else {
|
|
request.reject();
|
|
}
|
|
}
|
|
this.active = false;
|
|
}
|
|
|
|
tick(ticks: number): void {}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|