#Main RingQuest Event #2
# For main map, acquisition of Orin's Ring
from eventAPI import getTag, setTag, getPartyCount, hasItem, optionInput, removeItem
from APIUtils import isclearall, showMessage, poseYesNo, firstHasItem

def fireEvent(e):
    return runRingEvent(e, 0x1000, "Orin's Ring", "Orin the Mighty")

def runRingEvent(e, flag, item, hero):
    RingPlt1 = getTag(e, "RingPlt1")
    if (not isclearall(RingPlt1, flag)):
        return 1
    holder = firstHasItem(e, item)
    text = ["You see before you a wall, with a small shelf.",
            "The shelf has a small protrusion, about the right size for a ring.",
            "",
            "Above the shelf are written these words:",
            "",
            "\"Here you must apply the proof that you have lain to rest the spirit of "+hero+"\""]
    if (holder > -1):
        text.extend(["", "Do you place "+item+" on the protrusion?"])
        fn = poseYesNo
    else:
        fn = showMessage
    if (fn(e, text)):
        removeItem(e, holder, item)
        showMessage(e,
            ["As you place "+item+" upon the protrusion, the wall melts away, taking the Ring with it."],
            optionInput)
        RingPlt1 |= flag
        setTag(e, "RingPlt1", RingPlt1)
    return 0
