Exemplo n.º 1
0
    def display_recipes(self, recipes):
        from server.utils import arx_more

        if not recipes:
            self.msg("(No recipes qualify.)")
            return
        known_list = CraftingRecipe.objects.filter(
            known_by__player__player=self.caller.player)
        table = PrettyTable(
            ["{wKnown{n", "{wName{n", "{wAbility{n", "{wLvl{n", "{wCost{n"])

        def getter(a):
            return a.ability or ""

        recipes = sorted(recipes, key=getter)
        for recipe in recipes:
            known = "{wX{n" if recipe in known_list else ""
            table.add_row([
                known,
                str(recipe),
                recipe.ability,
                recipe.difficulty,
                recipe.additional_cost,
            ])
        arx_more.msg(self.caller, str(table), justify_kwargs=False)
Exemplo n.º 2
0
 def view_action(self, action, disp_old=False):
     """Views an action for caller"""
     text = action.view_action(caller=self.caller, disp_old=disp_old)
     arx_more.msg(self.caller,
                  text,
                  justify_kwargs=False,
                  pages_by_char=True)
Exemplo n.º 3
0
 def list_actions(self):
     """Lists the actions for the matching queryset"""
     qs = self.get_queryset_from_switches()
     table = EvTable("{wID",
                     "{wplayer",
                     "{wtldr",
                     "{wdate",
                     "{wcrisis",
                     width=78,
                     border="cells")
     for action in qs:
         if action.unanswered_questions:
             action_id = "{c*%s{n" % action.id
         else:
             action_id = action.id
         date = action.date_submitted.strftime(
             "%m/%d") if action.date_submitted else "----"
         table.add_row(action_id, action.dompc, action.topic, date,
                       action.plot)
     table.reformat_column(0, width=9)
     table.reformat_column(1, width=10)
     table.reformat_column(2, width=37)
     table.reformat_column(3, width=8)
     table.reformat_column(4, width=14)
     arx_more.msg(self.caller,
                  str(table),
                  justify_kwargs=False,
                  pages_by_char=True)
Exemplo n.º 4
0
    def list(self, caller):
        table = PrettyTable([
            "{wId{n",
            "{wName{n",
            "{wAttribution{n",
            "{wMarkup{n",
            "{wAccess Level{n",
            "{wIn Use{n",
        ])

        for template in Template.objects.accessible_by(self.caller):
            attribution = template.attribution if template.apply_attribution else ""

            in_use = "TRUE" if template.in_use() else "FALSE"

            if template.owner != self.caller.roster.current_account:
                in_use = ""

            access_level = ""

            for var in Template.ACCESS_LEVELS:
                if template.access_level == var[0]:
                    access_level = var[1]

            table.add_row([
                template.id,
                template.title,
                attribution,
                template.markup(),
                access_level,
                in_use,
            ])
        arx_more.msg(caller, str(table), justify_kwargs=False)
Exemplo n.º 5
0
 def disp_rumors(self, caller, rumors, add_heard=True):
     table = evtable.EvTable("{w#{n", "{w%s{n" % self.key.capitalize(),
                             border="cells", width=78, align="l", justify=True)
     x = 0
     heard_rumors = caller.ndb.heard_rumors or []
     week = get_week()
     for rumor in rumors:
         now = time_now()
         if (now - rumor.db_date_created).days > RUMOR_LIFETIME:
             continue
         x += 1
         table.add_row(x, rumor.db_message)
         if add_heard and rumor not in heard_rumors:
             heard_rumors.append(rumor)
     if add_heard:
         caller.ndb.heard_rumors = heard_rumors
     msg = "{w%s{n" % self.key.capitalize().center(78)
     msg += "\n"
     msg += str(table)
     stories = AssignedTask.objects.filter(finished=True, week__gte=week-3, observer_text__isnull=False)
     if stories:
         msg += "\n"
         msg += "{wOther Rumors{n".center(78)
         msg += "\n"
         table = evtable.EvTable("{wRumored Story #{n", "{wWeek{n", border="cells", width=78)
         for story in stories:
             table.add_row(story.id, story.week)
         msg += str(table)
     return arx_more.msg(caller, msg, justify_kwargs=False)
Exemplo n.º 6
0
 def disp_rumors(self, caller, rumors, add_heard=True):
     table = evtable.EvTable("{w#{n", "{wTopic{n", "{w%s{n" % self.key.capitalize(),
                             border="cells", width=78, align="l", justify=True)
     x = 0
     week = get_week()
     heard_rumors = caller.ndb.heard_rumors or []
     for rumor in rumors:
         x += 1
         player = rumor.db_receivers_players.all()
         if not player:
             continue
         player = player[0].key.capitalize()[:12]
         table.add_row(x, player, rumor.db_message)
         if add_heard and rumor not in heard_rumors:
             heard_rumors.append(rumor)
     table.reformat_column(0, width=5)
     table.reformat_column(1, width=12)
     table.reformat_column(2, width=61)
     if add_heard:
         caller.ndb.heard_rumors = heard_rumors
     msg = "{w%s{n" % self.key.capitalize().center(78)
     msg += "\n"
     msg += str(table)
     stories = AssignedTask.objects.filter(finished=True, week__gte=week-3, observer_text__isnull=False)
     if stories:
         msg += "\n"
         msg += "{wOther Rumors{n".center(78)
         msg += "\n"
         table = evtable.EvTable("{wRumored Story #{n", "{wWeek{n", border="cells", width=78)
         for story in stories:
             table.add_row(story.id, story.week)
         msg += str(table)
     return arx_more.msg(caller, msg, justify_kwargs=False)
Exemplo n.º 7
0
 def func(self):
     try:
         book = self.search(self.lhs)
         try:
             chapter = book.get_chapter(self.rhs)
         except AttributeError:
             raise ChapterNotFoundError(f"{book} is not a book.")
         if (chapter.written_work.language
                 and chapter.written_work.language.lower()
                 not in self.caller.languages.known_languages):
             raise ChapterNotFoundError(
                 "That chapter is written in a language you don't understand."
             )
         arx_more.msg(self.caller, chapter.get_chapter_text())
     except (ChapterNotFoundError, self.error_class) as err:
         self.msg(err)
Exemplo n.º 8
0
 def display_recipes(self, recipes):
     from server.utils import arx_more
     known_list = CraftingRecipe.objects.filter(
         known_by__player__player=self.caller.player)
     table = PrettyTable([
         "{wKnown{n", "{wName{n", "{wAbility{n", "{wDifficulty{n",
         "{wCost{n"
     ])
     from operator import attrgetter
     recipes = sorted(recipes,
                      key=attrgetter('ability', 'difficulty', 'name'))
     for recipe in recipes:
         known = "{wX{n" if recipe in known_list else ""
         table.add_row([
             known, recipe.name, recipe.ability, recipe.difficulty,
             recipe.additional_cost
         ])
     arx_more.msg(self.caller, str(table), justify_kwargs=False)
Exemplo n.º 9
0
 def send_msg(lines):
     msgs = "".join(line for line in lines)
     arx_more.msg(caller, msgs, justify_kwargs=False)
Exemplo n.º 10
0
    def func(self):
        """
        Handle the looking - add fallback to details.
        """
        caller = self.caller
        args = self.args
        looking_at_obj = None
        if args:
            alist = args.split("'s ")
            if len(alist) == 2:
                obj = caller.search(alist[0], use_nicks=True, quiet=True)
                if obj:
                    obj = utils.make_iter(obj)
                    looking_at_obj = caller.search(alist[1],
                                                   location=obj[0],
                                                   use_nicks=True,
                                                   quiet=True)
            else:
                looking_at_obj = caller.search(args,
                                               use_nicks=True,
                                               quiet=True)
            # originally called search with invalid arg of no_error or something instead of quiet
            if not looking_at_obj:
                # no object found. Check if there is a matching
                # detail at location.
                if self.check_detail():
                    return
                # no detail found. Trigger delayed error messages
                _AT_SEARCH_RESULT(looking_at_obj, caller, args, False)
                return
            else:
                # we need to extract the match manually.
                if len(utils.make_iter(looking_at_obj)) > 1:
                    _AT_SEARCH_RESULT(looking_at_obj, caller, args, False)
                    self.check_detail()
                    return
                looking_at_obj = utils.make_iter(looking_at_obj)[0]
        else:
            looking_at_obj = caller.location
            if not looking_at_obj:
                caller.msg("You have no location to look at!")
                return

        if not hasattr(looking_at_obj, "return_appearance"):
            # this is likely due to us having a player instead
            looking_at_obj = looking_at_obj.character
        if not looking_at_obj.access(caller, "view"):
            caller.msg("Could not find '%s'." % args)
            self.check_detail()
            return
        # get object's appearance
        desc = looking_at_obj.return_appearance(caller, detailed=False)
        # if it's a written object, we'll paginate the description
        if looking_at_obj.db.written:
            from server.utils import arx_more

            desc = desc.replace("%r", "\n")
            arx_more.msg(caller, desc, pages_by_char=True)
        else:
            caller.msg(desc)
        # the object's at_desc() method.
        looking_at_obj.at_desc(looker=caller)
        self.check_detail()