Moved the last hard-wired emits from objects/models.py into scriptparent hooks. This allows the admin to customize this without having to mess with the engine.

Other small bugfixes, fixes to @dig to properly call creation hooks of all newly created objects (it was not setting anything before). Also fixed some of the annoying bugs around using several of the building commands that didn't properly handle spaces around the separator = symbol.
/Griatch
This commit is contained in:
Griatch 2009-09-19 15:18:42 +00:00
parent b95d45e251
commit 8fbeea99dc
5 changed files with 73 additions and 17 deletions

View file

@ -783,17 +783,23 @@ def cmd_dig(command):
defines_global.OTYPE_ROOM, defines_global.OTYPE_ROOM,
None, None,
source_object) 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,)) source_object.emit_to("Created a new room '%s'." % (new_room,))
if parent: if parent:
#(try to) set the script parent #(try to) set the script parent
if not new_room.set_script_parent(parent): if not new_room.set_script_parent(parent):
source_object.emit_to("%s is not a valid parent. Used default room." % 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: if exits:
#create exits to (and possibly back from) the new room) #create exits to (and possibly back from) the new room)
destination = new_room #search_for_object(roomname) destination = new_room #search_for_object(roomname)
if destination and not destination.is_exit(): if destination and not destination.is_exit():
#create an exit from this room
location = source_object.get_location() location = source_object.get_location()
new_object = Object.objects.create_object(exits[0].strip(), new_object = Object.objects.create_object(exits[0].strip(),
@ -801,15 +807,24 @@ def cmd_dig(command):
location, location,
source_object, source_object,
destination) 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)) 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: if len(exits)>1:
new_object = Object.objects.create_object(exits[1].strip(), new_object = Object.objects.create_object(exits[1].strip(),
defines_global.OTYPE_EXIT, defines_global.OTYPE_EXIT,
destination, destination,
source_object, source_object,
location) 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)) 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: if 'teleport' in switches:
source_object.move_to(new_room) 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?") source_object.emit_to("How would you like to describe that object?")
return 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. # Use search_for_object to handle duplicate/nonexistant results.
if not target_obj: if not target_obj:
return return
@ -884,7 +899,7 @@ def cmd_description(command):
source_object.emit_to(defines_global.NOCONTROL_MSG) source_object.emit_to(defines_global.NOCONTROL_MSG)
return return
new_desc = eq_args[1] new_desc = eq_args[1].strip()
if not new_desc: if not new_desc:
source_object.emit_to("%s - description cleared." % target_obj) source_object.emit_to("%s - description cleared." % target_obj)
target_obj.set_attribute('desc', 'Nothing special.') target_obj.set_attribute('desc', 'Nothing special.')

View file

@ -410,6 +410,9 @@ class ObjectManager(models.Manager):
if new_object.get_owner().get_zone(): if new_object.get_owner().get_zone():
new_object.zone = 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 # If we have a 'home' key, use that for our home value. Otherwise use
# the location key. # the location key.
if home: if home:

View file

@ -878,27 +878,21 @@ class Object(models.Model):
force_look: (bool) If true and self is a player, make them 'look'. 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: if self.scriptlink.at_before_move(target) != None:
return return
if not quiet: if not quiet:
location = self.get_location() #tell the old room we are leaving
if location: self.scriptlink.announce_move_from()
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()))
#perform move
self.location = target self.location = target
self.save() self.save()
if not quiet: if not quiet:
arrival_message = "%s has arrived." % (self.get_name()) #tell the new room we are there.
self.get_location().emit_to_contents(arrival_message, exclude=self) self.scriptlink.announce_move_to()
if self.location.is_player():
self.location.emit_to("%s is now in your inventory." % (self.get_name()))
#execute eventual extra commands on this object after moving it #execute eventual extra commands on this object after moving it
self.scriptlink.at_after_move() self.scriptlink.at_after_move()

View file

@ -83,13 +83,35 @@ class EvenniaBasicObject(object):
""" """
pass 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): def at_after_move(self):
""" """
This hook is called just after the object was successfully moved. This hook is called just after the object was successfully moved.
No return values. No return values.
""" """
pass pass
def at_drop(self, pobject): def at_drop(self, pobject):
""" """
Perform this action when someone uses the DROP command on the object. Perform this action when someone uses the DROP command on the object.

View file

@ -57,6 +57,28 @@ class EvenniaBasicPlayer(object):
""" """
pass 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): def at_after_move(self):
""" """
This hook is called just after the player has been successfully moved. This hook is called just after the player has been successfully moved.