-
Notifications
You must be signed in to change notification settings - Fork 823
Fix/refactor: centralized removals on death + remove alliances too #3168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ces + remove renew request for those alliances
WalkthroughCentralized death cleanup was added via a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
…ecause the latter can be used for non-removed alliances too (for example PR 3148 will use removeAllianceRenewalEvents after renewal acceptance was done from the radial menu)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/client/graphics/layers/EventsDisplay.ts`:
- Line 645: The handler for alliance expiration currently returns early only
when other is missing or myPlayer is dead; add the missing alive-check for the
other player to avoid showing "alliance expired" for players who died in the
same tick — i.e., update the condition in EventsDisplay (the
AllianceExpired/removeOnDeath handler) from "if (!other || !myPlayer.isAlive())
return;" to also check other.isAlive() so it reads effectively as "if (!other ||
!myPlayer.isAlive() || !other.isAlive()) return;". Ensure the change is applied
where the AllianceExpired/PlayerExecution expiry handling logic references other
and myPlayer.
🧹 Nitpick comments (1)
src/core/game/GameImpl.ts (1)
1166-1175: Replace repeated nuke type checks with thenukeTypesconstant.The same four nuke types are already defined as
nukeTypesinGame.ts(line 343-348) and are exported. Hardcoding them here creates duplicate logic that must be maintained in multiple places—if a new nuke type is added, you'll need to update both locations.Import
nukeTypesfromGame.tsand use it instead:Suggested change
import { Alliance, AllianceRequest, Cell, ColoredTeams, Duos, EmojiMessage, Execution, Game, GameMode, GameUpdates, HumansVsNations, MessageType, MutableAlliance, Nation, Player, PlayerID, PlayerInfo, PlayerType, Quads, Team, TerrainType, TerraNullius, Trios, Unit, UnitInfo, UnitType, + nukeTypes, } from "./Game";deadPlayer.units().forEach((u) => { - if ( - u.type() !== UnitType.AtomBomb && - u.type() !== UnitType.HydrogenBomb && - u.type() !== UnitType.MIRVWarhead && - u.type() !== UnitType.MIRV - ) { + if (!nukeTypes.includes(u.type())) { u.delete(); } });
…spawn tile, and check if they're both still alive after the attack and counter-attack (so the alliance won't be removed because of death of one of them)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/Attack.test.ts (1)
296-303:⚠️ Potential issue | 🟡 MinorplayerC should use unique name and ID, not duplicate playerB's.
In
addPlayer()(GameImpl.ts:1442-1454), players are stored in a Map keyed byplayerInfo.id. When playerC is created with ID"playerB_id", it overwrites the playerB entry in that Map. The test currently works only because it holds direct object references to playerB, but any future code callinggame.player("playerB_id")would incorrectly retrieve playerC instead of playerB.Proposed fix
const playerCInfo = new PlayerInfo( - "playerB", + "playerC", PlayerType.Human, null, - "playerB_id", + "playerC_id", );
Description:
Centralize cleanup on death: Do the same for Bots as was already done for Nations and human Players on death, that is deleting remaining non-nuke units and gold. (by the way, seen from NationExecution it wasn't all too clear that a PlayerExecution is also running for Nations and when that becomes inActive it is what deletes eg. Nation warships on death. Added comment in NationExecution clarifying that it happens from PlayerExecution, if that's ok). Bots can conquer units even when they can't build them. There may also be edge cases in which Bots have gold left at death. So it seems better to run the same centralized cleanup for them too.
Remove alliances on death too from the centralized function: after death, alliances would stay active including countdown timers and (when dead player kept spectating) icons. Now remove alliances from the central function.
Remove renewal request from Events Display when Alliance doesn't exist anymore (after death or otherwise).
Also cleanup this.alliancesCheckedAt when alliance doesn't exist anymore. Before, old/broken alliance id's would accumulate in it during a game.
Removed now-redundant isAlive check in EventsDisplay. Both the alliances array as the isAlive are updated in the same tick from PlayerUpdates so now alliance is removed from alliances array on player death, the other.isAlive() check is no longer needed. Of course we could keep it in just to be very safe, so just let me know when you're doubtful about this.
Attack.test.ts: fix failing test. Player B dies because of the attack, meaning the alliance now gets removed. Prevent this by gving both a different, adjecent, starting tile. And to be more clear about what is needed for the test to pass, add isAlive check for both of them after the attacks.
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
tryout33