Skip to content

Commit

Permalink
pool.Roll refactor, pt. 2
Browse files Browse the repository at this point in the history
  • Loading branch information
tiltowait committed May 11, 2021
1 parent 6a01ff3 commit 18955c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
16 changes: 9 additions & 7 deletions storyteller/parse/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __pool_roll(ctx, command):

title = f"Pool {dice_pool}, diff. {difficulty}"
if command["chronicles"]:
title = f"Pool {dice_pool}"
title = f"Pool {dice_pool}, {options['xpl_target']}-again"

# Sometimes, a roll may have auto-successes that can be canceled by 1s.
autos = int(command["auto"] or 0)
Expand All @@ -93,13 +93,15 @@ def __pool_roll(ctx, command):

specialty = command["specialty"] # Doubles 10s if set
options["double_tens"] = __should_double(command, specialty is not None)
options["exploding"] = __should_explode(command, specialty is not None)

if not chronicles:
options["xpl_target"] = __explosion_target(command, specialty is not None)

# Perform rolls, format them, and figure out how many successes we have
results = roll.Pool(dice_pool, difficulty, autos, will, chronicles, options)

# Add explosion info, if applicable
if options["exploding"] and results.explosions > 0:
if results.explosions > 0:
explosions = "explosion" if results.explosions == 1 else "explosions"
title += f" (+{results.explosions} {explosions})"

Expand Down Expand Up @@ -236,10 +238,10 @@ def __should_double(command: dict, spec: bool) -> bool:
return False


def __should_explode(command: dict, spec: bool) -> bool:
def __explosion_target(command: dict, spec: bool) -> bool:
"""Determines whether 10s on a roll should explode."""
if command["xpl_always"]:
return True
return 10
if command["xpl_spec"] and spec:
return True
return False
return 10
return 11 # Rolls can never be 11, so this is effectively ignored
42 changes: 17 additions & 25 deletions storyteller/roll/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ class Pool:
def __init__(self, pool, diff, autos, wp, cofd, options):
# pylint: disable=too-many-arguments
self.difficulty = diff
self.autos = autos
self.xpl_target = options["xpl_target"]

if cofd:
self.will = False
if wp:
pool += 3

# In CofD, difficulty is always 8; if the user supplies it, make an X-again roll
self.xpl_target = options["xpl_target"]
else:
self.will = wp
self.xpl_target = 10

self.should_double = options["double_tens"]
self.autos = autos
self.no_botch = options["no_botch"]
self.nullify_ones = options["nullify_ones"]
self.should_explode = options["exploding"]
self.ignore_ones = options["nullify_ones"]
self.wp_cancelable = options["wp_cancelable"]

self.explosions = 0
self.dice = self.__roll(pool)
self.successes = self.__calculate_successes()
Expand All @@ -34,7 +33,6 @@ def __init__(self, pool, diff, autos, wp, cofd, options):
@property
def formatted_result(self):
"""Format the successes to something nice for people to read."""
# Determine roll string
successes = self.successes
result_str = ""
if successes > 0:
Expand All @@ -59,7 +57,7 @@ def formatted_dice(self):
"""
formatted = []
for die in self.dice:
if die == 1 and not (self.nullify_ones and self.no_botch):
if die == 1 and not (self.ignore_ones and self.no_botch):
formatted.append(f"~~***{die}***~~")
elif die < self.difficulty:
formatted.append(f"~~{die}~~")
Expand Down Expand Up @@ -96,7 +94,7 @@ def __calculate_successes(self) -> int:
suxx += 1
if die == 10 and self.should_double:
suxx += 1
elif die == 1 and not (self.nullify_ones and self.no_botch):
elif die == 1 and not (self.ignore_ones and self.no_botch):
fails += 1

# Three possible results:
Expand All @@ -120,22 +118,16 @@ def __calculate_successes(self) -> int:

def __roll(self, pool) -> list:
"""Roll the dice!"""

# Exploding dice: on a ten, roll an additional die. This is recursive
if self.should_explode:
dice = []
for _ in range(pool):
die = traditional.roll(1, 10)[0]
while die >= self.xpl_target:
dice.append(die)
die = traditional.roll(1, 10)[0]
self.explosions += 1
dice = []
for _ in range(pool):
die = traditional.roll(1, 10)[0]
while die >= self.xpl_target:
dice.append(die)
die = traditional.roll(1, 10)[0]
self.explosions += 1
dice.append(die)

return sorted(dice, reverse=True)

# Normal, non-exploding rolling
return sorted(traditional.roll(pool, 10), reverse=True)
return sorted(dice, reverse=True)


@property
Expand All @@ -146,7 +138,7 @@ def dice_emoji_names(self):
name = ""
if die >= self.difficulty:
name = f"s{die}"
elif die > 1 or (self.nullify_ones and self.no_botch):
elif die > 1 or (self.ignore_ones and self.no_botch):
name = f"f{die}"
else:
name = "b1"
Expand Down

0 comments on commit 18955c8

Please sign in to comment.