<spanid="evennia-contrib-tutorials-evadventure-rules"></span><h1>evennia.contrib.tutorials.evadventure.rules<aclass="headerlink"href="#module-evennia.contrib.tutorials.evadventure.rules"title="Permalink to this headline">¶</a></h1>
<p>MUD ruleset based on the _Knave_ OSR tabletop RPG by Ben Milton (modified for MUD use).</p>
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.contrib.tutorials.evadventure.rules.</code><codeclass="sig-name descname">EvAdventureRollEngine</code><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/rules.html#EvAdventureRollEngine"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.rules.EvAdventureRollEngine"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">roll</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">roll_string</span></em>, <emclass="sig-param"><spanclass="n">max_number</span><spanclass="o">=</span><spanclass="default_value">10</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/rules.html#EvAdventureRollEngine.roll"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.rules.EvAdventureRollEngine.roll"title="Permalink to this definition">¶</a></dt>
<dd><p>NOTE: In evennia/contribs/rpg/dice/ is a more powerful dice roller with
more features, such as modifiers, secret rolls etc. This is much simpler and only
gets a simple sum of normal rpg-dice.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>roll_string</strong> (<em>str</em>) – A roll using standard rpg syntax, <number>d<diesize>, like
1d6, 2d10 etc. Max die-size is 1000.</p></li>
<li><p><strong>max_number</strong> (<em>int</em>) – The max number of dice to roll. Defaults to 10, which is usually
more than enough.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>int</em>– The rolled result - sum of all dice rolled.</p>
</dd>
<dtclass="field-odd">Raises</dt>
<ddclass="field-odd"><p><strong>TypeError</strong>– If roll_string is not on the right format or otherwise doesn’t validate.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Since we may see user input to this function, we make sure to validate the inputs (we
wouldn’t bother much with that if it was just for developer use).</p>
<codeclass="sig-name descname">roll_with_advantage_or_disadvantage</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">advantage</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <emclass="sig-param"><spanclass="n">disadvantage</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/rules.html#EvAdventureRollEngine.roll_with_advantage_or_disadvantage"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.rules.EvAdventureRollEngine.roll_with_advantage_or_disadvantage"title="Permalink to this definition">¶</a></dt>
<dd><p>Base roll of d20, or 2d20, based on dis/advantage given.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>bonus</strong> (<em>int</em>) – The ability bonus to apply, like strength or charisma.</p></li>
<li><p><strong>advantage</strong> (<em>bool</em>) – Roll 2d20 and use the bigger number.</p></li>
<li><p><strong>disadvantage</strong> (<em>bool</em>) – Roll 2d20 and use the smaller number.</p></li>
</ul>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Disadvantage and advantage cancel each other out.</p>
<codeclass="sig-name descname">saving_throw</code><spanclass="sig-paren">(</span><emclass="sig-param">character</em>, <emclass="sig-param">bonus_type=<Ability.STR: 'strength'></em>, <emclass="sig-param">target=15</em>, <emclass="sig-param">advantage=False</em>, <emclass="sig-param">disadvantage=False</em>, <emclass="sig-param">modifier=0</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/rules.html#EvAdventureRollEngine.saving_throw"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.rules.EvAdventureRollEngine.saving_throw"title="Permalink to this definition">¶</a></dt>
<dd><p>A saving throw without a clear enemy to beat. In _Knave_ all unopposed saving
throws always tries to beat 15, so (d20 + bonus + modifier) > 15.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>character</strong> (<em>Object</em>) – The one attempting to save themselves.</p></li>
<li><p><strong>bonus_type</strong> (<em>enum.Ability</em>) – The ability bonus to apply, like strength or
charisma.</p></li>
<li><p><strong>target</strong> (<em>int</em><em>, </em><em>optional</em>) – Used for opposed throws (in Knave any regular
saving through must always beat 15).</p></li>
<li><p><strong>advantage</strong> (<em>bool</em><em>, </em><em>optional</em>) – Roll 2d20 and use the bigger number.</p></li>
<li><p><strong>disadvantage</strong> (<em>bool</em><em>, </em><em>optional</em>) – Roll 2d20 and use the smaller number.</p></li>
<li><p><strong>modifier</strong> (<em>int</em><em>, </em><em>optional</em>) – An additional +/- modifier to the roll.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><p><em>tuple</em>–</p>
<dlclass="simple">
<dt>A tuple <strong>(bool, str, str)</strong>. The bool indicates if the save was passed or not.</dt><dd><p>The second element is the quality of the roll - None (normal),
“critical fail” and “critical success”. Last element is a text detailing
the roll, for display purposes.</p>
</dd>
</dl>
</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Advantage and disadvantage cancel each other out.</p>
<pclass="rubric">Example</p>
<p>Trying to overcome the effects of poison, roll d20 + Constitution-bonus above 15.</p>
<codeclass="sig-name descname">opposed_saving_throw</code><spanclass="sig-paren">(</span><emclass="sig-param">attacker</em>, <emclass="sig-param">defender</em>, <emclass="sig-param">attack_type=<Ability.STR: 'strength'></em>, <emclass="sig-param">defense_type=<Ability.ARMOR: 'armor'></em>, <emclass="sig-param">advantage=False</em>, <emclass="sig-param">disadvantage=False</em>, <emclass="sig-param">modifier=0</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/rules.html#EvAdventureRollEngine.opposed_saving_throw"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.rules.EvAdventureRollEngine.opposed_saving_throw"title="Permalink to this definition">¶</a></dt>
<dd><p>An saving throw that tries to beat an active opposing side.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>attacker</strong> (<em>Character</em>) – The attacking party.</p></li>
<li><p><strong>defender</strong> (<em>Character</em>) – The one defending.</p></li>
<li><p><strong>attack_type</strong> (<em>str</em>) – Which ability to use in the attack, like ‘strength’ or ‘willpower’.
Minimum is always 1.</p></li>
<li><p><strong>defense_type</strong> (<em>str</em>) – Which ability to defend with, in addition to ‘armor’.
Minimum is always 11 (bonus + 10 is always the defense in _Knave_).</p></li>
<li><p><strong>advantage</strong> (<em>bool</em>) – Roll 2d20 and use the bigger number.</p></li>
<li><p><strong>disadvantage</strong> (<em>bool</em>) – Roll 2d20 and use the smaller number.</p></li>
<li><p><strong>modifier</strong> (<em>int</em>) – An additional +/- modifier to the roll.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><p><em>tuple</em>–</p>
<dlclass="simple">
<dt>(bool, str, str): If the attack succeed or not. The second element is the</dt><dd><p>quality of the roll - None (normal), “critical fail” and “critical success”. Last
element is a text that summarizes the details of the roll.</p>
</dd>
</dl>
</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Advantage and disadvantage cancel each other out.</p>
<codeclass="sig-name descname">roll_random_table</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">dieroll</span></em>, <emclass="sig-param"><spanclass="n">table_choices</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/rules.html#EvAdventureRollEngine.roll_random_table"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.rules.EvAdventureRollEngine.roll_random_table"title="Permalink to this definition">¶</a></dt>
<dd><p>Make a roll on a random table.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>dieroll</strong> (<em>str</em>) – The dice to roll, like 1d6, 1d20, 3d6 etc).</p></li>
<li><p><strong>table_choices</strong> (<em>iterable</em>) – If a list of single elements, the die roll
should fully encompass the table, like a 1d20 roll for a table
with 20 elements. If each element is a tuple, the first element
of the tuple is assumed to be a string ‘X-Y’ indicating the
range of values that should match the roll.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>Any</em>– The result of the random roll.</p>
<codeclass="sig-name descname">morale_check</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">defender</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/rules.html#EvAdventureRollEngine.morale_check"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.rules.EvAdventureRollEngine.morale_check"title="Permalink to this definition">¶</a></dt>
<dd><p>A morale check is done for NPCs/monsters. It’s done with a 2d6 against
their morale.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>defender</strong> (<em>NPC</em>) – The entity trying to defend its morale.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>bool</em>– False if morale roll failed, True otherwise.</p>
<codeclass="sig-name descname">heal_from_rest</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">character</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/rules.html#EvAdventureRollEngine.heal_from_rest"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.rules.EvAdventureRollEngine.heal_from_rest"title="Permalink to this definition">¶</a></dt>
<dd><p>A meal and a full night’s rest allow for regaining 1d8 + Const bonus HP.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>character</strong> (<em>Character</em>) – The one resting.</p>
<codeclass="sig-name descname">roll_death</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">character</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/tutorials/evadventure/rules.html#EvAdventureRollEngine.roll_death"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.tutorials.evadventure.rules.EvAdventureRollEngine.roll_death"title="Permalink to this definition">¶</a></dt>
<dd><p>Happens when hitting <= 0 hp. unless dead,</p>