Update Object.announce_move_* to take advantage of mapping

This commit is contained in:
Vincent Le Goff 2017-03-27 17:04:31 -07:00 committed by Griatch
parent d811d7577e
commit 4f41582127

View file

@ -1162,7 +1162,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
# return has_perm(self, destination, "can_move") # return has_perm(self, destination, "can_move")
return True return True
def announce_move_from(self, destination): def announce_move_from(self, destination, msg=None):
""" """
Called if the move is to be announced. This is Called if the move is to be announced. This is
called while we are still standing in the old called while we are still standing in the old
@ -1170,25 +1170,51 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
Args: Args:
destination (Object): The place we are going to. destination (Object): The place we are going to.
msg (str, optional): a replacement message.
You can override this method and call its parent with a
message to simply change the default message. In the string,
you can use the following as mappings (between braces):
character: the character who is moving.
exit: the exit from which the character is moving (if found).
origin: the location of the character before the move.
destination: the location of the character after moving.
""" """
if not self.location: if not self.location:
return return
string = "%s is leaving %s, heading for %s." if msg:
location = self.location string = msg
for obj in self.location.contents: else:
if obj != self: string = "{character} is leaving {origin}, heading for {destination}."
obj.msg(string % (self.get_display_name(obj),
location.get_display_name(obj) if location else "nowhere",
destination.get_display_name(obj)))
def announce_move_to(self, source_location): location = self.location
exits = [o for o in location.contents if o.location is location and o.destination is destination]
mapping = {
"character": self,
"exit": exits[0] if exits else "somwhere",
"origin": location or "nowhere",
"destination": destination or "nowhere",
}
location.msg_contents(string, exclude=(self, ), mapping=mapping)
def announce_move_to(self, source_location, msg=None):
""" """
Called after the move if the move was not quiet. At this point Called after the move if the move was not quiet. At this point
we are standing in the new location. we are standing in the new location.
Args: Args:
source_location (Object): The place we came from source_location (Object): The place we came from
msg (str, optional): the replacement message if location.
You can override this method and call its parent with a
message to simply change the default message. In the string,
you can use the following as mappings (between braces):
character: the character who is moving.
exit: the exit from which the character is moving (if found).
origin: the location of the character before the move.
destination: the location of the character after moving.
""" """
@ -1199,13 +1225,28 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
self.location.msg(string) self.location.msg(string)
return return
string = "%s arrives to %s%s." if source_location:
location = self.location if msg:
for obj in self.location.contents: string = msg
if obj != self: else:
obj.msg(string % (self.get_display_name(obj), string = "{character} arrives to {destination} from {origin}."
location.get_display_name(obj) if location else "nowhere", else:
" from %s" % source_location.get_display_name(obj) if source_location else "")) string = "{character} arrives to {destination}."
origin = source_location
destination = self.location
exits = []
if origin:
exits = [o for o in destination.contents if o.location is destination and o.destination is origin]
mapping = {
"character": self,
"exit": exits[0] if exits else "somewhere",
"origin": origin or "nowhere",
"destination": destination or "nowhere",
}
destination.msg_contents(string, exclude=(self, ), mapping=mapping)
def at_after_move(self, source_location): def at_after_move(self, source_location):
""" """