Advertisement
Kovitikus

announce_move_to and from

Sep 13th, 2019
2,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.17 KB | None | 0 0
  1.     """Goes in the Character class."""
  2.     def announce_move_from(self, destination, msg=None, mapping=None, **kwargs):
  3.         """
  4.        Called if the move is to be announced. This is
  5.        called while we are still standing in the old
  6.        location.
  7.        Args:
  8.            destination (Object): The place we are going to.
  9.            msg (str, optional): a replacement message.
  10.            mapping (dict, optional): additional mapping objects.
  11.            **kwargs (dict): Arbitrary, optional arguments for users
  12.                overriding the call (unused by default).
  13.        You can override this method and call its parent with a
  14.        message to simply change the default message.  In the string,
  15.        you can use the following as mappings (between braces):
  16.            object: the object which is moving.
  17.            exit: the exit from which the object is moving (if found).
  18.            origin: the location of the object before the move.
  19.            destination: the location of the object after moving.
  20.        """
  21.         #TODO: Fix broken move when room has no exits. https://i.imgur.com/D4nUQJt.png
  22.         if not self.location:
  23.             return
  24.         location = self.location
  25.         origin = location or "nowhere"
  26.         exits = [o for o in location.contents if o.location is location and o.destination is destination]
  27.         var_exit = exits[0] if exits else "somewhere"
  28.  
  29.         if inherits_from(var_exit, "typeclasses.exits.Door"):
  30.             self_str = f"You walk away through {var_exit.db.desc}, to the {var_exit.name}."
  31.             others_str = f"{self.name} walks away through {var_exit.db.desc}, to the {var_exit.name}."
  32.         elif inherits_from(var_exit, "typeclasses.exits.Stair"):
  33.             if var_exit.name in ['up', 'down']:
  34.                 self_str = f"You depart, climbing {var_exit.name} {var_exit.db.desc}."
  35.                 others_str = f"{self.name} departs, climbing {var_exit.name} {var_exit.db.desc}."
  36.             else:
  37.                 self_str = f"You depart, climbing {var_exit.name} to the {var_exit.db.desc}."
  38.                 others_str = f"{self.name} departs, climbing {var_exit.name} to the {var_exit.db.desc}."
  39.         else:
  40.             self_str = f"You walk away to {var_exit.destination.name}, to the {var_exit.name}."
  41.             others_str = f"{self.name} walks away to {var_exit.destination.name}, to the {var_exit.name}."
  42.  
  43.         self.msg(self_str)
  44.         location.msg_contents(others_str, exclude=(self, ))
  45.  
  46.     def announce_move_to(self, source_location, msg=None, mapping=None, **kwargs):
  47.         """
  48.        Called after the move if the move was not quiet. At this point
  49.        we are standing in the new location.
  50.        Args:
  51.            source_location (Object): The place we came from
  52.            msg (str, optional): the replacement message if location.
  53.            mapping (dict, optional): additional mapping objects.
  54.            **kwargs (dict): Arbitrary, optional arguments for users
  55.                overriding the call (unused by default).
  56.        Notes:
  57.            You can override this method and call its parent with a
  58.            message to simply change the default message.  In the string,
  59.            you can use the following as mappings (between braces):
  60.                object: the object which is moving.
  61.                exit: the exit from which the object is moving (if found).
  62.                origin: the location of the object before the move.
  63.                destination: the location of the object after moving.
  64.        """
  65.         #TODO: Fix broken move when room has no exits. https://i.imgur.com/D4nUQJt.png
  66.         #TODO: Add contents of hands and wielding description for arriving characters.
  67.  
  68.         if not source_location and self.location.has_account:
  69.             # This was created from nowhere and added to an account's
  70.             # inventory; it's probably the result of a create command.
  71.             string = f"You now have {self.get_display_name(self.location)} in your possession."
  72.             self.location.msg(string)
  73.             return
  74.  
  75.         origin = source_location
  76.         destination = self.location
  77.         exits = []
  78.         if origin:
  79.             exits = [o for o in destination.contents if o.location is destination and o.destination is origin]
  80.             origin_exit = exits[0] if exits else "somewhere"
  81.  
  82.         if origin:
  83.             if inherits_from(origin_exit, "typeclasses.exits.Door"):
  84.                 others_str = f"{self.name} walks in through {origin_exit.db.desc}, from the {origin_exit.name}."
  85.             elif inherits_from(origin_exit, "typeclasses.exits.Stair"):
  86.                 if origin_exit.name in ['up', 'down']:
  87.                     others_str = f"{self.name} arrives, climbing {'down' if origin_exit.name == 'up' else 'up'} {origin_exit.db.desc}."
  88.                 else:
  89.                     others_str = f"{self.name} arrives, climbing {origin_exit.db.desc} from the {origin_exit.name}."
  90.             else:
  91.                 others_str = f"{self.name} walks in from {origin.name}, from the {origin_exit.name}."
  92.         else:
  93.             others_str = f"{self.name} arrives."
  94.  
  95.         destination.msg_contents(others_str, exclude=(self, ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement