Skip to content

Commit

Permalink
Pool roll refactor, pt. 3. Closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
tiltowait committed May 11, 2021
1 parent 18955c8 commit 4c47b0d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
38 changes: 21 additions & 17 deletions storyteller/parse/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
40 changes: 20 additions & 20 deletions storyteller/roll/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

0 comments on commit 4c47b0d

Please sign in to comment.