evennia.contrib.rpg.dice.dice¶
Dice¶
Rolls dice for roleplaying, ingame gambling or GM:ing
Evennia contribution  Griatch 2012
This module implements a a diceroller and a dice/roll command to go with it. It uses standard RPG ‘d’syntax (e.g. 2d6 to roll two sixsided die) and also supports modifiers such as 3d6 + 5.
> roll 1d20 + 2
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).
Installation:¶
Add the CmdDice command from this module to your character’s cmdset (and then restart the server):
# in mygame/commands/default_cmdsets.py
# ...
from evennia.contrib.rpg import dice <
class CharacterCmdSet(default_cmds.CharacterCmdSet):
# ...
def at_cmdset_creation(self):
# ...
self.add(dice.CmdDice()) # <
Usage:¶
roll 1d100 + 10
To roll dice in code, use the roll function from this module:
from evennia.contrib.rpg import dice
dice.roll(“3d10 + 2”)
If your system generates the dice dynamically you can also enter each part of the roll separately:
dice.roll(3, 10, (“+”, 2)) # 3d10 + 2

evennia.contrib.rpg.dice.dice.
roll
(dice, dicetype=6, modifier=None, conditional=None, return_tuple=False, max_dicenum=10, max_dicetype=1000)[source]¶ This is a standard dice roller.
 Parameters
dice (int or str) – If an int, this is the number of dice to roll, and dicetype is used to determine the type. If a str, it should be on the form NdM where N is the number of dice and M is the number of sides on each die. Also NdM [modifier] [number] [conditional] is understood, e.g. 1d6 + 3 or 2d10 / 2 > 10.
dicetype (int, optional) – Number of sides of the dice to be rolled. Ignored if dice is a string.
modifier (tuple, optional) – A tuple (operator, value), where operator is one of “+”, “”, “/” or “*”. The result of the dice roll(s) will be modified by this value. Ignored if dice is a string.
conditional (tuple, optional) – A tuple (conditional, value), where conditional is one of “==”,**”<”,”>”,”>=”,”<=**” or “!=”. Ignored if dice is a string.
return_tuple (bool) – Return a tuple with all individual roll results or not.
max_dicenum (int) – The max number of dice to allow to be rolled.
max_dicetype (int) – The max number of sides on the dice to roll.
 Returns
int, bool or tuple – By default, this is the result of the roll + modifiers. If conditional is given, or dice is a string defining a conditional, then a True/False value is returned. Finally, if return_tuple is set, this is a tuple (result, outcome, diff, rolls), where, result is the the normal result of the roll + modifiers, outcome and diff are the boolean absolute difference between the roll and the conditional input; both will be will be None if conditional is not set. The rolls a tuple holding all the individual rolls (one or more depending on how many dice were rolled).
 Raises
TypeError if nonsupported modifiers or conditionals are given. –
Notes
All input numbers are converted to integers.
Examples
 ::
# string form print roll(“3d6 + 2”) 10 print roll(“2d10 + 2 > 10”) True print roll(“2d20  2 >= 10”) (8, False, 2, (4, 6)) # roll was 4 + 6  2 = 8
# explicit arguments print roll(2, 6) # 2d6 7 print roll(1, 100, (‘+’, 5) # 1d100 + 5 4 print roll(1, 20, conditional=(‘<’, 10) # let’say we roll 3 True print roll(3, 10, return_tuple=True) (11, None, None, (2, 5, 4)) print roll(2, 20, (‘’, 2), conditional=(‘>=’, 10), return_tuple=True) (8, False, 2, (4, 6)) # roll was 4 + 6  2 = 8

evennia.contrib.rpg.dice.dice.
roll_dice
(dice, dicetype=6, modifier=None, conditional=None, return_tuple=False, max_dicenum=10, max_dicetype=1000)¶ This is a standard dice roller.
 Parameters
dice (int or str) – If an int, this is the number of dice to roll, and dicetype is used to determine the type. If a str, it should be on the form NdM where N is the number of dice and M is the number of sides on each die. Also NdM [modifier] [number] [conditional] is understood, e.g. 1d6 + 3 or 2d10 / 2 > 10.
dicetype (int, optional) – Number of sides of the dice to be rolled. Ignored if dice is a string.
modifier (tuple, optional) – A tuple (operator, value), where operator is one of “+”, “”, “/” or “*”. The result of the dice roll(s) will be modified by this value. Ignored if dice is a string.
conditional (tuple, optional) – A tuple (conditional, value), where conditional is one of “==”,**”<”,”>”,”>=”,”<=**” or “!=”. Ignored if dice is a string.
return_tuple (bool) – Return a tuple with all individual roll results or not.
max_dicenum (int) – The max number of dice to allow to be rolled.
max_dicetype (int) – The max number of sides on the dice to roll.
 Returns
int, bool or tuple – By default, this is the result of the roll + modifiers. If conditional is given, or dice is a string defining a conditional, then a True/False value is returned. Finally, if return_tuple is set, this is a tuple (result, outcome, diff, rolls), where, result is the the normal result of the roll + modifiers, outcome and diff are the boolean absolute difference between the roll and the conditional input; both will be will be None if conditional is not set. The rolls a tuple holding all the individual rolls (one or more depending on how many dice were rolled).
 Raises
TypeError if nonsupported modifiers or conditionals are given. –
Notes
All input numbers are converted to integers.
Examples
 ::
# string form print roll(“3d6 + 2”) 10 print roll(“2d10 + 2 > 10”) True print roll(“2d20  2 >= 10”) (8, False, 2, (4, 6)) # roll was 4 + 6  2 = 8
# explicit arguments print roll(2, 6) # 2d6 7 print roll(1, 100, (‘+’, 5) # 1d100 + 5 4 print roll(1, 20, conditional=(‘<’, 10) # let’say we roll 3 True print roll(3, 10, return_tuple=True) (11, None, None, (2, 5, 4)) print roll(2, 20, (‘’, 2), conditional=(‘>=’, 10), return_tuple=True) (8, False, 2, (4, 6)) # roll was 4 + 6  2 = 8

class
evennia.contrib.rpg.dice.dice.
CmdDice
(**kwargs)[source]¶ Bases:
evennia.commands.default.muxcommand.MuxCommand
roll dice
 Usage:
dice[/switch] <nr>d<sides> [modifier] [success condition]
 Switch:
hidden  tell the room the roll is being done, but don’t show the result secret  don’t inform the room about neither roll nor result
Examples
dice 3d6 + 4 dice 1d100  2 < 50
This will roll the given number of dice with given sides and modifiers. So e.g. 2d6 + 3 means to ‘roll a 6sided die 2 times and add the result, then add 3 to the total’. Accepted modifiers are +, , * and /. A success condition is given as normal Python conditionals (<,>,<=,>=,==,!=). So e.g. 2d6 + 3 > 10 means that the roll will succeed only if the final result is above 8. If a success condition is given, the outcome (pass/fail) will be echoed along with how much it succeeded/failed with. The hidden/secret switches will hide all or parts of the roll from everyone but the person rolling.

key
= 'dice'¶

aliases
= ['roll', '@dice']¶

locks
= 'cmd:all()'¶

help_category
= 'general'¶

lock_storage
= 'cmd:all()'¶

search_index_entry
= {'aliases': 'roll @dice', 'category': 'general', 'key': 'dice', 'no_prefix': ' roll 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 6sided 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 "}¶

class
evennia.contrib.rpg.dice.dice.
DiceCmdSet
(cmdsetobj=None, key=None)[source]¶ Bases:
evennia.commands.cmdset.CmdSet
a small cmdset for testing purposes. Add with @py self.cmdset.add(“contrib.dice.DiceCmdSet”)

path
= 'evennia.contrib.rpg.dice.dice.DiceCmdSet'¶
