diff --git a/src/commands/objmanip.py b/src/commands/objmanip.py index eb7c27cc13..d2a6646b83 100644 --- a/src/commands/objmanip.py +++ b/src/commands/objmanip.py @@ -783,17 +783,23 @@ def cmd_dig(command): defines_global.OTYPE_ROOM, None, source_object) + new_room.set_attribute("desc", "There is nothing special about this place.") source_object.emit_to("Created a new room '%s'." % (new_room,)) if parent: #(try to) set the script parent if not new_room.set_script_parent(parent): source_object.emit_to("%s is not a valid parent. Used default room." % parent) + + # Run custon creation commands on the script parent + new_room.scriptlink.at_object_creation() + if exits: #create exits to (and possibly back from) the new room) destination = new_room #search_for_object(roomname) if destination and not destination.is_exit(): + #create an exit from this room location = source_object.get_location() new_object = Object.objects.create_object(exits[0].strip(), @@ -801,15 +807,24 @@ def cmd_dig(command): location, source_object, destination) + new_object.set_attribute("desc", "This is an exit out of here.") source_object.emit_to("Created exit from %s to %s named '%s'." % (location,destination,new_object)) - + + # Run custon creation commands on the exit + new_object.scriptlink.at_object_creation() + if len(exits)>1: new_object = Object.objects.create_object(exits[1].strip(), defines_global.OTYPE_EXIT, destination, source_object, location) + new_object.set_attribute("desc", "This is an exit out of here.") source_object.emit_to("Created exit back from %s to %s named '%s'" % (destination, location, new_object)) + # Run custon creation commands on the exit + new_object.scriptlink.at_object_creation() + + if 'teleport' in switches: source_object.move_to(new_room) @@ -875,7 +890,7 @@ def cmd_description(command): source_object.emit_to("How would you like to describe that object?") return - target_obj = source_object.search_for_object(eq_args[0]) + target_obj = source_object.search_for_object(eq_args[0].strip()) # Use search_for_object to handle duplicate/nonexistant results. if not target_obj: return @@ -884,7 +899,7 @@ def cmd_description(command): source_object.emit_to(defines_global.NOCONTROL_MSG) return - new_desc = eq_args[1] + new_desc = eq_args[1].strip() if not new_desc: source_object.emit_to("%s - description cleared." % target_obj) target_obj.set_attribute('desc', 'Nothing special.') diff --git a/src/objects/managers/object.py b/src/objects/managers/object.py index 3e35a39e07..fcf4586399 100644 --- a/src/objects/managers/object.py +++ b/src/objects/managers/object.py @@ -410,6 +410,9 @@ class ObjectManager(models.Manager): if new_object.get_owner().get_zone(): new_object.zone = new_object.get_owner().get_zone() + # Run the script parent's oncreation function + + # If we have a 'home' key, use that for our home value. Otherwise use # the location key. if home: diff --git a/src/objects/models.py b/src/objects/models.py index cae7ccae6e..f1c58c7588 100755 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -878,27 +878,21 @@ class Object(models.Model): force_look: (bool) If true and self is a player, make them 'look'. """ - #before the move, call the appropriate hook + #before the move, call eventual pre-commands. if self.scriptlink.at_before_move(target) != None: return if not quiet: - location = self.get_location() - if location: - location.emit_to_contents("%s has left." % - (self.get_name(),), exclude=self) - if location.is_player(): - location.emit_to("%s has left your inventory." % - (self.get_name())) + #tell the old room we are leaving + self.scriptlink.announce_move_from() + #perform move self.location = target self.save() - + if not quiet: - arrival_message = "%s has arrived." % (self.get_name()) - self.get_location().emit_to_contents(arrival_message, exclude=self) - if self.location.is_player(): - self.location.emit_to("%s is now in your inventory." % (self.get_name())) + #tell the new room we are there. + self.scriptlink.announce_move_to() #execute eventual extra commands on this object after moving it self.scriptlink.at_after_move() diff --git a/src/script_parents/basicobject.py b/src/script_parents/basicobject.py index 12c0a4a08e..f613dcc174 100644 --- a/src/script_parents/basicobject.py +++ b/src/script_parents/basicobject.py @@ -83,13 +83,35 @@ class EvenniaBasicObject(object): """ pass + def announce_move_from(self): + """ + Called when announcing to leave a destination. + """ + obj = self.scripted_obj + loc = obj.get_location() + if loc: + loc.emit_to_contents("%s has left." % (obj.get_name(),), exclude=self) + if loc.is_player(): + loc.emit_to("%s has left your inventory." % (obj.get_name())) + + def announce_move_to(self): + """ + Called when announcing one's arrival at a destination. + """ + obj = self.scripted_obj + loc = obj.get_location() + if loc: + loc.emit_to_contents("%s has arrived." % obj.get_name()) + if loc.is_player(): + loc.emit_to("%s is now in your inventory." % self.get_name()) + def at_after_move(self): """ This hook is called just after the object was successfully moved. No return values. """ pass - + def at_drop(self, pobject): """ Perform this action when someone uses the DROP command on the object. diff --git a/src/script_parents/basicplayer.py b/src/script_parents/basicplayer.py index 80f72322c3..74e682df41 100644 --- a/src/script_parents/basicplayer.py +++ b/src/script_parents/basicplayer.py @@ -57,6 +57,28 @@ class EvenniaBasicPlayer(object): """ pass + def announce_move_from(self): + """ + Called when announcing to leave a destination. + """ + obj = self.scripted_obj + loc = obj.get_location() + if loc: + loc.emit_to_contents("%s has left." % (obj.get_name(),), exclude=self) + if loc.is_player(): + loc.emit_to("%s has left your inventory." % (obj.get_name())) + + def announce_move_to(self): + """ + Called when announcing one's arrival at a destination. + """ + obj = self.scripted_obj + loc = obj.get_location() + if loc: + loc.emit_to_contents("%s has arrived." % obj.get_name()) + if loc.is_player(): + loc.emit_to("%s is now in your inventory." % obj.get_name()) + def at_after_move(self): """ This hook is called just after the player has been successfully moved.