diff --git a/game/gamesrc/commands/basecommand.py b/game/gamesrc/commands/basecommand.py index 025c4b443..6d7dd7572 100644 --- a/game/gamesrc/commands/basecommand.py +++ b/game/gamesrc/commands/basecommand.py @@ -116,6 +116,19 @@ class Command(BaseCommand): """ return permissions.has_perm(srcobj, self, 'cmd') + def at_pre_cmd(self): + """ + This hook is called before self.parse() on all commands + """ + pass + + def at_post_cmd(self): + """ + This hook is called after the command has finished executing + (after self.func()). + """ + pass + def parse(self): """ This method is called by the cmdhandler once the command name diff --git a/src/commands/cmdhandler.py b/src/commands/cmdhandler.py index cb787ef06..de5135a47 100644 --- a/src/commands/cmdhandler.py +++ b/src/commands/cmdhandler.py @@ -385,9 +385,15 @@ def cmdhandler(caller, raw_string, unloggedin=False, testing=False): # only return the command instance return cmd + # pre-command hook + cmd.at_pre_cmd() + # Parse and execute cmd.parse() cmd.func() + + # post-command hook + cmd.at_post_cmd() # Done! except ExecSystemCommand, exc: diff --git a/src/commands/command.py b/src/commands/command.py index 53ddc3e52..77f90d60c 100644 --- a/src/commands/command.py +++ b/src/commands/command.py @@ -126,6 +126,19 @@ class Command(object): # Common Command hooks + def at_pre_cmd(self): + """ + This hook is called before self.parse() on all commands + """ + pass + + def at_post_cmd(self): + """ + This hook is called after the command has finished executing + (after self.func()). + """ + pass + def parse(self): """ Once the cmdhandler has identified this as the command we diff --git a/src/commands/default/muxcommand.py b/src/commands/default/muxcommand.py index fc02956a8..c4fcd7336 100644 --- a/src/commands/default/muxcommand.py +++ b/src/commands/default/muxcommand.py @@ -25,6 +25,19 @@ class MuxCommand(Command): are satisfied using the default check in Command. """ return super(MuxCommand, self).has_perm(srcobj) + + def at_pre_cmd(self): + """ + This hook is called before self.parse() on all commands + """ + pass + + def at_post_cmd(self): + """ + This hook is called after the command has finished executing + (after self.func()). + """ + pass def parse(self): """ diff --git a/src/objects/models.py b/src/objects/models.py index b967d86c1..a4034191b 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -352,6 +352,16 @@ class ObjectDB(TypedObject): return ObjectDB.objects.get_contents(self) contents = property(contents_get) + #@property + def exits_get(self): + """ + Returns all exits from this object, i.e. all objects + at this location having the property _destination. + """ + return [exi for exi in self.contents + if exi.has_attribute('_destination')] + exits = property(exits_get) + # # Nicks - custom nicknames # @@ -552,7 +562,9 @@ class ObjectDB(TypedObject): """ Moves this object to a new location. - destination: (Object) Reference to the object to move to. + destination: (Object) Reference to the object to move to. This + can also be an exit object, in which case the _destination + attribute is used as destination. quiet: (bool) If true, don't emit left/arrived messages. emit_to_obj: (Object) object to receive error messages """ @@ -563,6 +575,9 @@ class ObjectDB(TypedObject): if not destination: emit_to_obj.msg("The destination doesn't exist.") return + if destination.has_attribute('_destination'): + # traverse exits + destination = destination.get_attribute('_destination') # Before the move, call eventual pre-commands. try: @@ -646,8 +661,7 @@ class ObjectDB(TypedObject): Destroys all of the exits and any exits pointing to this object as a destination. """ - for out_exit in [obj for obj in self.contents - if obj.attr('_destination')]: + for out_exit in self.exits: out_exit.delete() for in_exit in \ ObjectDB.objects.get_objs_with_attr_match('_destination', self):