mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Changed the way ExitCommands work by adding at_traverse() as a new hook to do the actual moving. This should allow for more flexibility in overloading new Exit typeclasses without having to re-implement the Exit Cmdset functionality more than necessary. By default the same error hooks are called wether the failure is due to a lock or some other error, this is (now) easy to modify as needed.
This commit is contained in:
parent
d80daccb70
commit
99c2dda8dc
2 changed files with 37 additions and 13 deletions
|
|
@ -1,12 +1,12 @@
|
|||
"""
|
||||
Makes it easier to import by grouping all relevant things already at this level.
|
||||
Makes it easier to import by grouping all relevant things already at this level.
|
||||
|
||||
You can henceforth import most things directly from src.objects
|
||||
You can henceforth import most things directly from src.objects
|
||||
Also, the initiated object manager is available as src.objects.manager.
|
||||
|
||||
"""
|
||||
|
||||
from src.objects.objects import *
|
||||
from src.objects.objects import *
|
||||
from src.objects.models import ObjectDB
|
||||
|
||||
manager = ObjectDB.objects
|
||||
|
|
|
|||
|
|
@ -578,6 +578,16 @@ class Object(TypeClass):
|
|||
"""
|
||||
pass
|
||||
|
||||
def at_traverse(self, traversing_object, target_location):
|
||||
"""
|
||||
This hook is responsible for handling the actual traversal, normally
|
||||
by calling traversing_object.move_to(target_location). It is normally
|
||||
only implemented by Exit objects. If it returns False (usually because move_to
|
||||
returned False), at_after_traverse below should not be called and
|
||||
instead at_failed_traverse should be called.
|
||||
"""
|
||||
pass
|
||||
|
||||
def at_after_traverse(self, traversing_object, source_location):
|
||||
"""
|
||||
Called just after an object successfully used this object to
|
||||
|
|
@ -836,17 +846,9 @@ class Exit(Object):
|
|||
|
||||
if self.obj.access(self.caller, 'traverse'):
|
||||
# we may traverse the exit.
|
||||
|
||||
old_location = None
|
||||
if hasattr(self.caller, "location"):
|
||||
old_location = self.caller.location
|
||||
|
||||
# call pre/post hooks and move object.
|
||||
self.obj.at_before_traverse(self.caller)
|
||||
self.caller.move_to(self.obj.destination)
|
||||
self.obj.at_after_traverse(self.caller, old_location)
|
||||
|
||||
self.obj.at_traverse(self.caller, self.obj.destination)
|
||||
else:
|
||||
# exit is locked
|
||||
if self.obj.db.err_traverse:
|
||||
# if exit has a better error message, let's use it.
|
||||
self.caller.msg(self.obj.db.err_traverse)
|
||||
|
|
@ -906,6 +908,28 @@ class Exit(Object):
|
|||
"Called once, when object is first created (after basetype_setup)."
|
||||
pass
|
||||
|
||||
def at_traverse(self, traversing_object, target_location):
|
||||
"""
|
||||
This implements the actual traversal. The traverse lock has already been
|
||||
checked (in the Exit command) at this point.
|
||||
"""
|
||||
source_location = traversing_object.location
|
||||
if traversing_object.move_to(target_location):
|
||||
self.at_after_traverse(traversing_object, source_location)
|
||||
else:
|
||||
if self.db.err_traverse:
|
||||
# if exit has a better error message, let's use it.
|
||||
self.caller.msg(self.db.err_traverse)
|
||||
else:
|
||||
# No shorthand error message. Call hook.
|
||||
self.at_failed_traverse(traversing_object)
|
||||
|
||||
def at_after_traverse(self, traversing_object, source_location):
|
||||
"""
|
||||
Called after a successful traverse.
|
||||
"""
|
||||
pass
|
||||
|
||||
def at_failed_traverse(self, traversing_object):
|
||||
"""
|
||||
This is called if an object fails to traverse this object for some
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue