Bernardo-MG / dice-notation-java

Tools and parsers for handling Dice/RPG notation using Java
Apache License 2.0
17 stars 3 forks source link

Add support for complex value generation rules #51

Open Bernardo-MG opened 5 years ago

Bernardo-MG commented 5 years ago

For example:

These rules are applied to the parsed expression. So they should be applied with transformers.

But maybe they can be activated through special keywords in the grammar, which would require an extension of the basic grammar.

Bernardo-MG commented 5 years ago

Roll20 makes use of a much more complex DSL:

https://wiki.roll20.net/Dice_Reference

Bernardo-MG commented 5 years ago

Wikipedia includes more examples:

https://en.wikipedia.org/wiki/Dice_notation

Bernardo-MG commented 5 years ago

More examples of additional rules:

https://anydice.com/

Bernardo-MG commented 5 years ago

Another parser:

https://github.com/cro-ki/xdice

danlangford commented 5 years ago

i was going to make an issue about this. for those perusing the thread ill give some examples:

advantage/disadvantage from 5e roll20: 2d20kh1 for "keep highest 1" or 2d20kl1 for "keep lowest 1" anydice: [highest 1 of 2d20] or [lowest 1 of 2d20]

character creation from D&D roll20: 4d6dl1 for "drop lowest 1" anydice: [highest 3 of 4d6]

Bernardo-MG commented 5 years ago

This may be easier, and cleaner, to handle as functions.

Keep lowest: "kl(2d20)" Repeat values of 6: "r(1d6, 6)"

This would require a new node, for the functions.

Ideally there would be a way to map functions into objects, to ease extension and adding new functions.

The rule could be something like:

operation: FUNCNAME LPAREN function RPAREN;

The default rule is named function. This is confusing and should be changed before this.