#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

GtowerFlag1 = 0

def fireEvent(e):
    global GtowerFlag1
    GtowerFlag1 = getTag(e, "GtowerFlag1")
    if (GtowerFlag1 == 1):
        return 1
    elif (GtowerFlag1 == 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, "GtowerFlag1", GtowerFlag1)
    return 0


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

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

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

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