def get_appearance(self, caller): """ This is a convenient hook for a 'look' command to call. """ # get name and description if caller.is_exit_unlocked(self.get_info_key()): return super(MudderyLockedExit, self).get_appearance(caller) can_unlock = script_handler.match_condition(caller, self.exit_lock["condition"]) desc = self.exit_lock["message_lock"] cmds = [] if can_unlock: verb = self.exit_lock["verb"] if not verb: verb = LS("UNLOCK") cmds = [{"name":verb, "cmd":"unlock_exit", "args":self.dbref}] info = {"dbref": self.dbref, "name": self.name, "desc": desc, "cmds": cmds} return info
def get_default_sentences(self, caller, npc): """ """ if not caller: return if not npc: return sentences = [] # get npc's default dialogues for dlg_key in npc.dialogues: npc_dlg = self.get_dialogue(dlg_key) if not npc_dlg: continue if not script_handler.match_condition(caller, npc_dlg["condition"]): continue match = True for dep in npc_dlg["dependences"]: if not QUEST_DEP_HANDLER.match_dependence(caller, dep["quest"], dep["type"]): match = False break; if not match: continue if npc_dlg["sentences"]: # if has sentence, use it sentences.append(npc_dlg["sentences"][0]) return sentences
def get_appearance(self, caller): """ This is a convenient hook for a 'look' command to call. """ # get name and description if caller.is_exit_unlocked(self.get_info_key()): return super(MudderyLockedExit, self).get_appearance(caller) can_unlock = script_handler.match_condition( caller, self.exit_lock["condition"]) desc = self.exit_lock["message_lock"] cmds = [] if can_unlock: verb = self.exit_lock["verb"] if not verb: verb = LS("UNLOCK") cmds = [{"name": verb, "cmd": "unlock_exit", "args": self.dbref}] info = { "dbref": self.dbref, "name": self.name, "desc": desc, "cmds": cmds } return info
def get_default_sentences(self, caller, npc): """ """ if not caller: return if not npc: return sentences = [] # get npc's default dialogues for dlg_key in npc.dialogues: npc_dlg = self.get_dialogue(dlg_key) if not npc_dlg: continue if not script_handler.match_condition(caller, npc_dlg["condition"]): continue match = True for dep in npc_dlg["dependences"]: if not QUEST_DEP_HANDLER.match_dependence( caller, dep["quest"], dep["type"]): match = False break if not match: continue if npc_dlg["sentences"]: # if has sentence, use it sentences.append(npc_dlg["sentences"][0]) return sentences
def dialogue_have_quest(self, caller, npc, dialogue, achieved_quests): """ find quests by recursion """ provide_quest = False finish_quest = False # check if the dialogue is available npc_dlg = self.get_dialogue(dialogue) if not npc_dlg: return (provide_quest, finish_quest) if not script_handler.match_condition(caller, npc_dlg["condition"]): return (provide_quest, finish_quest) match = True for dep in npc_dlg["dependences"]: if not QUEST_DEP_HANDLER.match_dependence(caller, dep["quest"], dep["type"]): match = False break if not match: return (provide_quest, finish_quest) # find quests in its sentences for sen in npc_dlg["sentences"]: if sen["finish_quest"] in achieved_quests: finish_quest = True return (provide_quest, finish_quest) if not provide_quest and sen["provide_quest"]: quest_key = sen["provide_quest"] if not caller.quest.is_finished(quest_key) and\ not caller.quest.is_in_progress(quest_key) and\ caller.quest.match_dependences(quest_key): provide_quest = True if not achieved_quests: return (provide_quest, finish_quest) for dlg_key in npc_dlg["nexts"]: # get next dialogue provide, finish = self.dialogue_have_quest(caller, npc, dlg_key, achieved_quests) provide_quest = (provide_quest or provide) finish_quest = (finish_quest or finish) if finish_quest: break if not achieved_quests: if provide_quest: break return (provide_quest, finish_quest)
def dialogue_have_quest(self, caller, npc, dialogue, achieved_quests): """ find quests by recursion """ provide_quest = False finish_quest = False # check if the dialogue is available npc_dlg = self.get_dialogue(dialogue) if not npc_dlg: return (provide_quest, finish_quest) if not script_handler.match_condition(caller, npc_dlg["condition"]): return (provide_quest, finish_quest) match = True for dep in npc_dlg["dependences"]: if not QUEST_DEP_HANDLER.match_dependence(caller, dep["quest"], dep["type"]): match = False break; if not match: return (provide_quest, finish_quest) # find quests in its sentences for sen in npc_dlg["sentences"]: if sen["finish_quest"] in achieved_quests: finish_quest = True return (provide_quest, finish_quest) if not provide_quest and sen["provide_quest"]: quest_key = sen["provide_quest"] if not caller.quest.is_finished(quest_key) and\ not caller.quest.is_in_progress(quest_key) and\ caller.quest.match_dependences(quest_key): provide_quest = True if not achieved_quests: return (provide_quest, finish_quest) for dlg_key in npc_dlg["nexts"]: # get next dialogue provide, finish = self.dialogue_have_quest(caller, npc, dlg_key, achieved_quests) provide_quest = (provide_quest or provide) finish_quest = (finish_quest or finish) if finish_quest: break if not achieved_quests: if provide_quest: break return (provide_quest, finish_quest)
def get_available_commands(self, caller): """ This returns a list of available commands. "args" must be a string without ' and ", usually it is self.dbref. """ if caller.is_exit_unlocked(self.get_info_key()): return super(MudderyLockedExit, self).get_available_commands(caller) cmds = [] can_unlock = script_handler.match_condition(caller, self.exit_lock["condition"]) if can_unlock: verb = self.exit_lock["verb"] if not verb: verb = LS("UNLOCK") cmds = [{"name":verb, "cmd":"unlock", "args":self.dbref}] return cmds
def get_available_commands(self, caller): """ This returns a list of available commands. "args" must be a string without ' and ", usually it is self.dbref. """ if caller.is_exit_unlocked(self.get_info_key()): return super(MudderyLockedExit, self).get_available_commands(caller) cmds = [] can_unlock = script_handler.match_condition( caller, self.exit_lock["condition"]) if can_unlock: verb = self.exit_lock["verb"] if not verb: verb = LS("UNLOCK") cmds = [{"name": verb, "cmd": "unlock", "args": self.dbref}] return cmds
def get_next_sentences(self, caller, npc, current_dialogue, current_sentence): """ """ if not caller: return if not npc: return # get current dialogue dlg = self.get_dialogue(current_dialogue) if not dlg: return sentences = [] try: # if has next sentence, use next sentence sentences.append(dlg["sentences"][current_sentence + 1]) except Exception, e: # get next dialogues for dlg_key in dlg["nexts"]: # get next dialogue next_dlg = self.get_dialogue(dlg_key) if not next_dlg: continue if not next_dlg["sentences"]: continue if not script_handler.match_condition(caller, next_dlg["condition"]): continue for dep in next_dlg["dependences"]: if not QUEST_DEP_HANDLER.match_dependence( caller, dep["quest"], dep["type"]): continue sentences.append(next_dlg["sentences"][0])
def get_next_sentences(self, caller, npc, current_dialogue, current_sentence): """ """ if not caller: return if not npc: return # get current dialogue dlg = self.get_dialogue(current_dialogue) if not dlg: return sentences = [] try: # if has next sentence, use next sentence sentences.append(dlg["sentences"][current_sentence + 1]) except Exception, e: # get next dialogues for dlg_key in dlg["nexts"]: # get next dialogue next_dlg = self.get_dialogue(dlg_key) if not next_dlg: continue if not next_dlg["sentences"]: continue if not script_handler.match_condition(caller, next_dlg["condition"]): continue for dep in next_dlg["dependences"]: if not QUEST_DEP_HANDLER.match_dependence(caller, dep["quest"], dep["type"]): continue sentences.append(next_dlg["sentences"][0])
def can_unlock(self, caller): """ Unlock an exit. """ return script_handler.match_condition(caller, self.exit_lock["condition"])