Narrative Dice Roller (Dice Engine)
Format: #roll XdYZA X - number of dice. Optional, default 1. Range: 1-20. Y - sides per die. Range: 2-1000. Whole number only. Z - Suffixes optional reroll, filter, and keep/drop modifiers. A - Modifiers optional +, -, *, or / followed by a number. Decimals are supported. Multiple modifiers are allowed. Dice count and sides Minimum dice: 1; maximum dice: 20. Minimum sides: 2; maximum sides: 1000. Reroll suffixes r<N - dice lower than N are rerolled once. r>N - dice higher than N are rerolled once. A rerolled die keeps its new value; it is never rerolled a second time. Examples: #roll 4d6r<2 - dice showing 1 are rerolled once. #roll 4d20r<10 - dice below 10 are rerolled once. #roll 4d20r>15 - dice above 15 are rerolled once. Filter suffixes n<N - keeps only dice lower than N. n>N - keeps only dice higher than N. Dice that do not match the condition are removed from the pool before keep/drop and modifiers. Examples: #roll 4d6n>3 - keeps only dice showing 4, 5, or 6. #roll 4d6n<3 - keeps only dice showing 1 or 2. #roll 6d6n>4kh2 - filters the pool, then keeps the two highest remaining dice. If no dice match the filter, the result is 0. This is intentional, not an error. Keep and drop suffixes kh - keep highest. kl - keep lowest. dh - drop highest. dl - drop lowest. adv - same as kh. dis - same as kl. Optionally followed by a number. Without a number, it means 1. #roll 4d6dl1 rolls four d6 and drops the lowest. #roll 4d6kh3 keeps the three highest dice. #roll 3d6adv keeps the highest of three dice (advantage). #roll 3d20dis keeps the lowest of three dice (disadvantage). Keep/drop values are flexible: kh0 or kl0 keeps no dice, so the total is 0. dh0 or dl0 drops nothing. kh/kl with a number higher than the pool keeps all dice. dh/dl with a number equal to or higher than the pool drops everything, so the total is 0. Modifiers Use +, -, *, and /. Spaces around operators are allowed. Multiple modifiers are allowed and are applied after keep/drop. Multiplication and division are applied before addition and subtraction. Decimal modifiers are supported, such as *1.5, /2.5, or +0.5. The final total is rounded once at the end. Fractional results are rounded down unless they are within 0.1 of the next whole number. Division by zero gives 0. For example, #roll 1d20/0 produces a total of 0. This is intentional, not an error. Dice chains A +, -, *, or / followed by dice (such as +2d6) starts a new, independent dice group. Numeric modifiers after a group belong to that group. Examples: #roll 2d10+d8 - adds a d8 roll to 2d10. #roll 2d10-d8 - subtracts a d8 roll from 2d10. #roll 2d10*d8 - multiplies 2d10 by a d8 roll. #roll 2d10/d8 - divides 2d10 by a d8 roll. #roll 2d10+d8*2 - adds (d8 × 2) to 2d10. #roll 2d6+1d4*2-1d3 - three separate dice groups. #roll 20d20r<10+20d20r>10 - two independent 20d20 groups with different reroll rules. Each group is rolled independently. Chains are calculated from left to right. AI output The AI sees one compact system line per roll, showing the dice pools and the total. For example, #roll 4d20 might produce: (SYSTEM: 4d20 → [7, 12, 3, 17], total 39) Here, the dice rolled 7, 12, 3, and 17; their total is 39. Other examples: #roll 4d6dl1 → (SYSTEM: 4d6dl1 → [4, 5, 6], total 15) In the last example, the dice rolled 2, 4, 5, and 6; the lowest die, 2, is dropped, so the total is 15 (4 + 5 + 6). #roll 2d10+d8 → (SYSTEM: 2d10+d8 → [7, 3][5], total 15) Here, 2d10 rolled 7 and 3, the d8 rolled 5, and the total is 15. #roll 1d20/0 → (SYSTEM: 1d20/0 → [14], total 0) The original #roll command is removed from the context. The AI sees only the (SYSTEM: ...) line with the dice pools and total. Invalid rolls Invalid commands remain unchanged and generate no result: #roll 0d20 #roll 1d1 #roll 25d6 #roll 1d1001 Dice count must be 1-20; sides must be 2-1000. Division by zero is allowed and produces 0. Keep/drop and filter values are always valid. Exploding dice Add ! to make maximum rolls explode: the die rolls an additional die of the same type, which is added to the pool. #roll 4d6! - any die showing 6 rolls an extra d6, which is added to the pool. An extra die can also explode if it rolls the maximum value, creating a chain. By default, a group can produce up to 3 extra dice from explosions. You can change the limit with !N: #roll 4d6!2 - up to 2 extra dice per group. #roll 4d6!0 - explosions disabled. For the AI, an exploded die appears as one combined value: if a d6 rolled 6 and the extra die rolled 4, the pool shows 10. Exploding dice are the only form of "exploding" supported: the extra roll replaces nothing and is simply added; there is no separate "explode and keep rolling forever" mode.
