Modular core with shared helpers and game-logic fixes - #40
Open
Royaleint wants to merge 1 commit into
Open
Conversation
…he game logic The addon had grown into a few large files with the same helper code pasted in several places, and the game flow had a number of holes that only showed up when more than one person in the group ran the addon. This change breaks the code into small single-purpose files (Utils, DB, Minimap, Comm, ChatEvents, Players, ModeRegistry, Game, DebugBots) plus one file per game mode, all written in the existing style (methods on the CrossGambling object, the CGCall message table, the same START/REGISTER/ROLL states). The addon-message protocol is unchanged apart from a new GAME_OVER message, so it still plays with the released build. Why the logic needed work: the host is the only one who should process joins and rolls, but clients were also acting on chat, applying their own ban lists, and re-sending ADD_PLAYER, which caused duplicate joins and ban spam. Clients also did not listen for addon messages until they had hosted once, and while no game was running anyone in the group could change your wager, mode or roster. Bugs fixed along the way: Utils.lua and BigTwoMode.lua were never loaded by the .toc files; host buttons stayed disabled after joining someone else's game; another user clicking "New Game" wiped the host's on-screen roster; a tie for both high and low crashed the game at close; DeathRoll ended without closing or recording the game; removing a player mid-game crashed Elimination and DeathRoll and stalled the other modes; switching chat channel mid-registration kept listening on the old one; "Roll Me" ignored the mode's roll range; /roll parsing was English-only and broke for cross-realm names; BigTwo and joining a game both overwrote the saved wager; house-cut totals were never recorded. Rule changes to confirm with the owner: BigTwo is now a 1-2 roll for the configured wager; lowest-roll ties in HotPotato/Elimination re-roll; results are announced one line per debt to stay under the chat length limit. A headless Lua 5.1 test suite (tests/, 211 checks) and a luacheck config are included; tests are excluded from the packaged addon. Not yet verified in-game. Co-Authored-By: Royaleint and Claude Code
Royaleint
marked this pull request as ready for review
August 26, 2026 02:12
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.
Summary
This splits the addon into small, single-purpose files with shared helpers, keeps the existing code style (
function CrossGambling:Method(),CGCallmessage table, the same "START"/"REGISTER"/"ROLL" states), and fixes a batch of logic bugs found along the way. The wire protocol is unchanged apart from one newGAME_OVERmessage, so a player on this build can still play with players on the released build.Draft: the logic has been exercised by a headless test suite (
tests/, 211 checks covering every mode, joins/leaves, bans, client mirroring and the chat panel) andluacheck, but it has not yet been run inside the game client. Please give it an in-game pass before merging.Structure
core/Utils.lua– string/number helpers (name normalising, trimming, comma formatting)core/DB.lua– saved variables, wager and house-cut accessors, join words, ban listcore/Minimap.lua– minimap buttoncore/Comm.lua– addon messages: sending, theCGCalldispatch table, host-only gatingcore/ChatEvents.lua– chat event registration, combat suspension, /roll parsingcore/Players.lua– roster, roll bookkeeping, roll extremescore/ModeRegistry.lua– mode registration and the documented hook APIcore/Game.lua– host/join/roll/settle/close lifecyclecore/DebugBots.lua– one generic bot stepper for every modemodes/*.lua– each mode is just its rules on top of the helpers; Classic and BigTwo shareNewHighLowModecore/Events.luais folded intoComm.lua; the load order in every.tocis updated.Bugs fixed
core/Utils.luaandmodes/BigTwoMode.luawere never listed in the.tocfiles, so BigTwo is effectively a new mode for players.ADD_PLAYER, causing duplicate joins and ban spam./rollparsing was English-only and failed for players on other realms (realm suffix).Rule changes to confirm
These change gameplay slightly, so please say if you'd rather keep the old behaviour:
Not done
Two pre-existing issues were found during review and left for a follow-up (neither crashes or moves gold):
The two GUI files (
core/GUI.lua,core/ClassicGUI.lua) still duplicate each other; they were only touched where the new game flow required it. Merging them is a separate job.🤖 Generated with Claude Code
https://claude.ai/code/session_017j4ymvH64AfHhk2Yd4DAkt