#Cellar 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

CellarFlag2 = 0

def fireEvent(e):
    global CellarFlag2
    CellarFlag2 = getTag(e, "CellarFlag2")
    if (CellarFlag2 == 1):
        return 1
    elif (CellarFlag2 == 2):
        showMessage(e,
            ["Back again are we? HAVE AT YOU!!!"])
    else:
        showMessage(e,
            ["As you approach the corner, you hear a voice call out to you.",
             "This is the band of fearsome warriors Yeodaugh would send? Laughable.",
             "The shadows come alive, and your attackers swarm down upon you."],
            optionInput)
    fightThem(e)
    setTag(e, "CellarFlag2", CellarFlag2)
    return 0


def fightThem(e):
    combatRet = combat(e, [("Dark Rogue", 4, 0, 20), ("Black Claw Warlock", 3, 0, 50), ("Fire Elemental", 1, 0, 10)])
    if (combatRet == 1):
        wonCellarFight(e)
    elif (combatRet == 3):
        lostCellarFight(e)
    else:
        defeatedCellarFight(e)

def wonCellarFight(e):
    global CellarFlag2
    showMessage(e, 
        ["As the last standing foe falls to the ground in the throes of death,",
         "the banestaff Yeodaugh gave you begins to glow brightly.",
         "The light begins to spread throughout all the crates around you, nullifying",
         "the dastardly effects of the Devil's Whiskey"])
    showMessage(e,
        ["As the light dies down, you see a small glint of metal amidst the remains on the floor"])
    giveItems(e, ["Skeleton Key", "Rune Sword", "PyroWand", "Defender Ring"])
    showMessage(e,
        ["Knowing that you have put a temporary end to the influx of liquid evil, you feel",
	 "you should go and report your findings to Yeodaugh"])
    CellarFlag2 = 1
    setTag(e, "CellarFlag2", CellarFlag2)

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

def defeatedCellarFight(e):
    global CellarFlag2
    showMessage(e,
        ["Your retreating footsteps are followed by laughter"])
    CellarFlag2 = 2
    setTag(e, "CellarFlag2", CellarFlag2)
    
