# taireHouse
from eventAPI import *
from APIUtils import *
from SDLKeys import *
import genericEmptyHouse

lFlagU = 0
TairePlt1 = 0

def fireEvent(e):
    global TairePlt1, lFlagU
    TairePlt1 = getTag(e, "TairePlt1")
    GuardPlt1 = getTag(e, "GuardPlt1")
    if (issetall(GuardPlt1, 0x4)):
        # 5 arrest attempts made, she'll be home
        TairePlt1 |= 1
    # make sure Taire is home...
    if (not issetall(TairePlt1, 0x1)):
        MallornPlt1 = getTag(e, "MallornPlt1")
        if (issetall(MallornPlt1, 0x2)):
            # Met Mallorn, so she's gotta be home... he told the party to come here
            TairePlt1 |= 1
        else:
            genericEmptyHouse.fireEvent(e)
            return 0
    lFlagU = getTag(e, "lFlagU")
    TaireState1 = getTag(e, "TaireState1")
    setTag(e, "PltF1", (getTag(e, "PltF1") & ~0x4) | 0x8)
    showPicture(e, "House")
    showMessage(e, ["The door opens by itself and a small breeze follows you in..."])
    if (firstHasItem(e,"Amulet of S'amoht") >= 0):
        returnAmulet(e)
    if (lFlagU == 0):
        # First meeting
        lFlagU = 1
        showPicture(e, "Taireninaugh")
        playSpecAudio(e, "Taire")
        showMessage(e,
            ["From around the corner comes the most bewitching grace of a Fae Maiden. Her entire countenance",
             "is like that of the colors of the sea. The fluid effortless movements of her body are enchanting to watch..."])
        if (optionInput(e,
            ["\"I saw that you would come. Welcome.",
             "",
             "\"I can help you with your problems for I have lived so long, through many stars of problems.",
             "",
             "\"This Naris is an imposter, and I can see that you already know that in your heart. I've been watching him closely for more than a few seasons now.",
             "",
             "\"I have also been keeping watch on the fellow southeast of here. Naris has visited him quite a few times. I think you should seek out some evidence there that might help bring credence to your claims of innocence.",
             "",
             "\"It won't be long before the Guards are the hunt for you. When they find you, more than your freedom will be lost. We the people, will lose our way of life, if all is not made right. The deception will be near complete for the dark cult to mix it's poison into all of our lives. Time now is not for wasting.",
             "",
             "\"That dark fellow Naris has been visiting, has been in keep close by. His house is southeast of here, but it is not poor old Aldorik's house. Leave him be and may the goddesses bless his soul. He knows not what company lurks just over his old shoulders.",
             "",
             "\"Whatever you find in that dark ones keep, take it with haste to the Guardians of the city. They will be apprehensive at first, but when they see the evidence, they will know what to do.",
             "",
             "\"I have many graces of to offer. My gratitude will flow free like the rivers should you complete this quest. Will you help me in this pursuit?\""],
            ["(Y)es. We will help", "(N)o. We're not burglars"],
            [SDLK_y, SDLK_n]) == SDLK_y):
            acceptDorukanQuest(e)
        else:
            declineDorukanQuest(e)
    else:
        if (TaireState1 == 0):
            cameBackForDorukanQuest(e)
        elif (TaireState1 == 1):
            # Working on Dorukan
            if (getTag(e, "DorPlt1") == 1):
                # already beat Dorukan down
                if (GuardPlt1 == 0):
                    # Haven't gone to get the Pardon yet
                    returnedWithDorukanEvidence(e)
                else:
                    # Got the Pardon already
                    returnedWithPardon(e)
            else:
                # They don't have it yet, nor have they visited Dorukan.  She will assume
                #   that they just haven't gotten the pardon yet.
                returnedWithPardon(e)
        elif (TaireState1 == 2):
            # Finished Dorukan, not started white antidote (but already offered)
            returnAfterRefusingWhiteAntidoteQuest(e)
        elif (TaireState1 == 3):
            # Check for white antidote quest completion (just go see Yeodaugh at his house
            #  with the antidote, a red vial, and the amulet or Erda)
            YeodPlt = getTag(e, "YeodPlt")
            if (issetall(YeodPlt, 0x4)):
                # Gave him the antidote... what to do?
                #finishedWhiteAntidoteQuest(e)
                genericEmptyHouse.fireEvent(e)
            else:
                returnBeforeFinishingWhiteAntidoteQuest(e)
        else: #if (TaireState1 == 4):
            # Gone for now, when we script up more plot stuff will start here
            genericEmptyHouse.fireEvent(e)

    setTag(e, "TairePlt1", TairePlt1)
    setTag(e, "lFlagU", lFlagU)
    return 0

#############################################################################
## Dorukan Quest
#############################################################################
def acceptDorukanQuest(e):
    global TairePlt1
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    optionInput(e,
        ["She smiles...",
         "",
         "\"As bright as stars may your goodness shine. I have had my other sources out researching this and they have provided me with a key to this ratty fellow's keep. Your entrance will be easy.",
         "",
         "\"Remember to take the vial and any evidence with a quickness to the guards. The best way to find them is to go to the Barracks at Palace Square.\""],
        ["(V)enture forth"], [SDLK_v])
    giveItems(e, ["Dorukan's Key"])
    TairePlt1 = 3
    setTag(e, "TaireState1", 1)

def declineDorukanQuest(e):
    global TairePlt1
    #if (not issetall(TairePlt1, 0x8)):
    #    return
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    optionInput(e,
        ["\"If that's as you wish it. Fare thee well.",
         "",
         "I was quite taken with you and was for certain that it was you who could help us. If you wish, you may visit 'Yeodaugh' at the Collegium of Magika.",
         "",
         "He can tell you more than I. Maybe he can persuade you to help us.\"",
         "",
         "She leaves a little sullen and lost of hope..."],
        ["(L)eave her in shame"], [SDLK_l])
    TairePlt1 = 5

def cameBackForDorukanQuest(e):
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    if (optionInput(e,
        ["\"You've changed your minds! Good Rivers flow for your sakes. This Naris is an impostor, as you already feel. I've been watching the fellow southeast of here. Naris has visited him quite a few times. I think you should seek out some evidence there that might help bring credence to your claims of innocence. Whatever you find, take it with haste to the Guardians of the city. They will know what to do.",
         "",
         "Is this something you would be interested in?"],
        ["(Y)es", "(N)o. That's trespassing..."], [SDLK_y, SDLK_n]) == SDLK_y):
        acceptDorukanQuest(e)
    else:
        declineDorukanQuest(e)

def returnedWithDorukanEvidence(e):
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    showMessage(e,
        ["\"You were quite foolish not to believe me when I said surrender your evidence to the guards!",
         "",
         "\"HOW COULD YOU!\"",
         "",
         "Something happens... a mist overcomes the party..."])
    i, c = 0, getPartyCount(e)
    while (i < c):
        modifyBP(e, i, -5, 1)
        modifyHP(e, i, -1)
        modifySP(e, i, -5, 1)
        i += 1
    if (optionInput(e,
        ["\"There...I feel much better now...\"",
         "",
         "You, however, do not feel better...",
         "",
         "\"There are dark times coming and you have taken the first step in helping us stop it's",
         "morose tide, though you need to heed my advice next time! ummm!... ",
         "",
         "\"This Devil Whiskey of soul reaving is nothing like what COULD come, should he who seeks to",
         "harness all the power of the nether worlds succeed. He has gone mad with a sickness more perverse than the most wretched blood spilling of war could ever hope to shadow and he's beyond all hope now.",
         "",
         "\"I may have had a hand in this, but I cannot surrender my sources. All I can ask is that you help me.. help US heal our conscience and stop this before it's too late. I've already lost a brother to this. If we don't avert it now, we'll lose all the Orkney Nation and the lands beyond.",
         "",
         "\"I have another quest if you would be so endeavored as to help us. It will help you get to the bottom of all of this.",
         "",
         "\"Will you help us?\""],
         ["(Y)es, our lady", "(N)o. We can't"], [SDLK_y, SDLK_n]) == SDLK_y):
        whiteAntidoteQuestStart(e)
    else:
        annoyedTaire(e)

def returnedWithPardon(e):
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    if (firstHasItem(e, "Guard Pardon") < 0):
        optionInput(e,
            ["\"Did you misplace the Guards' Pardon?  Return to me when I can see it with my own eyes!"],
            ["(L)eave in shame"],
            [SDLK_l])
    else:
        showMessage(e,
            ["\"I see you have made it back and you have done as I asked.",
             "",
             "Thank you!\"",
             "",
             "Her generous almond shaped eyes intensify your spirit...",
             "",
             "\"Here are the graces I promised to you.\""])
        giveGoldToFirstPC(e, 1600)
        giveItems(e, ["Elf Bow", "Cloak of Elvenkind"])
        showMessage(e,
            ["\"There are dark times coming and you have taken the first step in helping us stop it's morose tide. We can only do this if we work together.",
             "",
             "\"This Devil Whiskey of soul reaving is nothing like what COULD come. Should he who seeks to",
             "harness all the power of the nether worlds succeeds all life as we know it will cease to be.",
             "",
             "\"He has gone mad with a sickness more perverse than the most wretched blood spilling of war could ever hope to shadow and he's beyond all hope now. Young human children have been enslaved and robbed of their souls just so he could further his work with this soul reaving brew.",
             "",
             "\"These children were ripped from their homes in the darkness of night and dropped in underground labs to have ghastly experiments performed upon them by his twisted alchemists. You are just now seeing the effects of this here in your village, though many afar have already been fallen prey to their menace.",
             "",
             "\"I may have had a hand in this by virtue of blood kin, but I cannot surrender my sources. All I can ask is that you help me...",
             "",
             "\"Help us heal our conscience and stop this before it's too late. I've already lost a brother to this. If we don't avert it now, we'll lose all the Orkney Nation and the lands beyond.\""])
        if (optionInput(e,
            ["\"I have another quest if you would be so endeavored as to help us. It will help you get to the bottom of all of this.",
             "",
             "\"Will you help us?\""],
            ["(Y)es our lady.", "(N)o. We really can't."], [SDLK_y, SDLK_n]) == SDLK_y):
            whiteAntidoteQuestStart(e)
        else:
            annoyedTaire(e)

#############################################################################
## White Antidote Quest
#############################################################################
def whiteAntidoteQuestAskAgain(e):
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    if (optionInput(e,
        ["\"I have a quest if you would be so endeavored as to help us. It will help you get to the bottom of all of this.",
         "",
         "\"Will you help us?\""],
        ["(Y)es our lady.", "(N)o. We really can't."], [SDLK_y, SDLK_n]) == SDLK_y):
        whiteAntidoteQuestStart(e)
    else:
        annoyedTaire(e)

def whiteAntidoteQuestStart(e):
    global TairePlt1
    showMessage(e,
        ["\"Here is one vial of the White Antidote. You CANNOT use this precious antidote at any time or for any reason. You must deliver it to a Gnomish Sage named Yeodaugh. Do not tamper with it at all.",
         "",
         "\"Yeodaugh will be near the Arcanium in the north of town. Do this at all costs!\"",
         "",
         "She pauses, looking deeply into your eyes and then smiles...",
         "",
         "\"You have my faith. Hurry back when all is done.\"",
         "",
         "Through your eyes very yielding eyes, she entreats you for what seems a long restful daydream...",
         "",
         "As your party awakens, you ready yourself to leave and fulfill your quest."])
    giveItems(e, ["Amulet of Erda", "White Antidote"])
    TairePlt1 |= 0x20
    setTag(e, "YeodPlt", getTag(e, "YeodPlt") & 0x3) # he's no longer at Magic College
    setTag(e, "TaireState1", 3)

def returnAfterRefusingWhiteAntidoteQuest(e):
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    if (optionInput(e,
        ["\"I suppose that Yeodaugh has convinced you otherwise.  Shall we continue?\""],
        ["(Y)es", "(N)o. Sorry..."], [SDLK_y, SDLK_n]) == SDLK_y):
        whiteAntidoteQuestAskAgain(e)
    else:
        annoyedTaire(e)

def returnBeforeFinishingWhiteAntidoteQuest(e):
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    optionInput(e,
        ["\"I am certain that Yeodaugh grows impatient for the antidote.  Go to him!\""],
        ["(L)eave in shame"],
        [SDLK_l])

def finishedWhiteAntidoteQuest(e):
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    optionInput(e,
        ["She reaches in her robes and pulls out the most brilliant talisman you have ever seen. You feel suddenly at ease and at one with the realm around you. The jeweled center shines like a thousand stars.",
         "",
         "\"This is an Amulet of Erda for grounding. It precludes all Netherworld witchery and it will keep your souls locked in this realm.",
         "",
         "\"Though it is a useful gift I offer, it is with all my heart and gratitude, that I give this to you. This is for helping me. Thank you.\""],
        ["(V)enture forth"], [SDLK_v])
    setTag(TaireState1, 4)

#############################################################################

def annoyedTaire(e):
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    optionInput(e,
        ["\"You try my patience and I have a lot of it. Many years have I been on the troubled rivers and NEVER a group more disgraceful and fallow have I encountered.",
         "",
         "\"Why do you bother? Put away your pathetic costuming and trite posturing, for you are not ones who would be the saving of us all. Be gone!\""],
        ["(L)eave her in shame"], [SDLK_l])

#############################################################################
# Differing levels of Taire annoyance... use this later, not enough time to finish
#############################################################################
def runSection13(e):
    global TairePlt1
    #+eq lFlagU 0x00000014
    #!goto 7
    #+eq lFlagU 0x00000013
    #!goto 15
    if (not isclearall(TairePlt1, 0x8)):
        decidedToHelpTaire(e)
        return 0
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    if (optionInput(e,
        ["\"Clarity has not escaped you I assume. Do you have the vials?\""],
        ["(Y)es we do.", "(N)ot at all."], [SDLK_y, SDLK_n]) == SDLK_y):
        runSection8(e)
    else:
        runSection10(e)

def runSection14(e):
    global TairePlt1, lFlagU
    if (not isclearall(TairePlt1, 0x8)):
        decidedToHelpTaire(e)
    elif (not isclearall(TairePlt1, 0x14)):
        runSection16(e)
    elif (lFlagU != 0x12):
        runSection7(e)
    elif (lFlagU != 0x13):
        runSection16(e)
    #+issetall TairePlt1 0x00000004
    #+eq lFlagU 0x01a00000
    elif (not isclearall(TairePlt1, 0x2)):
        runSection13(e)
    #+eq lFlagU 0x00000002
    #!goto 12
    #+eq lFlagU 0x00000011
    else:
        showPicture(e, "Taireninaugh")
        showMessage(e, ["Taireninaugh is not here..."])

def runSection15(e):
    global TairePlt1
    if (not issetall(TairePlt1, 0x9)):
        return 0
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    if (optionInput(e,
        ["Her open lips turn into a thin stern line...",
         "",
         "\"If you wish to let evil pass into this good city, then that's your business. Time will see you judged for your deeds.\"",
         "",
         "She motions you to the door and leaves the room."],
        ["(W)AIT! We'll help.", "(SPACE) to leave"], [SDLK_w, SDLK_SPACE]) == SDLK_w):
        runSection17(e)
    else:
        TairePlt1 |= 0x14
        runSection7(e)

def runSection16(e):
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    if (optionInput(e,
        ["You hear Taireninaugh's silvery voice, but can't see her...",
         "",
         "\"Either you will help us or you will help us not. What is you final answer?\""],
        ["We'll (h)elp", "(W)e will NOT help you."], [SDLK_h, SDLK_w]) == SDLK_h):
        runSection17(e)
    else:
        runSection18(e)

def runSection17(e):
    global lFlagU
    showPicture(e, "House")
    showMessage(e,
        ["\"This has been quite difficult. Lessening your payment might be in order.",
         "",
         "\"If you fail us now, we will be forced to deal with you as if you were the enemy.\""])
    lFlagU = 0x20
    acceptTaireHelpRequest(e)

def runSection18(e):
    global lFlagU
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    optionInput(e,
        ["\"You ARE quite foolish!",
         "",
         "\"HOW COULD YOU IGNORE THE IMPORT OF WHAT WE ARE TRYING TO DO!",
         "",
         "\"You do not claim to be for the dark ones, but you stand in our way now.\"",
         "",
         "Everyone except Taireninaugh doubles over in intense pain...",
         "",
         "There was no sign or warning for her silent attack!"],
        ["(SPACE) to walk away"], [SDLK_SPACE])
    i, c = 0, getPartyCount(e)
    while (i < c):
        modifyHP(e, i, -10)
        i += 1
    lFlagU = 0x30
    runSection19(e)

def runSection19(e):
    global lFlagU
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    if (optionInput(e,
        ["\"How do you feel NOW?",
         "",
         "\"Do you stand with us or against us?\""],
        ["We'll (h)elp", "(W)e will NOT help you."], [SDLK_h, SDLK_w]) == SDLK_h):
        runSection17(e)
    else:
        lFlagU = 0x33

def runSection21(e):
    showPicture(e, "House")
    optionInput(e,
        ["She smiles at you and leaves the room pleased."],
        ["(V)enture forth"], [SDLK_v])

def returnAmulet(e):
    showPicture(e, "Taireninaugh")
    playSpecAudio(e, "Taire")
    showMessage(e,
        ["\"What is this? Surely it's not...\"",
         "A smile with a hint of sadness slowly crosses her face.",
         "\"Thanks be to you brave ones. May the gods smile upon you and may the hammer of truth be right with you.",
         "This amulet once belonged to someone special who is someone now lost.",
         "I must leave now and YOU must return to Yeodaugh. I may yet see you again."])
    holder = firstHasItem(e, "Amulet of S'amoht")
    removeItem(e,holder,"Amulet of S'amoht")
    setTag(e, "TaireState1", 5)
    return 0
