Exemplo n.º 1
0
 def move_to(self, destination, quiet=False, emit_to_obj=None, use_destination=True, to_none=False, followers=None, redirectable=True, look=True):
     # Check for a destination redirect
     if redirectable:
         seen_destinations = set()
         while True:
             if not hasattr(destination, 'move_redirect'):
                 break
             new_destination = destination.move_redirect(self)
             if not new_destination:
                 break
             # Ensure we haven't already seen this destination (there's a loop)
             if new_destination in seen_destinations:
                 raise Exception('move_redirect() loop detected!  ' + destination.dbref + ' lead to itself!')
             seen_destinations.add(new_destination)
             # Looks good.  Change the destination.
             destination = new_destination
     # Perform the move
     source_loc = self.location
     retval = self.dbobj.move_to(destination, quiet=quiet, emit_to_obj=emit_to_obj, use_destination=use_destination)
     # Display the new location to the user if requested
     if look and self.player:
         self.player.at_display_context(self.sessid)
     # Manage followers if requested
     if followers != None:
         if followers:
             # Bring followers as well
             for follower in search_object(self, attribute_name='follow_following'):
                 # Ensure that the follower is still at your source location.
                 # (Safety check.  Moving around on your own should clear your 'following' attribute)
                 if not follower.location or follower.location != source_loc:
                     self.msg(self.objsub('You move away from &1N, and &1s loses you.', follower))
                     self.msg(self.objsub('&0N moves away from you, you lose &1o.', follower))
                     del follower.db.follow_following
                     break
                 # Check te ensure that the follower is awake.
                 # (Safety check.  Disconnecting your character should clear your 'following' attribute)
                 if not follower.player:
                     self.msg(self.objsub('&1N has fallen asleep, and got left behind.', follower))
                     self.msg(self.objsub('You fall asleep, and get left behind by &0N.', follower))
                     del follower.db.follow_following
                     break
                 # Bring the follower alonga
                 follower.move_to(self.location, redirectable=True, followers=True)
         else:
             # Drop followers
             for follower in search_object(self, attribute_name='follow_following'):
                 del follower.db.follow_following
                 self.msg('%s seems to have lost you, and is no longer following you.' % follower.key)
                 follower.msg('%s moves off, but you find yourself unable to follow.' % self.key)
     return retval
Exemplo n.º 2
0
    def at_object_receive(self, character, source_location):
        """
        This hook is called by the engine whenever the player is moved into
        this room.
        """
        if not character.has_player:
            # only act on player characters.
            return
        #print character.db.puzzle_clue, self.db.puzzle_value
        if character.db.puzzle_clue != self.db.puzzle_value:
            # we didn't pass the puzzle. See if we can teleport.
            teleport_to = self.db.failure_teleport_to  # this is a room name
        else:
            # passed the puzzle
            teleport_to = self.db.success_teleport_to  # this is a room name

        results = search_object(teleport_to)
        if not results or len(results) > 1:
            # we cannot move anywhere since no valid target was found.
            print "no valid teleport target for %s was found." % teleport_to
            return
        if character.player.is_superuser:
            # superusers don't get teleported
            character.msg("Superuser block: You would have been teleported to %s." % results[0])
            return
        # teleport
        character.execute_cmd("look")
        character.location = results[0]  # stealth move
        character.location.at_object_receive(character, self)
Exemplo n.º 3
0
 def func(self):
     default_location = ev.search_object(IC_START)[MAIN]
     last_location = self.caller.db.ic_location
     if not last_location:
         last_location = default_location
     self.switches = [switch.lower() for switch in self.switches]
     if self.caller.location and self.caller.location.db.ic and 'reset' not in self.switches:
         self.caller.msg("{rYou are already in an IC area!{n")
         return
     if 'reset' in self.switches:
         del self.caller.db.ic_location
         if self.caller.location and self.caller.location.db.ic:
             self.caller.msg(
                 "\n{yYour IC location has been reset the starting point.{n\n"
             )
         last_location = default_location
     pre_warp(self.caller)
     self.caller.move_to(last_location)
     post_warp(self.caller)
     if not last_location == default_location:
         self.caller.msg(
             "{y>> {CYou have been returned to your last saved IC location. If there is an error with this warp, or if you are lost, type {gIC/reset{n"
         )
     else:
         self.caller.msg(
             "{y>> {CYou are at the IC realm starting point. To return to the OOC realm, type {gnexus{C.{n"
         )
Exemplo n.º 4
0
def load_objects(objspec):
    objects = {}
    # Create objects
    for identifier, spec in objspec.iteritems():
        obj = create_object(spec['typeclass'])
        if 'key' in spec:
            obj.key = spec['key']
        if 'aliases' in spec:
            obj.aliases = spec['aliases']
        if 'permissions' in spec:
            obj.permissions = spec['permissions']
        if 'locks' in spec:
            obj.locks.replace(spec['locks'])
        if 'db' in spec:
            for key, val in spec['db'].iteritems():
                obj.set_attribute(key, val)
        objects[identifier] = obj
    # Handle links between objects
    for identifier, spec in objspec.iteritems():
        if 'location' in spec:
            if spec['location'].startswith('#'):
                objects[identifier].location = search_object(spec['location'])[0]
            else:
                objects[identifier].location = objects[spec['location']]
        if 'home' in spec:
            if spec['home'].startswith('#'):
                objects[identifier].home = ev.search_object(spec['home'])[0]
            else:
                objects[identifier].home = objects[spec['home']]
        if 'destination' in spec:
            if spec['destination'].startswith('#'):
                objects[identifier].destination = ev.search_object(spec['destination'])[0]
            else:
                objects[identifier].destination = objects[spec['destination']]
    return objects
Exemplo n.º 5
0
    def at_object_receive(self, character, source_location):
        "This hook is called by the engine whenever the player is moved into this room."
        if not character.has_player:
            # only act on player characters.
            return
        #print character.db.puzzle_clue, self.db.puzzle_value
        if character.db.puzzle_clue != self.db.puzzle_value:
            # we didn't pass the puzzle. See if we can teleport.
            teleport_to = self.db.failure_teleport_to # this is a room name
        else:
            # passed the puzzle
            teleport_to = self.db.success_teleport_to # this is a room name

        results = search_object(teleport_to)
        if not results or len(results) > 1:
            # we cannot move anywhere since no valid target was found.
            print "no valid teleport target for %s was found." % teleport_to
            return
        if character.player.is_superuser:
            # superusers don't get teleported
            character.msg("Superuser block: You would have been teleported to %s." % results[0])
            return
        # teleport
        character.execute_cmd("look")
        character.location = results[0] # stealth move
        character.location.at_object_receive(character, self)
Exemplo n.º 6
0
def equipped(accessing_obj, accessed_obj, *args, **kwargs):
    """
    Checks if an object is equipped by accessing_obj

    Usage:
        equipped() - Returns true if accessed_obj is equipped by accessing_obj
        equipped(dbref) - Returns true if a given object is equipped by accessing_obj
    """
    if not args:
        equipment = accessed_obj
    elif len(args) == 1:
        equipment = utils.dbref(args[0])
        if not equipment:
            return False
        equipment = search_object('#' + str(equipment))
        if not equipment:
            return False
        equipment = equipment[0]
    else:
        return False
    if not equipment:
        return False
    if not hasattr(equipment, 'is_equipped_by'):
        return False
    return equipment.is_equipped_by(accessing_obj)
Exemplo n.º 7
0
def get_from_ref(obj_id):
    """
    Cleaner wrapper for getting an object from its DBREF
    """
    try:
        return ev.search_object('#' + str(obj_id))[MAIN]
    except:
        return None
Exemplo n.º 8
0
    def attack(self):
        """
        This is the main mode of combat. It will try to hit players in
        the location. If players are defeated, it will whisp them off
        to the defeat location.
        """
        last_attacker = self.db.last_attacker
        players = [
            obj for obj in self.location.contents
            if utils.inherits_from(obj, BASE_CHARACTER_TYPECLASS)
            and not obj.is_superuser
        ]
        if players:

            # find a target
            if last_attacker in players:
                # prefer to attack the player last attacking.
                target = last_attacker
            else:
                # otherwise attack a random player in location
                target = players[random.randint(0, len(players) - 1)]

            # try to use the weapon in hand
            attack_cmds = ("thrust", "pierce", "stab", "slash", "chop")
            cmd = attack_cmds[random.randint(0, len(attack_cmds) - 1)]
            self.execute_cmd("%s %s" % (cmd, target))

            # analyze result.
            if target.db.health <= 0:
                # we reduced enemy to 0 health. Whisp them off to
                # the prison room.
                tloc = search_object(self.db.defeat_location)
                tstring = self.db.defeat_text
                if not tstring:
                    tstring = "You feel your conciousness slip away ... you fall to the ground as "
                    tstring += "the misty apparition envelopes you ...\n The world goes black ...\n"
                target.msg(tstring)
                ostring = self.db.defeat_text_room
                if tloc:
                    if not ostring:
                        ostring = "\n%s envelops the fallen ... and then their body is suddenly gone!" % self.key
                        # silently move the player to defeat location
                        # (we need to call hook manually)
                    target.location = tloc[0]
                    tloc[0].at_object_receive(target, self.location)
                elif not ostring:
                    ostring = "%s falls to the ground!" % target.key
                self.location.msg_contents(ostring, exclude=[target])
                # Pursue any stragglers after the battle
                self.battle_mode = False
                self.roam_mode = False
                self.pursue_mode = True
        else:
            # no players found, this could mean they have fled.
            # Switch to pursue mode.
            self.battle_mode = False
            self.roam_mode = False
            self.pursue_mode = True
Exemplo n.º 9
0
    def attack(self):
        """
        This is the main mode of combat. It will try to hit players in
        the location. If players are defeated, it will whisp them off
        to the defeat location.
        """
        last_attacker = self.db.last_attacker
        players = [obj for obj in self.location.contents
                   if utils.inherits_from(obj, BASE_CHARACTER_TYPECLASS) and not obj.is_superuser]
        if players:

            # find a target
            if last_attacker in players:
                # prefer to attack the player last attacking.
                target = last_attacker
            else:
                # otherwise attack a random player in location
                target = players[random.randint(0, len(players) - 1)]

            # try to use the weapon in hand
            cmd = "fight %s=" % target.dbref
            attack_cmds = ("stab", "slash")
            cmd += attack_cmds[random.randint(0, len(attack_cmds) - 1)]
            self.execute_cmd(cmd)

            # analyze result.
            if target.db.health <= 0:
                # we reduced enemy to 0 health. Whisp them off to
                # the prison room.
                tloc = search_object(self.db.defeat_location)
                tstring = self.db.defeat_text
                if not tstring:
                    tstring = "你被幽灵缠绕着,意识渐渐变得模糊了……你重重地摔倒在地上。\n"
                    tstring += "整个世界变得一片漆黑……\n"
                    tstring += target.get_available_cmd_desc(target)
                target.msg(tstring)
                ostring = self.db.defeat_text_room
                if tloc:
                    if not ostring:
                        ostring = "\n%s缠绕着勇士的尸体……一下子尸体就消失不见了!" % self.key
                        # silently move the player to defeat location
                        # (we need to call hook manually)
                    target.location = tloc[0]
                    tloc[0].at_object_receive(target, self.location)
                elif not ostring:
                    ostring = "%s倒在了地上!" % target.key
                self.location.msg_contents(ostring, exclude=[target])
                # Pursue any stragglers after the battle
                self.battle_mode = False
                self.roam_mode = False
                self.pursue_mode = True
        else:
            # no players found, this could mean they have fled.
            # Switch to pursue mode.
            self.battle_mode = False
            self.roam_mode = False
            self.pursue_mode = True
Exemplo n.º 10
0
 def func(self):
     nexus = ev.search_object(NEXUS)[MAIN]
     if self.caller.location == nexus:
         self.caller.msg("{rYou are already in the Nexus.{n")
         return
     if self.caller.location and self.caller.location.db.ic:
         self.caller.msg("\n{gYour location has been saved.{n\n")
     pre_warp(self.caller)
     self.caller.move_to(nexus, quiet=True)
     post_warp(self.caller)
Exemplo n.º 11
0
 def at_object_receive(self, character, source_location):
     """
     This hook is called by the engine whenever the player is moved
     into this room.
     """
     if character.has_player:
         # we only run this if the entered object is indeed a player object.
         # check so our east/west exits are correctly defined.
         wexit = search_object(self.db.west_exit)
         eexit = search_object(self.db.east_exit)
         fexit = search_object(self.db.fall_exit)
         if not wexit or not eexit or not fexit:
             character.msg("The bridge's exits are not properly configured. Contact an admin. Forcing west-end placement.")
             character.db.tutorial_bridge_position = 0
             return
         if source_location == eexit[0]:
             character.db.tutorial_bridge_position = 4
         else:
             character.db.tutorial_bridge_position = 0
Exemplo n.º 12
0
 def func(self):
     nexus = ev.search_object(NEXUS)[MAIN]
     if self.caller.location == nexus:
         self.caller.msg("{rYou are already in the Nexus.{n")
         return
     if self.caller.location and self.caller.location.db.ic:
         self.caller.msg("\n{gYour location has been saved.{n\n")
     pre_warp(self.caller)
     self.caller.move_to(nexus,quiet=True)
     post_warp(self.caller)
Exemplo n.º 13
0
 def at_object_receive(self, character, source_location):
     """
     This hook is called by the engine whenever the player is moved
     into this room.
     """
     if character.has_player:
         # we only run this if the entered object is indeed a player object.
         # check so our east/west exits are correctly defined.
         wexit = search_object(self.db.west_exit)
         eexit = search_object(self.db.east_exit)
         fexit = search_object(self.db.fall_exit)
         if not wexit or not eexit or not fexit:
             character.msg("The bridge's exits are not properly configured. Contact an admin. Forcing west-end placement.")
             character.db.tutorial_bridge_position = 0
             return
         if source_location == eexit[0]:
             character.db.tutorial_bridge_position = 4
         else:
             character.db.tutorial_bridge_position = 0
Exemplo n.º 14
0
    def attack(self):
        """
        This is the main mode of combat. It will try to hit players in
        the location. If players are defeated, it will whisp them off
        to the defeat location.
        """
        last_attacker = self.db.last_attacker
        players = [obj for obj in self.location.contents
                   if utils.inherits_from(obj, BASE_CHARACTER_TYPECLASS) and not obj.is_superuser]
        if players:

            # find a target
            if last_attacker in players:
                # prefer to attack the player last attacking.
                target = last_attacker
            else:
                # otherwise attack a random player in location
                target = players[random.randint(0, len(players) - 1)]

            # try to use the weapon in hand
            attack_cmds = ("thrust", "pierce", "stab", "slash", "chop")
            cmd = attack_cmds[random.randint(0, len(attack_cmds) - 1)]
            self.execute_cmd("%s %s" % (cmd, target))

            # analyze result.
            if target.db.health <= 0:
                # we reduced enemy to 0 health. Whisp them off to
                # the prison room.
                tloc = search_object(self.db.defeat_location)
                tstring = self.db.defeat_text
                if not tstring:
                    tstring = "You feel your conciousness slip away ... you fall to the ground as "
                    tstring += "the misty apparition envelopes you ...\n The world goes black ...\n"
                target.msg(tstring)
                ostring = self.db.defeat_text_room
                if tloc:
                    if not ostring:
                        ostring = "\n%s envelops the fallen ... and then their body is suddenly gone!" % self.key
                        # silently move the player to defeat location
                        # (we need to call hook manually)
                    target.location = tloc[0]
                    tloc[0].at_object_receive(target, self.location)
                elif not ostring:
                    ostring = "%s falls to the ground!" % target.key
                self.location.msg_contents(ostring, exclude=[target])
                # Pursue any stragglers after the battle
                self.battle_mode = False
                self.roam_mode = False
                self.pursue_mode = True
        else:
            # no players found, this could mean they have fled.
            # Switch to pursue mode.
            self.battle_mode = False
            self.roam_mode = False
            self.pursue_mode = True
Exemplo n.º 15
0
 def give(self, caller):
     "Give weapon"
     string = "\n{c=============================================================={n"
     string += "\n{c取走武器{n"
     string += "\n{c=============================================================={n"
     string += "\n"
     
     if caller.ndb.weapon:
         # we don't allow a player to take more than one weapon from rack.
         string += "你已经有一把武器了。\n"
         string += "(你要先丢弃行囊中的武器才能拿取新武器)\n"
         string += caller.get_available_cmd_desc(caller)
         caller.msg(string, clear_links=True)
         return
     
     dmg, name, aliases, desc, magic = self.randomize_type()
     new_weapon = create_object(Weapon, key=name, aliases=aliases, location=self, home=self)
     new_weapon.db.damage = dmg
     new_weapon.db.desc = desc
     new_weapon.db.magic = magic
     
     #take the object
     if not new_weapon.move_to(caller, quiet=True, emit_to_obj=caller):
         new_weapon.delete()
         return
     
     ostring = self.db.get_text
     if not ostring:
         ostring = "你拿起了%s。"
     if '%s' in ostring:
         ostring = ostring % name
     string += ostring + "\n"
     string += caller.get_available_cmd_desc(caller)
     caller.msg(string, clear_links=True)
     
     destination = search_object("tut#17")
     if not destination:
         destination = search_object("#2")
     if destination:
         source = caller.location
         caller.location = destination[0]  # stealth move
         caller.location.at_object_receive(caller, source)
Exemplo n.º 16
0
def at_server_start():
    """
    This is called every time the server starts up, regardless of
    how it was shut down.
    """
    
    # Find all objects with scripts and start them
    objects = ev.search_object(True, attribute_name="_has_script", exact=True) #, typeclass="game.gamesrc.objects.room.Room"
    count = 0
    for o in objects:
        o.start_scripts()
Exemplo n.º 17
0
 def get_owner(self):
     # Do some security checks to prevent messed up characters from having an official owner
     owner = self.db.owner
     if not owner:
         return None
     # Verify that the player data also shows ownership
     if not self in owner.db.characters:
         return None
     # Verify that, among character objects, this one has a unique name
     if len([char for char in search_object(self.key, attribute_name='key') if isinstance(char, Character)]) != 1:
         return None
     # Verify this doesn't match the name of any player, unless that player is our own
     if self.key.lower() != owner.key.lower() and search_player(self.key):
         return None
     # Looks good, return the owner.
     return self.db.owner
Exemplo n.º 18
0
    def func(self):
        "Looking around, including a chance to fall."
        bridge_position = self.caller.db.tutorial_bridge_position

        messages =("你正站在吊桥上,{w离西面的出口很近{n。如果你向西走可以回到坚实的大地上……",
                   "你已经在这座不太牢固的桥上走了{w一半{n的路程了。",
                   "你正站在吊桥上,{w离东面的出口很近{n。如果你向东走可以回到坚实的大地上……")
        moods = ("桥在风中摇晃着。",
                 "吊桥在嘎嘎作响,让你感到有些害怕。",
                 "你脚下的桥摇晃着发出嘎吱嘎吱的声响,你紧紧地抓着边上的绳索。",
                 "从城堡方向传来了远远的嚎叫声,像是由一条大狗或什么野兽发出的。",
                 "桥在你的脚下嘎嘎作响,那些木板看上去不太牢固。",
                 "大海远远地在你下面,正咆哮着将海浪砸向悬崖,仿佛想要拍到你身上。",
                 "几块木板在你身后断裂开,坠如下面的深渊中。",
                 "一阵狂风吹过,吊桥摇晃了起来。",
                 "你脚下的一块木板松脱了,翻滚着坠落下去。你的半个身子悬在了空中……",
                 "你手中握着的绳索部分断裂开了,你摇摆着努力恢复平衡。")

        message = "\n{c=============================================================={n"
        message += "\n{c%s{n" % self.obj.key
        message += "\n{c=============================================================={n"
        message += "\n" + messages[bridge_position] + "\n" + moods[random.randint(0, len(moods) - 1)]
        chars = [obj for obj in self.obj.contents if obj != self.caller and obj.has_player]
        if chars:
            message += "\n你看见:%s" % ", ".join("{c%s{n" % char.key for char in chars)

        message += "\n{lceast{lt向东走{le  {lcwest{lt向西走{le"
        self.caller.msg(message, clear_links=True)

        # there is a chance that we fall if we are on the western or central
        # part of the bridge.
        if bridge_position < 3 and random.random() < 0.05 and not self.caller.is_superuser:
            # we fall on 5% of the times.
            fexit = search_object(self.obj.db.fall_exit)
            if fexit:
                string = "\n{r突然,你脚下的木板断开了!你掉下去了!"
                string += "\n你想尽力抓住相邻的木板,但只是改变了你坠落的方向。你正摔向西面的悬崖。这次肯定要受伤了……"
                string += "\n……整个世界一片黑暗……{n\n"
                string += self.caller.get_available_cmd_desc(self.caller)
                # note that we move silently so as to not call look hooks (this is a little trick to leave
                # the player with the "world goes dark ..." message, giving them ample time to read it. They
                # have to manually call look to find out their new location). Thus we also call the
                # at_object_leave hook manually (otherwise this is done by move_to()).
                self.caller.msg(string, clear_links=True)
                self.obj.at_object_leave(self.caller, fexit)
                self.caller.location = fexit[0] # stealth move, without any other hook calls.
                self.obj.msg_contents("一块木板在%s的脚下断开了,他摔下桥了!" % self.caller.key)
Exemplo n.º 19
0
 def func(self):
     character = self.character
     args = self.args.lower()
     if args == 'leading':
         followers = search_object(character, attribute_name='follow_following')
         if not followers:
             character.msg("You're not currently leading anyone.")
             return
         for follower in followers:
             follower.action_stop(character)
     elif args:
         target = character.search(args)
         if not target:
             return # Search function takes care of error messages
         target.action_stop(character)
     else:
         character.action_stop(character)
Exemplo n.º 20
0
    def func(self):
        "move forward"
        caller = self.caller

        bridge_step = max(-1, caller.db.tutorial_bridge_position - 1)

        if bridge_step < 0:
            # we have reached the far west end of the bridge. Move to the west room.
            wexit = search_object(self.obj.db.west_exit)
            if wexit:
                caller.move_to(wexit[0])
            else:
                caller.msg("No west exit was found for this room. Contact an admin.")
            return
        caller.db.tutorial_bridge_position = bridge_step
        caller.location.msg_contents("%s steps westwartswards across the bridge." % caller.name, exclude=caller)
        caller.execute_cmd("look")
Exemplo n.º 21
0
    def func(self):
        "move forward"
        caller = self.caller

        bridge_step = max(-1, caller.db.tutorial_bridge_position - 1)

        if bridge_step < 0:
            # we have reached the far west end of the bridge.#
            # Move to the west room.
            wexit = search_object(self.obj.db.west_exit)
            if wexit:
                caller.move_to(wexit[0])
            else:
                caller.msg("No west exit was found for this room. Contact an admin.")
            return
        caller.db.tutorial_bridge_position = bridge_step
        caller.location.msg_contents("%s steps westwartswards across the bridge." % caller.name, exclude=caller)
        caller.execute_cmd("look")
Exemplo n.º 22
0
    def func(self):
        "Looking around, including a chance to fall."
        bridge_position = self.caller.db.tutorial_bridge_position


        messages =("You are standing {wvery close to the the bridge's western foundation{n. If you go west you will be back on solid ground ...",
                   "The bridge slopes precariously where it extends eastwards towards the lowest point - the center point of the hang bridge.",
                   "You are {whalfways{n out on the unstable bridge.",
                   "The bridge slopes precariously where it extends westwards towards the lowest point - the center point of the hang bridge.",
                   "You are standing {wvery close to the bridge's eastern foundation{n. If you go east you will be back on solid ground ...")
        moods = ("The bridge sways in the wind.", "The hanging bridge creaks dangerously.",
                 "You clasp the ropes firmly as the bridge sways and creaks under you.",
                 "From the castle you hear a distant howling sound, like that of a large dog or other beast.",
                 "The bridge creaks under your feet. Those planks does not seem very sturdy.",
                 "Far below you the ocean roars and throws its waves against the cliff, as if trying its best to reach you.",
                 "Parts of the bridge come loose behind you, falling into the chasm far below!",
                 "A gust of wind causes the bridge to sway precariously.",
                 "Under your feet a plank comes loose, tumbling down. For a moment you dangle over the abyss ...",
                 "The section of rope you hold onto crumble in your hands, parts of it breaking apart. You sway trying to regain balance.")
        message = "{c%s{n\n" % self.obj.key + messages[bridge_position] + "\n" + moods[random.randint(0, len(moods) - 1)]
        chars = [obj for obj in self.obj.contents if obj != self.caller and obj.has_player]
        if chars:
            message += "\n You see: %s" % ", ".join("{c%s{n" % char.key for char in chars)

        self.caller.msg(message)

        # there is a chance that we fall if we are on the western or central
        # part of the bridge.
        if bridge_position < 3 and random.random() < 0.05 and not self.caller.is_superuser:
            # we fall on 5% of the times.
            fexit = search_object(self.obj.db.fall_exit)
            if fexit:
                string = "\n Suddenly the plank you stand on gives way under your feet! You fall!"
                string += "\n You try to grab hold of an adjoining plank, but all you manage to do is to "
                string += "divert your fall westwards, towards the cliff face. This is going to hurt ... "
                string += "\n ... The world goes dark ...\n"
                # note that we move silently so as to not call look hooks (this is a little trick to leave
                # the player with the "world goes dark ..." message, giving them ample time to read it. They
                # have to manually call look to find out their new location). Thus we also call the
                # at_object_leave hook manually (otherwise this is done by move_to()).
                self.caller.msg("{r%s{n" % string)
                self.obj.at_object_leave(self.caller, fexit)
                self.caller.location = fexit[0] # stealth move, without any other hook calls.
                self.obj.msg_contents("A plank gives way under %s's feet and they fall from the bridge!" % self.caller.key)
Exemplo n.º 23
0
 def func(self):
     default_location = ev.search_object(IC_START)[MAIN]
     last_location = self.caller.db.ic_location
     if not last_location:
         last_location = default_location
     self.switches = [switch.lower() for switch in self.switches]
     if self.caller.location and self.caller.location.db.ic and 'reset' not in self.switches:
         self.caller.msg("{rYou are already in an IC area!{n")
         return
     if 'reset' in self.switches:
         del self.caller.db.ic_location
         if self.caller.location and self.caller.location.db.ic:     
             self.caller.msg("\n{yYour IC location has been reset the starting point.{n\n")
         last_location = default_location
     pre_warp(self.caller)
     self.caller.move_to(last_location)
     post_warp(self.caller)
     if not last_location == default_location:
         self.caller.msg("{y>> {CYou have been returned to your last saved IC location. If there is an error with this warp, or if you are lost, type {gIC/reset{n")
     else:
         self.caller.msg("{y>> {CYou are at the IC realm starting point. To return to the OOC realm, type {gnexus{C.{n")
Exemplo n.º 24
0
 def cmd_new(self):
     player = self.player
     key = self.args
     # Verify that the account has a free character slot
     max_characters = player.max_characters()
     playable_characters = player.get_characters()
     if len(playable_characters) >= player.max_characters():
         self.msg("{RYou may only create a maximum of %i characters." % max_characters)
         return
     # Check the character name
     if re.search('[^a-zA-Z0-9._ -]', key) or not (3 <= len(key) <= 20):
         self.msg('{R[Character names must be between 3 and 20 characters, and only contain english letters, numbers, dot (.), underscore (_), or dash(-), or space ( )]')
         return
     # Verify that the character name is not already taken
     for existing_object in search_object(key, attribute_name='key'):
         if utils.inherits_from(existing_object, "src.objects.objects.Character"):
             self.msg("{R[That character name is already taken]")
             return
     # Verify that this is not the name of a player, unless it's your own
     if key.lower() != player.key.lower():
         if search_player(key):
             self.msg("{R[That name is already taken by a player account]")
             return
     # create the character
     from src.objects.models import ObjectDB
     default_home = ObjectDB.objects.get_id(settings.CHARACTER_DEFAULT_HOME)
     typeclass = settings.BASE_CHARACTER_TYPECLASS
     permissions = settings.PERMISSION_PLAYER_DEFAULT
     new_character = create_object(typeclass, key=key, location=default_home, home=default_home, permissions=permissions)
     # only allow creator (and admins) to puppet this char
     new_character.locks.add("puppet:id(%i) or pid(%i) or perm(Janitors)" % (new_character.id, player.id))
     # Set this new character as owned by this player
     new_character.set_owner(player)
     # Configure the character as a new character in the world
     new_character.db.desc = "This is a Player."
     # Inform the user that we're done.
     self.msg("{G[Created new character %s. Use {g%s/ic %s{G to enter the game as this character]" % (new_character.key, self.key, new_character.key))
Exemplo n.º 25
0
 def at_after_traverse(self, traveller, source_loc):
     # Check for followers
     for follower in search_object(traveller, attribute_name='follow_following'):
         # Ensure that the follower is still at your source location.
         # (Safety check.  Moving around on your own should clear your 'following' attribute)
         if not follower.location or follower.location != source_loc:
             self.at_failed_follow(traveller, follower)
             del follower.db.follow_following
             break
         # Check te ensure that the follower is awake.
         # (Safety check.  Disconnecting your character should clear your 'following' attribute)
         if not follower.player:
             self.at_failed_follow(traveller, follower)
             del follower.db.follow_following
             break
         # Ensure the follower has access to travel through the exit
         if not self.access(follower, 'traverse_follow'):
             self.at_failed_follow(traveller, follower)
             del follower.db.follow_following
             break
         # Bring the follower alonga
         self.at_before_follow(traveller, follower)
         follower.move_to(traveller.location, redirectable=True, followers=None)
         self.at_after_follow(traveller, follower, source_loc)
Exemplo n.º 26
0
#HEADER
from ev import create_object, search_object

#CODE (Npcs)
from ev import create_object, search_object
caller.msg("Creating Battle Dummy")
tutorial3 = search_object("tutorial3")[0]
tut_enemynpc = create_object("game.gamesrc.objects.world.npc.Npc", key="Battle Dummy", location=tutorial3)
desc = "What seems to be an animated..scarecrow...thing.  \"Mmph...mppphhnnmm\" is the only sounds it seems capable of making.\n"
desc += "In its hand materializes a magically summoned hammer and shield."
tut_enemynpc.db.desc = desc
tut_enemynpc.db.actions = { 'taunt': "Mpphhgmm mph, hpmmhhhgn!", "mock": "Hmmgpf mmpphmmgjf" }
tut_enemynpc.rating = 'hero'
tut_enemynpc.db.attributes['level'] = 1
tut_enemynpc.generate_attributes()

caller.msg("Creating Kayleigh")
tutorial1_room = search_object("tutorial1")[0]
tutorial1_npc = create_object("game.gamesrc.objects.world.npc.Npc", key="Kayleigh", location=tutorial1_room)
desc = "This striking woman is clearly far stronger than you and could probably kill you with a mere flick of her finger.\n"
desc += "She is dressed in a black ensemble that hides all of her features except her eyes.  As you look at her face, you\n"
desc += "notice that her eyes are entirely white, though she does not seem to be blind."
tutorial1_npc.desc = desc
tutorial1_npc.name = "{Y!{n %s" % tutorial1_npc.name
tutorial1_npc.db.real_name = "Kayleigh"
tutorial1_npc.db.quests = ['Speak And Be Heard', 'Learning New Skills']
tutorial1_npc.db.merchant = False
tutorial1_npc.db.quest_giver = True
tutorial1_npc.db.trainer = False

caller.msg("Creating Green Warden")
Exemplo n.º 27
0
    def func(self):
        "Do checks and create account"

        session = self.caller
        args = self.args.strip()

        # extract quoted parts
        parts = [part.strip() for part in re.split(r"\"|\'", args) if part.strip()]
        if len(parts) == 1:
            # this was (hopefully) due to no quotes being found
            parts = parts[0].split(None, 1)
        if len(parts) != 2:
            string = "\n Usage (without <>): create <name> <password>"
            string += "\nIf <name> or <password> contains spaces, enclose it in quotes."
            session.msg(string)
            return
        playername, password = parts

        # Drop the player name to lowercase
        playername = playername.lower()
        # sanity checks
        if re.search('[^a-zA-Z0-9._-]', playername) or not (3 <= len(playername) <= 20):
            session.msg('{RPlayer names must be between 3 and 20 characters, and only contain english letters, numbers, dot (.), underscore (_), or dash(-)')
            return
        # Verify this player doesn't already exist
        if PlayerDB.objects.filter(user__username__iexact=playername) or User.objects.filter(username__iexact=playername):
            # player already exists (we also ignore capitalization here)
            session.msg("Sorry, there is already a player with the name '%s'." % playername)
            return
        # Verify that this player name does not match an existing character name
        for existing_object in search_object(playername, attribute_name='key'):
            if utils.inherits_from(existing_object, "src.objects.objects.Character"):
                session.msg("Sorry, there is already a character with the name '%s'." % playername)
                return
        # Security check the password
        if not re.findall('^[\w. @+-]+$', password) or not (3 < len(password)):
            string = "\n\r Password should be longer than 3 characers. Letters, spaces, digits and @\.\+\-\_ only."
            string += "\nFor best security, make it longer than 8 characters. You can also use a phrase of"
            string += "\nmany words if you enclose the password in quotes."
            session.msg(string)
            return

        # everything's ok. Create the new player account.
        try:
            default_home = ObjectDB.objects.get_id(settings.CHARACTER_DEFAULT_HOME)

            typeclass = settings.BASE_CHARACTER_TYPECLASS
            permissions = settings.PERMISSION_PLAYER_DEFAULT

            try:
                new_player = create.create_player(playername, None, password,
                                                     permissions=permissions)


            except Exception, e:
                session.msg("There was an error creating the default Player/Character:\n%s\n If this problem persists, contact an admin." % e)
                return

            # This needs to be called so the engine knows this player is logging in for the first time.
            # (so it knows to call the right hooks during login later)
            utils.init_new_player(new_player)

            # join the new player to the public channel
            pchanneldef = settings.CHANNEL_PUBLIC
            if pchanneldef:
                pchannel = Channel.objects.get_channel(pchanneldef[0])
                if not pchannel.connect_to(new_player):
                    string = "New player '%s' could not connect to public channel!" % new_player.key
                    logger.log_errmsg(string)


            # tell the caller everything went well.
            string = "A new account '%s' was created. Welcome!"
            if " " in playername:
                string += "\n\nYou can now log in with the command 'connect \"%s\" <your password>'."
            else:
                string += "\n\nYou can now log with the command 'connect %s <your password>'."
            session.msg(string % (playername, playername))
Exemplo n.º 28
0
 def func(self):
     character = self.character
     # Sanity check
     if not character.location:
         self.msg("{R[You don't appear to have any specific location to drop items into.]")
         return
     # Parse arguments
     target_name = self.args
     quantity = None
     match = re.match(r'(\d+)\s+of\s+(.*)$', target_name)
     if match:
         target_name = match.group(2)
         quantity = int(match.group(1))
     # Call a special action hook if we're dealing with a deposit
     container = None
     match = re.search(r'(^|.*)\s*into\s+(.+)$', target_name)
     if match:
         target_name = match.group(1).strip() or None
         container_name = match.group(2)
         results = search_object(container_name, exact=False, candidates=[con for con in character.location.contents if con != character])
         container = _AT_SEARCH_RESULT(character, container_name, results, global_search=False)
         if not container:
             return # User is alerted by search hook
     # Find object
     if not target_name:
         self.msg('Get what?')
         return
     results = search_object(target_name, exact=False, candidates=character.contents)
     target = _AT_SEARCH_RESULT(character, target_name, results, global_search=False)
     if not target:
         return # Search result hook should handle informing the user
     # Verify permissions
     if not target.access(character, 'drop'):
         return # Access failure hook should inform the user
     # If a container is specified, then call a special deposit hook instead
     if container:
         container.action_deposit(character, target)
         return
     # Do some safety checks in case somehow a user manages to target some room or character or something bizzare
     if not utils.inherits_from(target, 'game.gamesrc.latitude.objects.item.Item'):
         raise Exception('"drop" on non-item object')
     if target.bad():
         raise Exception('Interaction with bad object')
     # Verify the quantity
     if utils.inherits_from(target, 'game.gamesrc.latitude.objects.stackable.Stackable'):
         if quantity == None:
             quantity = target.db.quantity
         elif quantity > target.db.quantity:
             self.msg("There aren't enough in that stack.")
             return
         elif quantity < 1:
             self.msg("You need to specify at least one.")
             return
     else:
         if quantity == None:
             quantity = 1
         elif quantity != 1:
             self.msg('You need to pick that up one at a time.')
             return
     # Looks good.  Perform the actual move.
     if utils.inherits_from(target, 'game.gamesrc.latitude.objects.stackable.Stackable'):
         typeclass = target.path
         target.db.quantity -= quantity
         if target.db.quantity <= 0:
             target.delete()
         target = character.location.give(typeclass, quantity=quantity)[0]
     else:
         target.move_to(character.location, quiet=True)
     # Alert characters
     if quantity > 1:
         character.msg(character.objsub('You drop some &1m.', target))
         character.location.msg_contents(character.objsub('&0N drops some &1m.', target), exclude=character)
     else:
         character.msg(character.objsub('You drop &1i.', target))
         character.location.msg_contents(character.objsub('&0N drops &1i.', target), exclude=character)
     # Call hook
     target.at_drop(character, quantity=quantity)
Exemplo n.º 29
0
 def cmd_visit(self):
     character = self.character
     region = character.get_region()
     area = character.get_area()
     areas = [option for option in region.contents if hasattr(option, "can_visit") and option.can_visit(character)]
     results = search_object(self.args, exact=False, candidates=areas)
     destination = _AT_SEARCH_RESULT(
         character,
         self.args,
         results,
         global_search=False,
         nofound_string="You can't find that area.",
         multimatch_string="More than one area matches '%s':" % (self.args),
     )
     if not destination:
         return  # The search result hook should have informed the user
     # Ensure the player has permission to leave this area
     if character.location:
         if not character.location.access(character, "leave"):
             # The access check should display a message
             return
     # Ensure the user isn't trying to go where they already are
     if area == destination:
         self.msg("{Y[You're already in that area]")
         return
     # Ensure the user has enough points to travel  (If their maximum is too low to travel here, let them go into negatives.)
     visit_cost = region.db.region_visit_cost
     may_go_negative = False
     if self.capable_cost(visit_cost):
         if not self.satisfies_cost(visit_cost):
             region.at_visit_insufficient(character)
             self.msg("You're too tired.")
             return
     else:
         if not self.maxed_cost(visit_cost):
             region.at_visit_incapable(character)
             self.msg(
                 "This region looks very difficult to navigate.  If you're going to attempt it, you should rest as much as possible first."
             )
             return
         may_go_negative = True
     # Move the character
     if character.get_room() or may_go_negative:
         prompt_script = create_script(
             "game.gamesrc.latitude.scripts.prompt_leave.PromptLeave", obj=character, autostart=False
         )
         if may_go_negative:
             prompt_script.db.question = "This region seems to be beyond your capabilities.  If you try to navigate here, you may be very drained.  Are you sure you want to leave the area?"
         prompt_script.db.destination = destination
         prompt_script.db.cost = visit_cost
         prompt_script.db.followers = True
         prompt_script.db.yes_message = "You head off in search of your destination."
         prompt_script.db.no_message = "You decide to stay where you are."
         prompt_script.start()
     else:
         message = ["You head off in search of your destination."]
         if visit_cost:
             message = [character.game_attribute_offset(attr, -cost) for attr, cost in visit_cost.iteritems()]
         self.msg(" ".join(message))
         character.move_to(
             destination, redirectable=True, followers=False
         )  # If you're in the region object, then you shouldn't have followers.  If you somehow do, then it's best you lose them now rather than drag them off.
Exemplo n.º 30
0
#HEADER
from ev import create_object, search_object

#CODE (Npcs)
from ev import create_object, search_object
caller.msg("Creating Battle Dummy")
tutorial3 = search_object("tutorial3")[0]
tut_enemynpc = create_object("game.gamesrc.objects.world.npc.Npc",
                             key="Battle Dummy",
                             location=tutorial3)
desc = "What seems to be an animated..scarecrow...thing.  \"Mmph...mppphhnnmm\" is the only sounds it seems capable of making.\n"
desc += "In its hand materializes a magically summoned hammer and shield."
tut_enemynpc.db.desc = desc
tut_enemynpc.db.actions = {
    'taunt': "Mpphhgmm mph, hpmmhhhgn!",
    "mock": "Hmmgpf mmpphmmgjf"
}
tut_enemynpc.rating = 'hero'
tut_enemynpc.db.attributes['level'] = 1
tut_enemynpc.generate_attributes()

caller.msg("Creating Kayleigh")
tutorial1_room = search_object("tutorial1")[0]
tutorial1_npc = create_object("game.gamesrc.objects.world.npc.Npc",
                              key="Kayleigh",
                              location=tutorial1_room)
desc = "This striking woman is clearly far stronger than you and could probably kill you with a mere flick of her finger.\n"
desc += "She is dressed in a black ensemble that hides all of her features except her eyes.  As you look at her face, you\n"
desc += "notice that her eyes are entirely white, though she does not seem to be blind."
tutorial1_npc.desc = desc
tutorial1_npc.name = "{Y!{n %s" % tutorial1_npc.name
Exemplo n.º 31
0
 def func(self):
     if not self.args:
         self.msg('Lead what?')
         return
     leader = self.character
     follower = leader.search(self.args)
     if not follower:
         return # Error message is handled by the search call
     if follower == leader:
         leader.msg("You march to the beat of your own drum.")
         return
     if not isinstance(follower, Object):
         leader.msg("You can't follow that!")
         return
     already_following = search_object(leader, attribute_name='follow_following')
     if already_following:
         leader.msg("{Y[Try \"stop leading\" to stop leading, first.]")
         leader.msg("You're already leading %s." % (conj_join([char.key for char in already_following], 'and')))
         return
     if follower.db.follow_following:
         leader.msg("%s is already following someone." % (follower.key))
         return
     # Start leading, if we have permissions.
     if not follower.access(leader, 'follow') and not (follower.db.follow_pending and follower.db.follow_pending == leader and not follower.db.follow_pending_tolead):
         # Looks like it's not going to happen.  If we're dealing with a character, give them a chance to give permission
         if isinstance(follower, Character):
             # TODO: ALREADY WAITING
             # Warn the user that existing requests are being cleared
             if leader.db.follow_pending and not leader.db.follow_pending_tolead:
                 leader.msg('You no longer want to follow %s' % (leader.db.follow_pending.key))
                 del leader.db.follow_pending
                 del leader.db.follow_pending_tolead
             # Set the new request, adding to the list if a lead request already exists
             leader.db.follow_pending_tolead = True
             if leader.db.follow_pending:
                 # For some reason I can't store sets.  So extract it as a list, and convert it to a set, then store it back in.
                 follow_pending_set = set(leader.db.follow_pending)
                 follow_pending_set.add(follower)
                 leader.db.follow_pending = follow_pending_set
             else:
                 leader.db.follow_pending = set([follower])
             # Alert both parties
             follower.msg('{Y[Use "{yfollow %s{Y" to follow.]' % (leader.key))
             follower.msg('%s wants to lead you.' % (leader.key))
             leader.msg('You wait for %s to follow you.' % (follower.key))
             return
         # It's not a character.  Fail out.
         self.msg("You can't follow that!")
         return
     # Start leading
     follower.db.follow_following = leader
     follower.msg('%s starts leading you.' % (leader.key))
     leader.msg('You start leading %s.' % (follower.key))
     # Clear existing follow/lead requests if needed.
     if leader.db.follow_pending:
         if leader.db.follow_pending_tolead:
             if follower in leader.db.follow_pending:
                 leader.db.follow_pending.remove(follower)
         else:
             follower.msg("It seems you're now too busy to follow %s." % (leader.db.follow_pending.key))
             del leader.db.follow_pending
             del leader.db.follow_pending_tolead
     if follower.db.follow_pending and not follower.db.follow_pending_tolead:
         del follower.db.follow_pending
         del follower.db.follow_pending_tolead
Exemplo n.º 32
0
# The following variable is automatically made available for the script:

# caller - the object executing the script
#


# HEADER

# everything in this block will be appended to the beginning of
# all other #CODE blocks when they are executed.

from ev import create_object, search_object
from game.gamesrc.objects.examples import red_button
from ev import Object

limbo = search_object("Limbo")[0]


# CODE (create red button)

# This is the first code block. Within each block, python
# code works as normal. Note how we make use if imports and
# 'limbo' defined in the #HEADER block. This block's header
# offers no information about red_button variable, so it
# won't be able to be deleted in debug mode.

# create a red button in limbo
red_button = create_object(red_button.RedButton, key="Red button", location=limbo, aliases=["button"])

# we take a look at what we created
caller.msg("A %s was created." % red_button.key)
Exemplo n.º 33
0
# The following variable is automatically made available for the script:

# caller - the object executing the script
#

#HEADER

# everything in this block will be appended to the beginning of
# all other #CODE blocks when they are executed.

from ev import create_object, search_object
from game.gamesrc.objects.examples import red_button
from ev import Object

limbo = search_object('Limbo')[0]

#CODE (create red button)

# This is the first code block. Within each block, python
# code works as normal. Note how we make use if imports and
# 'limbo' defined in the #HEADER block. This block's header
# offers no information about red_button variable, so it
# won't be able to be deleted in debug mode.

# create a red button in limbo
red_button = create_object(red_button.RedButton,
                           key="Red button",
                           location=limbo,
                           aliases=["button"])
Exemplo n.º 34
0
# The following variable is automatically made available for the script:

# caller - the object executing the script
#


#HEADER

# everything in this block will be appended to the beginning of
# all other #CODE blocks when they are executed.

from ev import create_object, search_object
from game.gamesrc.objects.examples import red_button
from ev import Object

limbo = search_object('Limbo')[0]


#CODE (create red button)

# This is the first code block. Within each block, python
# code works as normal. Note how we make use if imports and
# 'limbo' defined in the #HEADER block. This block's header
# offers no information about red_button variable, so it
# won't be able to be deleted in debug mode.

# create a red button in limbo
red_button = create_object(red_button.RedButton, key="Red button",
                                  location=limbo, aliases=["button"])

# we take a look at what we created
Exemplo n.º 35
0
#HEADER
from ev import create_object, search_object
from game.gamesrc.objects.world.quests import Quest

#CODE
from ev import create_object, search_object
from game.gamesrc.objects.world.quests import Quest
storage = search_object('Limbo')[0]
copy_dir = 'gamesrc/copy/'

tut_speak = create_object(Quest, key="Speak And Be Heard", location=storage)
tut_speak.tags.add(tut_speak.key)
tut_speak.short_description = "Speak in OOC chat."
tut_speak.aliases = ['tutorial quests']
tut_speak.set_description('%squests/speak_and_be_heard.txt' % copy_dir)
tut_speak.db.gold_reward = 100
tut_speak.db.exp_reward = 100
objective = {'objective_name': 'Use the ooc command to speak in the global public channel', 'counter': 0, 'threshold': 3, 'completed': False, 'type': 'use_public'}
tut_speak.add_objective(objective)
Exemplo n.º 36
0
#HEADER
from ev import create_object, search_object
from game.gamesrc.objects.world.quests import Quest

#CODE
from ev import create_object, search_object
from game.gamesrc.objects.world.quests import Quest
storage = search_object('Limbo')[0]
copy_dir = 'gamesrc/copy/'

tut_speak = create_object(Quest, key="Speak And Be Heard", location=storage)
tut_speak.tags.add(tut_speak.key)
tut_speak.short_description = "Speak in OOC chat."
tut_speak.aliases = ['tutorial quests']
tut_speak.set_description('%squests/speak_and_be_heard.txt' % copy_dir)
tut_speak.db.gold_reward = 100
tut_speak.db.exp_reward = 100
objective = {
    'objective_name':
    'Use the ooc command to speak in the global public channel',
    'counter': 0,
    'threshold': 3,
    'completed': False,
    'type': 'use_public'
}
tut_speak.add_objective(objective)