#Orin's Ring, event 1, main map
# Covers Orin's Symbol - search clue, followed by retrieval of item
from SDLKeys import SDLK_y, SDLK_n, SDLK_l
from eventAPI import getTag, optionInput, setTag, getPartyCount, hasItem, removeItem
from APIUtils import isclearall, showMessage

def fireEvent(e):
    RingPlt1 = getTag(e, "RingPlt1")
    if (not isclearall(RingPlt1, 0x2)):
        return 1
    i, max = 0, getPartyCount(e)
    hasAxe = 0
    while (i < max):
        if (hasItem(e, i, "Orin's Axe")):
            hasAxe = 1
            break
        i += 1
    text = ["You see a large door before you, with what appears to be a recessed hole for some sort of battle axe.",
         "Written below the hole is the following inscription:",
         "",
         "\"Those who wish to pass must first return the chosen symbol of the warrior here entombed, Orin the Mighty.",
         "",
         "\"The symbol may be found where the great warrior fell, in the Test of Valor.\""]
    if (hasAxe):
        optionTexts = ["(Y)es", "(N)o"]
        optionsKeys = [SDLK_y, SDLK_n]
        text.extend(["", "Do you place Orin's Axe in the hole?"])
    else:
        optionTexts = ["(L)eave the Scene"]
        optionsKeys = [SDLK_l]
    if (optionInput(e, text, optionTexts, optionsKeys) == SDLK_y):
        removeItem(e, i, "Orin's Axe")
        showMessage(e,
            ["Orin's Axe is a perfect fit for the recessed portion of wall.",
             "As you place the Axe in its resting place, the wall begins to glow.",
             "Before your eyes, the wall dissolves, with the Axe, and the way ahead is clear."])
        setTag(e, "RingPlt1", RingPlt1 | 0x2)
    return 0
