Fix nations being blocked by PVP immunity 🛡️#4282
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughIn ChangesPVP immunity guard fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed due to a network error. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/core/game/PlayerImpl.ts (1)
1607-1616:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd core tests for the new immunity gate behavior.
This
src/core/behavior changed, but no accompanying test change is present in the provided diff. Please add/attach tests covering: (1) Human attacker blocked by immune human target, and (2) Nation/Bot attacker bypassing target PVP immunity while still respecting friendliness.
As per coding guidelines, "All changes tosrc/core/must include tests".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/core/game/PlayerImpl.ts` around lines 1607 - 1616, The canAttackPlayer method behavior in PlayerImpl was modified to add new immunity gate logic, but the diff lacks accompanying test coverage. Add tests for the canAttackPlayer method that verify both scenarios: (1) a Human type attacker cannot attack an immune Human target (blocked by immunity check), and (2) a Nation or Bot type attacker can bypass the target's PVP immunity check but still respects friendliness rules. These tests are required per the coding guideline that all changes to src/core/ must include tests.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/core/game/PlayerImpl.ts`:
- Around line 1607-1616: The canAttackPlayer method behavior in PlayerImpl was
modified to add new immunity gate logic, but the diff lacks accompanying test
coverage. Add tests for the canAttackPlayer method that verify both scenarios:
(1) a Human type attacker cannot attack an immune Human target (blocked by
immunity check), and (2) a Nation or Bot type attacker can bypass the target's
PVP immunity check but still respects friendliness rules. These tests are
required per the coding guideline that all changes to src/core/ must include
tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0f51d5ee-8402-4c32-9813-917ef0e4146a
📒 Files selected for processing (1)
src/core/game/PlayerImpl.ts
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(), onlyPlayerType.Botwas 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.Bottothis.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:
Please put your Discord username so you can be contacted if a bug or regression is found:
FloPinguin