コード例 #1
0
ファイル: room.py プロジェクト: jinxo13/QuestGame
 def unlock(self, player, item):
     with Observer(item) as ob:
         key = item.get_key()
         if player.is_carrying(key):
             item.unlock(player, key=key)
         elif self.__player.can_picklock():
             item.unlock(player)
         elif player.can_cast_spell(spells.UnlockSpell()): #TODO fix
             item.unlock(player, spell=spells.UnlockSpell())
         else:
             return ReplyHelpers.render_room_template('nothing_to_unlock_item', item=item.description)
         return self.__build_reply(ob)
コード例 #2
0
ファイル: test_spells.py プロジェクト: jinxo13/QuestGame
 def test_unlock_spell(self):
     #Unlock spell unlocks openable objects
     #If already unlocked it's 100% effective....
     player = mockPlayer('player')
     chest = mockItem('chest')
     chest.is_locked = True
     spell = spells.UnlockSpell()
     self.assertTrue(chest.is_locked)
     player.current_action = Actions.CAST
     self.assertTrue(spell.cast(player, chest))
     self.assertFalse(chest.is_locked)
     player.current_action = False
コード例 #3
0
ファイル: room.py プロジェクト: jinxo13/QuestGame
 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
コード例 #4
0
ファイル: room.py プロジェクト: jinxo13/QuestGame
 def __is_unlock_action(self, action, spell_text):
     return action in (Actions.UNLOCK, Actions.PICK_LOCK) or (action == Actions.CAST and spells.UnlockSpell().is_match(spell_text))
コード例 #5
0
ファイル: room.py プロジェクト: jinxo13/QuestGame
 def __is_openable_action(self, action, spell_text):
     openable_spells = filter(lambda x: x.is_match(spell_text), [spells.OpenSpell(), spells.CloseSpell(), spells.LockSpell(), spells.UnlockSpell()])
     return action in Actions.OPENABLE_ACTIONS or (action == Actions.CAST and True in openable_spells)
コード例 #6
0
    def test_CellRoom_Mage(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))
        user.save_game()

        user.load_game()

        #Search room
        request = AlexaRequest(self.app,
                               user_id='fred',
                               application_id='quest_game')
        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())
        player = user.room.player

        #Pull loose stone
        request.set_intent('PullIntent')
        request.set_slots([request.create_slot('item', 'loose stone')])
        response = request.post()
        print(response.get_output_text())
        scroll = items.Scroll(spells.UnlockSpell())
        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=scroll.description) in
            response.get_output_text())
        self.assertTrue(player.is_carrying(scroll))

        unlocked = False
        while not unlocked:
            #Cast open at door
            if user.player.mana_points < 1:
                user.player.pickup(potions.ManaPotion())
                user.player.drink_potion(potions.ManaPotion())
            request.set_intent('CastTargetIntent')
            request.set_slots([
                request.create_slot('target', 'door'),
                request.create_slot('spell', 'unlock')
            ])
            response = request.post()
            print(response.get_output_text())
            unlocked = not user.room.get_room_item_by_name('door').is_locked

        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
        rat = user.room.get_monsters()[0]
        rat.max_hit_points = 20
        while len(user.room.get_alive_monsters()) > 0:
            if user.player.mana_points < 1:
                user.player.pickup(potions.ManaPotion())
                user.player.drink(potions.ManaPotion())
            request.set_intent('CastIntent')
            request.set_slots([request.create_slot('spell', 'fireball')])
            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())