Skip to content

Modular core with shared helpers and game-logic fixes - #40

Open
Royaleint wants to merge 1 commit into
LoyalFTW:masterfrom
Royaleint:refactor/modular-core
Open

Modular core with shared helpers and game-logic fixes#40
Royaleint wants to merge 1 commit into
LoyalFTW:masterfrom
Royaleint:refactor/modular-core

Conversation

@Royaleint

Copy link
Copy Markdown

Summary

This splits the addon into small, single-purpose files with shared helpers, keeps the existing code style (function CrossGambling:Method(), CGCall message 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 new GAME_OVER message, 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) and luacheck, 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 list
  • core/Minimap.lua – minimap button
  • core/Comm.lua – addon messages: sending, the CGCall dispatch table, host-only gating
  • core/ChatEvents.lua – chat event registration, combat suspension, /roll parsing
  • core/Players.lua – roster, roll bookkeeping, roll extremes
  • core/ModeRegistry.lua – mode registration and the documented hook API
  • core/Game.lua – host/join/roll/settle/close lifecycle
  • core/DebugBots.lua – one generic bot stepper for every mode
  • modes/*.lua – each mode is just its rules on top of the helpers; Classic and BigTwo share NewHighLowMode

core/Events.lua is folded into Comm.lua; the load order in every .toc is updated.

Bugs fixed

  • core/Utils.lua and modes/BigTwoMode.lua were never listed in the .toc files, so BigTwo is effectively a new mode for players.
  • Clients only started listening for addon messages after they had hosted once; now the addon listens from login.
  • Host buttons stayed disabled after joining someone else's game.
  • Clients applied their own ban list to the host's roster and every client re-sent ADD_PLAYER, causing duplicate joins and ban spam.
  • Another addon user clicking "New Game" wiped the host's on-screen player list mid-game.
  • While no game was running, any group member's messages could change your wager, mode, or roster.
  • A tie for both highest and lowest roll crashed the game at close.
  • DeathRoll ended without closing the game, recording the result, or resetting state.
  • Banning or removing a player mid-game crashed Elimination and DeathRoll and left Classic, BigTwo and HotPotato stuck waiting on a roll that could never come. DeathRoll now ends by forfeit; the others carry on with the remaining players, or close with no debt if fewer than two are left.
  • Changing the chat channel while entries were open kept listening on the old channel.
  • "Roll Me" ignored the mode's roll range.
  • /roll parsing was English-only and failed for players on other realms (realm suffix).
  • BigTwo overwrote the saved wager; joining a game overwrote the client's saved wager.
  • House cut totals were never added to the house stats.
  • The Classic theme had its own second addon-message listener that skipped every host check and handled each message twice; removed.
  • Four copy-pasted name/ban helpers collapsed into one.

Rule changes to confirm

These change gameplay slightly, so please say if you'd rather keep the old behaviour:

  1. BigTwo is now a 1–2 roll for the configured wager (it used to force the wager to 2).
  2. HotPotato / Elimination: a tie for the lowest roll now triggers a re-roll among the tied players instead of picking one arbitrarily.
  3. Results are announced one line per debt (chat lines are capped at 255 characters, so long games no longer get cut off).

Not done

Two pre-existing issues were found during review and left for a follow-up (neither crashes or moves gold):

  • Changing the game mode with the mode button while a round is in progress silently abandons the round. A state check on the button would fix it.
  • In Elimination, if every player in an active tie-break is removed while more than two players remain, the round stalls.

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

…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
Royaleint marked this pull request as ready for review August 26, 2026 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant