Ejemplo n.º 1
0
    def __init__(self, environment, *args, **kwargs):
        """
        Instantiate an Engine for an Environment.
        """
        super(Game, self).__init__(*args, **kwargs)
        self.environment = environment
        self.processes = []
        self.connections = []
        self.unique_connection_id = 0

        self.data = {}  # Main memory core, reference relationships by ID only.

        from mud.entities.area import Area

        # FIXME put somewhere better, like an AreaManager
        for area_name in Area.query_available_uids(game=self):
            area_data = Area.load_from_file(area_name, game=self)
            Area.add(area_data, game=self)
            self.log("Loaded area '{}' with {} rooms".format(
                area_name, len(area_data["rooms"])))

        from mud.entities.social import Social

        # FIXME put somewhere better, like an AreaManager
        for social_name in Social.query_available_uids(game=self):
            social = Social.load_from_file(social_name, game=self)
            Social.add(social, game=self)
            self.log("Loaded social '{}'".format(social_name))
Ejemplo n.º 2
0
    def __init__(self, environment, *args, **kwargs):
        """
        Instantiate an Engine for an Environment.
        """
        super(Game, self).__init__(*args, **kwargs)
        self.environment = environment
        self.processes = []
        self.connections = []
        self.unique_connection_id = 0

        self.data = {}  # Main memory core, reference relationships by ID only.

        from mud.entities.area import Area

        # FIXME put somewhere better, like an AreaManager
        for area_name in Area.query_available_uids(game=self):
            area_data = Area.load_from_file(area_name, game=self)
            Area.add(area_data, game=self)
            self.log("Loaded area '{}' with {} rooms".format(
                area_name,
                len(area_data["rooms"])
            ))

        from mud.entities.social import Social

        # FIXME put somewhere better, like an AreaManager
        for social_name in Social.query_available_uids(game=self):
            social = Social.load_from_file(social_name, game=self)
            Social.add(social, game=self)
            self.log("Loaded social '{}'".format(social_name))
Ejemplo n.º 3
0
def social_command(actor, command, game, params, *args, **kwargs):
    from mud.entities.social import Social
    from mud.entities.actor import Actor
    from mud.entities.character import Character

    social = Social.find_by("name", command, game=game)

    if not params:
        actor.echo(social["me_room"])
        actor.act_around(social["actor_room"])
        return

    target_name = params[0]
    target = actor.find_room_entity(keyword=target_name,
                                    types=[Character, Actor])

    if target_name == "self":
        target = actor

    if target and actor == target:
        actor.echo(social["me_self"])
        actor.act_around(social["actor_self"])

    elif target:
        actor.echo(social["me_actor"])
        actor.act_to(target, social["actor_me"])
        actor.act_around(social["actor_other"], exclude=[target])

    else:
        actor.echo("Target not found.")
Ejemplo n.º 4
0
def social_command(actor, command, game, params, *args, **kwargs):
    from mud.entities.social import Social
    from mud.entities.actor import Actor
    from mud.entities.character import Character

    social = Social.find_by("name", command, game=game)

    if not params:
        actor.echo(social["me_room"])
        actor.act_around(social["actor_room"])
        return

    target_name = params[0]
    target = actor.find_room_entity(keyword=target_name, types=[Character, Actor])

    if target_name == "self":
        target = actor

    if target and actor == target:
        actor.echo(social["me_self"])
        actor.act_around(social["actor_self"])

    elif target:
        actor.echo(social["me_actor"])
        actor.act_to(target, social["actor_me"])
        actor.act_around(social["actor_other"], exclude=[target])

    else:
        actor.echo("Target not found.")
Ejemplo n.º 5
0
    def query_command_handlers(self):
        if not self.__class__.CACHED_COMMANDS:
            from settings.directions import DIRECTIONS
            from settings.channels import CHANNELS

            commands = []

            commands = [
                {
                    "keywords": "password",
                    "handler": password_command,
                },
                {
                    "keywords": "quit",
                    "handler": quit_command,
                },
                {
                    "keywords": "commands",
                    "handler": commands_command,
                },
                {
                    "keywords": "affects",
                    "handler": affects_command
                },
                {
                    "keywords": "nocommand",
                    "role": "admin",
                    "handler": nocommand_command
                },
                {
                    "keywords": "effects",
                    "handler": affects_command
                },
                {
                    "keywords": "title",
                    "handler": title_command
                },
                {
                    "keywords": "bash",
                    "handler": bash_command
                },
                {
                    "keywords": "say",
                    "handler": say_command
                },
                {
                    "keywords": "sayooc",
                    "handler": sayooc_command
                },
                {
                    "keywords": "save",
                    "handler": save_command
                },
                {
                    "keywords": "tell",
                    "handler": tell_command
                },
                {
                    "keywords": "who",
                    "handler": who_command
                },
                {
                    "keywords": "prompt",
                    "handler": prompt_command
                },
                {
                    "keywords": "kill",
                    "handler": kill_command
                },
                {
                    "keywords": "string",
                    "handler": string_command
                },
            ]

            from mud.commands.sockets import sockets_command
            commands.append({
                "keywords": "sockets",
                "handler": sockets_command,
                "role": "admin"
            })

            from mud.commands.map import map_command
            commands.append({"keywords": "map", "handler": map_command})

            from mud.commands.look import look_command
            commands.append({"keywords": "look", "handler": look_command})

            from mud.commands.goto import goto_command
            commands.append({
                "keywords": "goto",
                "handler": goto_command,
                "role": "admin"
            })

            from mud.commands.roles import roles_command
            commands.append({
                "keywords": "roles",
                "handler": roles_command,
                "role": "admin"
            })

            from mud.commands.equipment import equipment_command
            commands.append({
                "keywords": "equipment",
                "handler": equipment_command
            })

            from mud.commands.recall import recall_command
            commands.append({"keywords": "recall", "handler": recall_command})

            from mud.commands.emote import emote_command
            commands.append({"keywords": "emote", "handler": emote_command})

            from mud.commands.pmote import pmote_command
            commands.append({"keywords": "pmote", "handler": pmote_command})

            from mud.commands.damage import damage_command
            commands.append({"keywords": "damage", "handler": damage_command})

            # Add walking in directions.
            for direction in DIRECTIONS.keys():
                commands.insert(0, {
                    "keywords": direction,
                    "handler": walk_command
                })

            # Add channel commands.
            for channel in CHANNELS.keys():
                commands.append({
                    "keywords": channel,
                    "handler": channel_command
                })

            # SOCIALS
            from mud.entities.social import Social
            from mud.commands.social import social_command

            for social in Social.query(game=self.game):
                commands.append({
                    "keywords": social["name"],
                    "handler": social_command
                })

            self.__class__.CACHED_COMMANDS = commands

        return self.__class__.CACHED_COMMANDS