from eventAPI import getTag, showPicture, optionInput, tickGame, setExit
from APIUtils import issetall, showMessage
from SDLKeys import SDLK_y, SDLK_n, SDLK_b, SDLK_p, SDLK_l, SDLK_SPACE

def fireEvent(eventPtr):
    RingPlt1 = getTag(eventPtr, "RingPlt1")
    if (not issetall(RingPlt1, 0x04000000)):
        runSection2(eventPtr)
        return 0
    showPicture(eventPtr, "Stairs_D")
    choice = optionInput(eventPtr,
                         ["After opening a locked trap door with the key Aldorik gave you, a dark and mysterious stair leads down into an unknown abyss.",
                          "Do you go down?"],
                         ["(Y)es", "(N)o"],
                         [SDLK_y, SDLK_n])
    if (choice == SDLK_y):
        tickGame(eventPtr, 30)
        setExit(eventPtr, "maps/ringQuest.cfg", 13, 10, 0)
        return 0
    else:
        return 0

def runSection2(eventPtr):
    choice = SDLK_SPACE
    showPicture(eventPtr, "House")
    while (choice != SDLK_l):
        choice = optionInput(eventPtr,
                             ["You see an empty house with a locked trap door in the center of the floor.",
                              "What do you wish to do?"],
                             ["(B)ash the Lock",
                              "(P)ick the Lock",
                              "(L)eave the House"],
                             [SDLK_b, SDLK_p, SDLK_l])
        if (choice == SDLK_b):
            showMessage(eventPtr, ["No matter how hard you hit it, the lock seems unharmed.  Perhaps it is somehow magically protected?"], optionInput)
        if (choice == SDLK_p):
            showMessage(eventPtr, ["Whether this is the most complex and well-built lock of all time, or there is some magical property that is confounding you, you fail to make any headway in defeating the lock mechanism."], optionInput)
