예제 #1
0
class Formatter:
    def __init__(self, character=None):
        self.character = character
        self.morgue_parser = MorgueParser(self.character.morgue_file())

    def print_command(self, name, value):
        fmt_str = f"{name}: {value}"
        print("\n\033[35m" + fmt_str + "\033[0m")
        return [fmt_str]

    def print_gods(self):
        gods = self.morgue_parser.gods()
        gods_remaining = 25 - len(gods)

        if len(gods) == 25:
            return ["Kreygasm YOU HAVE SEEN EVERY GOD! Kreygasm"]
        else:
            return [
                f"MercyWing1 Gods MercyWing2",
                ", ".join(sorted(gods)),
                f"You have {gods_remaining} to be found",
            ]

    def print_spells(self):
        morgue_parser = MorgueParser(self.character.morgue_file())
        raw_spells = morgue_parser.spells()
        spells = [spell for spell in raw_spells if (len(spell.split()) >= 5)]
        formatted_spells = []
        for spell in spells:
            spell_parts = spell.split()
            spell_parts.reverse()
            hunger, level, failure, power, spell_type, *spell = spell_parts
            formatted_spells.append(
                f"{' '.join(spell)} - {spell_type} - {power} - {failure}")

        return [
            "TakeNRG Listing All Spells TakeNRG",
            "Spell Type Power Failure",
        ] + formatted_spells

    def print_skills(self):
        skills = fetch_skills(self.character.morgue_file())

        formatted_skills = []
        for skill in skills:
            split_skills = skill.split()
            if len(split_skills) == 3:
                _, level, *skill = skill.split()
            else:
                _, _, level, *skill = skill.split()

            formatted_skills.append(f"Level {level} {' '.join(skill)}")

        return ["PowerUpL Listing All Skills PowerUpR"] + formatted_skills

    # ========================================================================================

    def print_version(self):
        return self.character.morgue_file().split("\n")[0]

    def print_mutations(self):
        title = [f"Squid1 Squid2 Listing All Mutations Squid4"]
        return title + [self.morgue_parser.mutations()]

    # ========================================================================================

    def find_unique_items(self, items, regex):
        if items is None:
            return None

        uniq_items = []
        for item in items:
            m = re.search(regex, item)
            if m:
                # This should check for the amout of groups to know whether it has amounts
                msg = m.group(1)
                uniq_items.append(m.group(1))

        return uniq_items

    def print_runes(self):
        return self.morgue_parser.runes()

    def print_weapons(self):
        weapons = self.morgue_parser.weapons()
        # weapons = self.find_unique_items(raw_weapons, "\w\s-\s(.*)")
        if weapons:
            return ["twitchRaid Listing All Weapons twitchRaid"] + weapons
        else:
            return ["No Weapons Found!"]

    def print_armour(self):
        armour = self.morgue_parser.armour()
        if armour:
            return ["BloodTrail Listing All Armour BloodTrail"] + armour
        else:
            return ["No Armour Found!"]

    def print_jewellery(self):
        jewellery = self.morgue_parser.jewellery()
        if jewellery:
            return ["CoolCat Listing All Jewellery CoolCat"] + jewellery
        else:
            return ["No Jewellery Found!"]

    def print_potions(self):
        potions = self.morgue_parser.potions()

        formatted_potions = []
        for potion in potions:
            m = re.search(f"\w\s-\s(\d+)\s(.*)", potion)
            if m:
                amount = m.group(1)
                potion_name = m.group(2)
                msg = f"{amount} {potion_name}"
                print(msg)

                formatted_potions.append(msg)

        return [f"DrinkPurple Listing All Potions DrinkPurple"
                ] + formatted_potions

    def print_scrolls(self):
        scrolls = self.morgue_parser.scrolls()

        formatted_scrolls = []
        for scroll in scrolls:
            m = re.search(f"\w\s-\s(\d+)\s(.*)", scroll)
            if m:
                amount = m.group(1)
                scroll_name = m.group(2)
                msg = f"{amount} {scroll_name}"
                print(msg)
                formatted_scrolls.append(msg)

        return ["copyThis Listing All Scrolls copyThis"] + formatted_scrolls

    # ========================================================================================

    def print_max_damage(self):
        weapons = self.morgue_parser.weapons()
        return WeaponsFormatter(character=self.character,
                                weapons=weapons).format_max_damages()
def test_fetch_armour():
    character_name = "kaostheory"
    morgue_parser = MorgueParser(open(f"support/{character_name}.txt").read())
    expected_armour = [" g - a +0 pair of boots (worn)", " h - a +0 ring mail (worn)"]
    armour = morgue_parser.armour()
    assert armour == expected_armour