/*! droll v0.2.1  http://github.com/thebinarypenguin/droll */
!function(a){"use strict";function b(){this.numDice=0,this.numSides=0,this.modifier=0,this.minResult=0,this.maxResult=0,this.avgResult=0}function c(){this.rolls=[],this.modifier=0,this.total=0}var d={};c.prototype.toString=function(){return 1===this.rolls.length&&0===this.modifier?this.rolls[0]+"":this.rolls.length>1&&0===this.modifier?this.rolls.join(" + ")+" = "+this.total:1===this.rolls.length&&this.modifier>0?this.rolls[0]+" + "+this.modifier+" = "+this.total:this.rolls.length>1&&this.modifier>0?this.rolls.join(" + ")+" + "+this.modifier+" = "+this.total:1===this.rolls.length&&this.modifier<0?this.rolls[0]+" - "+Math.abs(this.modifier)+" = "+this.total:this.rolls.length>1&&this.modifier<0?this.rolls.join(" + ")+" - "+Math.abs(this.modifier)+" = "+this.total:void 0},d.parse=function(a){var c=null,d=new b;return(c=a.match(/^([1-9]\d*)?d([1-9]\d*)([+-]\d+)?$/i))?(d.numDice=c[1]-0||1,d.numSides=c[2]-0,d.modifier=c[3]-0||0,d.minResult=1*d.numDice+d.modifier,d.maxResult=d.numDice*d.numSides+d.modifier,d.avgResult=(d.maxResult+d.minResult)/2,d):!1},d.validate=function(a){return d.parse(a)?!0:!1},d.roll=function(a){var b=null,e=new c;if(b=d.parse(a),!b)return!1;for(var f=0;f<b.numDice;f++)e.rolls[f]=1+Math.floor(Math.random()*b.numSides);e.modifier=b.modifier;for(var g=0;g<e.rolls.length;g++)e.total+=e.rolls[g];return e.total+=e.modifier,e},"undefined"!=typeof module&&module.exports?module.exports=d:a.droll=d}(this);