Esempio n. 1
0
    def testRandom(self):
        class Strategy(object):
            def roll(self):
                return 123

        a = Abilities()
        a.random(Strategy())
        for name, value in a:
            self.assertIn(name, Abilities.all)
            self.assertEquals(123, value)
Esempio n. 2
0
 def dump(self):
     print 'Monster: ' + self.name
     print 'HP: ' + str(self.hp)
     print 'AC: ' + str(self.ac)
     print 'Initialive: ' + str(self.initiative)
     print 'Damage: ' + str(self.damage)
     print 'Speed: ' + str(self.speed)
     print 'Abilities:'
     for name in Abilities.all:
         print '  ' + name + ': ' + str(self.abilities[name]) + ' / ' + str(
             Abilities.modifier(self.abilities[name]))
Esempio n. 3
0
 def testModifier(self):
     self.assertEquals(-5, Abilities.modifier(0))
     self.assertEquals(-5, Abilities.modifier(1))
     self.assertEquals(-3, Abilities.modifier(5))
     self.assertEquals(0, Abilities.modifier(10))
     self.assertEquals(4, Abilities.modifier(19))
     self.assertEquals(5, Abilities.modifier(20))
Esempio n. 4
0
    def _doAttack(self, me, other, weapon=None):

        if weapon:
            if not isinstance(weapon, Weapon):
                raise ValueError('You can only attack with weapons')
            ability = Abilities.STRENGTH if not weapon.isRanged else Abilities.DEXTERITY
            modifier = Abilities.modifier(me.abilities[ability])
            threatRange = weapon.threatRange
            damages = weapon.damage
            criticalDmg = weapon.critical
        else:
            modifier = 0
            threatRange = 20
            damages = me.damage
            criticalDmg = 2

        print '--'
        print '-- %s attacks %s' % (me.name, other.name)

        (touch, critical, critical_miss) = self.touch(threatRange, modifier,
                                                      other.ac)

        if critical_miss:
            print '-- Critical miss'
            return

        if not touch:
            print '-- Miss'
            return

        dmg = damages.calc()
        totalDmg = dmg + modifier
        if not critical:
            print '-- Damage dealt: %s + %s = %s' % (dmg, modifier, totalDmg)
        else:
            totalDmg *= criticalDmg
            print '-- Critical damage dealt: %s * (%s + %s) = %s' % (
                criticalDmg, dmg, modifier, totalDmg)

        other.hp -= totalDmg

        if other.hp > 0:
            print '-- %s HP: %s' % (str(other.name), other.hp)
        else:
            print '-- %s is dead' % other.name
Esempio n. 5
0
 def __init__(self,
              name,
              damage,
              abilityScores=False,
              initiative=1,
              speed=1,
              ac=1,
              description='',
              hp=1,
              firstStrike=False):
     super(Monster, self).__init__(name,
                                   abilityScores=abilityScores,
                                   initiative=initiative,
                                   ac=ac,
                                   hp=hp,
                                   firstStrike=firstStrike)
     self.description = description
     self.damage = damage
     self.abilities = Abilities(abilityScores)
     self.speed = speed
Esempio n. 6
0
 def testInit(self):
     a = Abilities()
     for name in Abilities.all:
         self.assertEquals(0, a[name])
Esempio n. 7
0
 def testRandomWrongStrategy(self):
     with self.assertRaises(ValueError):
         a = Abilities()
         a.random(self)
Esempio n. 8
0
 def testIter(self):
     a = Abilities([123, 123, 123, 123, 123, 123])
     for name, value in a:
         self.assertIn(name, Abilities.all)
         self.assertEquals(123, value)
Esempio n. 9
0
 def testSetItemError(self):
     with self.assertRaises(IndexError):
         a = Abilities()
         a['foobar'] = 0
Esempio n. 10
0
 def testGetSetItem(self):
     a = Abilities()
     self.assertEquals(0, a['Strength'])
     a['Strength'] = 10
     self.assertEquals(10, a['Strength'])
Esempio n. 11
0
 def testKeys(self):
     a = Abilities()
     self.assertItemsEqual(a.keys(), Abilities.all)
Esempio n. 12
0
 def testInitWithInvalidDefaults(self):
     with self.assertRaises(ValueError):
         a = Abilities([1])
Esempio n. 13
0
 def testInitWithDefaults(self):
     a = Abilities(scores=[1, 2, 3, 4, 5, 6])
     counter = 1
     for name in Abilities.all:
         self.assertEquals(counter, a[name])
         counter += 1