Beispiel #1
0
 def test_dedent(self):
     # Empty string, return empty string
     self.assertEqual("", utils.dedent(""))
     # No leading whitespace
     self.assertEqual("TestDedent", utils.dedent("TestDedent"))
     # Leading whitespace, single line
     self.assertEqual("TestDedent", utils.dedent("   TestDedent"))
     # Leading whitespace, multi line
     input_string = "  hello\n  world"
     expected_string = "hello\nworld"
     self.assertEqual(expected_string, utils.dedent(input_string))
Beispiel #2
0
    def format_help_entry(title, help_text, aliases=None, suggested=None):
        """
        This visually formats the help entry.
        This method can be overriden to customize the way a help
        entry is displayed.

        Args:
            title (str): the title of the help entry.
            help_text (str): the text of the help entry.
            aliases (list of str or None): the list of aliases.
            suggested (list of str or None): suggested reading.

        Returns the formatted string, ready to be sent.

        """
        string = _SEP + "\n"
        if title:
            string += "|CHelp for |w%s|n" % title
        if aliases:
            string += " |C(aliases: %s|C)|n" % ("|C,|n ".join(
                "|w%s|n" % ali for ali in aliases))
        if help_text:
            string += "\n%s" % dedent(help_text.rstrip())
        if suggested:
            string += "\n\n|CSuggested:|n "
            string += "%s" % fill("|C,|n ".join("|w%s|n" % sug
                                                for sug in suggested))
        string.strip()
        string += "\n" + _SEP
        return string
Beispiel #3
0
def format_help_entry(title,
                      help_text,
                      aliases=None,
                      suggested=None,
                      unavailable=False,
                      related_tags=None):
    """
    This visually formats the help entry.
    """
    string = SEP + "\n"
    if title:
        string += "{CHelp topic for {w%s{n" % title
    if aliases:
        string += " {C(aliases: {w%s{n{C){n" % (", ".join(aliases))
    if unavailable:
        string += "\n{rThis command is not presently available to you.{n"
    if help_text:
        string += "\n%s" % dedent(help_text.rstrip())
    if related_tags:
        entries = (HelpEntry.objects.exclude(db_key=title).filter(
            db_tags__db_key__in=related_tags).distinct().values_list(
                'db_key', flat=True))
        string += "\n\n{CRelated help entries: {w%s" % ", ".join(entries)
    if suggested:
        string += "\n\n{CSuggested:{n "
        string += "{w%s{n" % fill(", ".join(suggested))
    string.strip()
    string += "\n" + SEP
    return string
Beispiel #4
0
    def format_help_entry(title, help_text, aliases=None, suggested=None):
        """
        This visually formats the help entry.
        This method can be overriden to customize the way a help
        entry is displayed.

        Args:
            title (str): the title of the help entry.
            help_text (str): the text of the help entry.
            aliases (list of str or None): the list of aliases.
            suggested (list of str or None): suggested reading.

        Returns the formatted string, ready to be sent.

        """
        string = _SEP + "\n"
        if title:
            string += "|CHelp for |w%s|n" % title
        if aliases:
            string += " |C(aliases: %s|C)|n" % ("|C,|n ".join("|w%s|n" % ali for ali in aliases))
        if help_text:
            string += "\n%s" % dedent(help_text.rstrip())
        if suggested:
            string += "\n\n|CSuggested:|n "
            string += "%s" % fill("|C,|n ".join("|w%s|n" % sug for sug in suggested))
        string.strip()
        string += "\n" + _SEP
        return string
Beispiel #5
0
def format_help_entry(title, help_text, aliases=None, suggested=None):
    """
    This visually formats the help entry.
    """
    string = _SEP + "\n"
    if title:
        string += "{CHelp for {w%s{n" % title
    if aliases:
        string += " {C(aliases: %s{C){n" % ("{C,{n ".join("{w%s{n" % ali for ali in aliases))
    if help_text:
        string += "\n%s" % dedent(help_text.rstrip())
    if suggested:
        string += "\n\n{CSuggested:{n "
        string += "%s" % fill("{C,{n ".join("{w%s{n" % sug for sug in suggested))
    string.strip()
    string += "\n" + _SEP
    return string
Beispiel #6
0
def format_help_entry(title, help_text, aliases=None, suggested=None):
    """
    This visually formats the help entry.
    """
    string = _SEP + "\n"
    if title:
        string += "{CHelp for {w%s{n" % title
    if aliases:
        string += " {C(aliases: %s{C){n" % ("{C,{n ".join("{w%s{n" % ali for ali in aliases))
    if help_text:
        string += "\n%s" % dedent(help_text.rstrip())
    if suggested:
        string += "\n\n{CSuggested:{n "
        string += "%s" % fill("{C,{n ".join("{w%s{n" % sug for sug in suggested))
    string.strip()
    string += "\n" + _SEP
    return string
Beispiel #7
0
def format_help_entry(title,
                      help_text,
                      aliases=None,
                      suggested=None,
                      unavailable=False):
    """
    This visually formats the help entry.
    """
    string = SEP + "\n"
    if title:
        string += "{CHelp topic for {w%s{n" % title
    if aliases:
        string += " {C(aliases: {w%s{n{C){n" % (", ".join(aliases))
    if unavailable:
        string += "\n{rThis command is not presently available to you.{n"
    if help_text:
        string += "\n%s" % dedent(help_text.rstrip())
    if suggested:
        string += "\n\n{CSuggested:{n "
        string += "{w%s{n" % fill(", ".join(suggested))
    string.strip()
    string += "\n" + SEP
    return string
Beispiel #8
0
 def next_character_turn(self):
     """
     It is now a character's turn in the iniative list. They will
     be prompted to take an action. If there is no more characters,
     end the turn when this is called and start over at Phase 1.
     """
     if self.ndb.shutting_down:
         return
     if self.ndb.phase != 2:
         return
     self.ndb.initiative_list = [
         ob for ob in self.ndb.initiative_list
         if ob.can_act and ob.remaining_attacks > 0
     ]
     if not self.ndb.initiative_list:
         self.start_phase_1()
         self.display_phase_status_to_all()
         return
     character_state = self.ndb.initiative_list.pop(0)
     acting_char = character_state.character
     self.ndb.active_character = acting_char
     # check if they went LD, teleported, or something
     if acting_char.location != self.ndb.combat_location:
         self.msg("%s is no longer here. Removing them from combat." %
                  acting_char.name)
         self.remove_combatant(acting_char)
         return self.next_character_turn()
     # For when we put in subdue/hostage code
     elif not character_state.can_act:
         acting_char.msg(
             "It would be your turn, but you cannot act. Passing your turn."
         )
         self.msg("%s cannot act." % acting_char.name,
                  exclude=[acting_char])
         return self.next_character_turn()
     # turns lost from botches or other effects
     elif character_state.lost_turn_counter > 0:
         character_state.remaining_attacks -= 1
         character_state.lost_turn_counter -= 1
         if character_state.remaining_attacks == 0:
             acting_char.msg(
                 "It would be your turn, but you are recovering from a botch. Passing."
             )
             self.msg(
                 "%s is recovering from a botch and loses their turn." %
                 acting_char.name,
                 exclude=[acting_char],
             )
             return self.next_character_turn()
     self.msg("{wIt is now{n {c%s's{n {wturn.{n" % acting_char.name,
              exclude=[acting_char])
     if self.managed_mode:
         return self.send_managed_mode_prompt()
     result = character_state.do_turn_actions()
     if not result and self.ndb.phase == 2:
         mssg = dedent("""
         It is now {wyour turn{n to act in combat. Please give a little time to make
         sure other players have finished their poses or emits before you select
         an action. For your character's action, you may either pass your turn
         with the {wpass{n command, or execute a command like {wattack{n. Once you
         have executed your command, control will pass to the next character, but
         please describe the results of your action with appropriate poses.
         """)
         acting_char.msg(mssg)