#Guard tower fight at the base of the stair case, gonna make em work for these
from eventAPI import getTag, setTag, giveItems, optionInput, combat
from APIUtils import isclearall, showMessage

GtowerFlag6 = 0

def fireEvent(e):
    global GtowerFlag6
    GtowerFlag6 = getTag(e, "GtowerFlag6")
    if (GtowerFlag6 == 1):
        return 1
    elif (GtowerFlag6 == 2):
        showMessage(e,
            ["The enemy is ready at their post, and stand ready to deny you further access."])
    else:
        showMessage(e,
            ["The enemy is once again ready for you at the base of the stairs, one shouts out:",
             "\"THEY MUST NOT ADVANCE ANY FURTHER!!\"",
             "but you are able to catch a glimpse of the staircase before you are assaulted!"],
            optionInput)
    fightThem(e)
    setTag(e, "GtowerFlag6", GtowerFlag6)
    return 0


def fightThem(e):
    combatRet = combat(e, [("Demon Lord", 5, 0, 100), ("Stalker", 2, 0, 30), ("Yevil", 4, 0, 20), ("Dactyl", 9, 0, 10)])
    if (combatRet == 1):
        wonCataFight(e)
    elif (combatRet == 3):
        lostCataFight(e)
    else:
        defeatedCataFight(e)

def wonCataFight(e):
    global GtowerFlag6
    showMessage(e, 
        ["The guard post has been taken, and you can continue further up the tower"])
    GtowerFlag6 = 1
    setTag(e, "GtowerFlag6", GtowerFlag6)

def lostCataFight(e):
    showMesasge(e,
        ["You fall to the staircase guards"])

def defeatedCataFight(e):
    global GtowerFlag6
    showMessage(e,
        ["You manage to evade your opponents, and note that they stay entrenched at the base of the staircase"])
    GtowerFlag6 = 2
    setTag(e, "GtowerFlag6", GtowerFlag6)
    
