#Olias plot events
from eventAPI import getTag, setTag, playSpecAudio, showPicture, optionInput, giveItems, callEvent, removeItem
from APIUtils import showMessage, poseYesNo, firstHasItem

OliasPlt1 = 0

def fireEvent(e):
    showPicture(e, "Tavern")
    if(firstHasItem(e, "Elonian Pipes") >= 0):
        showPicture(e, "Olias")
        meetYouAtGTower(e)
    OliasPlt = getTag(e, "OliasPlt1")
    if(OliasPlt >= 3):
        leave(e)
        return 0
    if(OliasPlt == 0):
        leave(e)
        return 0
    if(OliasPlt == 2):
        showMessage(e,
            ["As you enter the green bard, a familiar face rises up to greet you"])
    else:
        showMessage(e,
            ["Upon Entering, you being to search for the bard that Yeodaugh described.",
             "You notice a tall, fair-skinned person in the corner that seems to match the description."])
    showPicture(e, "Olias")
    if (OliasPlt == 1):
        meetOlias(e)
    elif (OliasPlt == 2):
        getToDwarves(e)
    leave(e)
    return 0

def meetOlias(e):
    if(poseYesNo(e,
	["I know something that you don't, but something you must know. Am I right?"])):
        oliasIntro(e)
    else:
        dontKnowYou(e)

def dontKnowYou(e):
    showMessage(e, ["My mistake."])
    return 1


def oliasIntro(e):
    showMessage(e,
       ["\"You must be the ones Yeodaugh told me would come to visit shortly. I support your efforts to free this town, and am prepared to help you.",
        "The ExorArcanists are entrenched in the old guard tower here in Rennibister, and while no magics practiced here can open their enchantment, I can get you in.",
        "There is a mystical song I know of that can penetrate the defenses surrounding the tower, and gain you entrance, but there are a few problems to sort out.",
        "The magic of the song is only as powerful as the instrument that performs it, and this is a strong magic indeed."])
    showMessage(e,
       ["There is a bit of story I'd entertain you with first, if you'll listen:",
        "Outside of town there is an old cave that used to be an ancient Dwarven temple.",
        "The dwarves there were enslaved to serve the Mad Warlocks during the Dorendor Occupation of Rennibister. They made this small temple as well as a",
        "network of caves so that they could find respite and insight from their Gods.",
        "This is when all of the Stone Clerics were hunted and destroyed. Those that turned themselves in to save their clans became mindless slaves",
        "to the oppressors.  Many years later, closer to our time, the same fate befell Gnome Sorcerors who became Necromantic experiments known as Gnomicrons.",
        "The dwarven peoples that still live in these caves are focused on containing the onslaught of these mad clerics and gnomish perversions.",
        "These same dwarves have in their possession an heirloom in the form of a set of Elonian Pipes - which should be perfect for \"Soul Sources\".",
        "As you can imagine, these dwarves are a bit untrusting, so you may have to garner favor from them in order to solicit their help\""])
    setTag(e,"OliasPlt1", 2)
    getToDwarves(e)

def getToDwarves(e):
    showMessage(e,
       ["Please heros, if you are as valiant as Yeodaugh seems to think you are, continue to the Dwarf-home and bring back the Elonian Pipes, that we may"
        " free Rennibister from her captors!"])


def leave(e):
    callEvent(e, 1007, ["-1", "-1", "-1"])

def meetYouAtGTower(e):
    showMessage(e,
        ["Excellent work! I'll take these pipes and meet you at the entrance to the guard tower.It lies just to the north of here, I'll be waiting next to the gate.",
         "We should leave seperately to avoid drawing attention to ourselves. Make haste!"])
    holder = firstHasItem(e, "Elonian Pipes")
    removeItem(e, holder, "Elonian Pipes")
    setTag(e, "OliasPlt1", 3)
    leave(e)
