Skip to content

fix: evaluator modifier chaining doesn't match Roll20 #12

@edloidas

Description

@edloidas

Problem

Current evaluator evaluates nested modifiers independently, losing dice pool state.

Industry standard (Roll20, RPG Dice Roller): Each modifier sees ALL dice (including previously dropped ones) and can override previous modifiers.

Example: 4d6dl1kh3

Expected (Roll20/RPG Dice Roller):

  • Roll 4d6: [3, 5, 2, 6]
  • dl1 examines all 4 dice, drops lowest (2): [3(k), 5(k), 2(d), 6(k)]
  • kh3 examines all 4 dice, keeps highest 3: [3(k), 5(k), 2(d), 6(k)]
  • Result: 3 + 5 + 6 = 14

Current implementation:

  • Roll 4d6: [3, 5, 2, 6]
  • dl1 evaluates completely, produces result
  • kh3 sees only the evaluated result, not original dice pool
  • Modifiers cannot override each other

Reference

RPG Dice Roller Documentation:

"The keep and drop modifiers work really well together, but there are some caveats. They both look at the entire dice pool."

Solution

Refactor evaluator to pass dice pools through modifier chain instead of evaluating to totals.

Location: src/evaluator/evaluator.ts:184 - evalModifier() function

Complexity: Medium-High

  • Requires architectural change to how modifiers work
  • Need to preserve dice state through evaluation chain
  • Backward compatibility considerations

Stage

Stage 2/3 enhancement - deferred from parser bug fix PR.

Related

  • PR fixing parser bug for modifier chaining
  • Code comment at src/evaluator/evaluator.ts:185-189

Metadata

Metadata

Assignees

No one assigned

    Labels

    improvementUpdate of the existing functionalityrefactoringCode style changes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions