from eventAPI import *
from APIUtils import *

def fireEvent(e):
    if ((getTag(e, "lFlagS") & 0x100) == 0):
        return 1
    global k
    k = getTag(e, "kssAD")
    if (k < 4):
        return 1
    elif (k < 10):
        showMessage(e, ["In this corner of the study stands an old cabinet, maintained shut by a flimsy looking padlock.",
                        "","Surprisingly though, it resists all your attempts at defeating it, be it by magick, lockpicking or brute force."])
        return 1
    elif (k == 10):
        showMessage(e, ["Using the Arch-Druid's key, you're able to open the padlock on this cabinet. To your chagrin, it only contains more junk.",
                        "","After a bit of searching, you come upon two items that look a little less shabby than the rest."])
        k = 11
        giveItems(e, ["Faded Paper", "Strange Crystal"])
        if (firstHasItem(e, "Faded Paper") >= 0):
            k +=1
        if (firstHasItem(e, "Strange Crystal") >= 0):
            k +=2
        setTag(e, "kssAD", k)
        return 1
    elif (k == 11):
        showMessage(e, ["The two items you spotted earlier are still in the cabinet."])
        giveItems(e, ["Faded Paper", "Strange Crystal"])
        if (firstHasItem(e, "Faded Paper") >= 0):
            k +=1
        if (firstHasItem(e, "Strange Crystal") >= 0):
            k +=2
        setTag(e, "kssAD", k)
        return 1
    elif (k == 12):
        showMessage(e, ["A cracked crystal looks a little less useless than the other items in this cabinet."])
        giveItems(e, ["Strange Crystal"])
        if (firstHasItem(e, "Strange Crystal") >= 0):
            k +=2
        setTag(e, "kssAD", k)
        return 1
    elif (k == 13):
        showMessage(e, ["Amidst the cluttered junk there remains a piece of paper."])
        giveItems(e, ["Faded Paper"])
        if (firstHasItem(e, "Faded Paper") >= 0):
            k +=1
        setTag(e, "kssAD", k)
        return 1
    else:
        showMessage(e, ["Nothing of interest is left in the cabinet."])
        return 1
