def dialogue_have_quest(self, caller, npc, dialogue, accomplished_quests): """ Find quests by recursion. """ provide_quest = False complete_quest = False # check if the dialogue is available npc_dlg = self.get_dialogue(dialogue) if not npc_dlg: return (provide_quest, complete_quest) if not STATEMENT_HANDLER.match_condition(npc_dlg["condition"], caller, npc): return (provide_quest, complete_quest) match = True for dep in npc_dlg["dependencies"]: if not QUEST_DEP_HANDLER.match_dependency(caller, dep["quest"], dep["type"]): match = False break if not match: return (provide_quest, complete_quest) # find quests in its sentences for sen in npc_dlg["sentences"]: if sen["complete_quest"] in accomplished_quests: complete_quest = True return (provide_quest, complete_quest) if not provide_quest and sen["provide_quest"]: quest_key = sen["provide_quest"] if caller.quest_handler.can_provide(quest_key): provide_quest = True if not accomplished_quests: return (provide_quest, complete_quest) for dlg_key in npc_dlg["nexts"]: # get next dialogue provide, complete = self.dialogue_have_quest( caller, npc, dlg_key, accomplished_quests) provide_quest = (provide_quest or provide) complete_quest = (complete_quest or complete) if complete_quest: break if not accomplished_quests: if provide_quest: break return (provide_quest, complete_quest)
def get_npc_sentences(self, caller, npc): """ Get NPC's sentences that can show to the caller. Args: caller: (object) the character who want to start a talk. npc: (object) the NPC that the character want to talk to. Returns: sentences: (list) a list of available sentences. """ if not caller: return if not npc: return sentences = [] # Get npc's dialogues. for dlg_key in npc.dialogues: # Get all dialogues. npc_dlg = self.get_dialogue(dlg_key) if not npc_dlg: continue # Match conditions. if not STATEMENT_HANDLER.match_condition(npc_dlg["condition"], caller, npc): continue # Match dependencies. match = True for dep in npc_dlg["dependencies"]: if not QUEST_DEP_HANDLER.match_dependency( 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]) if not sentences: # Use default sentences. # Default sentences should not have condition and dependencies. for dlg_key in npc.default_dialogues: npc_dlg = self.get_dialogue(dlg_key) if npc_dlg: sentences.append(npc_dlg["sentences"][0]) return sentences
def get_npc_sentences(self, caller, npc): """ Get NPC's sentences that can show to the caller. Args: caller: (object) the character who want to start a talk. npc: (object) the NPC that the character want to talk to. Returns: sentences: (list) a list of available sentences. """ if not caller: return if not npc: return sentences = [] # Get npc's dialogues. for dlg_key in npc.dialogues: # Get all dialogues. npc_dlg = self.get_dialogue(dlg_key) if not npc_dlg: continue # Match conditions. if not STATEMENT_HANDLER.match_condition(npc_dlg["condition"], caller, npc): continue # Match dependencies. match = True for dep in npc_dlg["dependencies"]: if not QUEST_DEP_HANDLER.match_dependency(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]) if not sentences: # Use default sentences. # Default sentences should not have condition and dependencies. for dlg_key in npc.default_dialogues: npc_dlg = self.get_dialogue(dlg_key) if npc_dlg: sentences.append(npc_dlg["sentences"][0]) return sentences
def dialogue_have_quest(self, caller, npc, dialogue, accomplished_quests): """ Find quests by recursion. """ provide_quest = False complete_quest = False # check if the dialogue is available npc_dlg = self.get_dialogue(dialogue) if not npc_dlg: return (provide_quest, complete_quest) if not SCRIPT_HANDLER.match_condition(caller, npc, npc_dlg["condition"]): return (provide_quest, complete_quest) match = True for dep in npc_dlg["dependencies"]: if not QUEST_DEP_HANDLER.match_dependency(caller, dep["quest"], dep["type"]): match = False break; if not match: return (provide_quest, complete_quest) # find quests in its sentences for sen in npc_dlg["sentences"]: if sen["complete_quest"] in accomplished_quests: complete_quest = True return (provide_quest, complete_quest) if not provide_quest and sen["provide_quest"]: quest_key = sen["provide_quest"] if caller.quest.can_provide(quest_key): provide_quest = True if not accomplished_quests: return (provide_quest, complete_quest) for dlg_key in npc_dlg["nexts"]: # get next dialogue provide, complete = self.dialogue_have_quest(caller, npc, dlg_key, accomplished_quests) provide_quest = (provide_quest or provide) complete_quest = (complete_quest or complete) if complete_quest: break if not accomplished_quests: if provide_quest: break return (provide_quest, complete_quest)
def get_next_sentences(self, caller, npc, current_dialogue, current_sentence): """ Get current sentence's next sentences. Args: caller: (object) the character who want to start a talk. npc: (object) the NPC that the character want to talk to. dialogue: (string) the key of the currrent dialogue. sentence: (int) the number of current sentence. Returns: sentences: (list) a list of available sentences. """ if not caller: 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: # Else 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 STATEMENT_HANDLER.match_condition( next_dlg["condition"], caller, npc): continue for dep in next_dlg["dependencies"]: if not QUEST_DEP_HANDLER.match_dependency( caller, dep["quest"], dep["type"]): continue sentences.append(next_dlg["sentences"][0])
def get_sentences(self, caller, npc): """ Get NPC's sentences. """ if not caller: return if not npc: return sentences = [] # Get npc's dialogues. for dlg_key in npc.dialogues: # Get all dialogues. npc_dlg = self.get_dialogue(dlg_key) if not npc_dlg: continue # Match conditions. if not SCRIPT_HANDLER.match_condition(caller, npc, npc_dlg["condition"]): continue # Match dependeces. match = True for dep in npc_dlg["dependencies"]: if not QUEST_DEP_HANDLER.match_dependency(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]) if not sentences: # Use default sentences. # Default sentences should not have condition and dependencies. for dlg_key in npc.default_dialogues: npc_dlg = self.get_dialogue(dlg_key) if npc_dlg: sentences.append(npc_dlg["sentences"][0]) return sentences
def get_next_sentences(self, caller, npc, current_dialogue, current_sentence): """ Get current sentence's next sentences. Args: caller: (object) the character who want to start a talk. npc: (object) the NPC that the character want to talk to. dialogue: (string) the key of the currrent dialogue. sentence: (int) the number of current sentence. Returns: sentences: (list) a list of available sentences. """ if not caller: 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: # Else 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 STATEMENT_HANDLER.match_condition(next_dlg["condition"], caller, npc): continue for dep in next_dlg["dependencies"]: if not QUEST_DEP_HANDLER.match_dependency(caller, dep["quest"], dep["type"]): continue sentences.append(next_dlg["sentences"][0])
def get_next_sentences(self, caller, npc, current_dialogue, current_sentence): """ Get current sentence's next sentences. """ if not caller: 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: # Else 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, npc, next_dlg["condition"]): continue for dep in next_dlg["dependencies"]: if not QUEST_DEP_HANDLER.match_dependency(caller, dep["quest"], dep["type"]): continue sentences.append(next_dlg["sentences"][0])