cypher: distinguish between a task roll and an attack roll

attack = A, otherwise the same options as with a generic task (= T)

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
2025-02-08 23:51:00 -06:00
parent 3b7c871a94
commit 6d8ba18380
4 changed files with 35 additions and 12 deletions

View File

@@ -13,7 +13,7 @@ from ircbot.lib import Plugin
logger = logging.getLogger(__name__)
CYPHER_ROLL_REGEX = r'(T(?P<difficulty>\d+))?(?P<mods>(?:\s*(-|\+)\d+)*)\s*(?P<comment>.*)?'
CYPHER_ROLL_REGEX = r'((?P<type>A|T)(?P<difficulty>\d+))?(?P<mods>(?:\s*(-|\+)\d+)*)\s*(?P<comment>.*)?'
CYPHER_COMMAND_REGEX = r'^!cypher\s+(' + CYPHER_ROLL_REGEX + ')'
@@ -52,8 +52,9 @@ class Dice(Plugin):
task_group = re.search(CYPHER_ROLL_REGEX, task, re.IGNORECASE)
difficulty = int(task_group.group('difficulty')) if task_group.group('difficulty') else None
mods = task_group.group('mods')
is_attack = True if task_group.group('type') and task_group.group('type').upper() == 'A' else False
comment = task_group.group('comment')
result, beats, success, effect = cypher_roll(difficulty=difficulty, mods=mods)
result, beats, success, effect = cypher_roll(difficulty=difficulty, mods=mods, is_attack=is_attack)
if success is not None:
if success:
@@ -81,7 +82,8 @@ class Dice(Plugin):
if comment:
return self.bot.reply(event, f"{nick}: {comment} {result_str} {detail_str}")
else:
return self.bot.reply(event, f"{nick}: your check {result_str} {detail_str}")
type_str = 'attack' if is_attack else 'check'
return self.bot.reply(event, f"{nick}: your {type_str} {result_str} {detail_str}")
def handle_random(self, connection, event, match):
"""Handle the !random command which picks an item from a list."""

View File

@@ -6,12 +6,13 @@ import numexpr
rand = random.SystemRandom()
def cypher_roll(difficulty=None, mods=0):
def cypher_roll(difficulty=None, mods=0, is_attack=False):
"""Make a Cypher System roll.
Args:
difficulty: the original difficulty to beat; if provided, success or failure is indicated in the results
mods: eases(-) and hindrances(+) to apply to the check, as a string (e.g. '-3+1')
is_attack: if the roll is an attack (in which case the damage-only effects are included)
Returns:
tuple of:
- the result on the d20
@@ -24,9 +25,9 @@ def cypher_roll(difficulty=None, mods=0):
return (roll, None, False if difficulty else None, 'a GM intrusion')
effect = None
if roll == 17:
if roll == 17 and is_attack:
effect = '+1 damage'
elif roll == 18:
elif roll == 18 and is_attack:
effect = '+2 damage'
elif roll == 19:
effect = 'a minor effect'