#!/usr/pkg/bin/python3
"""
Usage: fairygen.py

Generates and prints a random Costume Fairy Adventures character. Uses only
the basics - no custom Kinds, no alternate powers. It does, however, shuffle
the standard facet array rather than use the dice method in the book.

Feel free to ignore any parts and pick your own values per the usual
rules. It's *your* fairy after all!
"""

import random

POWERS = {"Fairy": ["Superior Flight"],
          "Pixie": ["Flight", "Resiliant"],
          "Sprite": ["Flight", "Charmed Life"],
          "Brownie": ["Flight", "Instant Wardrobe"],
          "Goblin": ["Agility", "Keen Senses"],
          "Elf": ["Twinkle Toes", "Protagonist Syndrome"]}
KINDS = list(POWERS.keys())
QUIRKS = {"Moxie": (["Compelling", "Competitive", "Daredevil",
                     "Heroic", "Loudmouth", "Show-off"],
                    ["Cowardly", "Delicate", "Humble",
                     "Inconspicuous", "Lazy", "Subtle"]),
          "Focus": (["Cool", "Neat Freak", "Nosy",
                     "Paranoid", "Sneaky", "Stubborn"],
                    ["Dabbler", "Forgetful", "Gluttonous",
                     "Impatient", "Kleptomaniac", "Wired"]),
          "Craft": (["Curious", "Experienced", "Know-it-all",
                     "Meticulous", "Schemer", "Snarky"],
                    ["Honest", "Impulsive", "Oblivious",
                     "Pragmatic", "Straightforward", "Trustworthy"]),
          "Grace": (["Arrogant", "Dignified", "Dynamic",
                     "Magnanimous", "Melodramatic", "Sophisticated"],
                    ["Bull-headed", "Clumsy", "Insecure",
                     "Petty", "Rebellious", "Vulgar"]),
          "Shine": (["Dashing", "Destined", "Joker",
                     "Magnetic", "Optimistic", "Romantic"],
                    ["Clichéd", "Creepy", "Cursed",
                     "Gloomy", "Jinxed", "Stern"])}
FACETS = list(QUIRKS.keys())

def randomquirk(facet, hl):
    """Picks a random fairy quirk.
    
    facet is a string from FACETS.
    hl is a string, either 'high' for a high quirk or 'low' for a low
        quirk. (If it's something else, we assume low.)
    """
    if hl == "high":
        return random.choice(QUIRKS[facet][0])
    return random.choice(QUIRKS[facet][1])

class Fairy:
    """Represent a Costume Fairy Adventures character."""

    def highestfacet(self):
        sv = 0
        sf = ""
        for f, v in self.facets.items():
            if v > sv:
                sv = v
                sf = f
        return sf

    def lowestfacet(self):
        sv = float("inf")  # No more maxint, but 'infinity' will do.
        sf = ""
        for f, v in self.facets.items():
            if v < sv:
                sv = v
                sf = f
        return sf


class RandomFairy(Fairy):
    """Creates a random Fairy."""

    def __init__(self):
        self.kind = random.choice(KINDS)
        self.powers = POWERS[self.kind].copy()
        self.facets = {f: v for f, v in
                        zip(FACETS, random.sample([4, 3, 2, 2, 1], 5))}
        self.quirks = []
        self.quirks.append(randomquirk(self.highestfacet(), "high"))
        self.quirks.append(randomquirk(self.lowestfacet(), "low"))
        if "Resiliant" in self.powers:
            self.stresslimit = 15
        else:
            self.stresslimit = 10


def main():
    fairy = RandomFairy()
    print("Kind: " + fairy.kind)
    for f,v in fairy.facets.items():
        print(f + ": " + str(v))
    print("Stress Limit: " + str(fairy.stresslimit))
    for q in fairy.quirks:
        print("Quirk: " + q)
    for p in fairy.powers:
        print("Power: " + p)

if __name__ == "__main__":
    main()