From 4c47b0d5a263ac785c9b62702535cb2b3dc05a65 Mon Sep 17 00:00:00 2001 From: tiltowait <208040+tiltowait@users.noreply.github.com> Date: Tue, 11 May 2021 15:23:17 -0700 Subject: [PATCH] Pool roll refactor, pt. 3. Closes #12 --- storyteller/parse/pool.py | 38 ++++++++++++++++++++----------------- storyteller/roll/pool.py | 40 +++++++++++++++++++-------------------- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/storyteller/parse/pool.py b/storyteller/parse/pool.py index 8b5cc4d..2208273 100644 --- a/storyteller/parse/pool.py +++ b/storyteller/parse/pool.py @@ -78,39 +78,43 @@ def __pool_roll(ctx, command): if command["chronicles"] and not difficulty <= options["xpl_target"] <= 10: return f"Whoops! X-Again must be between {difficulty} and 10, not {command['xpl_target']}." - title = f"Pool {dice_pool}, diff. {difficulty}" - if command["chronicles"]: - 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) - if autos != 0: - title += f", {__pluralize_autos(autos)}" - - # Let the user know if we aren't allowing botches - if command["no_botch"] and not command["chronicles"]: - title += ", no botch" specialty = command["specialty"] # Doubles 10s if set options["double_tens"] = __should_double(command, specialty is not None) - if not chronicles: + if not chronicles: # Regular CofD rolls *always* explode options["xpl_target"] = __explosion_target(command, specialty is not None) - # Perform rolls, format them, and figure out how many successes we have + # Finally, roll it! results = roll.Pool(dice_pool, difficulty, autos, will, chronicles, options) - # Add explosion info, if applicable - if results.explosions > 0: - explosions = "explosion" if results.explosions == 1 else "explosions" - title += f" (+{results.explosions} {explosions})" + # OUTPUT GENERATION comment = command["comment"] + # Compact formatting if compact: return __build_compact(results, specialty, comment) - # If not compact, put the results into an embed + # Title creation + title = f"Pool {dice_pool}, diff. {difficulty}" + if command["chronicles"]: + title = f"Pool {dice_pool}, {options['xpl_target']}-again" + + if autos != 0: + title += f", {__pluralize_autos(autos)}" + + # Let the user know if we aren't allowing botches + if command["no_botch"] and not command["chronicles"]: + title += ", no botch" + + # Inform the user of any explosions + if results.explosions > 0: + explosions = "explosion" if results.explosions == 1 else "explosions" + title += f" (+{results.explosions} {explosions})" + return __build_embed(ctx, command["override"], results, specialty, will, autos, title, comment) diff --git a/storyteller/roll/pool.py b/storyteller/roll/pool.py index 8df5467..ee427e8 100644 --- a/storyteller/roll/pool.py +++ b/storyteller/roll/pool.py @@ -75,6 +75,26 @@ def formatted_dice(self): return formatted + @property + def dice_emoji_names(self): + """Returns the emoji names based on the dice, difficulty, spec, etc.""" + names = [] + for die in self.dice: + name = "" + if die >= self.difficulty: + name = f"s{die}" + elif die > 1 or (self.ignore_ones and self.no_botch): + name = f"f{die}" + else: + name = "b1" + + if die == 10 and self.should_double: + name = f"s{name}" + + names.append(name) + return names + + def __calculate_successes(self) -> int: """ Sums the number of successes, taking into account Willpower use. @@ -128,23 +148,3 @@ def __roll(self, pool) -> list: dice.append(die) return sorted(dice, reverse=True) - - - @property - def dice_emoji_names(self): - """Returns the emoji names based on the dice, difficulty, spec, etc.""" - names = [] - for die in self.dice: - name = "" - if die >= self.difficulty: - name = f"s{die}" - elif die > 1 or (self.ignore_ones and self.no_botch): - name = f"f{die}" - else: - name = "b1" - - if die == 10 and self.should_double: - name = f"s{name}" - - names.append(name) - return names