handle empty string comments in cypher results
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
+10
-4
@@ -4,7 +4,7 @@ import random
|
||||
rand = random.SystemRandom()
|
||||
|
||||
|
||||
def cypher_roll(difficulty=None, mod=0, is_attack=False):
|
||||
def cypher_roll(difficulty: int = None, mod: int = 0, is_attack: bool = False):
|
||||
"""Make a Cypher System roll.
|
||||
|
||||
Args:
|
||||
@@ -49,8 +49,14 @@ 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):
|
||||
def cypher_result(difficulty: int, modifier: int, is_attack: bool, stat: str, comment: str, ircify: bool = False):
|
||||
"""Turn the results of a Cypher System roll into a display string."""
|
||||
# tweak the comment to show task/attack in cases of empty string
|
||||
if comment:
|
||||
display_comment = comment
|
||||
else:
|
||||
display_comment = "attack" if is_attack else "task"
|
||||
|
||||
result, beats, success, effect, neg_effect, result_lvl, diff_level = cypher_roll(
|
||||
difficulty=difficulty, mod=modifier, is_attack=is_attack
|
||||
)
|
||||
@@ -95,7 +101,7 @@ def cypher_result(difficulty, modifier, is_attack, stat, comment, ircify=False):
|
||||
else:
|
||||
detail_str = f"(res. {result_lvl} (d20={result}) vs. {stat} diff. {diff_level} ({modded_diff}))"
|
||||
|
||||
return f"{comment} {result_str} {detail_str}"
|
||||
return f"{display_comment} {result_str} {detail_str}"
|
||||
else:
|
||||
# we don't know the difficulty, so don't know success or not
|
||||
if beats is not None:
|
||||
@@ -123,7 +129,7 @@ def cypher_result(difficulty, modifier, is_attack, stat, comment, ircify=False):
|
||||
else:
|
||||
detail_str = f"(res. {result_lvl}{modded_diff} (d20={result}) vs. {stat})"
|
||||
|
||||
return f"{comment} {result_str} {detail_str}"
|
||||
return f"{display_comment} {result_str} {detail_str}"
|
||||
|
||||
|
||||
def generic_roll(keep, dice, size):
|
||||
|
||||
@@ -88,6 +88,12 @@ class DiceLibTestCase(TestCase):
|
||||
result = dice.lib.cypher_roll(mod=2)
|
||||
self.assertEqual(result, (10, 1, None, None, None, 3, None))
|
||||
|
||||
def test_cypher_result(self):
|
||||
"""Test the Cypher result string generation."""
|
||||
with mock.patch('random.SystemRandom.randint', return_value=10):
|
||||
result = dice.lib.cypher_result(3, 0, False, "Might", "")
|
||||
self.assertEqual(result, "task succeeded! (res. 3 (d20=10) vs. Might diff. 3 (3))")
|
||||
|
||||
def test_reaction_roll(self):
|
||||
"""Roll possible reactions."""
|
||||
with mock.patch('random.SystemRandom.randint', return_value=1):
|
||||
|
||||
Reference in New Issue
Block a user