#Lair -1 entrance, must complete the elemental order game
from eventAPI import *
from APIUtils import *
from SDLKeys import SDLK_b, SDLK_a, SDLK_e, SDLK_f, SDLK_w, SDLK_l
ordered = 0

def fireEvent(e):
    global ordered
    ordered = getTag(e, "ordered")
    earthPush = 0
    airPush = 0
    waterPush = 0
    leaveIt = 0
    firstList = ["(B)lank", "(A)ir", "(E)arth", "(F)ire", "(W)ater", "(L)eave the pedestal"]
    firstKeys = [SDLK_b, SDLK_a, SDLK_e, SDLK_f, SDLK_w, SDLK_l]
    secondList = ["(B)lank", "(A)ir", "(F)ire", "(W)ater", "(L)eave the pedestal"]
    secondKeys = [SDLK_b, SDLK_a, SDLK_f, SDLK_w, SDLK_l]
    thirdList = ["(B)lank", "(A)ir", "(F)ire", "(L)eave the pedestal"]
    thirdKeys = [SDLK_b, SDLK_a, SDLK_f, SDLK_l]
    fourthList = ["(B)lank", "(F)ire", "(L)eave the pedestal"]
    fourthKeys = [SDLK_b, SDLK_f, SDLK_l]

    if( not ordered):
        showMessage(e, ["A large pedestal stands before you, with 5 buttons",
                        "4 of the buttons bear symbols representing the 4 elements",
                        "A fifth button appears to be blank"])

    while( (not ordered) and (not leaveIt) ):
        if(airPush):
            keyPress = optionInput(e, ["Which do you press?"], fourthList, fourthKeys)
            if(keyPress == SDLK_f):
                correctPush(e)
                ordered = 1
                setTag(e, "ordered", ordered)
            elif(keyPress == SDLK_b):
                resetPush(e)
                earthPush = 0
                waterPush = 0
                airPush = 0
            elif(keyPress == SDLK_l):
                leaving(e)
                leaveIt = 1
        elif(waterPush):
            keyPress = optionInput(e, ["Which do you press?"], thirdList, thirdKeys)
            if(keyPress == SDLK_a):
                correctPush(e)
                airPush = 1
            elif(keyPress == SDLK_l):
                leaving(e)
                leaveIt = 1
            else:
                if(keyPress == SDLK_b):
                    resetPush(e)
                else:
                    wrongPush(e)
                earthPush = 0
                waterPush = 0
        elif(earthPush):
            keyPress = optionInput(e, ["Which do you press?"], secondList, secondKeys)
            if(keyPress == SDLK_w):
                correctPush(e)
                waterPush =1
            elif(keyPress == SDLK_l):
                leaving(e)
                leaveIt = 1
            else:
                if(keyPress == SDLK_b):
                    resetPush(e)
                else:
                    wrongPush(e)
                earthPush = 0
        else:
            keyPress = optionInput(e, ["Which do you press?"], firstList, firstKeys)
            if(keyPress == SDLK_e):
                correctPush(e)
                earthPush = 1
            elif(keyPress == SDLK_l):
                leaving(e)
                leaveIt = 1
            else:
                if(keyPress == SDLK_b):
                    resetPush(e)
                else:
                    wrongPush(e)

    if(leaveIt):
        return 0
    showPicture(e, "Red_Vortex")
    if (poseYesNo(e,
        ["You see before you A swirling Red Vortex, do you enter?",
         "Do you enter?"])):
        tickGame(e, 60)
        setExit(e, "maps/lair-1.cfg", 12, 11, 0)
    return 0

def resetPush(e):
    showMessage(e, ["When you press the blank button, all the others push themselves back out",
                    "Looks like you'll have to start over again"])

def wrongPush(e):
    showMessage(e, ["As you press the button, you feel a great force compress your body",
                    "guess you picked wrong!"])
    i, c = 0, getPartyCount(e)
    while (i < c):
        modifyHP(e, i, -10)
        i += 1

def correctPush(e):
    showMessage(e, ["As you pres the button, the stone clicks into place and stays there",
                    "looks like you picked correctly!"])

def leaving(e):
    showMessage(e, ["Thinking it best to walk leave this problem be, you turn to walk away",
                    "as you do so, you hear several small clicks, seems the pedestal reset itself"])

