move the cypher roll result code into a common place
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
+77
@@ -49,6 +49,83 @@ def cypher_roll(difficulty=None, mod=0, is_attack=False):
|
||||
return (roll, beats, difficulty <= beats if difficulty else None, effect, None, result_lvl, net_difficulty)
|
||||
|
||||
|
||||
def cypher_result(difficulty, modifier, is_attack, stat, comment, ircify=False):
|
||||
"""Turn the results of a Cypher System roll into a display string."""
|
||||
result, beats, success, effect, neg_effect, result_lvl, diff_level = cypher_roll(
|
||||
difficulty=difficulty, mod=modifier, is_attack=is_attack
|
||||
)
|
||||
if success is not None:
|
||||
# we know the difficulty so we should always know the success/failure
|
||||
# TODO: less nested ifs
|
||||
if success:
|
||||
if ircify:
|
||||
style_prefix = '9'
|
||||
style_suffix = ''
|
||||
else:
|
||||
style_prefix = ''
|
||||
style_suffix = ''
|
||||
|
||||
if effect:
|
||||
result_str = f"{style_prefix}succeeded, with {effect}!{style_suffix}"
|
||||
else:
|
||||
result_str = f"{style_prefix}succeeded!{style_suffix}"
|
||||
else:
|
||||
if ircify:
|
||||
style_prefix = '4'
|
||||
style_suffix = ''
|
||||
else:
|
||||
style_prefix = ''
|
||||
style_suffix = ''
|
||||
|
||||
if neg_effect:
|
||||
result_str = f"{style_prefix}failed, with {neg_effect}!{style_suffix}"
|
||||
else:
|
||||
result_str = f"{style_prefix}failed.{style_suffix}"
|
||||
|
||||
# show the adjusted difficulty
|
||||
if modifier > 0:
|
||||
modded_diff = f"{difficulty}+{modifier}"
|
||||
elif modifier < 0:
|
||||
modded_diff = f"{difficulty}{modifier}"
|
||||
else:
|
||||
modded_diff = difficulty
|
||||
|
||||
if ircify:
|
||||
detail_str = f"14(res. {result_lvl} (d20={result}) vs. {stat} diff. {diff_level} ({modded_diff}))"
|
||||
else:
|
||||
detail_str = f"(res. {result_lvl} (d20={result}) vs. {stat} diff. {diff_level} ({modded_diff}))"
|
||||
|
||||
return f"{comment} {result_str} {detail_str}"
|
||||
else:
|
||||
# we don't know the difficulty, so don't know success or not
|
||||
if beats is not None:
|
||||
if effect:
|
||||
result_str = f"beats a difficulty {beats} task, with {effect}!"
|
||||
else:
|
||||
result_str = f"beats a difficulty {beats} task."
|
||||
else:
|
||||
# this can only happen on an intrusion
|
||||
if ircify:
|
||||
result_str = f"4beats nothing, with {neg_effect}!"
|
||||
else:
|
||||
result_str = f"beats nothing, with {neg_effect}!"
|
||||
|
||||
# show the adjusted difficulty
|
||||
if modifier > 0:
|
||||
modded_diff = f"-{modifier}"
|
||||
elif modifier < 0:
|
||||
modded_diff = f"+{-1 * modifier}"
|
||||
else:
|
||||
modded_diff = ""
|
||||
|
||||
if ircify:
|
||||
detail_str = f"14(res. {result_lvl}{modded_diff} (d20={result}) vs. {stat})"
|
||||
else:
|
||||
detail_str = f"(res. {result_lvl}{modded_diff} (d20={result}) vs. {stat})"
|
||||
|
||||
return f"{comment} {result_str} {detail_str}"
|
||||
|
||||
|
||||
def reaction_roll():
|
||||
"""Make a reaction roll, which gives some oracle-like randomness to uncertain situations (for solo play or similar).
|
||||
|
||||
|
||||
+2
-80
@@ -225,53 +225,7 @@ class DiceRoller(object):
|
||||
comment = f"{p[5].strip()} {p[6].strip()}"
|
||||
else:
|
||||
comment = f"{p[5].strip()}"
|
||||
result, beats, success, effect, neg_effect, result_lvl, diff_level = dice.lib.cypher_roll(difficulty=difficulty,
|
||||
mod=mod,
|
||||
is_attack=is_attack)
|
||||
|
||||
# sanity check; we know the difficulty so we should always know the success/failure
|
||||
assert success is not None
|
||||
|
||||
# TODO: less nested ifs
|
||||
if success:
|
||||
if self.ircify:
|
||||
style_prefix = '9'
|
||||
style_suffix = ''
|
||||
else:
|
||||
style_prefix = ''
|
||||
style_suffix = ''
|
||||
|
||||
if effect:
|
||||
result_str = f"{style_prefix}succeeded, with {effect}!{style_suffix}"
|
||||
else:
|
||||
result_str = f"{style_prefix}succeeded!{style_suffix}"
|
||||
else:
|
||||
if self.ircify:
|
||||
style_prefix = '4'
|
||||
style_suffix = ''
|
||||
else:
|
||||
style_prefix = ''
|
||||
style_suffix = ''
|
||||
|
||||
if neg_effect:
|
||||
result_str = f"{style_prefix}failed, with {neg_effect}!{style_suffix}"
|
||||
else:
|
||||
result_str = f"{style_prefix}failed.{style_suffix}"
|
||||
|
||||
# show the adjusted difficulty
|
||||
if mod > 0:
|
||||
modded_diff = f"{difficulty}+{mod}"
|
||||
elif mod < 0:
|
||||
modded_diff = f"{difficulty}{mod}"
|
||||
else:
|
||||
modded_diff = difficulty
|
||||
|
||||
if self.ircify:
|
||||
detail_str = f"14(res. {result_lvl} (d20={result}) vs. {stat} diff. {diff_level} ({modded_diff}))"
|
||||
else:
|
||||
detail_str = f"(res. {result_lvl} (d20={result}) vs. {stat} diff. {diff_level} ({modded_diff}))"
|
||||
|
||||
p[0] = f"{comment} {result_str} {detail_str}"
|
||||
p[0] = dice.lib.cypher_result(difficulty, mod, is_attack, stat=stat, comment=comment, ircify=self.ircify)
|
||||
output = p[0]
|
||||
|
||||
def p_cypher_graduated_task_roll(self, p):
|
||||
@@ -286,39 +240,7 @@ class DiceRoller(object):
|
||||
comment = f"{p[3].strip()} {p[4].strip()}"
|
||||
else:
|
||||
comment = f"{p[3].strip()}"
|
||||
result, beats, success, effect, neg_effect, result_lvl, diff_level = dice.lib.cypher_roll(difficulty=None,
|
||||
mod=mod,
|
||||
is_attack=is_attack)
|
||||
|
||||
# sanity check; we don't know the difficulty, so don't know success or not
|
||||
assert success is None
|
||||
|
||||
if beats is not None:
|
||||
if effect:
|
||||
result_str = f"beats a difficulty {beats} task, with {effect}!"
|
||||
else:
|
||||
result_str = f"beats a difficulty {beats} task."
|
||||
else:
|
||||
# this can only happen on an intrusion
|
||||
if self.ircify:
|
||||
result_str = f"4beats nothing, with {neg_effect}!"
|
||||
else:
|
||||
result_str = f"beats nothing, with {neg_effect}!"
|
||||
|
||||
# show the adjusted difficulty
|
||||
if mod > 0:
|
||||
modded_diff = f"-{mod}"
|
||||
elif mod < 0:
|
||||
modded_diff = f"+{-1 * mod}"
|
||||
else:
|
||||
modded_diff = ""
|
||||
|
||||
if self.ircify:
|
||||
detail_str = f"14(res. {result_lvl}{modded_diff} (d20={result}) vs. {stat})"
|
||||
else:
|
||||
detail_str = f"(res. {result_lvl}{modded_diff} (d20={result}) vs. {stat})"
|
||||
|
||||
p[0] = f"{comment} {result_str} {detail_str}"
|
||||
p[0] = dice.lib.cypher_result(None, mod, is_attack, stat=stat, comment=comment, ircify=self.ircify)
|
||||
output = p[0]
|
||||
|
||||
def p_comment(self, p):
|
||||
|
||||
Reference in New Issue
Block a user