Repository navigation
allow alliance extension Fixes #491 - #1314
Conversation
WalkthroughThis update introduces alliance expiration and renewal features to the game. Alliances now have unique IDs, expiration times, and can be extended if both players agree. New intent types and execution logic support alliance extension requests. The client displays proactive warnings for expiring alliances and allows players to request renewals. Changes
Sequence Diagram(s)sequenceDiagram
participant PlayerA
participant PlayerB
participant Client
participant Server
participant Game
PlayerA->>Client: Receives warning about expiring alliance
Client->>PlayerA: Shows "Renew Alliance?" prompt
PlayerA->>Client: Clicks "Request Renewal"
Client->>Server: Sends AllianceExtensionIntent (with PlayerB)
Server->>Game: Processes intent
Game->>Game: Checks if both players requested extension
alt Both players requested
Game->>Game: Extends alliance expiration
Game->>PlayerA: Sends renewal confirmation
Game->>PlayerB: Sends renewal confirmation
else Only one player requested
Game->>Game: Waits for other player's request
end
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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
npm error Exit handler never called! 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout of 90000ms (2)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/core/execution/alliance/AllianceExtensionExecution.ts (1)
31-47: Consider message type and logging approach.The extension logic is correct, but consider these improvements:
MessageType.ALLIANCE_ACCEPTEDmight not be semantically correct for alliance renewals - consider a more specific message type likeALLIANCE_RENEWED.- Console logging should use the game's logging system for consistency.
src/client/graphics/layers/EventsDisplay.ts (1)
54-54: Consider removing the unused tags field.The
tags?field is added to the GameEvent interface but doesn't appear to be used anywhere in the codebase.- tags?: string[];
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (19)
src/client/Transport.ts(3 hunks)src/client/Utils.ts(1 hunks)src/client/graphics/layers/EventsDisplay.ts(6 hunks)src/client/graphics/layers/PlayerPanel.ts(1 hunks)src/core/GameRunner.ts(1 hunks)src/core/Schemas.ts(4 hunks)src/core/configuration/Config.ts(1 hunks)src/core/configuration/DefaultConfig.ts(1 hunks)src/core/configuration/DevConfig.ts(1 hunks)src/core/execution/ExecutionManager.ts(2 hunks)src/core/execution/PlayerExecution.ts(1 hunks)src/core/execution/alliance/AllianceExtensionExecution.ts(1 hunks)src/core/game/AllianceImpl.ts(2 hunks)src/core/game/Game.ts(6 hunks)src/core/game/GameImpl.ts(4 hunks)src/core/game/GameUpdates.ts(4 hunks)src/core/game/GameView.ts(2 hunks)src/core/game/PlayerImpl.ts(4 hunks)tests/AllianceExtensionExecution.test.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (13)
📓 Common learnings
Learnt from: andrewNiziolek
PR: openfrontio/OpenFrontIO#1007
File: resources/lang/de.json:115-115
Timestamp: 2025-06-02T14:27:37.609Z
Learning: For OpenFrontIO project: When localization keys are renamed in language JSON files, the maintainers separate technical changes from translation content updates. They wait for community translators to update the actual translation values rather than attempting to translate in the same PR. This allows technical changes to proceed while ensuring accurate translations from native speakers.
src/core/GameRunner.ts (1)
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#1063
File: src/core/configuration/PastelThemeDark.ts:53-53
Timestamp: 2025-06-10T09:56:44.473Z
Learning: In ColorAllocator class in src/core/configuration/Colors.ts, the correct method names are assignColor(id: string): Colord for general color assignment and assignTeamColor(team: Team): Colord for team-specific colors. There are no assignPlayerColor() or assignBotColor() methods.
src/client/graphics/layers/PlayerPanel.ts (3)
Learnt from: 1brucben
PR: openfrontio/OpenFrontIO#977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#1063
File: src/core/configuration/PastelThemeDark.ts:53-53
Timestamp: 2025-06-10T09:56:44.473Z
Learning: In ColorAllocator class in src/core/configuration/Colors.ts, the correct method names are assignColor(id: string): Colord for general color assignment and assignTeamColor(team: Team): Colord for team-specific colors. There are no assignPlayerColor() or assignBotColor() methods.
Learnt from: VariableVince
PR: openfrontio/OpenFrontIO#1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
src/core/game/GameView.ts (3)
Learnt from: its-sii
PR: openfrontio/OpenFrontIO#1168
File: src/core/execution/WinCheckExecution.ts:157-176
Timestamp: 2025-06-13T20:53:16.380Z
Learning: In the alliance system, coalitions for peace voting are formed by taking each player with allies and creating a group of [player, ...player.allies()]. This means players can be in the same coalition even if they're not all directly allied with each other, as long as they share a common ally. For example, if A.allies()=[B], B.allies()=[A,C], and C.allies()=[B], then B, A, and C should be considered one coalition for voting purposes.
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#1000
File: src/core/configuration/Config.ts:83-83
Timestamp: 2025-06-02T01:42:57.407Z
Learning: PlayerView implements the Player interface, so methods accepting Player parameters can also accept PlayerView arguments without issue.
Learnt from: VariableVince
PR: openfrontio/OpenFrontIO#1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
src/core/configuration/DevConfig.ts (1)
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#1063
File: src/core/configuration/PastelThemeDark.ts:53-53
Timestamp: 2025-06-10T09:56:44.473Z
Learning: In ColorAllocator class in src/core/configuration/Colors.ts, the correct method names are assignColor(id: string): Colord for general color assignment and assignTeamColor(team: Team): Colord for team-specific colors. There are no assignPlayerColor() or assignBotColor() methods.
src/core/execution/PlayerExecution.ts (1)
Learnt from: its-sii
PR: openfrontio/OpenFrontIO#1168
File: src/core/execution/WinCheckExecution.ts:157-176
Timestamp: 2025-06-13T20:53:16.380Z
Learning: In the alliance system, coalitions for peace voting are formed by taking each player with allies and creating a group of [player, ...player.allies()]. This means players can be in the same coalition even if they're not all directly allied with each other, as long as they share a common ally. For example, if A.allies()=[B], B.allies()=[A,C], and C.allies()=[B], then B, A, and C should be considered one coalition for voting purposes.
src/core/execution/ExecutionManager.ts (1)
Learnt from: Egraveline
PR: openfrontio/OpenFrontIO#1012
File: src/core/execution/UpgradeStructureExecution.ts:49-54
Timestamp: 2025-06-05T02:34:45.899Z
Learning: In the upgrade system, gold deduction for structure upgrades is handled internally by the `upgradeUnit` method in PlayerImpl, not in the UpgradeStructureExecution class. The UpgradeStructureExecution only needs to check if the player has sufficient gold before calling `upgradeUnit`.
src/core/Schemas.ts (4)
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:44-53
Timestamp: 2025-05-21T04:10:59.706Z
Learning: In Zod, when a schema has `.optional()` applied at the object level, the TypeScript type inferred using `z.infer` already includes `undefined` in the union type. Therefore, when using such a type as a return type annotation, there's no need to explicitly add `| undefined`.
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:189-209
Timestamp: 2025-05-18T23:43:38.150Z
Learning: When working with zod schemas in the OpenFrontIO project, values can be marked as possibly undefined by zod even if logic suggests they should always be defined. It's better to preserve the `| undefined` union types in method signatures to align with zod's type inference, even if runtime checks throw errors for invalid cases.
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:44-53
Timestamp: 2025-05-21T04:10:59.706Z
Learning: The PlayerStats type from ArchiveSchemas already includes undefined in its definition, making explicit union types with undefined (PlayerStats | undefined) redundant.
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:34-38
Timestamp: 2025-05-21T04:10:33.435Z
Learning: In the codebase, PlayerStats is defined as `z.infer<typeof PlayerStatsSchema>` where PlayerStatsSchema has `.optional()` applied at the object level, making PlayerStats a union type that already includes undefined (PlayerStats | undefined).
src/core/game/GameImpl.ts (4)
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#1063
File: src/core/configuration/PastelThemeDark.ts:53-53
Timestamp: 2025-06-10T09:56:44.473Z
Learning: In ColorAllocator class in src/core/configuration/Colors.ts, the correct method names are assignColor(id: string): Colord for general color assignment and assignTeamColor(team: Team): Colord for team-specific colors. There are no assignPlayerColor() or assignBotColor() methods.
Learnt from: 1brucben
PR: openfrontio/OpenFrontIO#977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.
Learnt from: its-sii
PR: openfrontio/OpenFrontIO#1168
File: src/core/execution/WinCheckExecution.ts:157-176
Timestamp: 2025-06-13T20:53:16.380Z
Learning: In the alliance system, coalitions for peace voting are formed by taking each player with allies and creating a group of [player, ...player.allies()]. This means players can be in the same coalition even if they're not all directly allied with each other, as long as they share a common ally. For example, if A.allies()=[B], B.allies()=[A,C], and C.allies()=[B], then B, A, and C should be considered one coalition for voting purposes.
Learnt from: devalnor
PR: openfrontio/OpenFrontIO#1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.
src/core/game/GameUpdates.ts (1)
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:44-53
Timestamp: 2025-05-21T04:10:59.706Z
Learning: The PlayerStats type from ArchiveSchemas already includes undefined in its definition, making explicit union types with undefined (PlayerStats | undefined) redundant.
src/core/game/PlayerImpl.ts (2)
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:44-53
Timestamp: 2025-05-21T04:10:59.706Z
Learning: The PlayerStats type from ArchiveSchemas already includes undefined in its definition, making explicit union types with undefined (PlayerStats | undefined) redundant.
Learnt from: its-sii
PR: openfrontio/OpenFrontIO#1168
File: src/core/execution/WinCheckExecution.ts:157-176
Timestamp: 2025-06-13T20:53:16.380Z
Learning: In the alliance system, coalitions for peace voting are formed by taking each player with allies and creating a group of [player, ...player.allies()]. This means players can be in the same coalition even if they're not all directly allied with each other, as long as they share a common ally. For example, if A.allies()=[B], B.allies()=[A,C], and C.allies()=[B], then B, A, and C should be considered one coalition for voting purposes.
src/client/graphics/layers/EventsDisplay.ts (1)
Learnt from: VariableVince
PR: openfrontio/OpenFrontIO#1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
src/core/game/Game.ts (3)
Learnt from: its-sii
PR: openfrontio/OpenFrontIO#1168
File: src/core/execution/WinCheckExecution.ts:157-176
Timestamp: 2025-06-13T20:53:16.380Z
Learning: In the alliance system, coalitions for peace voting are formed by taking each player with allies and creating a group of [player, ...player.allies()]. This means players can be in the same coalition even if they're not all directly allied with each other, as long as they share a common ally. For example, if A.allies()=[B], B.allies()=[A,C], and C.allies()=[B], then B, A, and C should be considered one coalition for voting purposes.
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#1063
File: src/core/configuration/PastelThemeDark.ts:53-53
Timestamp: 2025-06-10T09:56:44.473Z
Learning: In ColorAllocator class in src/core/configuration/Colors.ts, the correct method names are assignColor(id: string): Colord for general color assignment and assignTeamColor(team: Team): Colord for team-specific colors. There are no assignPlayerColor() or assignBotColor() methods.
Learnt from: devalnor
PR: openfrontio/OpenFrontIO#1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.
🧬 Code Graph Analysis (6)
src/client/graphics/layers/PlayerPanel.ts (1)
src/core/game/AllianceImpl.ts (1)
expiresAt(66-68)
src/core/game/GameView.ts (1)
src/core/game/GameUpdates.ts (1)
AllianceView(165-170)
src/core/game/GameUpdates.ts (1)
src/core/game/Game.ts (2)
PlayerID(14-14)Tick(15-15)
src/core/game/PlayerImpl.ts (2)
src/core/game/Game.ts (1)
Alliance(337-343)src/core/game/GameUpdates.ts (1)
AllianceView(165-170)
src/client/graphics/layers/EventsDisplay.ts (5)
src/core/game/GameView.ts (2)
myPlayer(474-479)PlayerView(145-328)src/core/game/AllianceImpl.ts (1)
other(19-24)src/client/Utils.ts (1)
translateText(79-98)src/client/graphics/layers/Leaderboard.ts (1)
GoToPlayerEvent(20-22)src/client/Transport.ts (1)
SendAllianceExtensionIntentEvent(70-72)
src/core/game/AllianceImpl.ts (3)
src/core/game/Game.ts (3)
Tick(15-15)Game(598-672)Player(466-596)src/core/Schemas.ts (1)
Player(109-109)src/core/game/GameImpl.ts (1)
player(429-435)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: 🏗️ Build
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Deploy to openfront.dev
🔇 Additional comments (50)
src/core/configuration/DefaultConfig.ts (1)
841-843: LGTM! Clean implementation of alliance extension prompt timing.The method correctly implements the interface requirement and the 30-second offset before expiration is a reasonable default for user experience.
src/core/game/GameView.ts (2)
27-27: LGTM! Proper import for alliance view functionality.The import follows the established pattern and is necessary for the new alliance access method.
295-297: LGTM! Clean accessor method following established patterns.The
alliances()method follows the same pattern as other accessor methods in this class (allies(),targets(), etc.) and provides necessary access to alliance data for the extension feature.src/core/configuration/Config.ts (1)
161-161: LGTM! Well-named interface method for alliance extension timing.The method signature is clear and follows established naming conventions in the Config interface.
src/client/Utils.ts (1)
144-144: LGTM! Appropriate warning message styling for alliance notifications.The
MessageType.WARNcase is properly grouped with other warning-type messages and uses the appropriate yellow warning color.src/core/execution/ExecutionManager.ts (2)
5-5: LGTM! Import follows established patterns.The import is correctly placed with other alliance execution imports.
115-118: LGTM! Intent handling follows consistent patterns.The new alliance extension case correctly follows the same pattern as other alliance intents, taking the player and recipient parameters.
src/core/execution/PlayerExecution.ts (1)
75-75: Good improvement! Simplified alliance expiration logic.Using precomputed expiration timestamps is cleaner and more efficient than calculating elapsed time on each tick. The logic correctly expires alliances when current ticks reach the expiration time.
src/core/configuration/DevConfig.ts (1)
53-59: LGTM! Development configuration values are reasonable.The alliance duration of 30 seconds and prompt offset of 10 seconds provide good testing values. The
30 * 10calculation clearly shows the intent (30 seconds at 10 ticks per second).src/client/graphics/layers/PlayerPanel.ts (1)
179-181: LGTM! Correctly adapts to new alliance expiration tracking.Using
allianceExpiresAtdirectly is more reliable than calculating from creation time plus duration. This aligns well with the server-side changes to precompute expiration timestamps.src/client/Transport.ts (3)
70-72: LGTM! Event class follows established patterns.The
SendAllianceExtensionIntentEventcorrectly follows the same pattern as other alliance events with a simple recipient property.
201-203: LGTM! Event registration follows consistent pattern.The event bus registration correctly follows the same pattern as other intent events in the constructor.
429-437: LGTM! Handler implementation follows established patterns.The alliance extension intent handler correctly follows the same structure as other alliance intent handlers, sending the appropriate intent with client ID and recipient.
tests/AllianceExtensionExecution.test.ts (2)
55-89: Excellent test coverage for the happy path scenario.The test properly verifies that alliance extension maintains the same alliance instance while updating expiration. The assertion checking
allianceAfter.id() === allianceBefore.id()is particularly important for ensuring alliance identity preservation.
91-97: Good defensive test for non-existent alliance scenario.This test ensures the system gracefully handles attempts to extend alliances that don't exist, which is essential for robust error handling.
src/core/game/PlayerImpl.ts (3)
93-93: Well-named field following existing conventions.The
_expiredAlliancesfield follows the established naming pattern and properly tracks expired alliances for the player.
175-183: Proper alliance view serialization with complete data.The alliance mapping correctly provides all required fields from the
AllianceViewinterface including ID, other player, and expiration timing. The use ofsatisfies AllianceViewensures type safety.
360-362: Clean getter method following established patterns.The
expiredAlliances()method correctly returns a defensive copy of the expired alliances array, following the same pattern as other similar methods in the class.src/core/game/GameImpl.ts (3)
81-82: Good addition of unique alliance ID tracking.The
nextAllianceIDfield enables proper alliance identification for extension functionality. The initialization to 0 is appropriate.
154-156: Consistent public accessor method.The
alliances()method follows the established pattern of exposing internal collections and correctly returns the typedMutableAlliance[].
256-256: Proper unique ID assignment for new alliances.The use of
this.nextAllianceID++correctly assigns unique IDs to each alliance and increments the counter for the next alliance.src/core/Schemas.ts (4)
28-28: Proper addition to Intent union type.The
AllianceExtensionIntentis correctly added to the Intent union type, maintaining alphabetical ordering with other alliance-related intents.
71-73: Consistent type export pattern.The type export follows the established pattern using
z.inferand maintains consistency with other intent type exports in the file.
220-223: Well-structured schema definition.The
AllianceExtensionIntentSchemacorrectly extendsBaseIntentSchemawith the appropriate type literal and recipient field, following the same pattern asAllianceRequestIntentSchema.
366-366: Proper integration with discriminated union.The schema is correctly added to the discriminated union array, enabling proper validation and type discrimination.
src/core/execution/alliance/AllianceExtensionExecution.ts (2)
15-29: Solid validation logic with proper error handling.The validation correctly checks for player existence and alliance existence before proceeding. The early returns prevent unnecessary processing when preconditions aren't met.
50-61: Standard execution interface implementation.The execution interface methods are properly implemented with appropriate return values for this type of one-time execution.
src/core/game/GameUpdates.ts (5)
39-39: Clean addition to the enum.The new
AllianceExtensionenum value follows the existing naming convention and fits well with other alliance-related types.
64-64: Proper integration into the union type.The
AllianceExtensionUpdatetype is correctly added to theGameUpdateunion, maintaining type safety.
160-160: Good addition of alliance data to player updates.Adding the
alliancesarray toPlayerUpdateprovides clients with the necessary alliance expiration information.
165-170: Well-designed AllianceView interface.The interface is clean and provides all necessary data for tracking alliance expiration. The naming is consistent with other view interfaces in the codebase.
197-201: Simple and focused update interface.The
AllianceExtensionUpdateinterface contains exactly the data needed for alliance extension events. Good adherence to the single responsibility principle.src/core/game/AllianceImpl.ts (6)
4-7: Good state tracking for extension requests.The boolean flags for tracking extension requests from both players are clear and the
expiresAt_field properly manages alliance expiration timing.
13-17: Proper constructor updates with expiration calculation.The constructor correctly calculates the expiration time by adding the alliance duration to the creation time. The alliance ID parameter addition supports proper tracking.
42-48: Clean extension request handling.The method correctly identifies which player is making the request and sets the appropriate flag. The logic is straightforward and handles both requestor and recipient cases.
50-54: Simple and effective extension eligibility check.The
canExtend()method requires both players to have requested extension, which is the expected behavior for mutual agreement.
60-64: Proper extension implementation.The
extend()method correctly resets the extension request flags and updates the expiration time to the current game tick plus the alliance duration.
66-68: Simple getter method.The
expiresAt()method provides clean access to the expiration timestamp.src/client/graphics/layers/EventsDisplay.ts (5)
35-35: Proper import for alliance extension events.The import follows the existing pattern and provides access to the alliance extension intent event.
80-81: Smart spam prevention with alliance tracking.The
alliancesCheckedAtmap prevents repeated warnings for the same alliance, which improves user experience.
188-188: Good integration into the tick cycle.Calling
checkForAllianceExpirations()at the beginning of the tick ensures timely warnings before other updates are processed.
243-292: Well-implemented alliance expiration checking.The method correctly:
- Checks each alliance for upcoming expiration
- Prevents duplicate warnings using the tracking map
- Creates user-friendly warning events with appropriate buttons
- Uses proper translation keys for internationalization
The logic for determining when to show warnings is sound.
516-537: Clean alliance expiration event handling.The handler correctly identifies which player the current user had an alliance with and displays an appropriate message. The logic handles edge cases well.
src/core/game/Game.ts (7)
341-341: Good addition of expiration tracking to Alliance interface.Adding
expiresAt()method to the base Alliance interface provides consistent access to expiration information across the codebase.
348-351: Well-designed extension methods for MutableAlliance.The new methods provide a complete API for alliance extension:
canExtend()for checking eligibilityaddExtensionRequest()for tracking requestsextend()for performing the extensionid()for alliance identificationThe interface follows good design principles with focused, single-purpose methods.
543-543: Useful addition of expired alliance tracking.Adding
expiredAlliances()to the Player interface allows tracking of alliance history, which could be useful for UI and game logic.
620-621: Proper alliance management methods in Game interface.The
alliances()andexpireAlliance()methods provide necessary game-level alliance management capabilities.
704-704: Smart migration from creation time to expiration time.Changing from
allianceCreatedAtTicktoallianceExpiresAtin PlayerInteraction makes the timing information more directly useful for UI display and warning logic.
739-739: Appropriate addition of WARN message type.The new
WARNmessage type fills a gap in the messaging system for alliance expiration warnings and other non-critical alerts.
770-770: Correct categorization of WARN messages.Placing
WARNmessages in theALLIANCEcategory makes sense since the primary use case is alliance expiration warnings.
| const alliance = player.allianceWith(other as Player); | ||
| if (alliance) { | ||
| actions.interaction.allianceCreatedAtTick = alliance.createdAt(); | ||
| actions.interaction.allianceExpiresAt = alliance.expiresAt(); |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Verify property name change consistency and method existence.
The property name change from allianceCreatedAtTick to allianceExpiresAt aligns with the alliance extension feature. However, ensure that client-side code expecting this property has been updated accordingly.
🏁 Script executed:
#!/bin/bash
# Description: Verify that the property name change is consistent and the expiresAt() method exists
# Test 1: Check for any remaining references to the old property name
echo "=== Checking for remaining references to allianceCreatedAtTick ==="
rg "allianceCreatedAtTick" --type ts
# Test 2: Check for usage of the new property name
echo "=== Checking usage of allianceExpiresAt ==="
rg "allianceExpiresAt" --type ts -A 2
# Test 3: Verify expiresAt method exists on alliance objects
echo "=== Checking for expiresAt method definition ==="
ast-grep --pattern 'expiresAt() {
$$$
}'Length of output: 1098
Add missing expiresAt() method to Alliance
We’ve confirmed that:
- There are no remaining references to the old
allianceCreatedAtTick. - The new
allianceExpiresAtproperty is used consistently in:src/core/GameRunner.tssrc/core/game/Game.tssrc/client/graphics/layers/PlayerPanel.ts
- However, we didn’t find any implementation of
expiresAt()on the alliance object, so callingalliance.expiresAt()will fail at runtime.
Please implement the expiresAt(): Tick method (or equivalent) on your Alliance type/class—e.g. in src/core/game/Alliance.ts or wherever you define Alliance—so that the client and server both have a valid expiration timestamp.
🤖 Prompt for AI Agents
In src/core/GameRunner.ts at line 199, the code calls alliance.expiresAt(), but
the Alliance class lacks this method, causing runtime errors. To fix this, add
an expiresAt(): Tick method to the Alliance class, likely in
src/core/game/Alliance.ts, that returns the expiration timestamp of the
alliance. This ensures the property allianceExpiresAt is correctly set and
consistent across client and server.
| // TODO: remove this or throw error? | ||
| // Remove any existing alliance between the requestor and recipient | ||
| const existing = requestor.allianceWith(recipient); | ||
| if (existing) { | ||
| this.alliances_ = this.alliances_.filter((a) => a !== existing); | ||
| } |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Address the TODO comment about existing alliance removal.
The code removes existing alliances before creating new ones, but the TODO suggests uncertainty about this behavior. This logic might be incorrect - typically alliance requests should be rejected if an alliance already exists rather than replacing it.
🏁 Script executed:
#!/bin/bash
# Search for other alliance creation logic to understand expected behavior
rg -A 10 -B 5 "allianceWith.*existing|existing.*alliance" --type tsLength of output: 3278
Clarify and remove the TODO in alliance‐extension logic
The removal of an existing alliance is intentional (see the “Successfully extends existing alliance” test), so delete the // TODO and update the comment to explain that you’re replacing an old alliance to extend it.
• File: src/core/game/GameImpl.ts
Lines ~243–248
– Remove the // TODO: remove this or throw error? line
– Change the comment above existing to something like:
// Extend any existing alliance by removing it before creating a new one
Suggested diff:
- // TODO: remove this or throw error?
- // Remove any existing alliance between the requestor and recipient
+ // Extend an existing alliance by removing it before creating a new one
const existing = requestor.allianceWith(recipient);
if (existing) {
this.alliances_ = this.alliances_.filter((a) => a !== existing);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // TODO: remove this or throw error? | |
| // Remove any existing alliance between the requestor and recipient | |
| const existing = requestor.allianceWith(recipient); | |
| if (existing) { | |
| this.alliances_ = this.alliances_.filter((a) => a !== existing); | |
| } | |
| // Extend an existing alliance by removing it before creating a new one | |
| const existing = requestor.allianceWith(recipient); | |
| if (existing) { | |
| this.alliances_ = this.alliances_.filter((a) => a !== existing); | |
| } |
🤖 Prompt for AI Agents
In src/core/game/GameImpl.ts around lines 243 to 248, remove the TODO comment
"// TODO: remove this or throw error?" and update the existing comment to
clarify the intent by explaining that the code removes any existing alliance to
extend it. Change the comment to something like "// Extend any existing alliance
by removing it before creating a new one" to clearly document the purpose of
this logic.
2c99a15 to
b267006
Compare
b267006 to
c892868
Compare
c892868 to
9c2cfc9
Compare
9c2cfc9 to
6a54da4
Compare
6a54da4 to
c1aa97c
Compare
c1aa97c to
c25d57d
Compare
3bf9ca3 to
5359168
Compare
5359168 to
dec1e06
Compare
Description:
About 30s before an alliance is about to expire, both players receive a prompt to extend the alliance. If both players agree the alliance is extended.
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
evan