Beispiel #1
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]))
Beispiel #2
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))
Beispiel #3
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