#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

GtowerFlag2 = 0

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


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

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

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

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