def func(self): "Talk to an NPC." caller = self.caller if not self.args: caller.msg({"alert":LS("You should talk to someone.")}) return npc = caller.search(self.args, location=caller.location) if not npc: # Can not find the NPC in the caller's location. caller.msg({"alert":LS("Can not find the one to talk.")}) return # Set caller's target. caller.set_target(npc) # Get NPC's sentences. sentences = DIALOGUE_HANDLER.get_sentences(caller, npc) # Get the spearker's name to display. speaker = "" if sentences: speaker = DIALOGUE_HANDLER.get_dialogue_speaker(caller, npc, sentences[0]["speaker"]) dialogues = [] for s in sentences: dlg = {"speaker": speaker, # speaker's name "npc": npc.dbref, # NPC's dbref "dialogue": s["dialogue"], # dialogue's key "sentence": s["sentence"], # sentence's ordinal "content": s["content"]} # sentence's content dialogues.append(dlg) caller.msg({"dialogue": dialogues})
def do_dialogue(self, data, character): """ Start a dialogue. """ # Get sentence. sentence = DIALOGUE_HANDLER.get_sentence(data["dialogue"], 0) if sentence: npc = None if data["npc"]: npc = utils.search_obj_info_key(data["npc"]) if npc: npc = npc[0] speaker = DIALOGUE_HANDLER.get_dialogue_speaker(character, npc, sentence["speaker"]) dlg = {"speaker": speaker, "dialogue": sentence["dialogue"], "sentence": sentence["sentence"], "content": sentence["content"]} if npc: dlg["npc"] = npc.dbref character.msg({"dialogue": [dlg]})
dialogue, sentence) except Exception, e: ostring = "Can not finish sentence %s-%s: %s" % (dialogue, sentence, e) logger.log_tracemsg(ostring) # Get next sentence. sentences = DIALOGUE_HANDLER.get_next_sentences(caller, npc, dialogue, sentence) # Get speaker's name. speaker = "" if sentences: speaker = DIALOGUE_HANDLER.get_dialogue_speaker(caller, npc, sentences[0]["speaker"]) dialogues = [] for s in sentences: dlg = {"speaker": speaker, # speaker's name "dialogue": s["dialogue"], # dialogue's key "sentence": s["sentence"], # sentence's ordinal "content": s["content"]} # sentence's content if npc: dlg["npc"] = npc.dbref # NPC's dbref, if has NPC. dialogues.append(dlg) # Send dialogues to the player. caller.msg({"dialogue": dialogues})