Пример #1
0
def at_initial_setup():
    """
    Build up the default world and set default locations.
    """

    try:
        # load data
        from muddery.server.dao.worlddata import WorldData
        WorldData.reload()
        print("Reload world data.")

        # load game settings
        GAME_SETTINGS.reset()
        print("Reset game settings.")

        # build world
        builder.build_all()
        print("Builder build all.")

        # set limbo's desc
        limbo_obj = search.search_object("#2", exact=True)
        if limbo_obj:
            limbo_obj[0].db.desc = LIMBO_DESC
            limbo_obj[0].position = None
        print("Set limbo object.")

        # set default locations
        builder.reset_default_locations()
        print("Set default locations.")

        superuser = search.search_object("#1", exact=True)
        if superuser:
            superuser = superuser[0]

            # move the superuser to the start location
            start_location = search.search_object(settings.START_LOCATION,
                                                  exact=True)
            if start_location:
                start_location = start_location[0]
                superuser.move_to(start_location, quiet=True)

            # set superuser's data
            superuser.set_data_key(
                GAME_SETTINGS.get("default_player_character_key"), 1)
            superuser.set_nickname("superuser")

            print("Set superuser.")

    except Exception as e:
        ostring = "Can't set initial data: %s" % e
        print(ostring)
        print(traceback.format_exc())
Пример #2
0
    def save_current_dialogues(self, dialogues, npc):
        """
        Save player's current dialogues.

        Args:
            dialogues: the current dialogues
            npc: NPC whom the player is talking to.

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

        if not dialogues:
            self.clear_current_dialogue()
            return

        # Save the dialogue's id.
        dialogues = [d["dialogue"] for d in dialogues]

        npc_key = None
        if npc:
            npc_key = npc.get_data_key()

        location_key = None
        if self.location:
            location_key = self.location.get_data_key()

        self.db.current_dialogue = {"dialogues": dialogues,
                                    "npc": npc_key,
                                    "location": location_key}

        return
Пример #3
0
    def reborn(self):
        """
        Reborn after being killed.
        """
        # Reborn at its home.
        home = None
        default_home_key = GAME_SETTINGS.get("default_player_home_key")
        if default_home_key:
            rooms = utils.search_obj_data_key(default_home_key)
            if rooms:
                home = rooms[0]

        if not home:
            rooms = search.search_object(settings.DEFAULT_HOME)
            if rooms:
                home = rooms[0]

        if home:
            self.move_to(home, quiet=True)

        # Recover properties.
        self.recover()
        self.show_status()

        if home:
            self.msg({"msg": _("You are reborn at {C%s{n.") % home.get_name()})
        else:
            self.msg({"msg": _("You are reborn.")})
Пример #4
0
    def func(self):
        "Show the connect screen."
        game_name = GAME_SETTINGS.get("game_name")
        connection_screen = GAME_SETTINGS.get("connection_screen")
        records = EquipmentPositions.all()
        equipment_pos = [{
            "key": r.key,
            "name": r.name,
            "desc": r.desc,
        } for r in records]

        self.caller.msg({
            "game_name": game_name,
            "conn_screen": connection_screen,
            "equipment_pos": equipment_pos,
        })
Пример #5
0
def reset_default_locations():
    """
    Reset default home and start location, get new positions from
    settings.DEFAULT_HOME_KEY and settings.START_LOCATION_KEY. If they
    are empty, set them to to the first room in settings.WORLD_ROOMS.
    """
    # Set default home.
    default_home_key = GAME_SETTINGS.get("default_home_key")
    if not default_home_key:
        # If does not have the default_home_key, get the first room in WORLD_ROOMS.
        try:
            rooms = WorldRooms.all()
            if rooms:
                default_home_key = rooms[0].key
        except Exception as e:
            ostring = "Can not find default_home_key: %s" % e
            print(ostring)
            print(traceback.print_exc())

    if default_home_key:
        # If get default_home_key.
        default_home = utils.search_obj_data_key(default_home_key)
        if default_home:
            # Set default home.
            settings.DEFAULT_HOME = default_home[0].dbref
            print("settings.DEFAULT_HOME set to: %s" % settings.DEFAULT_HOME)

    # Set start location.
    start_location_key = GAME_SETTINGS.get("start_location_key")
    if not start_location_key:
        # If does not have the start_location_key, get the first room in WORLD_ROOMS
        try:
            rooms = WorldRooms.all()
            if rooms:
                start_location_key = rooms[0].key
        except Exception as e:
            ostring = "Can not find start_location_key: %s" % e
            print(ostring)
            print(traceback.print_exc())

    if start_location_key:
        # If get start_location_key.
        start_location = utils.search_obj_data_key(start_location_key)
        if start_location:
            settings.START_LOCATION = start_location[0].dbref
            print("settings.START_LOCATION set to: %s" %
                  settings.START_LOCATION)
Пример #6
0
    def after_data_loaded(self):
        """
        Init the character.
        """
        super(MudderyCharacter, self).after_data_loaded()

        # get level
        initial = False
        if not self.db.level:
            self.db.level = getattr(self.system, "level", 1)
            initial = True

        # friendly
        self.friendly = getattr(self.system, "friendly", 0)

        # skill's ai
        ai_choose_skill_class = class_from_module(settings.AI_CHOOSE_SKILL)
        self.ai_choose_skill = ai_choose_skill_class()

        # skill's gcd
        self.skill_gcd = GAME_SETTINGS.get("global_cd")
        self.auto_cast_skill_cd = GAME_SETTINGS.get("auto_cast_skill_cd")
        self.gcd_finish_time = 0

        # loop for auto cast skills
        self.auto_cast_loop = None

        # clear target
        self.target = None

        # set reborn time
        self.reborn_time = getattr(self.system, "reborn_time", 0)

        # A temporary character will be deleted after the combat finished.
        self.is_temp = False

        # update equipment positions
        self.reset_equip_positions()

        # load default skills
        self.load_default_skills()

        # load default objects
        self.load_default_objects()

        # refresh the character's properties.
        self.refresh_properties(not initial)
Пример #7
0
    def at_object_creation(self):
        """
        Called once, when this object is first created. This is the
        normal hook to overload for most object types.
            
        """
        super(MudderyCharacter, self).at_object_creation()

        # set default values
        if not self.attributes.has("team"):
            self.db.team = 0

        # init equipments
        if not self.attributes.has("equipments"):
            self.db.equipments = {}
        if not self.attributes.has("position_names"):
            self.db.position_names = {}
        self.reset_equip_positions()

        if not self.attributes.has("skills"):
            self.db.skills = {}

        # set quests
        if not self.attributes.has("finished_quests"):
            self.db.finished_quests = set()
        if not self.attributes.has("current_quests"):
            self.db.current_quests = {}

        # set closed events
        if not self.attributes.has("closed_events"):
            self.db.closed_events = set()

        # A combat instance only exists in a combat, it will be deleted after the combat finished.
        if not self.attributes.has("is_combat_instance"):
            self.db.is_combat_instance = False

        # skill's gcd
        self.skill_gcd = GAME_SETTINGS.get("global_cd")
        self.auto_cast_skill_cd = GAME_SETTINGS.get("auto_cast_skill_cd")
        self.gcd_finish_time = 0

        # loop for auto cast skills
        self.auto_cast_loop = None

        self.target = None
        self.reborn_time = 0
Пример #8
0
    def func(self):
        "Show the connect screen."
        game_name = GAME_SETTINGS.get("game_name")
        connection_screen = GAME_SETTINGS.get("connection_screen")
        honour_settings = HonourSettings.get_first_data()
        records = EquipmentPositions.all()
        equipment_pos = [{
            "key": r.key,
            "name": r.name,
            "desc": r.desc,
        } for r in records]

        self.caller.msg({
            "game_name": game_name,
            "conn_screen": connection_screen,
            "equipment_pos": equipment_pos,
            "min_honour_level": honour_settings.min_honour_level,
        })
Пример #9
0
 def get_available_commands(self, caller):
     """
     This returns a list of available commands.
     """
     commands = []
     if GAME_SETTINGS.get("can_give_up_quests"):
         commands.append({
             "name": _("Give Up"),
             "cmd": "giveup_quest",
             "args": self.get_data_key()
         })
     return commands
Пример #10
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()
Пример #11
0
    def get_data_key(self, default=""):
        """
        Get data's key.

        Args:
            default: (string) default value if can not find the data key.
        """
        key = GAME_SETTINGS.get("default_player_character_key")
        if not key:
            key = self.attributes.get(key="key", category=settings.DATA_KEY_CATEGORY, strattr=True)
            if not key:
                key = default
        return key
Пример #12
0
    def after_data_loaded(self):
        """
        """
        super(MudderyPlayerCharacter, self).after_data_loaded()

        self.solo_mode = GAME_SETTINGS.get("solo_mode")
        self.available_channels = {}

        # refresh data
        self.refresh_properties(True)

        # if it is dead, reborn at init.
        if not self.is_alive():
            if not self.db.is_combat_instance and self.reborn_time > 0:
                self.reborn()
Пример #13
0
    def get_surroundings(self, caller):
        """
        This is a convenient hook for a 'look'
        command to call.
        """
        # get name, description, commands and all objects in it
        info = {
            "exits": [],
            "npcs": [],
            "things": [],
            "players": [],
            "offlines": []
        }

        visible = (cont for cont in self.contents
                   if cont != caller and cont.access(caller, "view"))

        if GAME_SETTINGS.get("solo_mode"):
            visible = (cont for cont in visible if not cont.has_account)

        for cont in visible:
            # only show objects that match the condition
            if not cont.is_visible(caller):
                continue

            type = self.get_surrounding_type(cont)
            if type:
                appearance = {}

                if type == "npcs":
                    # add quest status
                    if hasattr(cont, "have_quest"):
                        provide_quest, complete_quest = cont.have_quest(caller)
                        appearance["provide_quest"] = provide_quest
                        appearance["complete_quest"] = complete_quest
                elif type == "offlines":
                    continue

                appearance["dbref"] = cont.dbref
                appearance["name"] = cont.get_name()
                appearance["key"] = cont.get_data_key()

                info[type].append(appearance)

        return info
Пример #14
0
    def get_message(self, caller, message):
        """
        Receive a message from a character.

        :param caller: talker.
        :param message: content.
        """
        output = {
            "type": ConversationType.LOCAL.value,
            "channel": self.get_name(),
            "from_dbref": caller.dbref,
            "from_name": caller.get_name(),
            "msg": message
        }

        if GAME_SETTINGS.get("solo_mode"):
            caller.msg({"conversation": output})
        else:
            self.msg_contents({"conversation": output})
Пример #15
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
Пример #16
0
    def set_owner(self, owner):
        """
        Set the owner of the skill.

        Args:
            owner: (object) skill's owner

        Returns:
            None
        """
        self.owner = owner
        self.owner_dbref = owner.dbref
        self.db.owner_dbref = owner.dbref

        if not self.passive:
            # Set skill cd. Add gcd to new the skill.
            gcd = GAME_SETTINGS.get("global_cd")
            if gcd > 0:
                self.db.cd_finish_time = time.time() + gcd
Пример #17
0
    def at_object_leave(self, moved_obj, target_location, **kwargs):
        """
        Called when an object leaves this object in any fashion.
        
        Args:
        moved_obj (Object): The object leaving
        target_location (Object): Where `moved_obj` is going.
        
        """
        super(MudderyRoom, self).at_object_leave(moved_obj, target_location)

        if not GAME_SETTINGS.get("solo_mode"):
            # send surrounding changes to player
            type = self.get_surrounding_type(moved_obj)
            if type:
                change = {
                    "type": type,
                    "dbref": moved_obj.dbref,
                    "name": moved_obj.get_name()
                }
                self.msg_contents({"obj_moved_out": change}, exclude=moved_obj)
Пример #18
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()            
Пример #19
0
    def at_object_receive(self, moved_obj, source_location, **kwargs):
        """
        Called after an object has been moved into this object.
        
        Args:
        moved_obj (Object): The object moved into this one
        source_location (Object): Where `moved_object` came from.
        
        """
        super(MudderyRoom, self).at_object_receive(moved_obj, source_location,
                                                   **kwargs)

        if not GAME_SETTINGS.get("solo_mode"):
            # send surrounding changes to player
            type = self.get_surrounding_type(moved_obj)
            if type:
                change = {
                    "type": type,
                    "dbref": moved_obj.dbref,
                    "name": moved_obj.get_name()
                }
                self.msg_contents({"obj_moved_in": change}, exclude=moved_obj)
Пример #20
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()
Пример #21
0
    def at_post_unpuppet(self, player, session=None, **kwargs):
        """
        We stove away the character when the player goes ooc/logs off,
        otherwise the character object will remain in the room also
        after the player logged off ("headless", so to say).

        Args:
            player (Player): The player object that just disconnected
                from this object.
            session (Session): Session controlling the connection that
                just disconnected.
        """
        if not self.sessions.count():
            # only remove this char from grid if no sessions control it anymore.
            if self.location:  # have to check, in case of multiple connections closing
                if not GAME_SETTINGS.get("solo_mode"):
                    # Notify other players in this location.
                    self.location.msg_contents("%s has left the game." %
                                               self.name,
                                               exclude=[self])

                # Save last location.
                self.db.prelogout_location = self.location
                self.location = None
Пример #22
0
    def give_up(self, quest_key):
        """
        Accept a quest.

        Args:
            quest_key: (string) quest's key

        Returns:
            None
        """
        if not GAME_SETTINGS.get("can_give_up_quests"):
            logger.log_tracemsg("Can not give up quests.")
            raise MudderyError(_("Can not give up this quest."))

        if quest_key not in self.current_quests:
            raise MudderyError(_("Can not find this quest."))

        self.current_quests[quest_key].delete()
        del(self.current_quests[quest_key])

        if quest_key in self.finished_quests:
            self.finished_quests.remove(quest_key)

        self.show_quests()
Пример #23
0
#
# This file defines global variables that will always be
# available in a view context without having to repeatedly
# include it. For this to work, this file is included in
# the settings file, in the TEMPLATE_CONTEXT_PROCESSORS
# tuple.
#

from django.conf import settings
from muddery.server.utils import utils
from muddery.server.utils.game_settings import GAME_SETTINGS

# Determine the site name and server version

try:
    GAME_NAME = GAME_SETTINGS.get("game_name")
except AttributeError:
    GAME_NAME = "Muddery"
SERVER_VERSION = utils.get_muddery_version()

# Setup lists of the most relevant apps so
# the adminsite becomes more readable.

PLAYER_RELATED = ['Players']
GAME_ENTITIES = ['Objects', 'Scripts', 'Comms', 'Help']
GAME_SETUP = ['Permissions', 'Config']
CONNECTIONS = ['Irc', 'Imc2']
WEBSITE = ['Flatpages', 'News', 'Sites']

# The main context processor function
WEBCLIENT_ENABLED = settings.WEBCLIENT_ENABLED
Пример #24
0
 def __init__(self):
     """
     Initialize the handler.
     """
     self.can_close_dialogue = GAME_SETTINGS.get("can_close_dialogue")
     self.dialogue_storage = {}
Пример #25
0
def create_character(new_player,
                     nickname,
                     permissions=None,
                     character_key=None,
                     level=1,
                     typeclass=None,
                     location=None,
                     home=None):
    """
    Helper function, creates a character based on a player's name.
    """
    if not character_key:
        character_key = GAME_SETTINGS.get("default_player_character_key")

    if not typeclass:
        typeclass = settings.BASE_PLAYER_CHARACTER_TYPECLASS

    if not permissions:
        permissions = settings.PERMISSION_ACCOUNT_DEFAULT

    if not home:
        default_home_key = GAME_SETTINGS.get("default_player_home_key")
        if default_home_key:
            rooms = utils.search_obj_data_key(default_home_key)
            if rooms:
                home = rooms[0]

    if not home:
        rooms = search.search_object(settings.DEFAULT_HOME)
        if rooms:
            home = rooms[0]

    if not location:
        location = home
        try:
            start_location_key = GAME_SETTINGS.get("start_location_key")
            if start_location_key:
                rooms = utils.search_obj_data_key(start_location_key)
                location = rooms[0]
        except:
            pass

    new_character = create.create_object(typeclass,
                                         key=new_player.key,
                                         location=location,
                                         home=home,
                                         permissions=permissions)

    # set character info
    new_character.set_data_key(character_key, level)
    new_character.after_creation()

    # set playable character list
    new_player.db._playable_characters.append(new_character)

    # allow only the character itself and the player to puppet this character (and Immortals).
    new_character.locks.add(
        "puppet:id(%i) or pid(%i) or perm(Immortals) or pperm(Immortals)" %
        (new_character.id, new_player.id))

    # If no description is set, set a default description
    if not new_character.db.desc:
        new_character.db.desc = "This is a Player."

    # Add nickname
    if not nickname:
        nickname = character_key
    new_character.set_nickname(nickname)

    # We need to set this to have @ic auto-connect to this character
    new_player.db._last_puppet = new_character

    return new_character