mirror of
https://github.com/evennia/evennia.git
synced 2026-03-28 18:47:16 +01:00
Update Object.announce_move_* to take advantage of mapping
This commit is contained in:
parent
d811d7577e
commit
4f41582127
1 changed files with 57 additions and 16 deletions
|
|
@ -1162,7 +1162,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
|||
# return has_perm(self, destination, "can_move")
|
||||
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 while we are still standing in the old
|
||||
|
|
@ -1170,25 +1170,51 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
|||
|
||||
Args:
|
||||
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:
|
||||
return
|
||||
string = "%s is leaving %s, heading for %s."
|
||||
location = self.location
|
||||
for obj in self.location.contents:
|
||||
if obj != self:
|
||||
obj.msg(string % (self.get_display_name(obj),
|
||||
location.get_display_name(obj) if location else "nowhere",
|
||||
destination.get_display_name(obj)))
|
||||
if msg:
|
||||
string = msg
|
||||
else:
|
||||
string = "{character} is leaving {origin}, heading for {destination}."
|
||||
|
||||
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
|
||||
we are standing in the new location.
|
||||
|
||||
Args:
|
||||
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)
|
||||
return
|
||||
|
||||
string = "%s arrives to %s%s."
|
||||
location = self.location
|
||||
for obj in self.location.contents:
|
||||
if obj != self:
|
||||
obj.msg(string % (self.get_display_name(obj),
|
||||
location.get_display_name(obj) if location else "nowhere",
|
||||
" from %s" % source_location.get_display_name(obj) if source_location else ""))
|
||||
if source_location:
|
||||
if msg:
|
||||
string = msg
|
||||
else:
|
||||
string = "{character} arrives to {destination} from {origin}."
|
||||
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):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue