Advertisement
Kovitikus

return room desc

Sep 4th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.82 KB | None | 0 0
  1. class Room(DefaultRoom):
  2.     """
  3.    Rooms are like any Object, except their location is None
  4.    (which is default). They also use basetype_setup() to
  5.    add locks so they cannot be puppeted or picked up.
  6.    (to change that, use at_object_creation instead)
  7.  
  8.    See examples/object.py for a list of
  9.    properties and methods available on all Objects.
  10.    """
  11.     def return_appearance(self, looker, **kwargs):
  12.         """
  13.        This formats a description. It is the hook a 'look' command
  14.        should call.
  15.        Args:
  16.            looker (Object): Object doing the looking.
  17.            **kwargs (dict): Arbitrary, optional arguments for users
  18.                overriding the call (unused by default).
  19.        """
  20.         if not looker:
  21.             return ""
  22.         # get and identify all objects
  23.         visible = (con for con in self.contents if con != looker and
  24.                    con.access(looker, "view"))
  25.         exits, users, things, destination = [], [], defaultdict(list), []
  26.         for con in visible:
  27.             key = con.get_display_name(looker)
  28.             if con.destination:
  29.                 exits.append(key)
  30.                 destination.append(con.destination.name)
  31.             elif con.has_account:
  32.                 users.append(f"|c{key}|n")
  33.             else:
  34.                 # things can be pluralized
  35.                 things[key].append(con)
  36.         # get description, build string
  37.         location_name = f"    You see {self.get_display_name(looker)}."
  38.         # if self.db.desc:
  39.         #     location_desc = self.db.desc
  40.         if exits:
  41.             num = 1
  42.             exit_len = len(exits)
  43.             exits_string = "    You see "
  44.             for _ in exits:
  45.                 if exit_len == 1:
  46.                     exits_string += f"|c{destination[exit_len - 1]}|n to the |c{exits[exit_len - 1]}|n."
  47.                 elif exit_len == num:
  48.                     exits_string += f"and |c{destination[exit_len - 1]}|n to the |c{exits[exit_len - 1]}|n."
  49.                 else:
  50.                     exits_string += f"|c{destination[exit_len - 1]}|n to the |c{exits[exit_len - 1]}|n, "
  51.                 num += 1
  52.         if users or things:
  53.             # handle pluralization of things (never pluralize users)
  54.             thing_strings = []
  55.             for key, itemlist in sorted(things.items()):
  56.                 nitem = len(itemlist)
  57.                 if nitem == 1:
  58.                     key, _ = itemlist[0].get_numbered_name(nitem, looker, key=key)
  59.                 else:
  60.                     key = [item.get_numbered_name(nitem, looker, key=key)[1] for item in itemlist][0]
  61.                 thing_strings.append(key)
  62.  
  63.         string = f"{location_name}"
  64.         if self.db.desc:
  65.             string = f"{string} {self.db.desc}"
  66.         if exits:
  67.             string = f"{string}\n{exits_string}"
  68.         if things:
  69.             string = f"{string}\n    {list_to_string(thing_strings)} |nlies upon the ground."
  70.         if users:
  71.             string = f"{string}\n    {list_to_string(users)} is here."
  72.  
  73.         return string
  74.  
  75.  
  76.  
  77.     # Calades Rendition
  78.     # def return_appearance(self,looker,**kwarfs):
  79.     #     """
  80.     #     This formats a description. It is the hook a 'look' command
  81.     #     should call
  82.        
  83.     #     args:
  84.     #         looker (object): object doing the looking
  85.     #         **kwargs (dict): Arbitrary, optional arguments for users
  86.     #             overriding the call (unused by default).
  87.     #     """
  88.     #     if not looker:
  89.     #         return ""
  90.     #     # get and identify all objects
  91.     #     visible = (con for con in self.contents if con != looker and
  92.     #                 con.access(looker, "view"))
  93.     #     exits, users, things, destination = [], [], defaultdict(list), []
  94.     #     for con in visible:
  95.     #         key = con.get_display_name(looker, pose=True)
  96.     #         if con.destination:
  97.     #             exits.append(key)
  98.     #             destination.append(con.destination)
  99.     #         elif con.has_account:
  100.     #             users.append("|c%s|n" % key)
  101.     #         else:
  102.     #             # things can be pluralized
  103.     #             things[key].append(con)
  104.     #         # get description, build string
  105.     #     string = "|cYou are located at %s. |n" % self.get_display_name(looker, pose=True)
  106.     #     desc = self.db.desc
  107.     #     if desc:
  108.     #         string += "%s" % desc
  109.     #     if exits:
  110.     #         num = 1
  111.     #         list_len = len(exits)
  112.     #         string += "\n   You see "
  113.     #         for i in exits:
  114.     #             if len(exits) == 1:
  115.     #                 string += f"|w{destination[0]} to the {exits[0]}."
  116.     #             elif num == list_len:
  117.     #                 string += f"|wand {destination[0]} to the {exits[0]}. "
  118.     #             else:
  119.     #                 string += f"|w{destination[num]} to the {exits[num]}, "
  120.     #                 num += 1
  121.     #     if users or things:
  122.     #         # handle pluralization of things (Never pluralize users)
  123.     #         thing_strings = []
  124.     #         for key, itemlist in sorted(things.items()):
  125.     #             nitem = len(itemlist)
  126.     #             if nitem == 1:
  127.     #                 key, _ = itemlist[0].get_numbered_name(nitem, looker, key=key)
  128.     #             else:
  129.     #                 key = [item.get_numbered_name(nitem, looker, key=key)[1] for item in itemlist][0]
  130.     #             thing_strings.append(key)
  131.     #         if len(users) < 1:
  132.     #             string += "\nYou are standing here alone.|n"
  133.     #         else:
  134.     #             string += "\nStanding around here are |n " + list_to_string(users, endsep="and", addquote=False)
  135.     #         if thing_strings:
  136.     #             string += "\nLaying on the ground infront of you is|n " + list_to_string(thing_strings, endsep="and", addquote=False)
  137.  
  138.     #     return string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement