Esempio n. 1
0
    def what_can_user_do(self, player):

        if player.is_in_battle:
            return ReplyHelpers.render_common_template('what')

        result = ''
        room_text, floor_text = self.__get_room_text()

        #1. Search dead body
        monster_count, monster_names = self.get_dead_monsters_list(not_looted=True, divider='or')
        if monster_count >= 1:
            result = ReplyHelpers.render_room_template('search_dead_bodies', floor_text=floor_text, monster_names=monster_names)

        #2. Search room
        elif not self.is_room_searched:
            result = ReplyHelpers.render_room_template('search_room', room=room_text)
        
        else:
            #3. Search items
            for item in self._room_items:
                if item.is_hidden: continue
                if isinstance(item, standard_items.OpenableItem):
                    if item.has_been_opened: continue
                    result = ReplyHelpers.render_room_template('room_options', option='open', item=item.description)
                    break

                elif isinstance(item, SearchableItem):
                    if item.is_empty: continue
                    result = ReplyHelpers.render_room_template('room_options', option='search', item=item.description)
                    break
        if result == '':
            result = ReplyHelpers.render_room_template('room_no_options', room_text=room_text)
        return result
Esempio n. 2
0
    def search(self, player, item=None, item_text=None):
        #Search floor
        if isinstance(item, Floor): return self.__search_floor(player)
        
        #Search room or walls
        if (item_text is None or item_text in ['room','area']) or isinstance(item, Walls):
            self._set_state('room_searched', True)
            self.on_search_room()
            floor_items = ''
            if len(self._floor_items) > 0:
                floor_text = self.__get_room_text()[1]
                floor_items = ReplyHelpers.render_room_template('items_on_floor',floor_text=floor_text)
            return ReplyHelpers.render_room_template('{}_search'.format(self.name.lower())) + ' ' + floor_items + ' ' + self.__check_for_bodies()
        
        #Search bodies
        if isinstance(item, players.Player):
            monster = item
            if monster.is_looted:
                return ReplyHelpers.render_action_template('monster_looted',monster_name=monster.class_name)
            found_items = player.loot_body(monster)
            result = ReplyHelpers.render_room_template('search_item',item=monster.class_name)
            result += ' ' + self.__list_items_reply(found_items, pickup=False)

        #Search items
        elif isinstance(item, SearchableItem):
            found_items = item.search()
            result = ReplyHelpers.render_room_template('search_item',item=item.description)
            result += ' ' + self.__list_items_reply(found_items, pickup=True, player=player)
        else:
            return ReplyHelpers.render_room_template('item_not_searchable')

        self.on_search_item(item, found_items)
        return result
Esempio n. 3
0
    def open(self, player, spell=False):

        if self.is_open:
            self.notify_observers_log('{} is already open'.format(self.name))
            self.notify_observers_reply(
                ReplyHelpers.render_room_template('already_open',
                                                  item=self.name))
            self.on_open(player)
            return False

        if self.is_locked:
            self.notify_observers_log('{} is locked'.format(self.name))
            self.notify_observers_reply(
                ReplyHelpers.render_room_template(
                    'locked_spell' if spell else 'locked', item=self.name))
            return False

        if spell:
            if not player.current_action == Actions.CAST:
                #Will only happen if there is a coding error
                self.notify_observers_log(
                    '{} is not being cast by the player'.format(spell.name))
                return False

        if self.is_trapped and self.__trap.is_armed:
            self.__trap.trigger(player)

        self._is_open = True
        self._has_been_opened = True
        self.notify_observers_reply(
            ReplyHelpers.render_room_template(
                'open_with_spell' if spell else 'open', item=self.name))
        self.on_open(player)
        return True
Esempio n. 4
0
 def enter(self, player):
     player._end_battle()
     monster_result = self.__check_for_monster(player)
     body_result = self.__check_for_bodies()
     if monster_result != '':
         reply_text = ReplyHelpers.render_room_template('{}_enter'.format(self.name.lower())) + ' ' + monster_result
     else:
         reply_text = ReplyHelpers.render_room_template('{}_enter'.format(self.name.lower())) + ' ' + body_result
     return QuestGameNormalReply(self, reply_text)
Esempio n. 5
0
 def __check_for_bodies(self):
     monster_count, monster_names = self.get_dead_monsters_list()
     floor_text = self.__get_room_text()[1]
     mon_results = ''
     if monster_count > 1:
         mon_results = ReplyHelpers.render_room_template('dead_bodies', floor_text=floor_text, monster_names=monster_names)
     elif monster_count == 1:
         mon_results = ReplyHelpers.render_room_template('dead_body', floor_text=floor_text, monster_names=monster_names)
     return mon_results
Esempio n. 6
0
    def unlock(self, player, key=False, spell=False):

        if not self.is_locked:
            self.notify_observers_log('{} is not locked'.format(self.name))
            self.notify_observers_reply(
                ReplyHelpers.render_room_template('not_locked',
                                                  item=self.name))
            return False

        if key:
            if key.id == self._key_id:
                self._is_locked = False
                self.notify_observers_log('{} is unlocked'.format(self.name))
                return True
            #Wrong key
            self.notify_observers_log('Wrong key used for {}'.format(
                self.name))
            return False

        if spell:
            if spell.__class__ == spells.UnlockSpell:
                self._is_locked = False
                self.notify_observers_log('{} is unlocked'.format(self.name))
                self.notify_observers_reply(
                    ReplyHelpers.render_room_template('spell_success',
                                                      action='unlocked',
                                                      target_name=self.name))
                return True
            #Wrong spell
            self.notify_observers_log('Wrong spell used for {}'.format(
                self.name))

        #Picklock
        if not player.current_action == Actions.PICK_LOCK:
            #Logic error
            self.notify_observers_log('Can'
                                      't pick lock, player doesn'
                                      't seem to be performing this action')
            return False

        #pick lock
        skill_roll = GameRules.roll_skill_check(player, skills.LockPicking())
        if skill_roll.total >= self.lock_resistance.value:
            self._is_locked = False
            self.notify_observers_reply(
                ReplyHelpers.render_room_template('picklock_success',
                                                  item=self.name))
            return True
        #pick failed
        self.notify_observers_reply(
            ReplyHelpers.render_room_template('picklock_fail', item=self.name))
        return False
Esempio n. 7
0
    def whats_for_sale(self):
        if len(self.__items) > 0:
            result = ReplyHelpers.render_room_template('sale_items')
        else:
            result = ReplyHelpers.render_room_template('sale_no_items')

        for item in self.__items:
            if self.is_unlimited(item):
                result += ' {}.'.format(item.description_plural)
            elif item.count > 1:
                result += ' {} {}.'.format(item.count, item.description_plural)
            else:
                result += ' {} {}.'.format(item.text_prefix, item.description)
        return result
Esempio n. 8
0
    def lock(self, player, key=False, spell=False):
        if self.is_locked:
            self.notify_observers_log('{} is already locked'.format(self.name))
            self.notify_observers_reply(
                ReplyHelpers.render_room_template('already_locked',
                                                  item=self.name))
            return False

        if self.is_open:
            self.close(player)

        if key:
            if key.id == self._key_id:
                self._is_locked = True
                self.notify_observers_log('{} is locked'.format(self.name))
                return True

            #Wrong key
            self.notify_observers_log('Wrong key used for {}'.format(
                self.name))
            return False

        if spell:
            if spell.__class__ == spells.LockSpell:
                self._is_locked = True
                self.notify_observers_log('{} is locked'.format(self.name))
                return True

            #Wrong spell
            self.notify_observers_log('Wrong spell used for {}'.format(
                self.name))
            return False
Esempio n. 9
0
 def __build_reply(self, ob):
     result = ''
     for reply in ob.replies:
         if Helpers.is_string(reply):
             result += ' ' + reply
             continue
         args = reply['args']
         key = reply['key']
         item = None
         if 'item' in args.keys():
             item_name = args['item']
             item = self.get_room_item_by_name(item_name)
         template = args['template']
         if 'attacker_name' in args.keys():
             if args['attacker_name'].lower() in ['thief','ranger','fighter','mage']:
                 key = 'player_'+key
             else:
                 key = 'monster_'+key
         if template == ReplyHelpers.TEMPLATE_ACTION:
             result += ' ' + ReplyHelpers.render_action_template(key, **args)
         elif template == ReplyHelpers.TEMPLATE_ROOM:
             if item:
                 result += ' ' + ReplyHelpers.try_render_room_template(self, item, key, **args)
             else:
                 result += ' ' + ReplyHelpers.render_room_template(key, **args)
         elif template == ReplyHelpers.TEMPLATE_COMMON:
             result += ' ' + ReplyHelpers.render_common_template(key, **args)
         elif template == ReplyHelpers.TEMPLATE_DESCRIPTION:
             result += ' ' + ReplyHelpers.render_descr_template(key, **args)
     return result
Esempio n. 10
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
Esempio n. 11
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)
Esempio n. 12
0
 def lock(self, player, item):
     with Observer(item) as ob:
         key = item.get_key()
         if player.is_carrying(key):
             item.lock_with_key(player)
         elif player.can_cast_spell(spells.LockSpell()):
             item.lock_with_spell(spells.LockSpell(), player)
         else:
             return ReplyHelpers.render_room_template('nothing_to_lock_item', item=item.description)
         return self.__build_reply(ob)
Esempio n. 13
0
 def __search_floor(self, player):
     #item = self.get_room_item_by_name('floor')
     self.on_search_floor()
     floor_text = self.__get_room_text()[1]
     result = ReplyHelpers.render_room_template('search_item',item=floor_text)
     result += ' ' + self.__list_items_reply(self._floor_items, pickup=True, player=player)
         
     mon_results = self.__check_for_bodies()
     self._set_state('floor_searched', True)
     return result + ' ' + mon_results
Esempio n. 14
0
 def __list_items_reply(self, items, pickup=False, player=None):
     result = ''
     i = 0
     for item in items:
         i += 1
         if i == 1:
             result += ' ' + ReplyHelpers.render_room_template('found_items',item=item.text_prefix + ' ' + item.description)
         elif i == len(items):
             result += ' and {} {}.'.format(item.text_prefix, item.description)
         else:
             result += ', {}'.format(item.description)
     if pickup:
         with Observer(player) as ob:
             for item in items:
                 player.pickup(item)
         result += self.__build_reply(ob)
     if i==0:
         result += ' ' + ReplyHelpers.render_room_template('found_nothing')
     return result
Esempio n. 15
0
    def close(self, player, spell=False):
        if not self.is_open:
            self.notify_observers_log('{} is already closed'.format(self.name))
            self.notify_observers_reply(
                ReplyHelpers.render_room_template('already_closed',
                                                  item=self.name))
            return False

        if spell and not player.current_action == Actions.CAST:
            #Will only happen if there is a coding error
            self.notify_observers_log(
                '{} is not being cast by the player'.format(spell.name))
            return False

        self.notify_observers_reply(
            ReplyHelpers.render_room_template(
                'close_with_spell' if spell else 'close', item=self.name))
        self._is_open = False
        self.on_close(player)
        return True
Esempio n. 16
0
 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)
Esempio n. 17
0
 def start(self):
     reply_text = ReplyHelpers.render_room_template('cellroom_start')
     return QuestGameNormalReply(self, reply_text)
Esempio n. 18
0
 def whats_for_sale(self):
     #Buy an item
     floor_text = self.__get_room_text()[1]
     return ReplyHelpers.render_room_template('sale_cannot', floor_text=floor_text)
Esempio n. 19
0
 def reply_yes(self):
     floor_text = self.__get_room_text()[1]
     return ReplyHelpers.render_room_template('yes', floor_text=floor_text)
Esempio n. 20
0
    def do_action(self, player, action, item_text, spell_text=None, target_text=None, amount=0):
        
        if player.is_in_battle and action not in Actions.ALLOWED_BATTLE_ACTIONS:
            reply_text = ReplyHelpers.render_action_template('battle_invalid_action', monster=self.get_next_monster().description)
            return QuestGameNormalReply(self, reply_text)

        item = None
        if not action in Actions.NO_ITEM_ACTIONS or item_text is not None:
            #Try and find a matching item
               
            if not item_text is None:

                if player.is_in_battle and action in Actions.ATTACK_ACTIONS:
                    #Look for matching monster
                    for m in self.get_monsters():
                        if m.is_match(item_text):
                            item = m
                            break
                    if item is None:
                        reply_text = ReplyHelpers.render_action_template('no_monster_to_battle')
                        return QuestGameNormalReply(self, reply_text)

                elif action == Actions.DESCRIBE:
                    #Could be in room or on player
                    item = self.get_room_item_by_text(item_text)
                    if item is None:
                        item = player.get_item_by_name(item_text)
                    if item is None:
                        #Look for matching monster
                        for m in self.get_monsters():
                            if m.is_match(item_text):
                                item = m
                                break
                    if item is None:
                        room_text = self.__get_room_text()[0]
                        reply_text = ReplyHelpers.render_room_template('no_such_room_item', room=room_text, action=Actions.get_action_text(action))
                        return QuestGameNormalReply(self, reply_text)

                elif action in Actions.PLAYER_ITEM_ACTIONS:
                    #Try items held by  player
                    item = player.get_item_by_name(item_text)
                    if item is None:
                        reply_text = ReplyHelpers.render_action_template('not_carrying_unknown', action=Actions.get_action_text(action))
                        return QuestGameNormalReply(self, reply_text)

                else:
                    #Item is in the room
                    item = self.get_room_item_by_text(item_text)
                    if item is None and not action in Actions.NO_ITEM_ACTIONS:
                        room_text = self.__get_room_text()[0]
                        reply_text = ReplyHelpers.render_room_template('no_such_room_item', room=room_text, action=Actions.get_action_text(action))
                        return QuestGameNormalReply(self, reply_text)

            if item is None:
                if player.is_in_battle and action in Actions.ATTACK_ACTIONS:
                    item = self.get_next_monster()
                    if item is None:
                        reply_text = ReplyHelpers.render_action_template('no_monster_to_battle')
                        return QuestGameNormalReply(self, reply_text)

                elif self.__is_openable_action(action, spell_text):
                    #Openable item
                    openable_items = []
                    for itm in self._room_items:
                        if not isinstance(itm, RoomOpenableItem):
                            continue
                        if (self.__is_lock_action(action, spell_text) and not itm.is_locked) or \
                            (self.__is_unlock_action(action, spell_text) and itm.is_locked) or \
                            (self.__is_open_action(action, spell_text) and not itm.is_open) or \
                            (self.__is_close_action(action, spell_text) and itm.is_open):
                            openable_items.append(itm)
                    if len(openable_items) == 1:
                        item = openable_items[0]
                    else:
                        reply_text = ReplyHelpers.render_room_template('select_openable_item', action=Actions.get_action_text(action), item_list=ReplyHelpers.build_list(openable_items, 'description'))
                        return QuestGameReply(reply_text, query_state=ReplyHelpers.QUERY_SELECT)

                    if item is None:
                        #Matching failed
                        reply_text = ReplyHelpers.render_room_template('no_item_provided', action=Actions.get_action_text(action))
                        return QuestGameNormalReply(self, reply_text)

                    #No item found
                    reply_text = ReplyHelpers.render_action_template('not_carrying', action=Actions.get_action_text(action), item_prefix=item.text_prefix, item_text=item.description)
                    return QuestGameNormalReply(self, reply_text)

        action = self.get_action_override(action, item)

        #Either no item required, item is carried by player, or item in room
        result_text = ''
        if action == Actions.PULL: result_text = self.pull(item)
        elif action == Actions.PUSH: result_text = self.push(item)
        elif action == Actions.SEARCH: result_text = self.search(item, item_text)
        elif action == Actions.CAST: result_text = self.cast(player, spell_text, item)
        elif action == Actions.THROW: result_text = self.throw(player, item, target_text)
        elif action == Actions.CLOSE: result_text = self.close(item)
        elif action == Actions.OPEN: result_text = self.open(item)
        elif action == Actions.LOCK: result_text = self.lock(player, item)
        elif action == Actions.UNLOCK: result_text = self.unlock(player, item)
        elif action == Actions.DESCRIBE: result_text = self.describe(item)
        elif action == Actions.NO: result_text = self.reply_no()
        elif action == Actions.YES: result_text = self.reply_yes()
        elif action == Actions.PICK_LOCK: result_text = self.pick_lock(item)
        elif action == Actions.SHOOT: result_text = self.shoot(player, item)
        elif action == Actions.STRIKE: result_text = self.strike(player, item)
        elif action == Actions.WHAT: result_text = self.what_can_user_do(player)
        elif action == Actions.PICKUP: result_text = self.pickup(item)
        elif action == Actions.DROP: result_text = self.drop(item)
        elif action == Actions.DRINK: result_text = self.drink(player, item)
        elif action == Actions.WHERE: result_text = self.where()
        elif action == Actions.EAT: result_text = self.eat(player, item)
        elif action == Actions.MONEY: result_text = self.count_money(player)
        elif action == Actions.BUY: result_text = self.buy(item_text, amount)
        elif action == Actions.SELL: result_text = self.sell(item_text, amount)
        elif action == Actions.WHAT_BUY: result_text = self.whats_for_sale()
        else:
            result_text = ReplyHelpers.render_common_template('no_action')
        
        return QuestGameNormalReply(self, result_text + ' ' + self.__check_for_monster(player))
Esempio n. 21
0
 def where(self):
     return ReplyHelpers.render_room_template('{}_enter'.format(self.name.lower()))
Esempio n. 22
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())
Esempio n. 23
0
 def drop(self, item):
     if self.__player.drop(item):
         self._floor_items.append(item)
     return ReplyHelpers.render_room_template('drop_item', item=item.description)
Esempio n. 24
0
 def sell(self, item, amount):
     #Buy an item
     floor_text = self.__get_room_text()[1]
     return ReplyHelpers.render_room_template('sell_cannot', floor_text=floor_text)
Esempio n. 25
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())
Esempio n. 26
0
 def pickup(self, item):
     with Observer(item) as ob:
         if self.__player.pickup(item):
             self._floor_items.remove(item)
         return ReplyHelpers.render_room_template('pickup_item', item=item.description) + ' ' + self.__build_reply(ob)
Esempio n. 27
0
 def open(self, player):
     if self.is_open:
         self.notify_observers_reply(ReplyHelpers.render_room_template('door_already_open'))
         return
     return RoomOpenableItem.open(self, player)