# 006_yeod_quest.evc 019***** 
# ITEMS needed:
# Amulet_of_Erda (immune to necro powers and devil whiskey)
# White Antidote (dispels effect of DW)
#
# THIS EVENT IS FOR HOUSE AT (25,32) in Rennibister
#Only active if never active before.
#+eq lFlagU 0x00000000
#If not active, do the empty house event.
#Yeodaugh's riddle
from eventAPI import *
from SDLKeys import *
from APIUtils import *
import genericEmptyHouse

lFlagU = 0
YeodPlt = 0

def fireEvent(e):
    global YeodPlt, lFlagU
    TairePlt = getTag(e, "TaireState1")
    YeodPlt = getTag(e, "YeodPlt")
    OliasPlt1 = getTag(e, "OliasPlt1")
    AlnurtiPlt = getTag(e, "AlnurtiPlt1")
    if ((not issetall(YeodPlt,0x04)) and
        ((firstHasItem(e, "Amulet of Erda") < 0) or
         (firstHasItem(e, "White Antidote") < 0))):
        genericEmptyHouse.fireEvent(e)
        return 0
    lFlagU = getTag(e, "lFlagU")
    if (TairePlt == 5):
        playSpecAudio(e, "Yeod")
        if(OliasPlt1 == 1):
            showPicture(e, "Yeodaugh")
            getBackToOlias(e)
        elif(OliasPlt1 == 6):
            showPicture(e, "Yeodaugh")
            if(AlnurtiPlt == 1):
                showPicture(e, "Yeodaugh")
                getToAlnurti(e)
            elif(AlnurtiPlt != 0):
                genericEmptyHouse.fireEvent(e)
                return 0
            else:
                showPicture(e, "Yeodaugh")
                sendToAlnurti(e)
        elif(OliasPlt1 != 0):    #anything other than no olias plot flag set
            genericEmptyHouse.fireEvent(e)
            return 0
        else:                    #Taire done, Olias not started
            showPicture(e, "Yeodaugh")
            sendToOlias(e)
        return 0
    if (firstHasItem(e,"Skeleton Key") >= 0):
        showPicture(e, "Yeodaugh")
        playSpecAudio(e, "Yeod")
        if(firstHasItem(e,"Amulet of S'amoht") >= 0):
            sendToTaire(e)
            return 0
        elif(issetany(YeodPlt, 0x08)):
            getToCataAlready(e)
            return 0
        else:
            sendToCata(e)
            return 0
    if (issetall(YeodPlt, 0x4)):
        # already gave him the vial
        if(lFlagU == 1 ):
            cellarNotDone(e)
        else:
            requestCellarQuest(e)
        setTag(e, "YeodPlt", YeodPlt)
        setTag(e, "lFlagU", lFlagU)
        return 0
    showPicture(e, "House")
    showMessage(e,
        ["You hear a high guttural old voice, but you don't see anyone..."])
    answer = stringInput(e,
        ["\"Here is a code phrase. Unscramble it and write it back down for me. If you are here to help, then you will know this.\"",
         "",
         "\"we lived his ky\""])
    if (answer.lower() == "devil whiskey"):
        meetYeodaugh(e)
    else:
        wrongAnswer(e)
    setTag(e, "YeodPlt", YeodPlt)
    setTag(e, "lFlagU", lFlagU)
    return 0

def wrongAnswer(e):
    showMessage(e, ["help you I cannot"])

def meetYeodaugh(e):
    global YeodPlt
    showPicture(e, "Yeodaugh")
    playSpecAudio(e, "Yeod")
    showMessage(e,
        ["\"Yes... you are the ones. Come here and let me have a closer look at those items... \"",
         "",
         "Some force beyond your control takes hold and you feel your feet sliding along the pebble and earth beneath you. This force pulls you nearer to the small old and bent gnome..."
         "",
         "\"You think me a crooked old gem collector do you not?... I am more than my size lets on, mind you. Psi Lord am I, and long in this land have I been. One of the oldest Psi Lords practicing the ancient art.",
         "",
         "\"Now... for those items... \"",
         ""
         "The Amulet and the antidote escape your pouches on their own and glide over to the Gnomes old and leathered hands."])
    holder = firstHasItem(e, "White Antidote")
    removeItem(e, holder, "White Antidote")
    holder = firstHasItem(e, "Amulet of Erda")
    removeItem(e, holder, "Amulet of Erda")
    YeodPlt = 0x4
    requestCellarQuest(e)

def requestCellarQuest(e):
    showPicture(e, "Yeodaugh")
    playSpecAudio(e, "Yeod")
    showMessage(e,
        ["\"This witchery with the Devil Whiskey is not the doing of Rennibister's Guards. Believe or what you will, but their work it's not. This evil is the work of a power mad band of Mage Chiefs called the 'ExorArcanists'.",
         "",
         "\"Their minds have been perverted by a foul malignant Warlock who has taken up residence in Rennibister to leech from our town. They are slowly pushing out the Arcanium and the small independant mage guilds to grow their mother collective.",
         "",
         "\"They only wanted to increase commerce through the control of all science and learning, but now their greed has grown and it has led them to greater evils who now control them. They would have themselves to be one large collective of Arcanists to rule us all, but corruption has made them slaves to a greater power, which they can neither control or explain. The corruption that now controls them, was cultivated by a group whom the evil Warlock in the cellars represents.",
         "",
         "\"Death deals this Warlock... Where he roams, no soul shall rest. Hidden are the foul spirits of the ExorArcanists. In the cellars underneath \"Melkorragn's Tavern\" they are. It's an older tavern Northeast of here. Teleport you there directly I shall, should you accept this quest.",
         "",
         "\"Once there, infiltrate it's evil brew stores and use this special arcanist staff I now give you to nullify the evil brew. I call this staff, made from my hands, the \"Banestaff\" and now it will be in your hands. Use it wisely. When called upon, it destroys the Devil brew's prime ingredient with a flare of radiant ethereal light. The brew then becomes a normal malted Whiskey again.",
         "",
         "\"You'll need to take this scarf so the barkeep will recognize you. Bring back a \"cured\" bottle and some proof of the Warlock's death. Once this is done, the Guards will once more open the gates of Rennibister to all of the world.\""])
    #
    # proof will be a lock of warlock hair to 
    # be put in the items list or maybe
    # some other item... something magical
    #
    if (optionInput(e,
        ["\"Do you accept this undertaking?\""],
        ["(Y)es, we will.",
         "(N)o, we will not."],
        [SDLK_y, SDLK_n]) == SDLK_y):
        acceptQuest(e)
    else:
        declineQuest(e)

def acceptQuest(e):
    global lFlagU
    optionInput(e,
        ["\"Splendid. Like diamonds you are, though polishing would do you some good.",
         "",
         "\"Take this scarf and the Banestaff and be off. Do not return until you have dispelled the darkness underneath. Bring back some proof that you have destroyed all stores of this Devil's Whiskey that exist.\""],
        ["(L)eave and quest"], [SDLK_l])
    giveItems(e, ["Banestaff", "Melkoran's Scarf"])
    lFlagU = 1
    setExit(e, "maps/renibister.cfg", 10, 33, 0)

def declineQuest(e):
    if (optionInput(e,
                    ["\"Then come back when you are ready.\""],
                    ["(A)re you mad?",
                     "(O)f course."],
                    [SDLK_a, SDLK_o]) == SDLK_a):
        talkinSmack(e)
    else:
        notReadyYet(e)

def talkinSmack(e):
    global lFlagU
    showPicture(e, "House")
    optionInput(e,
        ["\"Let this be a reminder to be more polite next time... \"",
         "",
         "Your knees buckle from the zap you receive..."],
        ["(L)eave the house"], [SDLK_l])
    x, c = 0, getPartyCount(e)
    while (x < c):
        modifyHP(e, x, -dice(2, 6, 3))
        x += 1
    lFlagU = 0x10

def notReadyYet(e):
    global lFlagU
    optionInput(e,
        ["\"Manners have you and that's a good start. Very well my tall friends. I'll attend my gems here and wait for your return.\"",
         "",
         "...the small bent gnome silently disappears out of site..."],
        ["(L)eave the house"], [SDLK_l])
    lFlagU = 0x11

def cellarNotDone(e):
    showPicture(e, "Yeodaugh")
    playSpecAudio(e, "Yeod")
    optionInput(e,
        ["Find the store of Devil Whiskey in the cellars you must! Imminent danger we are all in."], 
        ["(L)eave the house"], [SDLK_l])

def runSection11(e):
    global lFlagU
    if (not issetany(lFlagU, 0x11)):
        runSection12(e)
        return 0
    showPicture(e, "House")
    optionInput(e,
        ["You hear a voice...",
         "",
         "\"Seek you a great sage?\""],
        ["(L)eave the house"], [SDLK_l])

def runSection12(e):
    showPicture(e, "House")
    optionInput(e,
        ["\"Hello... come a little closer...\""
         "",
         "You walk over to the little Gnome.",
         "",
         "\"Whew....",
         "",
         "\"Your breath so bad, I know not whether to give you arse cloth or breath gum of chewing. STINK you do beyond all the realms compare!\"",
         "",
         "He has nothing more to say now. No cellars can you access."],
        ["(L)eave the house"], [SDLK_l])

def sendToCata(e):
    global YeodPlt
    showMessage(e,
        ["Good, good! Now you're half way through and I see you've found the Key to the Catacombs! ",
         "I need of you to go to the Catacombs to find an old family amulet which may have been taken ",
         "from the burial room of the last Akanubis sorcerers.",
         "",
         "When you find it, take the amulet to Tairenaugh.",
         "Belonged it once to her brother, who is all but lost now.  Please make haste then return to ",
         "me when you have done this. There are a few other rarities down in that dark hole that will ",
         "make it well worth your while."])
    YeodPlt |= 0x08
    setTag(e,"YeodPlt", YeodPlt)

def getToCataAlready(e):
    showMessage(e,
        ["Get you to the catacombs straight away! Understand how important this is you may not, but ",
         "continue on you must!"])

def sendToTaire(e):
    showMessage(e,
        ["Excellent- found the amulet you have, but told you to take it to Tairenaugh I did. ",
         "Please hurry to her home friends, and present her this amulet you must"])

def sendToOlias(e):
    showMessage(e,
        ["\"Thank you Sons of the Sun.  No idea, have you of how much that amulet meant to Taireninaugh,",
         " NOR of the import of what you now must do! No more magic gifts have I, but haste you must make to a tavern known as The Green Bard.  In the west side of Rennibister it lies.",
	 "For waiting there is a Spell Singer of much renown named Olias. Teach you he will, a song you may find you need."])
    setTag(e,"OliasPlt1",1)

def getBackToOlias(e):
    showMessage(e,
        ["\"Go to the Green Bard and learn ye the song Olias will teach you. Lead you it will, to dark despairs of the lost and those not meant to be there.",  
         "Afraid. yes afraid. Not now, but you will be...you will be...",
         "I can say no more, for much is at stake.  Only do as I ask and not stop to question why.\""])

def sendToAlnurti(e):
    showMessage(e,
        ["Pleased I am that you have returned. Yes... a job well done.  A fine triumph we have today, Rennibister is safe for now, but all is not over.  Prevail we will. Worry not.",
         "Someone looking for you there is.  Someone who seems to know Taireninaugh, though spoken to her about him I have not. ",
         "An important seer from lands beyond here he seems, and more knowledge of what is happening here he claims to have.  ",
         "Souls have been stolen and harvested, apparently for some evil forge of power. Helping protect the town's Palace right now he is. "]) 
    setTag(e, "AlnurtiPlt1", 1)
    getToAlnurti(e)

def getToAlnurti(e):
    showMessage(e,
       ["Think it may be wise to see what counsel the seer has to offer us I do. Some useful knowledge he may have.",
        "Go to the Palace you will, and seek out his knowledge."])
