mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 17:53:29 +00:00
Auto-reject alliance request when transport ship is sent to target player (#3477)
## Description: When a player sends a transport ship toward another player's territory, any pending alliance request from the target is now automatically rejected. This mirrors the behavior already in place for direct attacks, preventing a player from exploiting a pending alliance request while launching a naval invasion. ## 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
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
|||||||
Game,
|
Game,
|
||||||
MessageType,
|
MessageType,
|
||||||
Player,
|
Player,
|
||||||
|
PlayerType,
|
||||||
TerraNullius,
|
TerraNullius,
|
||||||
Unit,
|
Unit,
|
||||||
UnitType,
|
UnitType,
|
||||||
@@ -76,6 +77,16 @@ export class TransportShipExecution implements Execution {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.target.isPlayer()) {
|
||||||
|
const targetPlayer = this.target as Player;
|
||||||
|
if (
|
||||||
|
targetPlayer.type() !== PlayerType.Bot &&
|
||||||
|
this.attacker.type() !== PlayerType.Bot
|
||||||
|
) {
|
||||||
|
this.rejectIncomingAllianceRequests(targetPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.target.isPlayer() && !this.attacker.canAttackPlayer(this.target)) {
|
if (this.target.isPlayer() && !this.attacker.canAttackPlayer(this.target)) {
|
||||||
this.active = false;
|
this.active = false;
|
||||||
return;
|
return;
|
||||||
@@ -290,4 +301,13 @@ export class TransportShipExecution implements Execution {
|
|||||||
isActive(): boolean {
|
isActive(): boolean {
|
||||||
return this.active;
|
return this.active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private rejectIncomingAllianceRequests(target: Player) {
|
||||||
|
const request = this.attacker
|
||||||
|
.incomingAllianceRequests()
|
||||||
|
.find((ar) => ar.requestor() === target);
|
||||||
|
if (request !== undefined) {
|
||||||
|
request.reject();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -333,6 +333,54 @@ describe("Attack race condition with alliance requests", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Transport ship alliance rejection", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
game = await setup("ocean_and_land", {
|
||||||
|
infiniteGold: true,
|
||||||
|
instantBuild: true,
|
||||||
|
infiniteTroops: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const playerAInfo = new PlayerInfo(
|
||||||
|
"playerA",
|
||||||
|
PlayerType.Human,
|
||||||
|
null,
|
||||||
|
"playerA_id",
|
||||||
|
);
|
||||||
|
// close to the water to send boats
|
||||||
|
playerA = addPlayerToGame(playerAInfo, game, game.ref(7, 0));
|
||||||
|
|
||||||
|
const playerBInfo = new PlayerInfo(
|
||||||
|
"playerB",
|
||||||
|
PlayerType.Human,
|
||||||
|
null,
|
||||||
|
"playerB_id",
|
||||||
|
);
|
||||||
|
playerB = addPlayerToGame(playerBInfo, game, game.ref(7, 15));
|
||||||
|
|
||||||
|
while (game.inSpawnPhase()) {
|
||||||
|
game.executeNextTick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Should cancel alliance requests if the recipient sends a transport ship", async () => {
|
||||||
|
// Player A sends alliance request to Player B
|
||||||
|
const allianceRequest = playerA.createAllianceRequest(playerB);
|
||||||
|
expect(allianceRequest).not.toBeNull();
|
||||||
|
expect(playerB.incomingAllianceRequests()).toHaveLength(1);
|
||||||
|
|
||||||
|
// Player B sends a transport ship toward Player A's territory
|
||||||
|
game.addExecution(new TransportShipExecution(playerB, game.ref(7, 0), 0));
|
||||||
|
|
||||||
|
// Execute a tick to process the transport ship launch
|
||||||
|
game.executeNextTick();
|
||||||
|
|
||||||
|
// Alliance request should be rejected since player B sent a naval invasion
|
||||||
|
expect(playerA.outgoingAllianceRequests()).toHaveLength(0);
|
||||||
|
expect(playerB.incomingAllianceRequests()).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("Attack immunity", () => {
|
describe("Attack immunity", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
game = await setup("ocean_and_land", {
|
game = await setup("ocean_and_land", {
|
||||||
|
|||||||
Reference in New Issue
Block a user