Пример #1
0
    def test_pickup(self):
        player = players.Thief()

        #If scroll learn it
        #If weapon equip it - if no weapon equipped and proficient
        #If armor equip it - if no armor equipped and proficient

        #Scroll
        scroll = MockHelper.get_mock_scroll()
        player.learn_spell = Mock(return_value=True)
        self.assertTrue(player.pickup(scroll))
        player.learn_spell.assert_called_once()

        #Weapon
        weapon = MockHelper.get_mock_weapon()
        weapon.get_modifier_value = Mock(return_value=0)

        #Not proficient
        player.character_class.is_weapon_proficient = Mock(return_value=False)
        self.assertFalse(player.has_weapon_equipped())
        self.assertTrue(player.pickup(weapon))
        self.assertFalse(player.has_weapon_equipped())
        self.assertNotEqual(player.get_equipped_weapon(), weapon)

        #Proficient
        player.character_class.is_weapon_proficient = Mock(return_value=True)
        self.assertFalse(player.has_weapon_equipped())
        self.assertTrue(player.pickup(weapon))
        self.assertTrue(player.has_weapon_equipped())
        self.assertEqual(player.get_equipped_weapon(), weapon)

        #Already equipped
        another_weapon = MockHelper.get_mock_weapon()
        self.assertTrue(player.pickup(another_weapon))
        self.assertTrue(player.has_weapon_equipped())
        self.assertEqual(player.get_equipped_weapon(), weapon)

        #Armor
        myarmor = MockHelper.get_mock_armor()
        myarmor.get_modifier_value = Mock(return_value=0)

        #Not proficient
        player.character_class.is_armor_proficient = Mock(return_value=False)
        self.assertFalse(player.has_armor_equipped())
        self.assertTrue(player.pickup(myarmor))
        self.assertFalse(player.has_armor_equipped())
        self.assertNotEqual(player.get_equipped_armor(), myarmor)

        #Proficient
        player.character_class.is_armor_proficient = Mock(return_value=True)
        self.assertFalse(player.has_armor_equipped())
        self.assertTrue(player.pickup(myarmor))
        self.assertTrue(player.has_armor_equipped())
        self.assertEqual(player.get_equipped_armor(), myarmor)

        #Already equipped
        another_armor = MockHelper.get_mock_armor()
        self.assertTrue(player.pickup(another_armor))
        self.assertTrue(player.has_armor_equipped())
        self.assertEqual(player.get_equipped_armor(), myarmor)
Пример #2
0
    def test_equip_weapon(self):
        #Check default armor
        player = players.Thief()
        self.assertEqual(player.get_equipped_weapon(), player.default_weapon)

        #Equip something that isn't armor
        fake_weapon = Mock()
        self.assertFalse(player.equip_weapon(fake_weapon))

        #Not carrying
        good_weapon = MockHelper.get_mock_weapon()
        player.is_carrying = Mock(return_value=False)
        self.assertFalse(player.equip_weapon(good_weapon))
        player.is_carrying.assert_called_once()

        #Equip Weapon
        player.is_carrying = Mock(return_value=True)
        self.assertTrue(player.equip_weapon(good_weapon))

        #Equip None, should be default
        try:
            player.equip_weapon(None)
        except AttributeError:
            self.assertTrue(True, 'None is not valid')
        self.assertEqual(player.get_equipped_weapon(), good_weapon)
Пример #3
0
    def test_throw(self):
        player = players.Thief()
        rat = players.Rat()
        dagger = MockHelper.get_mock_weapon()
        not_a_dagger = MockHelper.get_mock_item()

        #Must be carrying item
        #Item must be a throwable weapon
        #Should decrease number of items when thrown
        #If none left then no longer carrying

        #Not carrying
        player.is_carrying = Mock(return_value=False)
        self.assertFalse(player.throw(dagger, rat))
        player.is_carrying.assert_called_once()

        #Not a weapon
        #TODO: Allow food to be thrown?
        player.is_carrying = Mock(return_value=True)
        self.assertFalse(player.throw(not_a_dagger, rat))

        #Not throwable
        #Mock class methods
        mock_is_throwable = PropertyMock(return_value=True)
        type(dagger).is_throwable = mock_is_throwable

        self.assertTrue(player.throw(dagger, rat))
        mock_is_throwable.assert_called_once()
Пример #4
0
    def test_remove_item(self):
        player = players.Thief()

        #Not carrying item does nothing
        #Removing equipped armor resets to default
        #Removing equipped weapon resets to default

        #Armor
        myarmor = MockHelper.get_mock_armor()
        myarmor.get_modifier_value = Mock(return_value=0)

        #Nothing to remove
        self.assertFalse(player.remove_item(myarmor))

        #Remove equipped armor
        player.character_class.is_armor_proficient = Mock(return_value=True)
        self.assertTrue(player.pickup(myarmor))
        self.assertEqual(player.get_equipped_armor(), myarmor)
        self.assertTrue(player.has_armor_equipped())
        self.assertTrue(player.remove_item(myarmor))
        self.assertNotEqual(player.get_equipped_armor(), myarmor)
        self.assertFalse(player.has_armor_equipped())

        #Remove equipped weapon
        weapon = MockHelper.get_mock_weapon()
        weapon.get_modifier_value = Mock(return_value=0)
        player.character_class.is_weapon_proficient = Mock(return_value=True)
        self.assertTrue(player.pickup(weapon))
        self.assertTrue(player.has_weapon_equipped())
        self.assertEqual(player.get_equipped_weapon(), weapon)
        self.assertTrue(player.remove_item(weapon))
        self.assertNotEqual(player.get_equipped_weapon(), weapon)
        self.assertFalse(player.has_weapon_equipped())
Пример #5
0
    def test_has_armor_equipped(self):
        player = players.Thief()
        self.assertFalse(player.has_weapon_equipped())

        dagger = MockHelper.get_mock_weapon()
        player.is_carrying = Mock(return_value=True)
        self.assertTrue(player.equip_weapon(dagger))
        self.assertTrue(player.has_weapon_equipped())
Пример #6
0
    def test_determine_ability_modifier(self):
        #Attack modifier is based on the weapons modifier attribute
        player = players.Thief()

        butter_knife = MockHelper.get_mock_weapon()
        player.is_carrying = Mock(return_value=True)
        self.assertTrue(player.equip_weapon(butter_knife))
        butter_knife_modifier = PropertyMock(
            return_value=[players.PlayerAttributes.DEXTERITY])
        type(butter_knife).modifier_attributes = butter_knife_modifier

        self.assertEqual(player.dexterity, 11)
        butter_knife.get_bonus_value.assert_called_once
        butter_knife_modifier.assert_called_once

        #Should be round down of (x - 10)/2
        attack = player.determine_ability_modifier()
        self.assertEqual(attack, math.floor((11 - 10) / 2))

        type(butter_knife).modifier_attributes = PropertyMock(
            return_value=[players.PlayerAttributes.INTELLIGENCE])
        self.assertEqual(player.intelligence, 8)
        attack = player.determine_ability_modifier()
        self.assertEqual(attack, math.floor((8 - 10) / 2))