Exemple #1
0
 def pick_lock(self, item):
     if not self.can_picklock():
         self.notify_observers_reply(
             ReplyHelpers.render_room_template('no_lockpick_ability'))
         return False
     self.remove_item(items.LockPick())
     return item.unlock(self)
Exemple #2
0
    def test_is_fragile(self):
        #Fragile
        beer = items.Beer()
        self.assertTrue(beer.is_fragile)

        #Not fragile
        lockpick = items.LockPick()
        self.assertFalse(lockpick.is_fragile)
Exemple #3
0
    def test_is_match(self):
        beer = items.Beer()
        self.assertTrue(beer.is_match('beer'))
        self.assertTrue(beer.is_match('a beer'))

        lockpick = items.LockPick()
        self.assertTrue(lockpick.is_match('Lock Pick'))
        self.assertTrue(lockpick.is_match('lockpick'))
        self.assertTrue(lockpick.is_match('a lockpick'))
Exemple #4
0
    def test_player_state(self):
        spell = spells.FireballSpell()
        player = players.Mage()
        player.learn_spell(spell)
        state = player.get_state()

        axe = weapons.Axe()
        player.pickup(axe)
        player.equip_weapon(axe)
        lightArmor = armor.LightArmor()
        player.pickup(lightArmor)
        player.equip_armor(lightArmor)

        player.add_experience(300)
        self.assertEqual(player.level, 2)
        player.pickup(items.LockPick())

        player2 = players.Player.create_from_state(state)
        self.assertTrue(player.__class__ == player2.__class__)
        self.assertTrue(player.get_equipped_weapon().__class__ == weapons.Axe)
        self.assertTrue(
            player.get_equipped_armor().__class__ == armor.LightArmor)
        self.assertTrue(player.is_carrying(items.LockPick()))
Exemple #5
0
 def pull(self, player, item):
     if item.name == 'loose_stone':
         result = ReplyHelpers.render_room_template('cellroom_pull_stone')
         if self._get_state('hidden_item_taken'):
             result += ' ' + ReplyHelpers.render_room_template('cellroom_pull_stone_empty')
         else:
             item._has_been_opened = True
             hidden_item = items.LockPick()
             if player.__class__ == players.Mage:
                 hidden_item = items.Scroll(spells.UnlockSpell())
             player.pickup(hidden_item)
             self._set_state('hidden_item_taken',True)
             result += ' ' + ReplyHelpers.render_room_template('cellroom_pull_stone_full',item_text=hidden_item.description)
     else:
         result = Room.pull(self, item)
     return result
Exemple #6
0
    def test_eat_actions(self):
        gm = game_manager
        player = gm.create_player('mage')
        gm.start_new_game('fred', player)
        user = gm.get_user('fred', 'test')
        user.set_room(rooms.CellRoom(player))
        room = user.room

        #Cast at room item
        player.pickup(items.StaleBread())
        reply = room.eat(items.StaleBread())
        print(reply)
        self.assertTrue('you eat the' in reply.lower())

        reply = room.eat(items.StaleBread())
        print(reply)
        self.assertTrue('not carrying' in reply)

        reply = room.eat(items.LockPick())
        print(reply)
        self.assertTrue("can't eat" in reply.lower())
Exemple #7
0
 def can_picklock(self):
     return self.can_act and self.is_carrying(
         items.LockPick()) and self.has_skill(skills.LockPicking())
Exemple #8
0
 def on_search_item(self, item, found_items):
     if item.name == 'straw' and len(found_items) > 0:
         rat = players.Rat()
         rat.inventory.add(items.StrengthRing())
         rat.inventory.add(items.LockPick())
         self._add_monster(rat)
Exemple #9
0
    def test_CellRoom_Thief(self):
        gm = game_manager
        player = gm.create_player('thief')
        gm.start_new_game('fred', player)
        user = gm.get_user('fred', 'test')
        user.set_room(rooms.CellRoom(player))

        #What can I do
        request = AlexaRequest(self.app,
                               user_id='fred',
                               application_id='quest_game')
        request.set_intent('WhatCanIDoIntent')
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            'you could search the room' in response.get_output_text().lower())
        player = user.room.player

        #Search room
        request = AlexaRequest(self.app,
                               user_id='fred',
                               application_id='quest_game')
        request.set_intent('SearchIntent')
        request.set_slots([request.create_slot('sitem', 'room')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_search') in
            response.get_output_text())
        player = user.room.player

        #What can I do
        request = AlexaRequest(self.app,
                               user_id='fred',
                               application_id='quest_game')
        request.set_intent('WhatCanIDoIntent')
        response = request.post()
        print(response.get_output_text())
        self.assertTrue('you could open the loose stone' in
                        response.get_output_text().lower())

        #Search room
        request.set_intent('SearchIntent')
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_search') in
            response.get_output_text())

        #What can I do
        request.set_intent('WhatCanIDoIntent')
        response = request.post()
        print(response.get_output_text())

        #Pull loose stone
        request.set_intent('PullIntent')
        request.set_slots([request.create_slot('item', 'loose stone')])
        response = request.post()
        print(response.get_output_text())
        lockpick = items.LockPick()
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_pull_stone') in
            response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_pull_stone_full',
                                              item_text=lockpick.description)
            in response.get_output_text())
        self.assertTrue(player.is_carrying(lockpick))

        #What can I do
        request = AlexaRequest(self.app,
                               user_id='fred',
                               application_id='quest_game')
        request.set_intent('WhatCanIDoIntent')
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            'you could search the straw' in response.get_output_text().lower())

        #Pull loose stone again
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'loose stone')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_pull_stone') in
            response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('cellroom_pull_stone_empty') in
            response.get_output_text())

        #Pull door
        request.set_intent('PullIntent')
        request.set_slots([request.create_slot('item', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('locked', item='door') in
            response.get_output_text())

        #Open something
        request.set_intent('OpenIntent')
        request.set_slots([])
        response = request.post()
        print(response.get_output_text())

        request.set_intent('SelectItemIntent')
        request.set_slots([request.create_slot('ditem', 'door')])
        response = request.post(request.session_id)
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('locked', item='door') in
            response.get_output_text())

        #Pull chest
        request.set_intent('PullIntent')
        request.set_slots([request.create_slot('item', 'chest')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'no_such_room_item', room='room', action='pull') in
            response.get_output_text())

        #Describe dagger
        request.set_intent('DescribeItemIntent')
        request.set_slots([request.create_slot('ditem', 'dagger')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'no_such_room_item', room='room', action='describe') in
            response.get_output_text())

        #Open door
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('locked', item='door') in
            response.get_output_text())

        #Open window
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'window')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'cellroom_barred_window_open_cannot') in
            response.get_output_text())

        #Pickup bread
        request.set_intent('PickupIntent')
        request.set_slots([request.create_slot('ditem', 'bread')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'pickup_item', item=items.StaleBread().description) in
            response.get_output_text())

        #Pickup bread
        request.set_intent('PickupIntent')
        request.set_slots([request.create_slot('ditem', 'bread')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'no_such_room_item', action='pickup', room='room') in
            response.get_output_text())

        #Drop bread
        request.set_intent('DropIntent')
        request.set_slots([request.create_slot('ditem', 'bread')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'drop_item', item=items.StaleBread().description) in
            response.get_output_text())

        #Pickup bread
        request.set_intent('PickupIntent')
        request.set_slots([request.create_slot('ditem', 'bread')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template(
                'pickup_item', item=items.StaleBread().description) in
            response.get_output_text())

        #Search floor
        request.set_intent('SearchIntent')
        request.set_slots([request.create_slot('sitem', 'floor')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('search_item', item='floor') in
            response.get_output_text())

        picked = False
        while not picked:
            #Picklock door
            request.set_intent('PickLockIntent')
            request.set_slots([request.create_slot('oitem', 'door')])
            response = request.post()
            picked = ReplyHelpers.render_room_template(
                'picklock_success', item='door') in response.get_output_text()
            self.assertTrue(
                ReplyHelpers.render_room_template('picklock_success',
                                                  item='door')
                in response.get_output_text()
                or ReplyHelpers.render_room_template('picklock_fail',
                                                     item='door')
                in response.get_output_text())

        player = user.player
        player.max_hit_points = 100
        player.strength_base = 15
        player.dexterity_base = 10

        #Search straw
        request.set_intent('SearchIntent')
        request.set_slots([request.create_slot('sitem', 'straw')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('search_item', item='straw') in
            response.get_output_text())

        #Rat has attacked
        #Describe rat
        monster = user.room.get_monsters()[0]
        monster.max_hit_points = 20
        request.set_intent('DescribeItemIntent')
        request.set_slots([request.create_slot('ditem', 'rat')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_descr_template('descr_rat',
                                               hit_points=monster.hit_points)
            in response.get_output_text())

        while len(user.room.get_alive_monsters()) > 0:
            if player.get_item(weapons.Dagger()).count == 4:
                request.set_intent('ThrowTargetIntent')
                request.set_slots([
                    request.create_slot('target', 'rat'),
                    request.create_slot('titem', 'dagger')
                ])
            elif player.get_item(weapons.Dagger()).count == 3:
                request.set_intent('ThrowIntent')
                request.set_slots([request.create_slot('titem', 'dagger')])
            else:
                request.set_intent('StrikeIntent')
                request.set_slots([request.create_slot('target', 'rat')])
                if player.get_item(weapons.Dagger()).count == 1:
                    player.pickup(weapons.Dagger(3))

            response = request.post()
            print(response.get_output_text())

        #search rat
        request.set_intent('SearchIntent')
        request.set_slots([request.create_slot('sitem', 'rat')])
        response = request.post()
        print(response.get_output_text())
        #self.assertTrue(ReplyHelpers.render_room_template('search_item',item='rat') in response.get_output_text())

        request.set_intent('DescribeItemIntent')
        request.set_slots([request.create_slot('ditem', 'rat')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_descr_template('descr_rat',
                                               hit_points=monster.hit_points)
            in response.get_output_text())

        #Describe dagger
        request.set_intent('DescribeItemIntent')
        request.set_slots([request.create_slot('ditem', 'dagger')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_descr_template('descr_dagger') in
            response.get_output_text())

        #Open door
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('door_open') in
            response.get_output_text())

        #Go back to cell
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())

        #Open door again
        request.set_intent('OpenIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('door_already_open') in
            response.get_output_text())

        #Unlock open door
        request.set_intent('UnlockIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('not_locked', item='door') in
            response.get_output_text())

        #Close an open door
        request.set_intent('CloseIntent')
        request.set_slots([request.create_slot('oitem', 'door')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_room_template('close', item='door') in
            response.get_output_text())

        #Describe dagger
        request.set_intent('DescribeItemIntent')
        request.set_slots([request.create_slot('ditem', 'dagger')])
        response = request.post()
        print(response.get_output_text())
        self.assertTrue(
            ReplyHelpers.render_descr_template('descr_dagger') in
            response.get_output_text())