Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief description
This PR implements a robust state machine for handling battle results in the
BattleService.It introduces logic to handle "Odd Man Out" scenarios where players report conflicting results (e.g., Team 1 claims victory while Team 2 also claims victory).The system now transitions from
OPENtoPROCESSINGwhen results conflict, triggering a 2-minute "Final Call" timer. After the timeout, the service resolves the conflict via a majority vote (defaulting to Team 1 in ties) and distributes Raid Tokens. This ensures the integrity of the game economy and prevents "silent agreements" or stuck matches.Change list
handleBattleResultwith conflict detection andresolveConflictwith a majority-vote algorithm.State Machine: Integrated
BattleStatus.PROCESSINGto represent matches awaiting a timeout resolution.Timer Logic: Added a 2-minute
setTimeoutmechanism to finalize matches that don't reach a natural consensus.Raid Token Distribution: Refactored
generateRaidTokensinto a dedicated private method to ensure rewards are only issued upon final verification.Data & Documentation
Schema Update: Updated
BattleSchemawith pre-validation middleware to prevent players from being assigned to multiple teams.JSDocs: Added comprehensive documentation for the
BattleService,Battle Schema,BattleStatusEnum, and associated DTOs.DTO Alignment: Fixed a property mismatch where result was used in the DTO but expected as
winnerTeamin the service.Testing & Quality
Unit Tests: Created
battle.service.test.tsusing Jest fake timers to verify the full lifecycle of a conflict resolution.Linting: Resolved ESLint errors regarding empty blocks and unused variables to pass Husky pre-commit hooks.