How to use the d20.ast.BinOp function in d20

To help you get started, we’ve selected a few d20 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github avrae / avrae / cogs5e / models / automation.py View on Github external
level_dice = 3
            else:
                level_dice = 4

            def mapper(node):
                if isinstance(node, d20.ast.Dice):
                    node.num = level_dice
                return node

            dice_ast = d20.utils.tree_map(mapper, dice_ast)

        if effect.higher and not autoctx.get_cast_level() == autoctx.spell.level:
            higher = effect.higher.get(str(autoctx.get_cast_level()))
            if higher:
                higher_ast = d20.parse(higher)
                dice_ast.roll = d20.ast.BinOp(dice_ast.roll, '+', higher_ast.roll)

    return dice_ast
github avrae / avrae / cogs5e / models / automation.py View on Github external
if d:
                    d = f"{d}+{effect_d}"
                else:
                    d = effect_d

        dice_ast = copy.copy(d20.parse(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}")

        d20.utils.simplify_expr(rolled.expr)
        autoctx.metavars[self.name] = RerollableStringifier().stringify(rolled.expr.roll)