mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 15:30:43 +00:00
Fix nations being blocked by PVP immunity 🛡️ (#4282)
## Description: ### Problem PVP immunity (the extended spawn immunity setting) was incorrectly preventing AI nations from attacking human players. The intent of PVP immunity is to protect human-vs-human combat only, but nations were subject to the same restriction. ### Root Cause In `canAttackPlayer()`, only `PlayerType.Bot` was exempt from checking target immunity. Nations fell through to the same path as humans, so when a nation tried to attack an immune human, `player.isImmune()` returned true and the attack was blocked. ### Fix Changed the immunity bypass condition from `this.type() === PlayerType.Bot` to `this.type() !== PlayerType.Human`. Now only human attackers check target immunity. Both bots and nations bypass it (they only check alliance status). This does not affect nation spawn immunity (`nationSpawnImmunityDuration`), which is a separate mechanism that protects newly spawned nations from all attackers and continues to work independently. ## 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 ## Please put your Discord username so you can be contacted if a bug or regression is found: FloPinguin
This commit is contained in:
@@ -1608,11 +1608,10 @@ export class PlayerImpl implements Player {
|
||||
player: Player,
|
||||
treatAFKFriendly: boolean = false,
|
||||
): boolean {
|
||||
if (this.type() === PlayerType.Bot) {
|
||||
// Bots are not affected by immunity
|
||||
if (this.type() !== PlayerType.Human) {
|
||||
// Only human attackers respect PVP immunity
|
||||
return !this.isFriendly(player, treatAFKFriendly);
|
||||
}
|
||||
// Humans and Nations respect immunity
|
||||
return !player.isImmune() && !this.isFriendly(player, treatAFKFriendly);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user