#Olias plot events
from eventAPI import *
from APIUtils import *

OliasPlt1 = 0
DKPlot1 = 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):
    if (getTag(e, "DKPlot1") == 1):
        dwaddonplot(e)
    else:
        if (getTag(e, "DKPlot1") == 2):
            showMessage(e,["There is no sign of the thief nor of his dwarven acolytes; you'll probably never see them again."])
            setTag(e, "DKPlot1", 3)
        callEvent(e, 1007, ["-1", "-1", "-1"])
        return 0

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)

def dwaddonplot(e):
    showMessage(e, ["As you enter the Green Bard, you begin to scan the patrons. While you did not see the man's face in the caves, you do remember his voice, clear as day."])
    showMessage(e, ["Suddenly, you hear that raspy voice coming from a table in the corner of the bar. Sitting at the table is a thief, surrounded by five tough looking dwarves, all of whom are drinking ale."])
    showMessage(e, ["As your eyes meet, a look of surprise comes across the man's face. The dwarves all turn to look at your party, and they don't look like a happy bunch."])
    showMessage(e, ["\"Get them!\" he shouts, and the dwarves ready themselves and attack you.", "", "I think you're in trouble!"])
    setTag(e, "DKPlot1", 2)
    fight(e)
    return 0
    
def fight(e):
    combatRet = combat(e, [("Dwarf", 5, 0, 10)])
    if (combatRet == 1):
        wonFight(e)
    elif (combatRet == 3):
        lostFight(e)
    else:
        defeatedFight(e)
        
def lostFight(e):
    showMessage(e, ["Alas, your party has expired, but has gone to Adventurer Heaven. Hopefully, someone will drag your carcasses to the temple and revive you, although your opportunity for revenge has passed. Perhaps your paths will cross again in the future."])

def defeatedFight(e):
    showMessage(e, ["Sensing defeat, your party quickly scrambles out of the bar and runs for safety. The thief uses this opportunity to slip out of the bar and disappear."])
    showMessage(e, ["I guess you will not be getting your revenge after all, but perhaps your paths will cross again in the future."])

def wonFight(e):
    showMessage(e, ["After disposing of the dwarves, you turn your attention back the the thief, but it seems that he slipped away during the battle. There is a sack of gold still on the table, which you help yourself to."])
    modifyGold (e, 0, 5000)
    showMessage(e, ["You find 5,000 gold pieces. You also see that there is a weapon left at the table."])
    giveItems(e, ["Shadow Blade"])
    showMessage(e, ["Your thirst for revenge is not quenched, but the trail has gone cold. Perhaps your paths will cross again in the future."])
    x, c = 0, getPartyCount(e)
    while (x < c):
        modifyXP(e, x, 3000)
        x += 1
    showMessage(e, ["Your party receives 3000 XP per person."])
    setTag(e, "DKPlot1", 4)
