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,
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.')

View file

@ -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:

View file

@ -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()

View file

@ -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.

View file

@ -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.