def help_area(area): try: help_text = ReplyHelpers.render_common_template('help_{}'.format(area)) except: help_text = ReplyHelpers.render_common_template( 'help_not_found') + ' ' + ReplyHelpers.render_common_template( 'help') return __query(help_text)
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
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
def __query(text, reprompt='', query_state=None): if query_state is None: if __is_in_battle(): __set_query(ReplyHelpers.QUERY_BATTLE) else: __set_query(ReplyHelpers.QUERY_WHAT) __set_query(query_state) if reprompt == '': if query_state == ReplyHelpers.QUERY_WHAT: reprompt = ReplyHelpers.render_common_template('what_reprompt') if query_state == ReplyHelpers.QUERY_BATTLE: reprompt = ReplyHelpers.render_common_template('battle_reprompt') if query_state == ReplyHelpers.QUERY_CLASS: reprompt = ReplyHelpers.render_common_template('choose_class') result = QuestGameReply(text, reprompt, query_state).get_alexa_reply() return result
def choose_char(name): if __get_query() == ReplyHelpers.QUERY_CLASS: if name.lower() not in ['thief', 'mage', 'fighter', 'ranger']: reply_text = ReplyHelpers.render_common_template( 'unsure') + ' ' + ReplyHelpers.render_common_template( 'choose_class') return __query(reply_text, query_state=ReplyHelpers.QUERY_CLASS) player = game_manager.create_player(name.lower()) reply_text = ReplyHelpers.render_common_template('chose_char', cls=name.lower()) reply_text += ' ' + game_manager.start_new_game( session.user.userId, player).prompt_text return __query(reply_text) if not game_manager.is_game_started(session.user.userId): return launch() reply_text = game_manager.continue_game(session.user.userId) return __query(reply_text)
def select_item(ditem): if not __get_query() == ReplyHelpers.QUERY_SELECT: return __query(ReplyHelpers.render_common_template('unsure')) #perform the last action with the supplied item action = None spell_text = None target_text = None #TODO: Make get with default if 'action' in session.attributes.keys(): action = int(session.attributes['action']) if 'spell_text' in session.attributes.keys(): spell_text = session.attributes['spell_text'] if 'target_text' in session.attributes.keys(): target_text = session.attributes['target_text'] if action is None: return __query(ReplyHelpers.render_common_template('unsure')) elif action == Actions.CAST: return __do_spell(spell_text, ditem) elif action == Actions.THROW: return __do_throw(ditem, target_text) else: return __do_action(action, ditem)
def launch(): if test_constants.UNITTEST_TEST_INTENTS: return ReplyHelpers.reply('launchIntent') user_id = session.user.userId if game_manager.is_game_started(user_id): return __continue_game() welcome_text = ReplyHelpers.render_common_template('welcome') #help_text = ReplyHelpers.render_common_template('help') #Look for saved games gm = LoadManager(user_id) if not gm.does_user_game_exist('test'): games_text = ReplyHelpers.render_common_template( 'no_games') + ' ' + ReplyHelpers.render_common_template( 'choose_class') return __query(welcome_text + ' ' + games_text, query_state=ReplyHelpers.QUERY_CLASS) else: games_text = ReplyHelpers.render_common_template('load_game') #If only one game load it game_manager.load_game(user_id, 'test') return __continue_game()
def yes(): query = __get_query() if query == ReplyHelpers.QUERY_NEW_GAME: __set_query(ReplyHelpers.QUERY_WHAT) user_id = session.user.userId gm = LoadManager(user_id) if gm.does_user_game_exist('test'): game_manager.delete_game(user_id, 'test') return launch() elif query == ReplyHelpers.QUERY_EXIT_GAME: bye_text = ReplyHelpers.render_common_template('bye') return statement(bye_text) else: return __do_action(Actions.YES)
def describe(ditem): if __get_query() == ReplyHelpers.QUERY_CLASS: itm = ditem.lower() reply_text = '' if itm == 'mage': reply_text = ReplyHelpers.render_descr_template('descr_mage') elif itm == 'thief': reply_text = ReplyHelpers.render_descr_template('descr_thief') elif itm == 'fighter': reply_text = ReplyHelpers.render_descr_template('descr_fighter') elif itm == 'ranger': reply_text = ReplyHelpers.render_descr_template('descr_ranger') reply_text += ' ' + ReplyHelpers.render_common_template('choose_class') return __query(reply_text, query_state=ReplyHelpers.QUERY_CLASS) return __do_action(Actions.DESCRIBE, ditem)
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))
def help(): help_text = ReplyHelpers.render_common_template('help') return __query(help_text)
def stop(): return __query(ReplyHelpers.render_common_template('exit'), query_state=ReplyHelpers.QUERY_EXIT_GAME)
def start(): return __query(ReplyHelpers.render_common_template('are_you_sure'), query_state=ReplyHelpers.QUERY_NEW_GAME)