#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

GtowerFlag3 = 0

def fireEvent(e):
    global GtowerFlag3
    GtowerFlag3 = getTag(e, "GtowerFlag3")
    if (GtowerFlag3 == 1):
        return 1
    elif (GtowerFlag3 == 2):
        showMessage(e,
            ["The enemy is ready at their post, and stand ready to deny you further access."])
    else:
        showMessage(e,
            ["As you push forward, you are suddenly assaulted on all sides by the enemy,",
             "but you are able to catch a glimpse of the staircase before you are assaulted!"],
            optionInput)
    fightThem(e)
    setTag(e, "GtowerFlag3", GtowerFlag3)
    return 0


def fightThem(e):
    combatRet = combat(e, [("Demon Lord", 3, 0, 40), ("Yevil", 3, 0, 20)])
    if (combatRet == 1):
        wonCataFight(e)
    elif (combatRet == 3):
        lostCataFight(e)
    else:
        defeatedCataFight(e)

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

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

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