dice: more syncing from the fork
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
+12
-10
@@ -55,7 +55,9 @@ def cypher_roll(difficulty: Optional[int] = None, mod: int = 0, is_attack: bool
|
||||
return (roll, beats, difficulty <= beats if difficulty else None, effect, None, result_lvl, net_difficulty)
|
||||
|
||||
|
||||
def cypher_result(difficulty: int, modifier: int, is_attack: bool, stat: str, comment: str, ircify: bool = False):
|
||||
def cypher_result(difficulty: Optional[int] = None, mod: int = 0, is_attack: bool = False, comment: str = '',
|
||||
stat: str = 'Unknown', ircify: bool = False) \
|
||||
-> Tuple[int, Optional[int], Optional[bool], Optional[str], Optional[str], int, Optional[int], str]:
|
||||
"""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:
|
||||
@@ -65,7 +67,7 @@ def cypher_result(difficulty: int, modifier: int, is_attack: bool, stat: str, co
|
||||
|
||||
# roll it
|
||||
result, beats, success, effect, neg_effect, result_lvl, diff_level = cypher_roll(
|
||||
difficulty=difficulty, mod=modifier, is_attack=is_attack
|
||||
difficulty=difficulty, mod=mod, is_attack=is_attack,
|
||||
)
|
||||
if success is not None:
|
||||
# we know the difficulty so we should always know the success/failure
|
||||
@@ -96,10 +98,10 @@ def cypher_result(difficulty: int, modifier: int, is_attack: bool, stat: str, co
|
||||
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}"
|
||||
if mod > 0:
|
||||
modded_diff = f"{difficulty}+{mod}"
|
||||
elif mod < 0:
|
||||
modded_diff = f"{difficulty}{mod}"
|
||||
else:
|
||||
modded_diff = str(difficulty)
|
||||
|
||||
@@ -122,10 +124,10 @@ def cypher_result(difficulty: int, modifier: int, is_attack: bool, stat: str, co
|
||||
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}"
|
||||
if mod > 0:
|
||||
modded_diff = f"-{mod}"
|
||||
elif mod < 0:
|
||||
modded_diff = f"+{-1 * mod}"
|
||||
else:
|
||||
modded_diff = ""
|
||||
|
||||
|
||||
+4
-4
@@ -129,8 +129,8 @@ class DiceRoller(object):
|
||||
comment = f"{p[5].strip()} {p[6].strip()}"
|
||||
else:
|
||||
comment = f"{p[5].strip()}"
|
||||
_, _, _, _, _, _, _, p[0] = dice.lib.cypher_result(difficulty, mod, is_attack, stat=stat,
|
||||
comment=comment, ircify=self.ircify)
|
||||
_, _, _, _, _, _, _, p[0] = dice.lib.cypher_result(difficulty=difficulty, mod=mod, is_attack=is_attack,
|
||||
stat=stat, comment=comment, ircify=self.ircify)
|
||||
output = p[0]
|
||||
|
||||
def p_cypher_graduated_task_roll(self, p):
|
||||
@@ -145,8 +145,8 @@ class DiceRoller(object):
|
||||
comment = f"{p[3].strip()} {p[4].strip()}"
|
||||
else:
|
||||
comment = f"{p[3].strip()}"
|
||||
_, _, _, _, _, _, _, p[0] = dice.lib.cypher_result(None, mod, is_attack, stat=stat,
|
||||
comment=comment, ircify=self.ircify)
|
||||
_, _, _, _, _, _, _, p[0] = dice.lib.cypher_result(difficulty=None, mod=mod, is_attack=is_attack,
|
||||
stat=stat, comment=comment, ircify=self.ircify)
|
||||
output = p[0]
|
||||
|
||||
def p_comment(self, p):
|
||||
|
||||
@@ -132,5 +132,6 @@ class CypherRollStringTestCase(TestCase):
|
||||
def test_simple_result(self):
|
||||
"""Test the basics of string output."""
|
||||
with mock.patch('random.SystemRandom.randint', return_value=10):
|
||||
_, _, _, _, _, _, _, result = dice.lib.cypher_result(3, 0, False, "Might", "")
|
||||
_, _, _, _, _, _, _, result = dice.lib.cypher_result(difficulty=3, mod=0, stat="Might",
|
||||
comment="")
|
||||
self.assertEqual(result, "task succeeded! (res. 3 (d20=10) vs. Might difficulty 3 (3))")
|
||||
|
||||
Reference in New Issue
Block a user