Exemplo n.º 1
0
    def test_Weapon(self):
        player = Thief()
        player.strength_base = 17
        player.equip_weapon(weapons.Dagger())

        player.add_experience(14000)
        self.assertEqual(player.level, 5)
        player.equip_weapon(weapons.Dagger())
        self.assertEqual(3, player.determine_ability_modifier())
        player.equip_weapon(weapons.LongBow())
        self.assertEqual(0, player.determine_ability_modifier())

        #Test damage
        player.strength_base = 17  #+3 modifier
        player.equip_weapon(weapons.Dagger())  #1D6

        self.assertTrue(player.get_equipped_weapon().is_critical_strike(20))
        self.assertFalse(player.get_equipped_weapon().is_critical_strike(21))
        self.assertFalse(player.get_equipped_weapon().is_critical_strike(19))

        for _i in range(100):
            dmg = player.get_equipped_weapon()._normal_strike(player)  #1D6
            print("Player Weapon Damage: {}".format(dmg))
            self.assertGreaterEqual(dmg, 4)
            self.assertLessEqual(dmg, 9)
        #Critical strike
        for _i in range(100):
            dmg = player.get_equipped_weapon()._critical_strike(
                player)  #1D6 + 1D6 + 3*2
            print("Player Weapon Damage: {}".format(dmg))
            self.assertGreaterEqual(dmg, 8)
            self.assertLessEqual(dmg, 18)
Exemplo n.º 2
0
 def test_get_attack_type(self):
     self.assertEqual(weapons.Spear().get_attack_type(), 'spear')
     self.assertEqual(weapons.Dagger().get_attack_type(), 'dagger')
     self.assertEqual(weapons.LongSword().get_attack_type(), 'sword')
     self.assertEqual(weapons.ShortSword().get_attack_type(), 'sword')
     self.assertEqual(weapons.LongBow().get_attack_type(), 'arrow')
     self.assertEqual(weapons.ShortBow().get_attack_type(), 'arrow')
     self.assertEqual(weapons.Spear().get_attack_type(), 'spear')
Exemplo n.º 3
0
    def test_Attack(self):
        player = Thief()  #+2 attack bonus at level 1
        player.strength_base = 17  #+3 strength modifier
        player.equip_weapon(weapons.Dagger())  #+2 proficiency
        for _i in range(100):
            dice_roll = GameRules.roll_weapon_attack_score(player)
            #critical_strike = player.get_equipped_weapon().is_critical_strike(dice_roll.roll)
            print("Player Attack score: {}".format(dice_roll.total))
            if not player.get_equipped_weapon().is_critical_miss(
                    dice_roll.roll):
                self.assertGreaterEqual(dice_roll.total, 7)
            self.assertLessEqual(dice_roll.total, 27)

        player.add_bonus('POTION', PlayerAttributes.STRENGTH,
                         4)  #21 strength, +5 strength modifer
        for _i in range(100):
            dice_roll = GameRules.roll_weapon_attack_score(player)
            #critical_strike = player.get_equipped_weapon().is_critical_strike(dice_roll.roll)
            print("Player Attack score: {}".format(dice_roll.total))
            if not player.get_equipped_weapon().is_critical_miss(
                    dice_roll.roll):
                self.assertGreaterEqual(dice_roll.total, 9)
            self.assertLessEqual(dice_roll.total, 29)

        player.remove_bonus('POTION')
        player.equip_weapon(weapons.LongBow())  #0 proficiency
        player.dexterity_base = 0  #-5 dexterity modifier, +2 attack bonus
        for _i in range(100):
            dice_roll = GameRules.roll_weapon_attack_score(player)
            #critical_strike = player.get_equipped_weapon().is_critical_strike(dice_roll.roll)
            print("Player Attack score: {}".format(dice_roll.total))
            if not player.get_equipped_weapon().is_critical_miss(
                    dice_roll.roll):
                self.assertGreaterEqual(dice_roll.total, -2)
            self.assertLessEqual(dice_roll.total, 17)

        player.dexterity_base = 12  #+1 dexterity modifier
        for _i in range(100):
            dice_roll = GameRules.roll_weapon_attack_score(player)
            #critical_strike = player.get_equipped_weapon().is_critical_strike(dice_roll.total)
            print("Player Attack score: {}".format(dice_roll.total))
            if not player.get_equipped_weapon().is_critical_miss(
                    dice_roll.roll):
                self.assertGreaterEqual(dice_roll.total, 4)
            self.assertLessEqual(dice_roll.total, 23)
Exemplo n.º 4
0
    def __init__(self, player, load_from_state=False):
        super(CellRoom, self).__init__(player)

        self._add_action_override(Actions.OPEN,'loose_stone',new_action=Actions.PULL)
        self._add_action_override(Actions.PICKUP,'loose_stone',new_action=Actions.PULL)
        self._add_action_override(Actions.PULL,'door',new_action=Actions.OPEN)

        if not load_from_state:
            RoomOpenableItem(self, 'loose_stone', is_hidden=True)
            if player.is_mage: itms = [weapons.Staff(), armor.Robe()]
            elif player.is_thief: itms = [weapons.Dagger(), armor.LightArmor()]
            elif player.is_fighter: itms = [weapons.LongSword(), armor.HeavyArmor()]
            elif player.is_ranger: itms = [weapons.LongBow(), armor.LightArmor(), weapons.WoodArrow(10)]
            SearchableItem(self, 'straw', itms)
            Door(self, 'door', is_open=False, key_id=Keys.CELLROOM_DOOR_KEY, spell_resistance=5, lock_resistance=5)
            RoomItem(self, 'barred_window')
            self.add_floor_item(items.StaleBread())
            self._set_state('hidden_item_taken', False)
Exemplo n.º 5
0
 def test_is_throwable(self):
     self.assertTrue(weapons.Spear().is_throwable)
     self.assertFalse(weapons.ShortSword().is_throwable)
     self.assertTrue(weapons.Dagger().is_throwable)
     self.assertFalse(weapons.LongBow().is_throwable)
     self.assertFalse(weapons.IronArrow().is_throwable)