Beispiel #1
0
 def func(self):
     if not self.args:
         self.msg('Follow what?')
         return
     follower = self.character
     leader = follower.search(self.args)
     if follower == leader:
         leader.msg("You march to the beat of your own drum.")
         return
     if not leader:
         return # Error message is handled by the search call
     if not isinstance(leader, Object):
         follower.msg("You can't follow that!")
         return
     if follower.db.follow_following:
         follower.msg("{Y[Try \"{ystop{Y\" to stop following, first.]")
         follower.msg("You're already following %s." % (follower.db.follow_following.key))
         return
     # Start following, if we have permissions.
     if not leader.access(follower, 'follow') and not (leader.db.follow_pending and leader.db.follow_pending_tolead and follower in leader.db.follow_pending):
         # Looks like it's not going to happen.  If we're dealing with a character, give them a chance to give permission
         if isinstance(leader, Character):
             # TODO: ALREADY WAITING
             # Warn the user that existing requests are being cleared
             if follower.db.follow_pending:
                 if follower.db.follow_pending_tolead:
                     follower.msg('You no longer want to lead %s' % (conj_join([char.key for char in follower.db.follow_pending], 'and')))
                 else:
                     follower.msg('You no longer want to follow %s' % (follower.db.follow_pending.key))
             # Set the new request
             follower.db.follow_pending = leader
             follower.db.follow_pending_tolead = False
             # Alert both parties
             leader.msg('{Y[Use "{ylead %s{Y" to lead.]' % (follower.key))
             leader.msg('%s wants to follow you.' % (follower.key))
             follower.msg('You wait for %s to lead you.' % (leader.key))
             return
         # It's not a character.  Fail out.
         self.msg("You can't follow that!")
         return
     # Start following
     follower.db.follow_following = leader
     follower.msg('You start following %s.' % (leader.key))
     leader.msg('%s starts following you.' % (follower.key))
     # Clear existing follow/lead requests if needed.
     if follower.db.follow_pending and follower.db.follow_pending != leader:
         if follower.db.follow_pending_tolead:
             follower.msg("It seems you're now too busy to lead %s." % (conj_join([char.key for char in follower.db.follow_pending], 'and')))
         else:
             follower.msg("It seems you're now too busy to follow %s." % (leader.db.follow_pending.key))
     del follower.db.follow_pending
     del follower.db.follow_pending_tolead
     if leader.db.follow_pending and leader.db.follow_pending_tolead and follower in leader.db.follow_pending:
         leader.db.follow_pending.remove(follower)
         if not leader.db.follow_pending:
             del leader.db.follow_pending
             del leader.db.follow_pending_tolead
Beispiel #2
0
 def gen_message_text(self, sender, receivers, raw_message):
     """
     Produces a pretty version of the message string requested by the user, handling page poses, etc.
     """
     character = self.character
     player = self.player
     message = raw_message
     if character:
         # If we have a character, then we can use the 'say' routines to format the message.
         if message.startswith(':'):
             message = character.speech_pose(message[1:])
         elif message.startswith('"'):
             message = character.speech_say(message[1:])
         else:
             message = character.speech_say(message)
     else:
         # If we have no character, we'll have to take care of the formatting
         if message.startswith(':'):
             message = '{b' + player.key + '{n ' + message[1:].replace('{', '{{').replace('%', '%%')
         elif message.startswith('"'):
             message = '{b' + player.key + '{n: ' + message[1:].replace('{', '{{').replace('%', '%%')
         else:
             message = '{b' + player.key + '{n: ' + message.replace('{', '{{').replace('%', '%%')
     message = "{n%s {Y| To %s" % (message, conj_join([obj.key for obj in receivers], 'and'))
     return message
Beispiel #3
0
 def cmd_last(self, num=None):
     now = datetime.now()
     player = self.player
     if num:
         # Get the messages we've sent (not to channels)
         pages = set(Msg.objects.get_messages_by_sender(player, exclude_channel_messages=True))
         # Get the messages we've received
         pages |= set(Msg.objects.get_messages_by_receiver(player))
         # Sort them in chronological order
         pages = sorted(pages, cmp=lambda x, y: cmp(x.date_sent, y.date_sent))
         # Filter out old messages.
         pages = filter(lambda page: page.date_sent > now - timedelta(days=14), pages)
         # Grab only the last 'num' pages
         if len(pages) > num:
             lastpages = pages[-num:]
         else:
             lastpages = pages
         if not lastpages:
             self.msg('{Y[You have no recent page history]')
             return
     else:
         if player.db.msg_unseen:
             lastpages = player.db.msg_unseen
             player.db.msg_unseen = None
         else:
             self.msg('{Y[You have no unread pages]')
             return
     self.msg("{x________________{W_______________{w_______________{W_______________{x_________________")
     output = []
     for page in lastpages:
         if page.header:
             header = pickle.loads(page.header)
             output.append("{n---- {nMessage from {C%s{n to {C%s{n at %s{n ----\n{n%s" % (header['from'], conj_join(['{C' + tostr + '{n' for tostr in header['to']], 'and'), utils.datetime_format(page.date_sent), page.message))
         else:
             output.append("{n---- {nMessage sent at %s{n ----\n{n%s" % (utils.datetime_format(page.date_sent), page.message))
     self.msg("\n\n".join(output))
     self.msg("{x________________{W_______________{w_______________{W_______________{x_________________")
Beispiel #4
0
 def at_visit_insufficient(self, wanderer):
     wanderer.msg("{R[You require %s to visit an area in this region]" % (conj_join([str(cost) + ' ' + attr for attr, cost in self.db.region_visit_cost.iteritems()], 'and')))
Beispiel #5
0
 def at_wander_incapable(self, wanderer):
     wanderer.msg("{R[You require %s to explore this region]" % (conj_join([str(cost) + ' ' + attr for attr, cost in self.db.region_wander_cost.iteritems()], 'and')))
Beispiel #6
0
 def cmd_list(self):
     character = self.character
     region = character.get_region()
     visit_cost = region.db.region_visit_cost
     wander_cost = region.db.region_wander_cost
     areas_plain = []
     areas_reason = []
     # Header
     self.msg("-------------------------------------------------------------------------------")
     self.msg(
         evennia_color_center(
             "{CRegion: {m%s   {CTravel Cost: %s%s   {CWander Cost: %s%s"
             % (
                 region.key,
                 self.satisfies_cost(visit_cost) and "{G" or "{R",
                 visit_cost
                 and conj_join([str(cost) + " " + attr for attr, cost in visit_cost.iteritems()], "and")
                 or "{GNone",
                 self.satisfies_cost(wander_cost) and "{G" or "{R",
                 wander_cost
                 and conj_join([str(cost) + " " + attr for attr, cost in wander_cost.iteritems()], "and")
                 or "{GNone",
             ),
             79,
         )
     )
     self.msg("  ---------------------------------------------------------------------------  ")
     # Get permissions (and returned reasons) for areas
     for area in region.contents:
         if not hasattr(area, "can_visit"):
             continue
         reason = area.can_visit(character)
         if not reason:
             continue
         # Add this to the 'plain listing' section if applicable
         if "Known" in reason or "Landmark" in reason:
             areas_plain.append((area, reason))
         # Add this to the 'detailed reason listing' section if applicable
         reason_misc = reason
         if "Known" in reason_misc:
             reason.remove("Known")
         if "Landmark" in reason_misc:
             reason.remove("Landmark")
         if reason_misc:
             areas_reason.append((area, reason_misc))
     if not (areas_plain or areas_reason):
         self.msg("{R[There are no areas you can currently visit.]")
         return
     # Sort the list of areas
     areas_plain.sort(key=lambda area: (area[0].key, area[1]))
     areas_reason.sort(key=lambda area: (area[0].key, area[1]))
     # Display the list of areas
     for index in range(0, len(areas_plain), 3):
         self.msg(
             "   ".join([evennia_color_left("{M" + area[0].key, 23) for area in areas_plain[index : index + 3]])
         )
     if areas_plain and areas_reason:
         self.msg("  ---------------------------------------------------------------------------  ")
     for area, reason in areas_reason:
         self.msg("{M%s {C(%s{C)" % (area.key, "{C,".join(reason)))
     # Footer
     self.msg("  ---------------------------------------------------------------------------  ")
     self.msg(evennia_color_center("{CUse visit <area name> to visit an area.", 79))
     self.msg("-------------------------------------------------------------------------------")
Beispiel #7
0
 def func(self):
     if not self.args:
         self.msg('Lead what?')
         return
     leader = self.character
     follower = leader.search(self.args)
     if not follower:
         return # Error message is handled by the search call
     if follower == leader:
         leader.msg("You march to the beat of your own drum.")
         return
     if not isinstance(follower, Object):
         leader.msg("You can't follow that!")
         return
     already_following = search_object(leader, attribute_name='follow_following')
     if already_following:
         leader.msg("{Y[Try \"stop leading\" to stop leading, first.]")
         leader.msg("You're already leading %s." % (conj_join([char.key for char in already_following], 'and')))
         return
     if follower.db.follow_following:
         leader.msg("%s is already following someone." % (follower.key))
         return
     # Start leading, if we have permissions.
     if not follower.access(leader, 'follow') and not (follower.db.follow_pending and follower.db.follow_pending == leader and not follower.db.follow_pending_tolead):
         # Looks like it's not going to happen.  If we're dealing with a character, give them a chance to give permission
         if isinstance(follower, Character):
             # TODO: ALREADY WAITING
             # Warn the user that existing requests are being cleared
             if leader.db.follow_pending and not leader.db.follow_pending_tolead:
                 leader.msg('You no longer want to follow %s' % (leader.db.follow_pending.key))
                 del leader.db.follow_pending
                 del leader.db.follow_pending_tolead
             # Set the new request, adding to the list if a lead request already exists
             leader.db.follow_pending_tolead = True
             if leader.db.follow_pending:
                 # For some reason I can't store sets.  So extract it as a list, and convert it to a set, then store it back in.
                 follow_pending_set = set(leader.db.follow_pending)
                 follow_pending_set.add(follower)
                 leader.db.follow_pending = follow_pending_set
             else:
                 leader.db.follow_pending = set([follower])
             # Alert both parties
             follower.msg('{Y[Use "{yfollow %s{Y" to follow.]' % (leader.key))
             follower.msg('%s wants to lead you.' % (leader.key))
             leader.msg('You wait for %s to follow you.' % (follower.key))
             return
         # It's not a character.  Fail out.
         self.msg("You can't follow that!")
         return
     # Start leading
     follower.db.follow_following = leader
     follower.msg('%s starts leading you.' % (leader.key))
     leader.msg('You start leading %s.' % (follower.key))
     # Clear existing follow/lead requests if needed.
     if leader.db.follow_pending:
         if leader.db.follow_pending_tolead:
             if follower in leader.db.follow_pending:
                 leader.db.follow_pending.remove(follower)
         else:
             follower.msg("It seems you're now too busy to follow %s." % (leader.db.follow_pending.key))
             del leader.db.follow_pending
             del leader.db.follow_pending_tolead
     if follower.db.follow_pending and not follower.db.follow_pending_tolead:
         del follower.db.follow_pending
         del follower.db.follow_pending_tolead