Add D&D-style dice notation support to /roll#317
Conversation
Agent-Logs-Url: https://github.com/Dans-Plugins/Medieval-Roleplay-Engine/sessions/1850c380-3b03-4a7f-89f8-e170bcbbcb57 Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Extends the /roll (and /dice) command to accept standard D&D-style dice notation (e.g., 2d6, d20+5) instead of only a single max integer, improving TTRPG usability while preserving legacy /roll 20 behavior.
Changes:
- Added dice-notation parsing (via a compiled regex) and multi-die rolling with modifiers.
- Updated the broadcast format to show individual rolls (when applicable) plus modifiers and totals.
- Updated help text and user documentation to describe the new notation and examples.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/main/java/dansplugins/rpsystem/commands/roll/RollCommand.java |
Implements dice-notation parsing, bounded roll execution, and updated broadcast message formatting. |
src/main/java/dansplugins/rpsystem/commands/help/HelpCommand.java |
Updates /roll help line to document dice notation usage. |
USER_GUIDE.md |
Documents supported dice formats and examples for players. |
COMMANDS.md |
Updates command reference with dice notation definition and examples. |
| int sum = 0; | ||
| for (int r : rolls) { | ||
| sum += r; | ||
| } | ||
| int total = sum + modifier; | ||
|
|
||
| String rollsDisplay = buildRollsDisplay(rolls); | ||
| String modDisplay = modifier != 0 ? (modifier > 0 ? " +" + modifier : " " + modifier) : ""; | ||
| String message = medievalRoleplayEngine.colorChecker.getNeutralAlertColor() + "" + ChatColor.ITALIC | ||
| + player.getName() + " rolled " + notation + ": " | ||
| + rollsDisplay + modDisplay + " = " + total; |
| if (m.group(1) != null) { | ||
| // NdM form | ||
| numDice = Integer.parseInt(m.group(1)); | ||
| dieSize = Integer.parseInt(m.group(2)); | ||
| } else if (m.group(3) != null) { | ||
| // dM form (implicit 1 die) | ||
| numDice = 1; | ||
| dieSize = Integer.parseInt(m.group(3)); | ||
| } else { | ||
| // plain number — treat as die size (legacy behaviour) | ||
| numDice = 1; | ||
| dieSize = Integer.parseInt(m.group(4)); | ||
| } | ||
|
|
||
| if (m.group(5) != null) { | ||
| modifier = Integer.parseInt(m.group(5)); |
|
@copilot address comments |
…ent overflow Agent-Logs-Url: https://github.com/Dans-Plugins/Medieval-Roleplay-Engine/sessions/a190ae5f-b9f4-4131-9d98-cffb87ff4fcc Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Both issues addressed in ace163e:
|
|
@copilot I created a snapshot release using this branch, causing the CI to build a JAR. This is from a user testing that JAR: Please resolve |
Agent-Logs-Url: https://github.com/Dans-Plugins/Medieval-Roleplay-Engine/sessions/a26eec07-1f65-4024-8eac-48dcd1bad694 Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Fixed in c0fa01c. The root cause is that the roll message was only delivered through the proximity-based local-chat system ( The fix splits delivery into two paths:
Regarding "file says 14": the JAR was correctly built from this branch. The version Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
RollCommand.javato parse full dice notation (NdM,dM,NdM+K,NdM-K, plain number legacy form)java.util.Randominstead ofMath.random()for better randomnessMAX_DICE=100,MAX_DIE_SIZE=10000) to prevent abuseInteger.parseIntcalls in try/catch to return friendly error on oversized inputs (e.g.999999999999d6)MAX_MODIFIER=10000bound to prevent integer overflow in total calculationplayer.sendMessage()so the roller never sees a blank response; nearby players receive the message viasendRPMessageToPlayersWithinDistanceExcludingTargetHelpCommand.javaCOMMANDS.mddocumentationUSER_GUIDE.mddocumentation