Beispiel #1
0
    def test_close(self):
        player = Mock()
        chest = standard_items.OpenableItem()
        chest.on_close = Mock()
        #Chest not open or locked
        self.assertFalse(chest.is_open)
        self.assertFalse(chest.is_locked)
        self.assertFalse(chest.close(player))
        chest.on_close.assert_not_called()

        #Chest open
        self.assertTrue(chest.open(player))
        self.assertTrue(chest.is_open)
        self.assertTrue(chest.close(player))
        chest.on_close.assert_called_once()

        #Open with chest locked
        chest = standard_items.OpenableItem(key_id=1)
        chest.on_close = Mock()
        key = Mock()
        key.id = 1
        self.assertTrue(chest.is_locked)
        self.assertFalse(chest.open(player))

        #unlock
        self.assertTrue(chest.unlock(player, key))
        self.assertFalse(chest.is_locked)
        self.assertTrue(chest.open(player))

        #With spell
        spell = Mock()
        self.assertTrue(chest.is_open)
        player.current_action = Actions.CAST
        self.assertTrue(chest.close(player, spell))
        chest.on_close.assert_called_once()
        player.current_action = False

        #Trap
        trap = Mock()
        trap.trigger = Mock()
        self.assertFalse(chest.is_trapped)
        self.assertFalse(chest.is_open)
        chest.set_trap(trap)
        self.assertTrue(chest.is_trapped)

        #Trigger Trap
        self.assertTrue(chest.open(player))
        trap.trigger.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_unlock(self):
     player = Mock()
     #key
     key = Mock()
     key.id = 1
     chest = standard_items.OpenableItem(key_id=1)
     chest.on_unlock = Mock()
     self.assertTrue(chest.is_locked)
     self.assertTrue(chest.unlock(player, key))
     self.assertTrue(chest.is_unlocked)
Beispiel #4
0
    def test_open(self):
        player = Mock()
        chest = standard_items.OpenableItem()
        chest.on_open = Mock()

        #Chest not open or locked
        self.assertFalse(chest.is_open)
        self.assertFalse(chest.is_locked)

        #Chest open
        self.assertTrue(chest.open(player))
        chest.on_open.assert_called_once()
        self.assertTrue(chest.is_open)

        #Open with chest locked
        chest = standard_items.OpenableItem(key_id=1)
        chest.on_open = Mock()
        key = Mock()
        key.id = 1
        self.assertTrue(chest.is_locked)
        self.assertFalse(chest.open(player))
        chest.on_open.assert_not_called()

        #unlock
        self.assertTrue(chest.unlock(player, key))
        self.assertFalse(chest.is_locked)
        self.assertTrue(chest.open(player))
        chest.on_open.assert_called_once()
        self.assertTrue(chest.is_open)

        #With spell
        spell = Mock()
        chest = standard_items.OpenableItem()
        chest.on_open = Mock()
        self.assertTrue(chest.is_closed)
        player.current_action = Actions.CAST
        self.assertTrue(chest.open(player, spell))
        chest.on_open.assert_called_once()
        player.current_action = False
Beispiel #5
0
    def test_check_trapped(self):
        player = Mock()
        trap = Mock()
        trap.difficulty_class = Difficulty.Easy

        dice = Mock()
        dice.total = 10

        standard_items.GameRules.roll_perception_check = Mock(
            return_value=dice)
        chest = standard_items.OpenableItem()
        self.assertTrue(chest.check_for_trap(player, trap))

        dice.total = 9
        self.assertFalse(chest.check_for_trap(player, trap))
Beispiel #6
0
    def test_lock_with_key(self):
        player = Mock()
        key = Mock()
        key.id = 1

        bad_key = Mock()
        bad_key.id = 2

        chest = standard_items.OpenableItem(key_id=1)
        self.assertTrue(chest.is_locked)
        self.assertFalse(chest.unlock(player, bad_key))
        self.assertTrue(chest.unlock(player, key))
        self.assertTrue(chest.is_unlocked)

        self.assertFalse(chest.lock(player, bad_key))
        self.assertTrue(chest.lock(player, key))
        self.assertTrue(chest.is_locked)
Beispiel #7
0
    def test_set_trap(self):
        player = Mock()
        #Trap
        trap = Mock()
        trap.trigger = Mock()
        chest = standard_items.OpenableItem()
        self.assertFalse(chest.is_trapped)
        self.assertFalse(chest.is_open)

        #Trigger Trap
        chest.set_trap(trap)
        self.assertTrue(chest.is_trapped)

        self.assertTrue(chest.open(player))
        trap.trigger.assert_called_once()

        #Check no retrigger
        self.assertTrue(chest.close(player))
        trap.trigger = Mock()
        trap.is_armed = False
        self.assertTrue(chest.open(player))
        trap.trigger.assert_not_called()
Beispiel #8
0
    def test_lock_with_spell(self):
        player = Mock()
        bad_spell = Mock()
        spell = MockHelper.get_mock_lock_spell()

        chest = standard_items.OpenableItem()
        self.assertFalse(chest.is_locked)
        self.assertFalse(chest.lock(player, spell=bad_spell))
        self.assertTrue(chest.lock(player, spell=spell))
        self.assertTrue(chest.is_locked)

        #Can't unlock with key
        key = Mock()
        key.id = 1
        self.assertFalse(chest.unlock(player, key))

        #Can picklock
        player.current_action = Actions.PICK_LOCK
        player.get_attribute_modifier = Mock(return_value=5)
        self.assertTrue(chest.unlock(player))
        player.get_attribute_modifier.assert_called_once()
        player.current_action = False
Beispiel #9
0
 def test_lock_resistance(self):
     chest = standard_items.OpenableItem()
     self.assertEqual(chest.lock_resistance, Difficulty.Easy)
Beispiel #10
0
 def test_is_trapped(self):
     chest = standard_items.OpenableItem()
     self.assertFalse(chest.is_trapped)
     trap = Mock()
     chest.set_trap(trap)
     self.assertTrue(chest.is_trapped)
Beispiel #11
0
 def test_has_been_opened(self):
     player = Mock()
     chest = standard_items.OpenableItem()
     self.assertFalse(chest.has_been_opened)
     chest.open(player)
     self.assertTrue(chest.has_been_opened)
Beispiel #12
0
 def test_trap(self):
     trap = Mock()
     chest = standard_items.OpenableItem()
     chest.set_trap(trap)
     self.assertTrue(chest.is_trapped)
     self.assertEqual(chest.trap, trap)
Beispiel #13
0
 def test_spell_resistance(self):
     chest = standard_items.OpenableItem()
     self.assertEqual(chest.spell_resistance,
                      standard_items.Difficulty.Easy)
Beispiel #14
0
 def test_set_locked(self):
     player = Mock()
     chest = standard_items.OpenableItem()