README.mkdn 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # roll.py: A command-line dice-rolling simulator for RPGs
  2. This was a weekend hobby project inspired by [Critical Role][1] and
  3. other D&D shows and podcasts. While a dice simulator is no substitute
  4. for physically rolling real dice, it might be useful for anyone who's
  5. on the go or otherwise unable to access their dice and a flat surface
  6. to roll them on (or for new players who want to try out RPGs without
  7. having to spend money on dice first). It's also great for when you
  8. finally get to cast that [*Meteor
  9. Swarm*](https://www.dndbeyond.com/spells/meteor-swarm) spell and don't
  10. want to make everyone wait while you roll 40d6 for the damage.
  11. It supports almost everything in the ["Standard Notation"][2] section
  12. of the Wikipedia page on dice notation, as well as the syntax in this
  13. online [RPG Dice Roller][3] and this [Android App][4].
  14. [1]: http://geekandsundry.com/shows/critical-role/
  15. [2]: https://en.wikipedia.org/wiki/Dice_notation#Standard_notation
  16. [3]: http://rpg.greenimp.co.uk/dice-roller/
  17. [4]: https://www.critdice.com/roll-advanced-dice
  18. ## Usage
  19. There are two ways to use this script. Either run it with any number
  20. of arguments, which will be concatenated and rolled, or run it with no
  21. arguments to enter interactive mode, where you can type a roll on each
  22. line and hit enter to roll it. In either case, the last line indicates
  23. the total roll, and all the lines before it indicate the individual
  24. dice rolls that led to it. Examples:
  25. ```
  26. # Single-roll command-line mode
  27. $ ./roll.py 2d4+2
  28. 2d4 rolled: [1 4], Total: 5
  29. Result: 7 (rolled 2d4+2)
  30. # Interactive mode
  31. $ ./roll.py
  32. # Advantage roll (drop lowest) in D&D, with a modifier
  33. Enter roll> 2d20-L+2
  34. 2d20-L rolled: 15 (dropped 11)
  35. Result: 17 (rolled 2d20-L+2)
  36. # Some more basic rolls
  37. Enter roll> 6d6+6
  38. 6d6 rolled: [5 2 6 1 1 5], Total: 20
  39. Result: 26 (rolled 6d6+6)
  40. Enter roll> d100
  41. d100 rolled: 35
  42. Result: 35 (rolled d100)
  43. # Complex arithmetic expressions and non-standard dice are allowed
  44. Enter roll> d4 + 2d6 + 4 - 3d8 + 6d7/2
  45. d4 rolled: 3
  46. 2d6 rolled: [6 6], Total: 12
  47. 3d8 rolled: [1 3 2], Total: 6
  48. 6d7 rolled: [1 2 5 7 5 1], Total: 21
  49. Result: 23.5 (rolled d4 + 2d6 + 4 - 3d8 + 6d7/2)
  50. # Any arithmetic expression is allowed, even if it doesn't roll any dice
  51. Enter roll> 4 + 6^2 / 3
  52. Result: 16 (rolled 4 + 6^2 / 3)
  53. # You can save specific rolls as named variables
  54. Enter roll> health_potion = 2d4 + 2
  55. Saving "health_potion" as "2d4 + 2"
  56. Enter roll> health_potion
  57. 2d4 rolled: [3 4], Total: 7
  58. Result: 9 (rolled 2d4 + 2)
  59. # Variables can reference other variables
  60. Enter roll> greater_health_potion = health_potion + health_potion
  61. Saving "greater_health_potion" as "health_potion + health_potion"
  62. Enter roll> greater_health_potion
  63. 2d4 rolled: [3 3], Total: 6
  64. 2d4 rolled: [1 3], Total: 4
  65. Result: 14 (rolled 2d4 + 2 + 2d4 + 2)
  66. # Show currently defined variables
  67. Enter roll> vars
  68. Currently defined variables:
  69. greater_health_potion = 'health_potion + health_potion'
  70. health_potion = '2d4 + 2'
  71. # Delete a variable
  72. Enter roll> del greater_health_potion
  73. Deleting saved value for "greater_health_potion".
  74. # Reroll ones once (rerolled dice are marked with 'r')
  75. Enter roll> 4d4r
  76. 4d4r rolled: [2 3r 4 4r], Total: 13
  77. Result: 13 (rolled 4d4r)
  78. # Reroll ones indefinitely (rerolls marked with 'R')
  79. Enter roll> 4d4R
  80. 4d4R rolled: [2R 3R 4R 3], Total: 12
  81. Result: 12 (rolled 4d4R)
  82. # Exploding dice (marked with '!')
  83. Enter roll> 6d6!
  84. 6d6! rolled: [4 2 4 4 5 6! 1], Total: 26
  85. Result: 26 (rolled 6d6!)
  86. # Explode any roll greater than 3
  87. Enter roll> 6d6!>3
  88. 6d6!>3 rolled: [2 4! 5! 4! 2 6! 5! 6! 6! 6! 3 4! 2 4! 4! 1 2], Total: 66
  89. Result: 66 (rolled 6d6!>3)
  90. # Penetrating dice
  91. Enter roll> 6d6!p
  92. 6d6!p rolled: [2 4 6!p 2 6!p 0 1 2], Total: 23
  93. Result: 23 (rolled 6d6!p)
  94. # Fate dice
  95. Enter roll> 4dF+2
  96. 4dF rolled: [1 0 1 -1], Total: 1
  97. Result: 3 (rolled 4dF+2)
  98. # Enter 'help' for other non-roll commands, 'quit' to quit
  99. Enter roll> quit
  100. 2018-12-15 09:56:33 INFO: Quitting.
  101. ```
  102. As you can see, it not only reports the total for each roll, but all
  103. the individual dice rolls as well, so you can understand how it came
  104. up with the total. This also lets you figure out whether you rolled a
  105. natural 20 or natural 1 on the die for critical hits and misses, and
  106. if your damage roll involves multiple different kinds of damage, it
  107. lets you figure out how much of each damage type was dealt.