#Lair Plot event, combat with cellar boss to clear and get the key to catacombs
from eventAPI import getTag, setTag, giveItems, optionInput, combat
from APIUtils import isclearall, showMessage

PhiliFlag = 0

def fireEvent(e):
    global PhiliFlag
    PhiliFlag = getTag(e, "PhiliFlag")
    if (PhiliFlag == 1):
        return 1
    elif (PhiliFlag == 2):
        showMessage(e,
            ["You hear a morbid screeching sound and know your foe is upon you."])
    else:
        showMessage(e,
            ["You are assaulted by a rank smell and a horrible noise, like a sword drawn across flagstone. ",
             "The screeching sound continues and you begin to understand it is actually the voice of some ",
             "fell creature."], optionInput)
        showPicture(e, "philibuster")
        showMessage(e,
            ["\"Thou hast braved my tower, mortals, only to find your doom!  Even if you bring me to defeat, ",
             "my fellows shall see to your end!\""], optionInput)
    fightThem(e)
    setTag(e, "PhiliFlag", PhiliFlag)
    return 0


def fightThem(e):
    combatRet = combat(e, [("Philibuster", 1, 0, 50), ("Earth Elemental", 2, 0, 10), ("Fire Elemental", 2, 0, 20), ("Water Elemental", 2, 0, 10), ("Air Elemental", 2, 0, 20)])
    if (combatRet == 1):
        wonLairFight(e)
    elif (combatRet == 3):
        lostLairFight(e)
    else:
        defeatedLairFight(e)

def wonLairFight(e):
    global PhiliFlag
    showMessage(e, 
        ["As the final shriek of the cursed Philibuster rings in your ears, ",
         "you see that he was apparently protecting something. ",
         "There appears to be a large stone table at the end of the hallway."])
    showMessage(e,
        ["As you begin to continue forth, one of your party trips over something on the floor!"])
    giveItems(e, ["Rune Sword", "Erda Pipes", "Salamander Figurine"])
    PhiliFlag = 1
    setTag(e, "PhiliFlag", PhiliFlag)

def lostLairFight(e):
    showMesasge(e,
        ["With your last gasp of breath, you see your enemies smiling as they know your end is near."])

def defeatedLairFight(e):
    global PhiliFlag
    showMessage(e,
        ["The horrifying screams of the Philibuster continue to blast your ears as you retreat."])
    PhiliFlag = 2
    setTag(e, "PhiliFlag", PhiliFlag)
    
