Exemplo n.º 1
0
 def max_hp(self, value):
     try:
         self._max_hp = int(value)
     except ValueError:
         # we have an expression for max hp, so roll it
         self._max_hp = dice.roll_dice_expr(value)
     # setting max_hp for the first time? we should set cur_hp too
     if self.cur_hp is None:
         self.cur_hp = self._max_hp
Exemplo n.º 2
0
 def do_command(self, *args):
     results = []
     for dice_expr in args:
         try:
             results.append(str(roll_dice_expr(dice_expr)))
         except ValueError:
             print(f"Invalid dice expression: {dice_expr}")
             return
     print(', '.join(results))
Exemplo n.º 3
0
def convert_to_int_or_dice_expr(value):
    try:
        value = int(value)
    except ValueError:
        if 'd' in value:
            try:
                value = roll_dice_expr(value)
            except ValueError:
                value = None
        else:
            value = None
    return value
Exemplo n.º 4
0
    def _determine_count(self, group, monster_groups):
        try:
            count = int(group['count'])
        except ValueError:
            if dice_expr.match(group['count']):
                if self.count_resolver:
                    count = self.count_resolver(group['count'],
                                                group['monster'])
                else:
                    count = roll_dice_expr(group['count'])
            elif group['count'] in monster_groups:
                count = len(monster_groups[group['count']])
            elif '+' in group['count']:
                keys = [x.strip() for x in group['count'].split('+')]
                count = sum([
                    len(monster_groups[x]) for x in keys if x in monster_groups
                ])
            else:
                raise ValueError(f"Invalid monster count: {group['count']}")

        return count