#script for melkoran's tavern
from eventAPI import *
from APIUtils import *

lFlag = 0

def fireEvent(e):
    global lFlag
    lFlag = getTag(e, "MelkoranPlt1")
    if ((not (lFlag & 0x01)) and (firstHasItem(e,"Melkoran's Scarf")<0)):
        callEvent(e, 1006, ["10", "33", "180"])
        return 0;
    elif(lFlag & 0x01):
        melkoranGreetReturning(e)
        setTag(e, "MelkoranPlt1", lFlag)
        return 0
    else:
        showPicture(e, "Tavern")
        playSpecAudio(e, "Tavern")
        showMessage(e,
            ["As you walk into the tavern, the grisled old inkeeper notices you...",
             "\"Mighty nice scarf you have there, quite the fashion\"",
            "He winks at you as you hand it to him",
            "\"I may have something you'd be interested in, but I want to know how well you know your surroundings first. It's important to be observant, you know...\""])
        holder = firstHasItem(e, "Melkoran's Scarf")
        removeItem(e, holder, "Melkoran's Scarf")
        lFlag |= 0x01
        melkoranAskRiddle(e)
        setTag(e, "MelkoranPlt1", lFlag)
        return 0

def melkoranGreetReturning(e):
    showMessage(e, ["\"Back are ya? Think you may know the answer now?\""])
    melkoranAskRiddle(e)

def melkoranAskRiddle(e):
    global lFlag
    answer = stringInput(e, ["\"It's the color of my first love's hair, with a temper as fiery to boot...\"", "\"What could it be?\""])
    if (answer.lower() == "whiskey"):
        showMessage(e,
                    ["\"You know your drinks!  I'm glad to hear it.  Here's the key to the cellars accross the street - I'm told you'll find what you're looking for there.  Be well, and join us again for a drink anytime!\"",
                     "",
                     "The old bartender hands you a key, and saunters off to drink with his other customers."]);
        giveItems(e, ["Cellar Key"])
        lFlag |= 0x02
        lFlag &= ~0x01
    else:
        showMessage(e, ["\"You'd best study up if you're to get ahead!\""])
