Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if __name__ == '__main__':
import traceback
resists = Resistances(resist=[Resistance('resist', ['magical']), Resistance('both')],
immune=[Resistance('immune'), Resistance('this', only=['magical'])],
vuln=[Resistance('vuln'), Resistance('both')],
neutral=[Resistance('neutral')])
while True:
try:
result = d20.roll(input())
print(str(result))
do_resistances(result.expr, resists)
print(d20.MarkdownStringifier().stringify(result.expr))
except Exception as e:
traceback.print_exc()
def __init__(self, result):
"""
:type result: d20.RollResult
"""
self.dice = d20.MarkdownStringifier().stringify(result.expr.roll)
self.total = result.total
self.full = str(result)
self.result = result
self.raw = result.expr
self._roll = result
import d20
class VerboseMDStringifier(d20.MarkdownStringifier):
def _str_expression(self, node):
return f"**{node.comment or 'Result'}**: {self._stringify(node.roll)}\n" \
f"**Total:** {int(node.total)}"
class PersistentRollContext(d20.RollContext):
"""
A roll context that tracks lifetime rolls as well as individual rolls.
"""
def __init__(self, max_rolls=1000, max_total_rolls=None):
"""
:param max_rolls: The maximum number of rolls allowed in an individual roll.
:param max_total_rolls: The maximum number of rolls allowed throughout this object's lifetime.
"""
super().__init__(max_rolls)
elif transforms:
for frm in transforms:
autoctx.meta_queue(f"**Damage Change**: {frm} > {transforms[frm]}")
# evaluate resistances
do_resistances(dmgroll.expr, resistances, always, transforms)
# generate output
result = d20.MarkdownStringifier().stringify(dmgroll.expr)
# output
if not hide:
autoctx.queue(f"**{roll_for}**: {result}")
else:
d20.utils.simplify_expr(dmgroll.expr)
autoctx.queue(f"**{roll_for}**: {d20.MarkdownStringifier().stringify(dmgroll.expr)}")
autoctx.add_pm(str(autoctx.ctx.author.id), f"**{roll_for}**: {result}")
autoctx.target.damage(autoctx, dmgroll.total, allow_overheal=self.overheal)
# return metadata for scripting
return {'damage': f"**{roll_for}**: {result}", 'total': dmgroll.total, 'roll': dmgroll}