Beispiel #1
0
    def test_is_unconscious(self):
        player = players.Thief()
        self.assertFalse(player.is_dead)
        self.assertFalse(player.is_unconscious)

        #Ensure Save from death, but not max save
        with MockHelper.Method(players.GameRules,
                               'roll_death_save',
                               return_value=19) as mock_death_save:
            self.assertTrue(player.wound(player.max_hit_points))
            self.assertEqual(player.hit_points, 0)
            self.assertFalse(player.is_dead)
            self.assertTrue(player.is_unconscious)
            #Can't wound if no points
            self.assertFalse(player.wound(0))
            mock_death_save.assert_called_once()

        #Massive damage, no save
        with MockHelper.Method(players.GameRules,
                               'roll_death_save',
                               return_value=20) as mock_death_save:
            self.assertTrue(player.wound(player.max_hit_points))
            self.assertEqual(player.hit_points, 0)
            self.assertTrue(player.is_dead)
            self.assertFalse(player.is_unconscious)
            #Dead can't wound anymore
            self.assertFalse(player.wound(player.max_hit_points))
            mock_death_save.assert_not_called()

        #Massive damage, no save
        with MockHelper.Method(players.GameRules,
                               'roll_death_save',
                               return_value=20) as mock_death_save:
            player = players.Thief()
            self.assertTrue(player.wound(player.max_hit_points * 2))
            self.assertTrue(player.is_dead)
            self.assertFalse(player.is_unconscious)
            mock_death_save.assert_not_called()

        #Large damage, save matters
        with MockHelper.Method(players.GameRules,
                               'roll_death_save',
                               return_value=20) as mock_death_save:
            player = players.Thief()
            self.assertTrue(player.wound(player.max_hit_points * 2 - 1))
            self.assertFalse(player.is_dead)
            self.assertEqual(player.hit_points, 0)
            self.assertTrue(player.is_unconscious)
            mock_death_save.assert_called_once()
Beispiel #2
0
 def test_get_key(self):
     key = Mock()
     chest = standard_items.OpenableItem(key_id=10)
     #Mock key lookup
     with MockHelper.Method(standard_items.items.ItemStats,
                            'get_key',
                            return_value=key) as mock_get_key:
         self.assertEqual(chest.get_key(), key)
         mock_get_key.assert_called_once()
Beispiel #3
0
    def test_is_dead(self):
        player = players.Thief()
        self.assertFalse(player.is_dead)

        #Ensure save on death
        with MockHelper.Method(players.GameRules,
                               'roll_death_save',
                               return_value=20) as mock_death_save:
            self.assertTrue(player.wound(player.max_hit_points))
            self.assertEqual(player.hit_points, 0)
            self.assertFalse(player.is_dead)
            mock_death_save.assert_called()

        #Massive damage - save has no effect
        with MockHelper.Method(players.GameRules,
                               'roll_death_save',
                               return_value=20) as mock_death_save:
            self.assertTrue(player.wound(player.max_hit_points))
            self.assertEqual(player.hit_points, 0)
            self.assertTrue(player.is_dead)
            mock_death_save.assert_not_called()

        #Massive damage - save has no effect
        with MockHelper.Method(players.GameRules,
                               'roll_death_save',
                               return_value=20) as mock_death_save:
            player = players.Thief()
            self.assertTrue(player.wound(player.max_hit_points * 2))
            self.assertTrue(player.is_dead)
            mock_death_save.assert_not_called()

        #Large damage - save has an effect
        with MockHelper.Method(players.GameRules,
                               'roll_death_save',
                               return_value=20) as mock_death_save:
            player = players.Thief()
            self.assertTrue(player.wound(player.max_hit_points * 2 - 1))
            self.assertFalse(player.is_dead)
            mock_death_save.assert_called_once()
Beispiel #4
0
    def test_strike_critical_miss(self):
        weapon = weapons.Spear()
        attacker = Mock()
        defender = Mock()
        is_throw = False

        attacker.get_reply_key = Mock(return_value='player_critical_miss')
        defender.get_reply_key = Mock(return_value='monster_critical_miss')
        attacker.determine_ability_modifier = Mock(return_value=2)
        defender.get_defense = Mock(return_value=5)

        with MockHelper.Method(weapons.GameRules,
                               'roll_weapon_attack_score') as mock_weapon_roll:
            mock_weapon_roll.return_value = MockDiceRoll(1, 0)
            strike = weapon.strike(attacker, defender, is_throw)
            weapons.GameRules.roll_weapon_attack_score.assert_called_once()
            self.assertFalse(strike.is_critical_hit)
            self.assertTrue(strike.is_critical_miss)
            self.assertEqual(strike.damage, 0)
            self.assertFalse(strike.is_hit)
            self.assertTrue(strike.is_miss)