btmorton / dice_roller Goto Github PK
View Code? Open in Web Editor NEWA node dice roller in the style of roll20
License: MIT License
A node dice roller in the style of roll20
License: MIT License
> const { DiceRoller } = require('dice-roller-parser')
undefined
> roller = new DiceRoller()
{ randFunction: [Function: random], maxRollCount: 1000 }
> roller.roll('1d4r1r4')
{
count: { type: 'number', value: 1, success: false, valid: true, order: 0 },
die: { type: 'number', value: 4, success: false, valid: true, order: 0 },
rolls: [
{
critical: 'success',
die: 4,
matched: false,
order: 0,
roll: 4,
success: false,
type: 'roll',
valid: false,
value: 4
},
{
critical: 'success',
die: 4,
matched: false,
order: 1,
roll: 4,
success: false,
type: 'roll',
valid: false,
value: 4
},
{
critical: 'failure',
die: 4,
matched: false,
order: 2,
roll: 1,
success: false,
type: 'roll',
valid: true,
value: 1
}
],
success: false,
type: 'die',
valid: true,
value: 1,
order: 0,
matched: false
}
With multiple rerolls in the formula, only the last one seems to be respected.
See the example, 1d4r1r4 -> 4 is rerolled, but 1 is used as last value.
The same forumla works on roll20:
This is a feature request to add a new public function to parse previously parsed dice roll input strings (RootType
) along with a provided DiceRollResult
object so it can be parsed into a final RollBase
object.
The application here is that I have created a 3D dice roller (using BabylonJS) that is capable of rolling dice on a canvas element and returns the face up value of the die rolled. I'd like to be able to return a "previously parsed dice roll input string" along with the roll results as an array of DiceRollResult
objects to then have dice-roller-parser compute the final RollBase
object. I really enjoy all the features of this package and would like to leverage it for my app.
Based on a quick review of the code, I think a good approach may be to allow the private RollType
function to accept another argument of rolls: DiceRollResult
that it can then pass onto the various rollType function. Then, if the rolls argument is undefined, rolls will be calculated by generateDiceRoll
. Otherwise it will use the provided object. Is this feasible?
If I input 5d6!!
whenever a six is rolled the value remains at six even though an additional d6 should be added to the value.
Additionally, since the compounded roll is not spliced into the rolls array, it can not be evaluated for additional exploding results.
[
{
"critical": "success",
"die": 6,
"matched": false,
"order": 4,
"roll": 6,
"success": false,
"type": "roll",
"valid": true,
"value": 6
}
]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.