Advertisement
Kovitikus

Room Return Appearance

Sep 4th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.14 KB | None | 0 0
  1. # Example Image 1: https://i.imgur.com/jpUyZMK.png
  2. # Example Image 2: https://i.imgur.com/AviFQib.png
  3.  
  4. class Room(DefaultRoom):
  5.     """
  6.    Rooms are like any Object, except their location is None
  7.    (which is default). They also use basetype_setup() to
  8.    add locks so they cannot be puppeted or picked up.
  9.    (to change that, use at_object_creation instead)
  10.  
  11.    See examples/object.py for a list of
  12.    properties and methods available on all Objects.
  13.    """
  14.     def return_appearance(self, looker, **kwargs):
  15.         """
  16.        This formats a description. It is the hook a 'look' command
  17.        should call.
  18.        Args:
  19.            looker (Object): Object doing the looking.
  20.            **kwargs (dict): Arbitrary, optional arguments for users
  21.                overriding the call (unused by default).
  22.        """
  23.         if not looker:
  24.             return ""
  25.         # get and identify all objects
  26.         visible = (con for con in self.contents if con != looker and
  27.                    con.access(looker, "view"))
  28.         exits, users, things, destination = [], [], defaultdict(list), []
  29.         for con in visible:
  30.             key = con.get_display_name(looker)
  31.             if con.destination:
  32.                 exits.append(key)
  33.                 destination.append(con.destination.name)
  34.             elif con.has_account:
  35.                 users.append(f"|c{key}|n")
  36.             else:
  37.                 # things can be pluralized
  38.                 things[key].append(con)
  39.         # get description, build string
  40.         location_name = f"    You see {self.get_display_name(looker)}."
  41.         # if self.db.desc:
  42.         #     location_desc = self.db.desc
  43.         if exits:
  44.             num = 1
  45.             exit_len = len(exits)
  46.             exits_string = "    You see "
  47.             for _ in exits:
  48.                 if exit_len == 1:
  49.                     exits_string += f"|c{destination[exit_len - 1]}|n to the |c{exits[exit_len - 1]}|n."
  50.                 elif exit_len == num:
  51.                     exits_string += f"and |c{destination[exit_len - 1]}|n to the |c{exits[exit_len - 1]}|n."
  52.                 else:
  53.                     exits_string += f"|c{destination[exit_len - 1]}|n to the |c{exits[exit_len - 1]}|n, "
  54.                 num += 1
  55.         if users or things:
  56.             # handle pluralization of things (never pluralize users)
  57.             thing_strings = []
  58.             for key, itemlist in sorted(things.items()):
  59.                 nitem = len(itemlist)
  60.                 if nitem == 1:
  61.                     key, _ = itemlist[0].get_numbered_name(nitem, looker, key=key)
  62.                 else:
  63.                     key = [item.get_numbered_name(nitem, looker, key=key)[1] for item in itemlist][0]
  64.                 thing_strings.append(key)
  65.  
  66.         string = f"{location_name}"
  67.         if self.db.desc:
  68.             string = f"{string} {self.db.desc}"
  69.         if exits:
  70.             string = f"{string}\n{exits_string}"
  71.         if things:
  72.             string = f"{string}\n    {list_to_string(thing_strings)} |nlies upon the ground."
  73.         if users:
  74.             string = f"{string}\n    {list_to_string(users)} is here."
  75.  
  76.         return string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement