<spanid="evennia-contrib-dice"></span><h1>evennia.contrib.dice<aclass="headerlink"href="#module-evennia.contrib.dice"title="Permalink to this headline">¶</a></h1>
<p>Dice - rolls dice for roleplaying, in-game gambling or GM:ing</p>
<p>Evennia contribution - Griatch 2012</p>
<p>This module implements a full-fledged dice-roller and a ‘dice’ command
to go with it. It uses standard RPG ‘d’-syntax (e.g. 2d6 to roll two
six-sided die) and also supports modifiers such as 3d6 + 5.</p>
<p>One can also specify a standard Python operator in order to specify
eventual target numbers and get results in a fair and guaranteed
unbiased way. For example a GM could (using the dice command) from
the start define the roll as 2d6 < 8 to show that a roll below 8 is
required to succeed. The command will normally echo this result to all
parties (although it also has options for hidden and secret rolls).</p>
<p>Installation:</p>
<p>To use in your code, just import the roll_dice function from this module.</p>
<p>To use the dice/roll command, just import this module in your custom
cmdset module and add the following line to the end of DefaultCmdSet’s
at_cmdset_creation():</p>
<blockquote>
<div><p>self.add(dice.CmdDice())</p>
</div></blockquote>
<p>After a reload the dice (or roll) command will be available in-game.</p>
<li><p><strong>dicenum</strong> (<em>int</em>) – Number of dice to roll (the result to be added).</p></li>
<li><p><strong>dicetype</strong> (<em>int</em>) – Number of sides of the dice to be rolled.</p></li>
<li><p><strong>modifier</strong> (<em>tuple</em>) – A tuple <strong>(operator, value)</strong>, where operator is
one of <strong>“+”</strong>, <strong>“-“</strong>, <strong>“/”</strong> or <strong>“*”</strong>. The result of the dice
roll(s) will be modified by this value.</p></li>
<li><p><strong>conditional</strong> (<em>tuple</em>) – A tuple <strong>(conditional, value)</strong>, where
conditional is one of <strong>“==”</strong>,**”<”<strong>,</strong>”>”<strong>,</strong>”>=”<strong>,</strong>”<=**” or “<strong>!=</strong>”.
This allows the roller to directly return a result depending
on if the conditional was passed or not.</p></li>
<li><p><strong>return_tuple</strong> (<em>bool</em>) – Return a tuple with all individual roll
<dt>The result of the roll + modifiers. This is the</dt><dd><p>default return.</p>
</dd>
<dt>condition_result (bool): A True/False value returned if <strong>conditional</strong></dt><dd><p>is set but not <strong>return_tuple</strong>. This effectively hides the result
of the roll.</p>
</dd>
<dt>full_result (tuple): If, return_tuple** is <strong>True</strong>, instead</dt><dd><p>return a tuple <strong>(result, outcome, diff, rolls)</strong>. Here,
<strong>result</strong> is the normal result of the roll + modifiers.
<strong>outcome</strong> and <strong>diff</strong> are the boolean result of the roll and
absolute difference to the <strong>conditional</strong> input; they will
be will be <strong>None</strong> if <strong>conditional</strong> is not set. <strong>rolls</strong> is
itself a tuple holding all the individual rolls in the case of
multiple die-rolls.</p>
</dd>
</dl>
</p>
</dd>
<dtclass="field-odd">Raises</dt>
<ddclass="field-odd"><p><strong>TypeError if non-supported modifiers</strong><strong> or </strong><strong>conditionals are given.</strong>–</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>All input numbers are converted to integers.</p>
<pclass="rubric">Examples</p>
<p>print roll_dice(2, 6) # 2d6
<<< 7
print roll_dice(1, 100, (‘+’, 5) # 1d100 + 5
<<< 34
print roll_dice(1, 20, conditional=(‘<’, 10) # let’say we roll 3
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.contrib.dice.</code><codeclass="sig-name descname">CmdDice</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/dice.html#CmdDice"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.dice.CmdDice"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">key</code><emclass="property"> = 'dice'</em><aclass="headerlink"href="#evennia.contrib.dice.CmdDice.key"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">aliases</code><emclass="property"> = ['roll', '@dice']</em><aclass="headerlink"href="#evennia.contrib.dice.CmdDice.aliases"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">locks</code><emclass="property"> = 'cmd:all()'</em><aclass="headerlink"href="#evennia.contrib.dice.CmdDice.locks"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">func</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/dice.html#CmdDice.func"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.dice.CmdDice.func"title="Permalink to this definition">¶</a></dt>
<dd><p>Mostly parsing for calling the dice roller function</p>
<codeclass="sig-name descname">help_category</code><emclass="property"> = 'general'</em><aclass="headerlink"href="#evennia.contrib.dice.CmdDice.help_category"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">lock_storage</code><emclass="property"> = 'cmd:all()'</em><aclass="headerlink"href="#evennia.contrib.dice.CmdDice.lock_storage"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">search_index_entry</code><emclass="property"> = {'aliases': 'roll @dice', 'category': 'general', 'key': 'dice', 'tags': '', 'text': "\n roll dice\n\n Usage:\n dice[/switch] <nr>d<sides> [modifier] [success condition]\n\n Switch:\n hidden - tell the room the roll is being done, but don't show the result\n secret - don't inform the room about neither roll nor result\n\n Examples:\n dice 3d6 + 4\n dice 1d100 - 2 < 50\n\n This will roll the given number of dice with given sides and modifiers.\n So e.g. 2d6 + 3 means to 'roll a 6-sided die 2 times and add the result,\n then add 3 to the total'.\n Accepted modifiers are +, -, * and /.\n A success condition is given as normal Python conditionals\n (<,>,<=,>=,==,!=). So e.g. 2d6 + 3 > 10 means that the roll will succeed\n only if the final result is above 8. If a success condition is given, the\n outcome (pass/fail) will be echoed along with how much it succeeded/failed\n with. The hidden/secret switches will hide all or parts of the roll from\n everyone but the person rolling.\n "}</em><aclass="headerlink"href="#evennia.contrib.dice.CmdDice.search_index_entry"title="Permalink to this definition">¶</a></dt>
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.contrib.dice.</code><codeclass="sig-name descname">DiceCmdSet</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmdsetobj</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">key</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/dice.html#DiceCmdSet"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.dice.DiceCmdSet"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">at_cmdset_creation</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/dice.html#DiceCmdSet.at_cmdset_creation"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.dice.DiceCmdSet.at_cmdset_creation"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">path</code><emclass="property"> = 'evennia.contrib.dice.DiceCmdSet'</em><aclass="headerlink"href="#evennia.contrib.dice.DiceCmdSet.path"title="Permalink to this definition">¶</a></dt>