Browse Source

Notify about natural 1 and natural 20 rolls

Ryan C. Thompson 9 years ago
parent
commit
3d777ff39e
2 changed files with 16 additions and 8 deletions
  1. 8 6
      README.mkdn
  2. 8 2
      roll.py

+ 8 - 6
README.mkdn

@@ -28,11 +28,11 @@ $ ~/temp/roll.py 2d4+2
 2016-03-13 14:43:16,691 INFO: Total roll: 8
 # Interactive mode
 $ ~/temp/roll.py
-Enter roll> 2d20-L+5
-2016-03-13 14:43:28,733 INFO: Rolling 2d20-L+5
-2016-03-13 14:43:28,735 INFO: 2d20-L+5 rolled: 15
-(Individual rolls: [10]; Dropped low: [3]; Original rolls: [3, 10])
-2016-03-13 14:43:28,735 INFO: Total roll: 15
+Enter roll> 2d20-L+2
+2016-03-13 15:17:24,496 INFO: Rolling 2d20-L+2
+2016-03-13 15:17:24,496 INFO: 2d20-L+2 rolled: 22 (NATURAL 20)
+(Individual rolls: [20]; Dropped low: [5]; Original rolls: [5, 20])
+2016-03-13 15:17:24,496 INFO: Total roll: 22
 Enter roll> 6d6+6
 2016-03-13 14:43:34,468 INFO: Rolling 6d6+6
 2016-03-13 14:43:34,468 INFO: 6d6+6 rolled: 25
@@ -61,7 +61,9 @@ Enter roll> exit
 As you can see, it not only reports the total, but all the individual
 dice rolls, so if you made a mistake on a modifier or something, you
 don't have to re-roll the entire thing, you can change the modifier
-and re-add the existing dice rolls manually.
+and re-add the existing dice rolls manually. Also, as a special
+feature, it tells you when you get a natural 1 or a natural 20 on a
+singular d20 roll.
 
 Notice the last few examples that demonstrate:
 

+ 8 - 2
roll.py

@@ -67,6 +67,12 @@ def roll_dice(s, n=1, mod=0, drop_low=0, drop_high=0):
         kept_rolls.remove(drop)
     total = mod + sum(kept_rolls)
     # TODO: Special reporting for natural 1 and natural 20 (only when a single d20 roll is returned)
+    natural = ''
+    if len(kept_rolls) == 1 and s == 20:
+        if kept_rolls[0] == 1:
+            natural = " (NATURAL 1)"
+        elif kept_rolls[0] == 20:
+            natural = " (NATURAL 20)"
     if n > 1:
         paren_stmts = [ ('Individual rolls', kept_rolls), ]
         if dropped_low_rolls:
@@ -76,9 +82,9 @@ def roll_dice(s, n=1, mod=0, drop_low=0, drop_high=0):
         if dropped_low_rolls or dropped_high_rolls:
             paren_stmts.append( ('Original rolls', rolls) )
         paren_stmt = "; ".join("%s: %s" % (k, repr(v)) for k,v in paren_stmts)
-        logger.info('%s rolled: %s\n(%s)', format_roll(s, n, mod, drop_low, drop_high), total, paren_stmt)
+        logger.info('%s rolled: %s%s\n(%s)', format_roll(s, n, mod, drop_low, drop_high), total, natural, paren_stmt)
     else:
-        logger.info('%s rolled: %s', format_roll(s, n, mod, drop_low, drop_high), total)
+        logger.info('%s rolled: %s%s', format_roll(s, n, mod, drop_low, drop_high), total, natural)
     return total
 
 def _roll_matchgroup(m):