Exemplo n.º 1
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["dialogues"]:
            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]

        dialogues = [
            DIALOGUE_HANDLER.get_dialogue(d) for d in current["dialogues"]
        ]
        dialogues = DIALOGUE_HANDLER.create_output_sentences(
            dialogues, self, npc_talking)
        self.msg({"dialogue": dialogues})
        return
Exemplo 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"]:
                # 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()            
Exemplo n.º 3
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    # load data
    from muddery.server.dao.worlddata import WorldData
    WorldData.reload()

    # reset settings
    from muddery.server.utils.game_settings import GAME_SETTINGS
    GAME_SETTINGS.reset()

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

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

    # localize model fields
    from muddery.server.utils.localiztion_handler import localize_model_fields
    localize_model_fields()
    
    # load condition descriptions
    from muddery.server.utils.desc_handler import DESC_HANDLER
    DESC_HANDLER.reload()

    # load honours
    from muddery.server.dao.honours_mapper import HONOURS_MAPPER
    HONOURS_MAPPER.reload()
Exemplo n.º 4
0
    def finish_dialogue(self, dlg_key, npc):
        """
        Continue current dialogue.

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

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

            if dlg_key not in self.db.current_dialogue["dialogue"]:
                # Can not find specified dialogue in current dialogues.
                return

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

        # Get next dialogue.
        next_dialogues = DIALOGUE_HANDLER.get_next_dialogues(
            dlg_key, self, npc)

        # Send dialogues_list to the player.
        self.save_current_dialogues(next_dialogues, npc)
        self.msg({"dialogue": next_dialogues})
        if not next_dialogues:
            # dialogue finished, refresh surroundings
            self.show_location()
Exemplo n.º 5
0
    def show_dialogue(self, dlg_key, npc):
        """
        Show a dialogue.

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

        Returns:
            None
        """
        # Get next sentences_list.
        dialogue = DIALOGUE_HANDLER.get_dialogues_by_key(dlg_key, npc)

        # Send the dialogue to the player.
        self.save_current_dialogues(dialogue, npc)
        self.msg({"dialogue": dialogue})
Exemplo n.º 6
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 dialogue list.
        dialogues = DIALOGUE_HANDLER.get_npc_dialogues(self, npc)

        self.save_current_dialogues(dialogues, npc)
        self.msg({"dialogue": dialogues})
Exemplo n.º 7
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})
Exemplo n.º 8
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)
Exemplo n.º 9
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

                    # Get record.
                    try:
                        record = WorldData.get_table_data(model_name,
                                                          key=object_key)
                        record = record[0]
                        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

                    # Get record.
                    try:
                        record = WorldData.get_table_data(model_name,
                                                          key=object_key)
                        record = record[0]
                        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