import random
import os

# Variables
ayitKey = False
ayitGift = False
ayitBook = False
effieKey = False
effieDagger = False


def playerAction():
    return input("What do you do: ").lower()

def closeRoom():
    ent = "No"
    while len(ent) > 0:
        ent = input("Press enter to continue.")
    print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
    print("Ayit and The Bloodmoon Dagger")
    print("-----------------------------")

def randomPatrons():
    patronStrings = [
        "A spider-person chitters a laugh at their friends.",
        "The tall person with the dark hair grins, and their fangs are revealed. They sip their wine.",
        "A demon yells a dare, and several others in the crowd approach to take them up on it.",
        "The group is giggling.",
        "Someone calls out, \"The next round is on me\" and cheers abound."
    ]
    patronStringNo = random.randint(0,len(patronStrings)-1)
    return patronStrings[patronStringNo]

# Rooms
def street():
    closeRoom()
    global ayitKey
    global ayitBook
    global ayitGift

    # Room Content
    print("The street is crowded, as usual. Several humans, but mostly other kinds of people - a few vampires, animal folk, faeries and more merfolk than you would expect from a town nestled in a cold mountain, far inland.")
    print("To the south is the local inn, several patrons are lounging in the doorway with drinks in their hands. " + randomPatrons())
    print("To the north is a chaotic collection of homes, stacked atop one another in a disorganised manner, smoke curling from chimneys.")
    if not(ayitGift):
        print("A pink-haired faerie looks stressed.")


    # Player Actions
    action = playerAction()
    
    if "north" in action or "home" in action or "house" in action:
        flats()
    elif "south" in action or "inn" in action:
        inn()

    # Insert other room actions here
    elif ("fae" in action or "ayit" in action) and (not(ayitGift)):
        if not(ayitKey):
            print("\"Oh, hello!\" Ayit says.")
            print("\"Could you get my book from my home up there?\" They point towards the houses.")
            print("They give you their key.")
            print("\"I'm going to sit and read in the inn.\"")
            ayitKey = True
        elif not(ayitBook):
            print("\"Do you have my book yet?\" Ayit asks.")
        elif not(ayitGift):
            print("Ayit looks relieved. \"You found it. Thank you so much.\" They say.")
            print("\"Here.\" They hand you a small apple-custard pastry in thanks.")
            ayitGift = True
        else:
            print("Ayit isn't in the street anymore.")

    else:
        print("You can't do that.")
    street()

def flats():
    closeRoom()
    global effieKey
    global ayitKey

    # Room Content
    print("There are two homes on the ground here. One to the east, one to the west.")
    if ayitKey:
        print("Ayit pointed in this direction.")
    print("There is also a vase.")
    if not(effieKey):
        print("You already found the key it was hiding.")
    print("The street south of you is muffled, thankfully, by the way the homes surround you.")

    # Player Actions
    action = playerAction()
    
    if "east" in action:
        if effieKey:
            flatEffie()
        else:            
            print("No keys you have work in this lock.")
    elif "south" in action or "street" in action or "back" in action:
        street()
    elif "west" in action:
        if ayitKey:
            flatAyit()
        else:
            print("No keys you have work in this lock.")

    # Insert other room actions here
    elif "vase" in action and not(effieKey):
        print("You examine the vase.")
        print("There's a key underneath.")
        effieKey = True
    else:
        print("You can't do that.")
    flats()

def flatAyit():
    closeRoom()
    global ayitBook

    # Room Content
    print("This is Ayit's home.")

    # Player Actions
    action = playerAction()
    
    if "east" in action or "leave" in action or "exit" in action:
        flats()
    # Insert other room actions here
    if "book" in action:
        ayitBook = True
        print("You got the book, eventually. Ayit sure has a lot of books, so it was a little difficult finding the right title.")

    else:
        print("You can't do that.")
    flatAyit()

def flatEffie():
    closeRoom()
    global effieDagger
    # Room Content
    print("The blue-haired birdfolk yells in outrage.")
    print("You did just break into their home.")
    print("You should leave.")
    if not(effieDagger):
        print("Although, that is a pretty dagger...")


    # Player Actions
    action = playerAction()
    if "west" in action or "leave" in action or "exit" in action:
        flats()
    # Insert other room actions here
    elif "dagger" in action and not(effieDagger):
        print("You swipe the dagger. It sure is shiny and there is a red gemstone inlaid in the handle.")
        print("You stash it away safely in your bag.")
        effieDagger = True
    else:
        print("You can't do that.")
    flatEffie()

def inn():
    closeRoom()
    # Room Content
    print("This is the inn.")
    print(randomPatrons())
    if ayitGift:
        print("Ayit is sat in a corner reading. There's a steaming coffee on their table. Every once in a while they pause to highlight some text, take a sip of their drink or push their long hair from their face. You wonder how they can concentrate.")
    print("You can't even hear the street outside.")
    # Player Actions
    action = playerAction()
    
    if "north" in action or "leave" in action or "exit" in action or "out" in action:
        street()
    # Insert other room actions here

    else:
        print("You can't do that.")
    inn()


# Run Program
print("Ayit and The Bloodmoon Dagger")
print("-----------------------------")
street()

