Ejemplo n.º 1
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    from muddery.utils.game_settings import GAME_SETTINGS
    GAME_SETTINGS.reset()

    # reload local strings
    from muddery.utils.localized_strings_handler import LOCALIZED_STRINGS_HANDLER
    LOCALIZED_STRINGS_HANDLER.reload()

    # reset default locations
    from muddery.utils import builder
    builder.reset_default_locations()
    
    # clear dialogues
    from muddery.utils.dialogue_handler import DIALOGUE_HANDLER
    DIALOGUE_HANDLER.clear()
    
    # reload equipment types
    from muddery.utils.equip_type_handler import EQUIP_TYPE_HANDLER
    EQUIP_TYPE_HANDLER.reload()

    # localize model fields
    from muddery.utils.localiztion_handler import localize_model_fields
    localize_model_fields()
    
    # load condition descriptions
    from muddery.utils.desc_handler import DESC_HANDLER
    DESC_HANDLER.reload()
Ejemplo n.º 2
0
    def continue_dialogue(self, npc, dialogue, sentence):
        """
        Continue current dialogue.

        Args:
            npc: (optional) NPC's object.
            dialogue: current dialogue's key.
            sentence: current sentence's ordinal.

        Returns:
            None
        """
        if GAME_SETTINGS.get("auto_resume_dialogues"):
            # Check current dialogue.
            if not self.db.current_dialogue:
                return

            if (dialogue, sentence) not in self.db.current_dialogue["sentences_all"]:
                # Can not find specified dialogue in current dialogues.
                return

        try:
            # Finish current sentence
            DIALOGUE_HANDLER.finish_sentence(self, npc, dialogue, sentence)
        except Exception, e:
            ostring = "Can not finish sentence %s-%s: %s" % (dialogue, sentence, e)
            logger.log_tracemsg(ostring)
Ejemplo n.º 3
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reload keys
    OBJECT_KEY_HANDLER.reload()

    # reset default locations
    builder.reset_default_locations()
    
    # clear dialogues
    DIALOGUE_HANDLER.clear()

    # clear quest dependencies
    QUEST_DEP_HANDLER.clear()

    # reload equipment types
    EQUIP_TYPE_HANDLER.reload()

    # reload local strings
    LOCALIZED_STRINGS_HANDLER.reload()

    # reload skill modules
    MudderySkill.load_skill_modules()
Ejemplo n.º 4
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    GAME_SETTINGS.reset()
    CLIENT_SETTINGS.reset()

    # reload keys
    OBJECT_KEY_HANDLER.reload()

    # reset default locations
    builder.reset_default_locations()

    # clear dialogues
    DIALOGUE_HANDLER.clear()

    # clear quest dependencies
    QUEST_DEP_HANDLER.clear()

    # reload equipment types
    EQUIP_TYPE_HANDLER.reload()

    # reload local strings
    LOCALIZED_STRINGS_HANDLER.reload()

    # localize model fields
    localize_model_fields()
Ejemplo n.º 5
0
    def continue_dialogue(self, npc, dialogue, sentence):
        """
        Continue current dialogue.

        Args:
            npc: (optional) NPC's object.
            dialogue: current dialogue's key.
            sentence: current sentence's ordinal.

        Returns:
            None
        """
        if GAME_SETTINGS.get("auto_resume_dialogues"):
            # Check current dialogue.
            if not self.db.current_dialogue:
                return

            if (dialogue, sentence) not in self.db.current_dialogue["sentences_all"]:
                # Can not find specified dialogue in current dialogues.
                return

        try:
            # Finish current sentence
            DIALOGUE_HANDLER.finish_sentence(self, npc, dialogue, sentence)
        except Exception, e:
            ostring = "Can not finish sentence %s-%s: %s" % (dialogue, sentence, e)
            logger.log_tracemsg(ostring)
Ejemplo n.º 6
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    GAME_SETTINGS.reset()

    # reload keys
    OBJECT_KEY_HANDLER.reload()

    # reset default locations
    builder.reset_default_locations()
    
    # clear dialogues
    DIALOGUE_HANDLER.clear()

    # clear quest dependencies
    QUEST_DEP_HANDLER.clear()

    # reload equipment types
    EQUIP_TYPE_HANDLER.reload()

    # reload local strings
    LOCALIZED_STRINGS_HANDLER.reload()

    # localize model fields
    localize_model_fields()
Ejemplo n.º 7
0
    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})
Ejemplo n.º 8
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    from muddery.utils.game_settings import GAME_SETTINGS
    GAME_SETTINGS.reset()

    # reload local strings
    from muddery.utils.localized_strings_handler import LOCALIZED_STRINGS_HANDLER
    LOCALIZED_STRINGS_HANDLER.reload()

    # reload attributes
    from muddery.utils.attributes_info_handler import CHARACTER_ATTRIBUTES_INFO
    CHARACTER_ATTRIBUTES_INFO.reload()

    from muddery.utils.attributes_info_handler import EQUIPMENT_ATTRIBUTES_INFO
    EQUIPMENT_ATTRIBUTES_INFO.reload()

    from muddery.utils.attributes_info_handler import FOOD_ATTRIBUTES_INFO
    FOOD_ATTRIBUTES_INFO.reload()

    # reset default locations
    from muddery.utils import builder
    builder.reset_default_locations()
    
    # clear dialogues
    from muddery.utils.dialogue_handler import DIALOGUE_HANDLER
    DIALOGUE_HANDLER.clear()
    
    # reload equipment types
    from muddery.utils.equip_type_handler import EQUIP_TYPE_HANDLER
    EQUIP_TYPE_HANDLER.reload()

    # localize model fields
    from muddery.utils.localiztion_handler import localize_model_fields
    localize_model_fields()

    # set character attribute field names
    CHARACTER_ATTRIBUTES_INFO.set_model_fields()
    EQUIPMENT_ATTRIBUTES_INFO.set_model_fields()
    FOOD_ATTRIBUTES_INFO.set_model_fields()
    
    # load condition descriptions
    from muddery.utils.desc_handler import DESC_HANDLER
    DESC_HANDLER.reload()
    
    # load honours
    from muddery.dao.honours_mapper import HONOURS_MAPPER
    HONOURS_MAPPER.reload()
Ejemplo n.º 9
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    from muddery.utils.game_settings import GAME_SETTINGS
    GAME_SETTINGS.reset()

    # reload local strings
    from muddery.utils.localized_strings_handler import LOCALIZED_STRINGS_HANDLER
    LOCALIZED_STRINGS_HANDLER.reload()

    # reload attributes
    from muddery.utils.attributes_info_handler import CHARACTER_ATTRIBUTES_INFO
    CHARACTER_ATTRIBUTES_INFO.reload()

    from muddery.utils.attributes_info_handler import EQUIPMENT_ATTRIBUTES_INFO
    EQUIPMENT_ATTRIBUTES_INFO.reload()

    from muddery.utils.attributes_info_handler import FOOD_ATTRIBUTES_INFO
    FOOD_ATTRIBUTES_INFO.reload()

    # reset default locations
    from muddery.utils import builder
    builder.reset_default_locations()

    # clear dialogues
    from muddery.utils.dialogue_handler import DIALOGUE_HANDLER
    DIALOGUE_HANDLER.clear()

    # reload equipment types
    from muddery.utils.equip_type_handler import EQUIP_TYPE_HANDLER
    EQUIP_TYPE_HANDLER.reload()

    # localize model fields
    from muddery.utils.localiztion_handler import localize_model_fields
    localize_model_fields()

    # set character attribute field names
    CHARACTER_ATTRIBUTES_INFO.set_model_fields()
    EQUIPMENT_ATTRIBUTES_INFO.set_model_fields()
    FOOD_ATTRIBUTES_INFO.set_model_fields()

    # load condition descriptions
    from muddery.utils.desc_handler import DESC_HANDLER
    DESC_HANDLER.reload()

    # load honours
    from muddery.dao.honours_mapper import HONOURS_MAPPER
    HONOURS_MAPPER.reload()
Ejemplo n.º 10
0
    def func(self):
        "Begin to talk to a 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:
            caller.msg({"alert":LS("Can not find the one to talk.")})
            return

        sentences = DIALOGUE_HANDLER.get_default_sentences(caller, npc)

        if sentences:
            speaker = sentences[0]["speaker"];
            if speaker == "n":
                speaker = npc.name
            elif speaker == "p":
                speaker = caller.name
            elif speaker[0] == '"' and speaker[-1] == '"':
                speaker = speaker[1:-1]

        dialogues = []
        for s in sentences:
            dlg = {"speaker": speaker,
                   "npc": npc.key,
                   "dialogue": s["dialogue"],
                   "sentence": s["sentence"],
                   "content": s["content"]}
            dialogues.append(dlg)

        caller.msg({"dialogue": dialogues})
Ejemplo n.º 11
0
    def func(self):
        "Begin to talk to a 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:
            caller.msg({"alert":LS("Can not find the one to talk.")})
            return

        sentences = DIALOGUE_HANDLER.get_default_sentences(caller, npc)

        if sentences:
            speaker = sentences[0]["speaker"];
            if speaker == "n":
                speaker = npc.name
            elif speaker == "p":
                speaker = caller.name
            elif speaker[0] == '"' and speaker[-1] == '"':
                speaker = speaker[1:-1]

        dialogues = []
        for s in sentences:
            dlg = {"speaker": speaker,
                   "npc": npc.key,
                   "dialogue": s["dialogue"],
                   "sentence": s["sentence"],
                   "content": s["content"]}
            dialogues.append(dlg)

        caller.msg({"dialogue": dialogues})
Ejemplo n.º 12
0
class CmdDialogue(Command):
    """
    Talk to NPC, using dialogues stored in db.

    Usage:
        {"cmd":"dialogue",
         "args":{"npc":<npc's dbref>,
                 "dialogue":[<talk's dialogue>],
                 "sentence":[<talk's sentence>]}
        }

    Dialogue and sentence refer to the current sentence.
    If dialogue or sentence is null, use the npc's default dialogue.
    """
    key = "dialogue"
    locks = "cmd:all()"
    help_cateogory = "General"

    def func(self):
        "Talk to NPC."
        caller = self.caller

        if not self.args:
            caller.msg({"alert":LS("You should talk to someone.")})
            return

        if not "npc" in self.args:
            caller.msg({"alert":LS("You should talk to someone.")})
            return

        # Get the npc at the player's location.
        npc = caller.search(self.args["npc"], location=caller.location)
        if not npc:
            caller.msg({"alert":LS("Can not find the one to talk.")})
            return

        # Get the current sentence.
        dialogue = ""
        sentence = 0

        have_current_dlg = False
        try:
            dialogue = self.args["dialogue"]
            sentence = int(self.args["sentence"])
            have_current_dlg = True
        except Exception, e:
            pass

        if have_current_dlg:
            try:
                # Finish this sentence
                DIALOGUE_HANDLER.finish_sentence(caller,
                                                 dialogue,
                                                 sentence)
            except Exception, e:
                ostring = "Can not finish sentence %s-%s: %s" % (dialogue, sentence, e)
                logger.log_errmsg(ostring)
                logger.log_errmsg(traceback.format_exc())
Ejemplo n.º 13
0
    def resume_last_dialogue(self):
        """
        Restore player's dialogues when he return to game.

        Returns:
            None
        """
        if not GAME_SETTINGS.get("auto_resume_dialogues"):
            # Can not auto resume dialogues.
            return

        if not self.db.current_dialogue:
            return

        current = self.db.current_dialogue

        if not current["sentences"]:
            return

        # Check dialogue's location
        if self.location.get_data_key() != current["location"]:
            # If player's location has changed, return.
            return

        # Check npc.
        npc_talking = None
        if current["npc"]:
            npc_list = utils.search_obj_data_key(current["npc"])
            npc_in_location = [
                npc for npc in npc_list if npc.location == self.location
            ]
            if not npc_in_location:
                # If the NPC has left it's location, return.
                return
            npc_talking = npc_in_location[0]

        sentences = [
            DIALOGUE_HANDLER.get_sentence(s[0], s[1])
            for s in current["sentence"]
        ]
        dialogue = DIALOGUE_HANDLER.create_output_sentences(
            sentences, self, npc_talking)
        self.msg({"dialogue": dialogue})
        return
Ejemplo n.º 14
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # reset settings
    GAME_SETTINGS.reset()

    # reload keys
    OBJECT_KEY_HANDLER.reload()

    # reload attributes
    CHARACTER_ATTRIBUTES_INFO.reload()
    EQUIPMENT_ATTRIBUTES_INFO.reload()
    FOOD_ATTRIBUTES_INFO.reload()

    # reset default locations
    builder.reset_default_locations()

    # clear dialogues
    DIALOGUE_HANDLER.clear()

    # clear quest dependencies
    QUEST_DEP_HANDLER.clear()

    # reload equipment types
    EQUIP_TYPE_HANDLER.reload()

    # reload local strings
    LOCALIZED_STRINGS_HANDLER.reload()

    # localize model fields
    localize_model_fields()

    # set character attribute field names
    CHARACTER_ATTRIBUTES_INFO.set_model_fields()
    EQUIPMENT_ATTRIBUTES_INFO.set_model_fields()
    FOOD_ATTRIBUTES_INFO.set_model_fields()

    # load condition descriptions
    DESC_HANDLER.reload()

    # load honours
    HONOURS_MAPPER.reload()
Ejemplo n.º 15
0
    def continue_dialogue(self, npc, dialogue, sentence):
        """
        Continue current dialogue.

        Args:
            npc: (optional) NPC's object.
            dialogue: current dialogue's key.
            sentence: current sentence's ordinal.

        Returns:
            None
        """
        if GAME_SETTINGS.get("auto_resume_dialogues"):
            # Check current dialogue.
            if not self.db.current_dialogue:
                return

            if (dialogue,
                    sentence) not in self.db.current_dialogue["sentences_all"]:
                # Can not find specified dialogue in current dialogues.
                return

        try:
            # Finish current sentence
            DIALOGUE_HANDLER.finish_sentence(self, npc, dialogue, sentence)
        except Exception as e:
            ostring = "Can not finish sentence %s-%s: %s" % (dialogue,
                                                             sentence, e)
            logger.log_tracemsg(ostring)

        # Get next sentences.
        sentences = DIALOGUE_HANDLER.get_next_sentences(
            self, npc, dialogue, sentence)

        # Send dialogues_list to the player.
        self.save_current_dialogue(sentences, npc)
        self.msg({"dialogue": sentences})
        if not sentences:
            # dialogue finished, refresh surroundings
            self.show_location()
Ejemplo n.º 16
0
    def resume_last_dialogue(self):
        """
        Restore player's dialogues when he return to game.

        Returns:
            None
        """
        if not GAME_SETTINGS.get("auto_resume_dialogues"):
            # Can not auto resume dialogues.
        	return

        if not self.db.current_dialogue:
            return

        current = self.db.current_dialogue
        
        if not current["sentences_begin"]:
            return

        # Check dialogue's location
        if self.location.get_data_key() != current["location"]:
            # If player's location has changed, return.
            return

        # Check npc.
        npc_talking = None
        if current["npc"]:
            npc_list = utils.search_obj_data_key(current["npc"])
            npc_in_location = [npc for npc in npc_list if npc.location == self.location]
            if not npc_in_location:
                # If the NPC has left it's location, return.
                return
            npc_talking = npc_in_location[0]

        sentences_list = [DIALOGUE_HANDLER.get_sentence(s[0], s[1]) for s in current["sentences_begin"]]
        output = DIALOGUE_HANDLER.create_output_sentences(sentences_list, self, npc_talking)
        self.msg({"dialogues_list": [output]})
        return
Ejemplo n.º 17
0
    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]})
Ejemplo n.º 18
0
    def talk_to_npc(self, npc):
        """
        Talk to an NPC.

        Args:
            npc: NPC's object.

        Returns:
            None
        """
        # Set caller's target.
        self.set_target(npc)

        # Get NPC's sentences_list.
        sentences_list = DIALOGUE_HANDLER.get_npc_sentences_list(self, npc)
        
        self.save_current_dialogue(sentences_list, npc)
        self.msg({"dialogues_list": sentences_list})
Ejemplo n.º 19
0
    def talk_to_npc(self, npc):
        """
        Talk to an NPC.

        Args:
            npc: NPC's object.

        Returns:
            None
        """
        # Set caller's target.
        self.set_target(npc)

        # Get NPC's sentences_list.
        sentences_list = DIALOGUE_HANDLER.get_npc_sentences_list(self, npc)
        
        self.save_current_dialogue(sentences_list, npc)
        self.msg({"dialogues_list": sentences_list})
Ejemplo n.º 20
0
    def show_dialogue(self, npc, dialogue):
        """
        Show a dialogue.

        Args:
            npc: (optional) NPC's object.
            dialogue: dialogue's key.

        Returns:
            None
        """
        # Get next sentences_list.
        sentences = DIALOGUE_HANDLER.get_dialogue_sentences(
            self, npc, dialogue)

        # Send the dialogue to the player.
        self.save_current_dialogue(sentences, npc)
        self.msg({"dialogue": sentences})
Ejemplo n.º 21
0
    def do_dialogue(self, event, character):
        """
        Start a dialogue.
        """
        # Get sentence.
        npc = None
        if event["npc"]:
            npc = utils.search_obj_data_key(event["npc"])
            if npc:
                npc = npc[0]

        sentence_list = DIALOGUE_HANDLER.get_next_sentences_list(character,
                                                                 npc,
                                                                 event["dialogue"],
                                                                 0,
                                                                 True)

        character.msg({"dialogues_list": sentence_list})
Ejemplo n.º 22
0
    def show_dialogue(self, npc, dialogue, sentence):
        """
        Show a dialogue.

        Args:
            npc: (optional) NPC's object.
            dialogue: dialogue's key.
            sentence: sentence's ordinal.

        Returns:
            None
        """
        # Get next sentences_list.
        sentences_list = DIALOGUE_HANDLER.get_next_sentences_list(
            self, npc, dialogue, sentence, True)

        # Send dialogues_list to the player.
        self.save_current_dialogue(sentences_list, npc)
        self.msg({"dialogues_list": sentences_list})
Ejemplo n.º 23
0
    def return_objectives(self):
        """
        """
        objectives = []
        for ordinal in self.objectives:
            obj_num = self.objectives[ordinal]["number"]
            achieved = self.db.achieved.get(ordinal, 0)
            
            if self.objectives[ordinal]["type"] == defines.OBJECTIVE_TALK:
                target = LS("Talk to")
                object = DIALOGUE_HANDLER.get_npc_name(self.objectives[ordinal]["object"])
    
                objectives.append({"target": target,
                                   "object": object,
                                   "achieved": achieved,
                                   "total": obj_num
                                   })

        return objectives
Ejemplo n.º 24
0
    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_list.
        sentences_list = DIALOGUE_HANDLER.get_sentences_list(caller, npc)

        caller.msg({"dialogues_list": sentences_list})
Ejemplo n.º 25
0
    def show_dialogue(self, npc, dialogue, sentence):
        """
        Show a dialogue.

        Args:
            npc: (optional) NPC's object.
            dialogue: dialogue's key.
            sentence: sentence's ordinal.

        Returns:
            None
        """
        # Get next sentences_list.
        sentences_list = DIALOGUE_HANDLER.get_next_sentences_list(self,
                                                                  npc,
                                                                  dialogue,
                                                                  sentence,
                                                                  True)

        # Send dialogues_list to the player.
        self.save_current_dialogue(sentences_list, npc)
        self.msg({"dialogues_list": sentences_list})
Ejemplo n.º 26
0
            pass

        if have_current_dlg:
            try:
                # Finish current sentence
                DIALOGUE_HANDLER.finish_sentence(caller,
                                                 npc,
                                                 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.
Ejemplo n.º 27
0
            if (dialogue, sentence) not in self.db.current_dialogue["sentences_all"]:
                # Can not find specified dialogue in current dialogues.
                return

        try:
            # Finish current sentence
            DIALOGUE_HANDLER.finish_sentence(self, npc, dialogue, sentence)
        except Exception, e:
            ostring = "Can not finish sentence %s-%s: %s" % (dialogue, sentence, e)
            logger.log_tracemsg(ostring)

        # Get next sentences_list.
        sentences_list = DIALOGUE_HANDLER.get_next_sentences_list(self,
                                                                  npc,
                                                                  dialogue,
                                                                  sentence,
                                                                  False)

        # Send dialogues_list to the player.
        self.save_current_dialogue(sentences_list, npc)
        self.msg({"dialogues_list": sentences_list})
        if not sentences_list:
            # dialogue finished, refresh surroundings
            self.show_location()            

    def add_exp(self, exp, combat=False):
        """
        Add character's exp.
        Args:
            exp: (number) the exp value to add.
Ejemplo n.º 28
0
        if have_current_dlg:
            try:
                # Finish current sentence
                DIALOGUE_HANDLER.finish_sentence(caller,
                                                 npc,
                                                 dialogue,
                                                 sentence)
            except Exception, e:
                ostring = "Can not finish sentence %s-%s: %s" % (dialogue, sentence, e)
                logger.log_tracemsg(ostring)

        # Get next sentences_list.
        sentences_list = DIALOGUE_HANDLER.get_next_sentences_list(caller,
                                                                  npc,
                                                                  dialogue,
                                                                  sentence,
                                                                  False)

        # Send dialogues_list to the player.
        caller.msg({"dialogues_list": sentences_list})


#------------------------------------------------------------
# loot objects
#------------------------------------------------------------

class CmdLoot(Command):
    """
    Loot from a specified object.
Ejemplo n.º 29
0
 def have_quest(self, caller):
     """
     If the npc can complete or provide quests.
     Returns (can_provide_quest, can_complete_quest).
     """
     return DIALOGUE_HANDLER.have_quest(caller, self)
Ejemplo n.º 30
0
    def return_objectives(self):
        """
        Get the information of all objectives.
        Set desc to an objective can hide the details of the objective.
        """
        output = []

        for ordinal, objective in self.objectives.items():
            desc = objective["desc"]
            if desc:
                # If an objective has desc, use its desc.
                output.append({"ordinal": ordinal, "desc": objective["desc"]})
            else:
                # Or make a desc by other data.
                obj_num = objective["number"]
                accomplished = self.db.accomplished.get(ordinal, 0)

                if objective["type"] == defines.OBJECTIVE_TALK:
                    # talking
                    target = _("Talk to")
                    name = DIALOGUE_HANDLER.get_npc_name(objective["object"])

                    output.append({
                        "ordinal": ordinal,
                        "target": target,
                        "object": name,
                        "accomplished": accomplished,
                        "total": obj_num,
                    })

                elif objective["type"] == defines.OBJECTIVE_OBJECT:
                    # getting
                    target = _("Get")

                    # Get the name of the objective object.
                    object_key = objective["object"]
                    model_name = TYPECLASS("OBJECT").model_name
                    model = apps.get_model(settings.WORLD_DATA_APP, model_name)
                    # Get record.
                    try:
                        record = model.objects.get(key=object_key)
                        name = record.name
                    except Exception as e:
                        logger.log_err("Can not find the quest object: %s" %
                                       object_key)
                        continue

                    output.append({
                        "ordinal": ordinal,
                        "target": target,
                        "object": name,
                        "accomplished": accomplished,
                        "total": obj_num,
                    })

                elif self.objectives[ordinal][
                        "type"] == defines.OBJECTIVE_KILL:
                    # getting
                    target = _("Kill")

                    # Get the name of the objective character.
                    object_key = self.objectives[ordinal]["object"]
                    model_name = TYPECLASS("OBJECT").model_name
                    model = apps.get_model(settings.WORLD_DATA_APP, model_name)

                    # Get record.
                    try:
                        record = model.objects.get(key=object_key)
                        name = record.name
                    except Exception as e:
                        logger.log_err("Can not find the quest object: %s" %
                                       object_key)
                        continue

                    output.append({
                        "ordinal": ordinal,
                        "target": target,
                        "object": name,
                        "accomplished": accomplished,
                        "total": obj_num,
                    })

        return output
Ejemplo n.º 31
0
    def return_objectives(self):
        """
        Get the information of all objectives.
        Set desc to an objective can hide the details of the objective.
        """
        objectives = []
        for ordinal in self.objectives:
            desc = self.objectives[ordinal]["desc"]
            if desc:
                # If an objective has desc, use its desc.
                objectives.append({"desc": self.objectives[ordinal]["desc"]})
            else:
                # Or make a desc by other data.
                obj_num = self.objectives[ordinal]["number"]
                accomplished = self.db.accomplished.get(ordinal, 0)

                if self.objectives[ordinal]["type"] == defines.OBJECTIVE_TALK:
                    # talking
                    target = LS("Talk to")
                    name = DIALOGUE_HANDLER.get_npc_name(
                        self.objectives[ordinal]["object"])

                    objectives.append({
                        "target": target,
                        "object": name,
                        "accomplished": accomplished,
                        "total": obj_num,
                    })
                elif self.objectives[ordinal][
                        "type"] == defines.OBJECTIVE_OBJECT:
                    # getting
                    target = LS("Get")
                    name = ""

                    # Get the name of the objective object.
                    for model_name in settings.COMMON_OBJECTS:
                        model = apps.get_model(settings.WORLD_DATA_APP,
                                               model_name)
                        if model:
                            # Get record.
                            try:
                                record = model.objects.get(
                                    key=self.objectives[ordinal]["object"])
                                name = record.name
                                break
                            except Exception, e:
                                pass

                    objectives.append({
                        "target": target,
                        "object": name,
                        "accomplished": accomplished,
                        "total": obj_num,
                    })
                elif self.objectives[ordinal][
                        "type"] == defines.OBJECTIVE_KILL:
                    # getting
                    target = LS("Kill")
                    name = ""

                    # Get the name of the objective character.
                    for model_name in settings.COMMON_OBJECTS:
                        # find in common objects
                        model = apps.get_model(settings.WORLD_DATA_APP,
                                               model_name)
                        if model:
                            # Get record.
                            try:
                                record = model.objects.get(
                                    key=self.objectives[ordinal]["object"])
                                name = record.name
                                break
                            except Exception, e:
                                pass

                    if not name:
                        # find in world_npcs
                        for model_name in settings.WORLD_NPCS:
                            # find in common objects
                            model = apps.get_model(settings.WORLD_DATA_APP,
                                                   model_name)
                            if model:
                                # Get record.
                                try:
                                    record = model.objects.get(
                                        key=self.objectives[ordinal]["object"])
                                    name = record.name
                                    break
                                except Exception, e:
                                    pass
Ejemplo n.º 32
0
 def have_quest(self, caller):
     """
     check if the npc can finish or provide quests
     finishing is higher than providing
     """
     return DIALOGUE_HANDLER.have_quest(caller, self)
Ejemplo n.º 33
0
            pass

        if have_current_dlg:
            try:
                # Finish this sentence
                DIALOGUE_HANDLER.finish_sentence(caller,
                                                 dialogue,
                                                 sentence)
            except Exception, e:
                ostring = "Can not finish sentence %s-%s: %s" % (dialogue, sentence, e)
                logger.log_errmsg(ostring)
                logger.log_errmsg(traceback.format_exc())

        # Get next sentence.
        sentences = DIALOGUE_HANDLER.get_next_sentences(caller,
                                                        npc,
                                                        dialogue,
                                                        sentence)

        if sentences:
            speaker = sentences[0]["speaker"];
            if speaker == "n":
                speaker = npc.get_name()
            elif speaker == "p":
                speaker = caller.get_name()
            elif speaker[0] == '"' and speaker[-1] == '"':
                speaker = speaker[1:-1]

        dialogues = []
        for s in sentences:
            dlg = {"speaker": speaker,
                   "npc": npc.key,
Ejemplo n.º 34
0
 def have_quest(self, caller):
     """
     If the npc can complete or provide quests.
     Returns (can_provide_quest, can_complete_quest).
     """
     return DIALOGUE_HANDLER.have_quest(caller, self)
Ejemplo n.º 35
0
    def return_objectives(self):
        """
        Get the information of all objectives.
        Set desc to an objective can hide the details of the objective.
        """
        objectives = []
        for ordinal in self.objectives:
            desc = self.objectives[ordinal]["desc"]
            if desc:
                # If an objective has desc, use its desc.
                objectives.append({"desc": self.objectives[ordinal]["desc"]})
            else:
                # Or make a desc by other data.
                obj_num = self.objectives[ordinal]["number"]
                accomplished = self.db.accomplished.get(ordinal, 0)
                
                if self.objectives[ordinal]["type"] == defines.OBJECTIVE_TALK:
                    # talking
                    target = _("Talk to")
                    name = DIALOGUE_HANDLER.get_npc_name(self.objectives[ordinal]["object"])
        
                    objectives.append({"target": target,
                                       "object": name,
                                       "accomplished": accomplished,
                                       "total": obj_num,
                                       })
                elif self.objectives[ordinal]["type"] == defines.OBJECTIVE_OBJECT:
                    # getting
                    target = _("Get")
                    name = ""
                    
                    # Get the name of the objective object.
                    object_key = self.objectives[ordinal]["object"]
                    model_names = OBJECT_KEY_HANDLER.get_models(object_key)
                    for model_name in model_names:
                        model = apps.get_model(settings.WORLD_DATA_APP, model_name)
                        # Get record.
                        try:
                            record = model.objects.get(key=object_key)
                            name = record.name
                            break
                        except Exception, e:
                            pass
        
                    objectives.append({"target": target,
                                       "object": name,
                                       "accomplished": accomplished,
                                       "total": obj_num,
                                       })
                elif self.objectives[ordinal]["type"] == defines.OBJECTIVE_KILL:
                    # getting
                    target = _("Kill")
                    name = ""

                    # Get the name of the objective character.
                    object_key = self.objectives[ordinal]["object"]
                    model_names = OBJECT_KEY_HANDLER.get_models(object_key)
                    for model_name in model_names:
                        model = apps.get_model(settings.WORLD_DATA_APP, model_name)
                        # Get record.
                        try:
                            record = model.objects.get(key=object_key)
                            name = record.name
                            break
                        except Exception, e:
                            pass

                    objectives.append({"target": target,
                                       "object": name,
                                       "accomplished": accomplished,
                                       "total": obj_num,
                                       })
Ejemplo n.º 36
0
            pass

        if have_current_dlg:
            try:
                # Finish this sentence
                DIALOGUE_HANDLER.finish_sentence(caller,
                                                 dialogue,
                                                 sentence)
            except Exception, e:
                ostring = "Can not finish sentence %s-%s: %s" % (dialogue, sentence, e)
                logger.log_errmsg(ostring)
                logger.log_errmsg(traceback.format_exc())

        # Get next sentence.
        sentences = DIALOGUE_HANDLER.get_next_sentences(caller,
                                                        npc,
                                                        dialogue,
                                                        sentence)

        if sentences:
            speaker = sentences[0]["speaker"];
            if speaker == "n":
                speaker = npc.name
            elif speaker == "p":
                speaker = caller.name
            elif speaker[0] == '"' and speaker[-1] == '"':
                speaker = speaker[1:-1]

        dialogues = []
        for s in sentences:
            dlg = {"speaker": speaker,
                   "npc": npc.key,