Exemple #1
0
    def value(self, advantage=False, disadvantage=False) -> str:
        roll = h.d20_roll(advantage, disadvantage,
                          self.character.bonuses.get('lucky', False))
        proficiency = self.character.proficiency

        mod = self.modifiers.get_value()
        return verbose(roll, modifiers=mod)
Exemple #2
0
 def do_attack(self):
     adv = self.advantage.get()
     dis = self.disadvantage.get()
     attack = h.d20_roll(adv, dis)
     attack += d.compile(self.attack.get())
     attroll = d.verbose(attack)
     ###
     if attack.is_critical():
         attroll = 'Critical Hit'
         damresult = d.verbose(self.damage.get(), d.Mode.CRIT)
     elif attack.is_fail():
         attroll = 'Critical Miss'
         damresult = '0'
     else:
         damresult = d.verbose(self.damage.get())
     ###
     self.attackResult['text'] = 'Attack result: ' + attroll
     self.damageResult['text'] = 'Damage done: ' + damresult
 def test_verbose_crit(self):
     expected = '{}+2 = 26'.format(Roll([4, 4, 4, 4, 4, 4], 4))
     self.assertEqual(verbose('3d4+2', mode=Mode.CRIT), expected)
 def test_verbose_wrong_type(self):
     with self.assertRaises(InputTypeError):
         verbose([40, 2])
 def test_verbose_max(self):
     expected = '{}+2 = 20'.format(Roll([6, 6, 6], 6))
     self.assertEqual(verbose('3d6+2', mode=Mode.MAX), expected)
 def test_verbose_average(self):
     expected = '{}+2 = 9.5'.format(Roll([2.5, 2.5, 2.5], 4))
     self.assertEqual(verbose('3d4+2', mode=Mode.AVERAGE), expected)
 def test_verbose_modifier(self):
     expected = '{roll}+2+1 = 15'.format(roll=Roll([4, 4, 4], 4))
     self.assertEqual(verbose('3d4 + 2', modifiers=1), expected)
 def test_verbose(self):
     expected = '{roll}+2 = 14'.format(roll=Roll([4, 4, 4], 4))
     self.assertEqual(verbose('3d4 + 2'), expected)
Exemple #9
0
        "(1d4-1)|(1d3-2>0)",
        "1dc8+1dc4+3",
        "1dm6+1d6",
        "2d4c2",
        "2da6",
        "3da6",
        "2d10%2",
        "1d4=4|1d4=3",
        "1d8>=6",
        "10d8r>4",
        "10d8R>4",
        "10d[3,3,3,5]",
        "10d[3, 3, 3, 5]",
        "15d6t5",
        "15d6T1",
    ]
    for expr in testCases:
        tree = EvalTree(expr)
        print('EVALUATING ' + expr)
        print('EVALUATING USING TREE DIRECTLY')
        print(tree.evaluate())
        print('EVALUATING USING ROLL FUNCTION')
        print(basic(expr))
        print('EVALUATING USING ROLL FUNCTION IN VERBOSE MODE')
        print(verbose(expr))
        print('EVALUATING USING ROLL FUNCTION AND MODIFIER')
        print(basic(expr, modifiers=3))
        print('EVALUATING USING ROLL FUNCTION IN VERBOSE MODE AND MODIFIER')
        print(verbose(expr, modifiers=3))
        print()