#Leughmagen asks for help in street.
from eventAPI import getTag, setTag, playSpecAudio, showPicture, optionInput, giveItems
from APIUtils import showMessage
from SDLKeys import SDLK_y, SDLK_s, SDLK_h, SDLK_l, SDLK_w

lFlagU = 0

def fireEvent(e):
    global lFlagU
    lFlagU = getTag(e, "lFlagU")
    if (lFlagU == 0xFFFFFFFF):
        return 1
    playSpecAudio(e, "1stHelp")
    showPicture(e, "Leughmagen")
    showMessage(e,
        ["...A young, but wise looking man stops you in the street... He looks deeply into your eyes before opening his mouth to speak.",
         "",
         "\"My name is Leughmagen.",
         "",
         "\"I represent the townspeople and I must speak to you now.",
         "",
         "\"A grave turn of events has loomed over our towne since 'Latruin's Veil' first seeped into our Easterly coast. "
         "",
         "\"Many of our town's men and women have vanished without a trace since the arrival of what some call The Devil Whiskey. Young girls are heard no more on the streets in derry a song. The men are all presumed to be dead. When any of them ARE found, either death is confirmed or they be in a silent stupor.\"",
         "",
         "...He pauses to look around..."])
    if (lFlagU != 0):
        runSection7(e)
    else:
        runSection2(e)
    setTag(e, "lFlagU", lFlagU)
    #print "setTag completed, about to return '1'."
    return 1
        
def runSection2(e):
    global lFlagU
    showMessage(e,
        ["\"We can NOT go on ignoring our very people! We can't let this injustice pass.",
         "",
         "\"The council has decided to close the city to outside trade until our people are found. The guards are turning up every stone in towne, but they have aimed their suspicions elsewhere. The guards have been a little less than helpful, I can tell ye.",
         "",
         "\"Strange wanderers from out realms, seem to pass without question, while our towne's people are watched like common prisoners.\"",
         "",
         "...His fists unclench and he continues..."])
    if (optionInput(e,
        ["\"Who can you trust? We have many despairs indeed, but trade must be restored or our city will starve clean out. Our lost must be returned.",
         "",
         "\"We beg that you and your party of young adventurers will start your career here in Rennibister and help us. Use any magic you possess, whether it's holy, elemental, song or arcane. Bind this silent darkness and feed it light!",
         "",
         "\"Find this evil and use your deadliest blades to destroy it!\"",
         "",
         "...You start to feel sick with his anguish..."
         "",
         "\"Old man Naris is one of us and can help you. He has a messenger in one of the shops waiting for you.",
         "",
         "\"Please help us...\""],
        ["(Y)es. We can help.", "(S)orry. We can't help you."], [SDLK_y, SDLK_s]) == SDLK_y):
        lFlagU = 0x1
        runSection4(e)
    else:
        lFlagU = 0x10
        runSection5(e)

def runSection4(e):
    global lFlagU
    if (lFlagU != 0x1):
        runSection5(e)
        return
    showMessage(e,
        ["\"The skies are blue today for my people. Very well.",
         "",
         "\"Here's some things to help you on your way. Save your gold and buy more when you can.",
         "",
         "\"You'll need it. And be wary - many of the townsfolk have taken to challenging any stranger they meet, and will not likely wait to hear that you're on our side.  Carry on now.\"",
         "",
         "...Your arms sink under the weight of the pack given to you.",
         "",
         "Leughmagen nods and disappears."])
    giveItems(e, ["Broad Sword", "Chain Mail", "Helm", "Leather Armor", "Mace"])
    lFlagU = 0xFFFFFFFF

def runSection5(e):
    global lFlagU
    if (lFlagU != 0x10):
        runSection6(e)
        return
    if (optionInput(e,
        ["...He looks down",
         "",
         "\"Well, you shall not readily build a reputation with inaction.\""],
        ["(H)elp, we will.", "(L)eave this fool."], [SDLK_h, SDLK_l]) == SDLK_h):
        lFlagU = 0x1
        runSection4(e)

def runSection6(e):
    global lFlagU
    if (lFlagU != 0x10):
        runSection2(e)
        return
    if (optionInput(e,
        ["...Leughmagen glares",
         "",
         "\"I assume you're here to help. If not, just be gone.\""],
        ["(W)e're here to help.", "(S)orry. We'll be gone"], [SDLK_w, SDLK_s]) == SDLK_w):
        lFlagU = 0x1
        runSection4(e)
    else:
        lFlagU = 0x11
        runSection7(e)

def runSection7(e):
    global lFlagU
    if (lFlagU != 0x10):
        runSection2(e)
        return
    if (optionInput(e,
        ["\"You shall not have another chance to join the side of good. If you refuse again, I will be forced to put you down to ensure the safety of our people.\""],
        ["(W)e're here to help.", "(S)orry. We'll be gone"], [SDLK_w, SDLK_s]) == SDLK_w):
        lFlagU = 0x1
        runSection4(e)
        return
    showMessage(e,
        ["\"Well I'm not giving you a choice... ",
         "",
         "\"Here ya go. Do with it as you wish, but know that I may see you again.\"",
         "",
         "...Leughmagen darts away before you have a chance to reply."])
    giveItems(e, ["Broad Sword", "Chain Mail", "Helm", "Mace", "Crossbow", "Bolts"])
    lFlagU = 0xFFFFFFFF
