mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:30:22 +00:00
Revoking alliances request during nuke (#2101)
Closes #2071 ## Description: - Created Functional Test for scenario - Added an alliance revoker function to 'NukeExection' ## Please complete the following: - [ ] I have added screenshots for all UI updates - [ ] 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: dpop
This commit is contained in:
committed by
GitHub
parent
2450ef29ca
commit
d16accafef
@@ -76,18 +76,26 @@ export class NukeExecution implements Execution {
|
||||
}
|
||||
|
||||
const threshold = this.mg.config().nukeAllianceBreakThreshold();
|
||||
for (const [other, tilesDestroyed] of attacked) {
|
||||
for (const [attackedPlayer, tilesDestroyed] of attacked) {
|
||||
if (
|
||||
tilesDestroyed > threshold &&
|
||||
this.nuke.type() !== UnitType.MIRVWarhead
|
||||
) {
|
||||
// Resolves exploit of alliance breaking in which a pending alliance request
|
||||
// was accepeted in the middle of an missle attack.
|
||||
const allianceRequest = attackedPlayer
|
||||
.incomingAllianceRequests()
|
||||
.find((ar) => ar.requestor() === this.player);
|
||||
if (allianceRequest) {
|
||||
allianceRequest?.reject();
|
||||
}
|
||||
// Mirv warheads shouldn't break alliances
|
||||
const alliance = this.player.allianceWith(other);
|
||||
const alliance = this.player.allianceWith(attackedPlayer);
|
||||
if (alliance !== null) {
|
||||
this.player.breakAlliance(alliance);
|
||||
}
|
||||
if (other !== this.player) {
|
||||
other.updateRelation(this.player, -100);
|
||||
if (attackedPlayer !== this.player) {
|
||||
attackedPlayer.updateRelation(this.player, -100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { AllianceRequestExecution } from "../src/core/execution/alliance/AllianceRequestExecution";
|
||||
import { AllianceRequestReplyExecution } from "../src/core/execution/alliance/AllianceRequestReplyExecution";
|
||||
import { Game, Player, PlayerType } from "../src/core/game/Game";
|
||||
import { NukeExecution } from "../src/core/execution/NukeExecution";
|
||||
import { Game, Player, PlayerType, UnitType } from "../src/core/game/Game";
|
||||
import { playerInfo, setup } from "./util/Setup";
|
||||
import { constructionExecution } from "./util/utils";
|
||||
|
||||
let game: Game;
|
||||
let player1: Player;
|
||||
@@ -74,4 +76,28 @@ describe("AllianceRequestExecution", () => {
|
||||
expect(player1.isAlliedWith(player2)).toBeFalsy();
|
||||
expect(player2.isAlliedWith(player1)).toBeFalsy();
|
||||
});
|
||||
|
||||
// Resolves exploit https://github.com/openfrontio/OpenFrontIO/issues/2071
|
||||
test("alliance request is revoked immediately if requester launches a nuke", () => {
|
||||
game.config().nukeAllianceBreakThreshold = () => 0;
|
||||
// Player 1 sends an alliance request to player 2.
|
||||
game.addExecution(new AllianceRequestExecution(player1, player2.id()));
|
||||
game.executeNextTick();
|
||||
|
||||
expect(player1.outgoingAllianceRequests().length).toBe(1);
|
||||
expect(player2.incomingAllianceRequests().length).toBe(1);
|
||||
|
||||
// Player 1 Builds a silo & launches a missle at player 2.
|
||||
constructionExecution(game, player1, 0, 0, UnitType.MissileSilo);
|
||||
game.addExecution(
|
||||
new NukeExecution(UnitType.AtomBomb, player1, game.ref(0, 1), null),
|
||||
);
|
||||
game.executeNextTick();
|
||||
game.executeNextTick();
|
||||
|
||||
expect(player1.outgoingAllianceRequests().length).toBe(0);
|
||||
expect(player2.incomingAllianceRequests().length).toBe(0);
|
||||
expect(player1.isAlliedWith(player2)).toBeFalsy();
|
||||
expect(player2.isAlliedWith(player1)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user