From fc21364a0cf84912899b46a551e9bac4608f97a2 Mon Sep 17 00:00:00 2001 From: Scott Tolksdorf Date: Sat, 21 Nov 2015 15:53:04 -0500 Subject: [PATCH] Improved the dice rolling algo --- .../monsterCard/attackSlot/attackSlot.jsx | 24 ++------------ client/naturalCrit/sidebar/dmDice/dmDice.jsx | 17 ++++++++++ client/naturalCrit/sidebar/dmDice/dmDice.less | 3 ++ .../sidebar/encounters/encounters.jsx | 17 ++++++++++ .../sidebar/encounters/encounters.less | 3 ++ client/naturalCrit/sidebar/sidebar.jsx | 7 +++- client/naturalCrit/sidebar/sidebar.less | 9 +++++- shared/naturalCrit/rollDice.js | 32 +++++++++++++++++++ 8 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 client/naturalCrit/sidebar/dmDice/dmDice.jsx create mode 100644 client/naturalCrit/sidebar/dmDice/dmDice.less create mode 100644 client/naturalCrit/sidebar/encounters/encounters.jsx create mode 100644 client/naturalCrit/sidebar/encounters/encounters.less create mode 100644 shared/naturalCrit/rollDice.js diff --git a/client/naturalCrit/encounter/monsterCard/attackSlot/attackSlot.jsx b/client/naturalCrit/encounter/monsterCard/attackSlot/attackSlot.jsx index f2dcd9bde..5e3bf7fc2 100644 --- a/client/naturalCrit/encounter/monsterCard/attackSlot/attackSlot.jsx +++ b/client/naturalCrit/encounter/monsterCard/attackSlot/attackSlot.jsx @@ -2,6 +2,8 @@ var React = require('react'); var _ = require('lodash'); var cx = require('classnames'); +var RollDice = require('naturalCrit/rollDice'); + var AttackSlot = React.createClass({ getDefaultProps: function() { return { @@ -18,27 +20,7 @@ var AttackSlot = React.createClass({ }, rollDice : function(key, notation){ - var additive = 0; - var dice = _.reduce([/\+(.*)/, /\-(.*)/], function(r, regexp){ - var res = r.match(regexp); - if(res){ - additive = res[0]*1; - r = r.replace(res[0], '') - } - return r; - }, notation) - - var numDice = dice.split('d')[0]; - var die = dice.split('d')[1]; - - var diceRoll = _.times(numDice, function(){ - return _.random(1, die); - }); - var res = _.sum(diceRoll) + additive; - if(numDice == 1 && die == 20){ - if(diceRoll[0] == 1) res = 'Fail!'; - if(diceRoll[0] == 20) res = 'Crit!'; - } + var res = RollDice(notation); this.state.lastRoll[key] = res this.state.lastRoll[key + 'key'] = _.uniqueId(key); this.setState({ diff --git a/client/naturalCrit/sidebar/dmDice/dmDice.jsx b/client/naturalCrit/sidebar/dmDice/dmDice.jsx new file mode 100644 index 000000000..f8f932091 --- /dev/null +++ b/client/naturalCrit/sidebar/dmDice/dmDice.jsx @@ -0,0 +1,17 @@ +var React = require('react'); +var _ = require('lodash'); +var cx = require('classnames'); + +var DmDice = React.createClass({ + + render : function(){ + var self = this; + return( +
+ DmDice Ready! +
+ ); + } +}); + +module.exports = DmDice; diff --git a/client/naturalCrit/sidebar/dmDice/dmDice.less b/client/naturalCrit/sidebar/dmDice/dmDice.less new file mode 100644 index 000000000..2c1685bf9 --- /dev/null +++ b/client/naturalCrit/sidebar/dmDice/dmDice.less @@ -0,0 +1,3 @@ +.dmDice{ + +} \ No newline at end of file diff --git a/client/naturalCrit/sidebar/encounters/encounters.jsx b/client/naturalCrit/sidebar/encounters/encounters.jsx new file mode 100644 index 000000000..a2cd44d4c --- /dev/null +++ b/client/naturalCrit/sidebar/encounters/encounters.jsx @@ -0,0 +1,17 @@ +var React = require('react'); +var _ = require('lodash'); +var cx = require('classnames'); + +var Encounters = React.createClass({ + + render : function(){ + var self = this; + return( +
+ Encounters Ready! +
+ ); + } +}); + +module.exports = Encounters; diff --git a/client/naturalCrit/sidebar/encounters/encounters.less b/client/naturalCrit/sidebar/encounters/encounters.less new file mode 100644 index 000000000..1144cab67 --- /dev/null +++ b/client/naturalCrit/sidebar/encounters/encounters.less @@ -0,0 +1,3 @@ +.encounters{ + +} \ No newline at end of file diff --git a/client/naturalCrit/sidebar/sidebar.jsx b/client/naturalCrit/sidebar/sidebar.jsx index 181c7a5f1..127b34414 100644 --- a/client/naturalCrit/sidebar/sidebar.jsx +++ b/client/naturalCrit/sidebar/sidebar.jsx @@ -103,8 +103,13 @@ var Sidebar = React.createClass({

Players

-