From d9c2ae4068dcf393369bcc2fa4b8b1a2ddccd739 Mon Sep 17 00:00:00 2001 From: xenofem Date: Mon, 3 Apr 2023 20:39:42 -0400 Subject: [PATCH] rollcake: fate dice --- .../zulip_bots/bots/rollcake/rollcake.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/zulip_bots/zulip_bots/bots/rollcake/rollcake.py b/zulip_bots/zulip_bots/bots/rollcake/rollcake.py index f3e694c..9b676e3 100644 --- a/zulip_bots/zulip_bots/bots/rollcake/rollcake.py +++ b/zulip_bots/zulip_bots/bots/rollcake/rollcake.py @@ -16,14 +16,34 @@ USAGE = '''@ me to roll RPG dice. Examples: @**Rollcake** void 3 *(Voidheart Symphony city roll, stress gauge 3: 2d6, check if either/both are above 3)* + +@**Rollcake** fate 1 +*(Fate, rating +1: 4 fate dice, add +1 to total)* ''' PBTA_RE = re.compile(r'(pbta|apoc(alypse)?|void(heart)? castle)\s+(?P[-+]?[0-9])(\s+(?Padv|dis))?') FITD_RE = re.compile(r'(fitd|forged)\s+(?P[0-9])\b') SBR_RE = re.compile(r'(sbr|res(istance)?)\s+(?P[0-9])(\s+(?Prisk|dang))?') VOID_RE = re.compile(r'(void(heart)?( city)?)\s+(?P[0-6])(\s+(?Padv|dis))?') +FATE_RE = re.compile(r'fate\s+(?P[-+]?[0-9])') DICE_RE = re.compile(r'\b(?P[0-9]*)d(?P[0-9]+)\s*(?P[-+][0-9]+)?') +FATE_LADDER = [ + 'Horrifying', + 'Catastrophic', + 'Terrible', + 'Poor', + 'Mediocre', + 'Average', + 'Fair', + 'Good', + 'Great', + 'Superb', + 'Fantastic', + 'Epic', + 'Legendary', +] + def roll(count, sides): return [random.randint(1, sides) for i in range(count)] @@ -154,6 +174,25 @@ def handle_roll(content): ) ) + fate = FATE_RE.search(content) + if fate: + rating = int(fate.group('rating') or '0') + results = [random.randint(-1, 1) for i in range(4)] + total = sum(results) + rating + ladder_entry = total + 4 + if ladder_entry >= 0 and ladder_entry < len(FATE_LADDER): + effort = FATE_LADDER[ladder_entry] + else: + effort = '' + return '**{:+d}{}**\nRolls: {}'.format( + total, + ' ' + effort if effort else '', + ', '.join( + '`{}`'.format('+' if d == 1 else '-' if d == -1 else ' ') + for d in results + ) + ) + return USAGE class RollcakeHandler(object):