예제 #1
0
    def consolidated(self):
        """
        Gets the most simplified version of the roll string. Consolidates totals and damage types together.

        Note that this modifies the result expression in place!

        >>> result = vroll("3d6[fire]+1d4[cold]")
        >>> str(result)
        '3d6 (3, 3, 2) [fire] + 1d4 (2) [cold] = `10`'
        >>> result.consolidated()
        '8 [fire] + 2 [cold]'

        :rtype: str
        """
        d20.utils.simplify_expr(self._roll.expr, ambig_inherit='left')
        return RerollableStringifier().stringify(self._roll.expr.roll)
예제 #2
0
    def run(self, autoctx):
        super(Roll, self).run(autoctx)
        d = autoctx.args.join('d', '+', ephem=True)
        maxdmg = autoctx.args.last('max', None, bool, ephem=True)
        mi = autoctx.args.last('mi', None, int)

        # add on combatant damage effects (#224)
        if autoctx.combatant:
            effect_d = '+'.join(autoctx.combatant.active_effects('d'))
            if effect_d:
                if d:
                    d = f"{d}+{effect_d}"
                else:
                    d = effect_d

        dice_ast = copy.copy(d20.parse(autoctx.parse_annostr(self.dice)))
        dice_ast = upcast_scaled_dice(self, autoctx, dice_ast)

        if not self.hidden:
            # -mi # (#527)
            if mi:
                dice_ast = d20.utils.tree_map(mi_mapper(mi), dice_ast)

            if d:
                d_ast = d20.parse(d)
                dice_ast.roll = d20.ast.BinOp(dice_ast.roll, '+', d_ast.roll)

            if maxdmg:
                dice_ast = d20.utils.tree_map(max_mapper, dice_ast)

        rolled = roll(dice_ast)
        if not self.hidden:
            autoctx.meta_queue(f"**{self.name.title()}**: {rolled.result}")

        simplified_expr = copy.deepcopy(rolled.expr)
        d20.utils.simplify_expr(simplified_expr)
        simplified = RerollableStringifier().stringify(simplified_expr.roll)
        autoctx.metavars[self.name] = simplified
        autoctx.metavars['lastRoll'] = rolled.total  # #1335
        return RollResult(result=rolled.total,
                          roll=rolled,
                          simplified=simplified,
                          hidden=self.hidden)
예제 #3
0
 def __init__(self, simplified_expr: d20.Expression):
     self._expr = simplified_expr
     self._str = RerollableStringifier().stringify(simplified_expr.roll)