#Second Ward: Air
from eventAPI import *
from APIUtils import *

TotEWard2 = 0

def fireEvent(e):
    if (getTag(e, "TotEWard1") != 10):
#Must have completed 1st ward
        showMessage(e, ["A gust of air pushes you back. The second ward won't accept you yet."])
        return 0
    global TotEWard2
    TotEWard2 = getTag(e, "TotEWard2")
    if (TotEWard2 == 0):
#Have not yet started the Ward
        begin(e)
    elif (TotEWard2 == 1):
#The first Ward Elemental
        wardelemental1(e)
    elif (TotEWard2 == 2):
#The second Ward Elemental
        wardelemental2(e)
    elif (TotEWard2 == 3):
#The third Ward Elemental
        wardelemental3(e)
    elif (TotEWard2 == 4):
#The fourth Ward Elemental
        wardelemental4(e)
    elif (TotEWard2 == 5):
#The fifth Ward Elemental
        wardelemental5(e)
    elif (TotEWard2 == 6):
#The sixth Ward Elemental
        wardelemental6(e)
    elif (TotEWard2 == 7):
#Guardian fight
        wardguardian(e)
    return 1

def begin(e):
    showMessage(e, ["As you pass into the second ward, you feel air currents and see swirling eddies of dust.  This is the Air Ward.  Tread carefully."])
    setTag(e, "TotEWard2", 1)

def trap(e):
    showMessage(e, ["Without warning, a stinking green cloud fills the air, choking the party!"], optionInput)
    for partyIdx in range(getPartyCount(e)):
        if (not savingThrow(e, "con", partyIdx, 0)):
            poison(e, partyIdx, 2, 2, 0, 20, 1, dice(20, 6, 230))
           
def lostCombat(e):
    showMessage(e, ["You find that you have become another victim of the evil terrors of the Temple of the Elements."])
    
def wardelemental1(e):
    value = (dice(1, 30, 0))
    if value == 1:
        fight1(e)
    elif value == 5:
        trap(e)

def fight1(e):
    combat1Ret = combat(e, [("Air Elemental", 10, 0, 10)])
    if (combat1Ret == 1):
        wonCombat1(e)
    elif (combat1Ret == 2):
        ranaway1(e)
    else:
        lostCombat(e)

def wonCombat1(e):
    setTag(e, "TotEWard2", 2)
    
def ranaway1(e):
    showMessage(e, ["You find that there is no escape."])
    fight1(e)

#Start of second guardian
def wardelemental2(e):
    value = (dice(1, 30, 0))
    if value == 1:
        fight2(e)
    elif value == 5:
        trap(e)

def fight2(e):
    combat2Ret = combat(e, [("Air Elemental", 20, 0, 10)])
    if (combat2Ret == 1):
        wonCombat2(e)
    elif (combat2Ret == 2):
        ranaway2(e)
    else:
        lostCombat(e)

def wonCombat2(e):
    setTag(e, "TotEWard2", 3)
    
def ranaway2(e):
    showMessage(e, ["You find that there is no escape."])
    fight2(e)
    
#Start of third guardian
def wardelemental3(e):
    value = (dice(1, 30, 0))
    if value == 1:
        fight3(e)
    elif value == 5:
        trap(e)

def fight3(e):
    combat3Ret = combat(e, [("Air Elemental", 30, 0, 10)])
    if (combat3Ret == 1):
        wonCombat3(e)
    elif (combat3Ret == 2):
        ranaway3(e)
    else:
        lostCombat(e)

def wonCombat3(e):
    setTag(e, "TotEWard2", 4)
    
def ranaway3(e):
    showMessage(e, ["You find that there is no escape."])
    fight3(e)
    
#Start of fourth guardian
def wardelemental4(e):
    value = (dice(1, 30, 0))
    if value == 1:
        fight4(e)
    elif value == 5:
        trap(e)

def fight4(e):
    combat4Ret = combat(e, [("Air Elemental", 40, 0, 10)])
    if (combat4Ret == 1):
        wonCombat4(e)
    elif (combat4Ret == 2):
        ranaway4(e)
    else:
        lostCombat(e)

def wonCombat4(e):
    setTag(e, "TotEWard2", 5)
    
def ranaway4(e):
    showMessage(e, ["You find that there is no escape."])
    fight4(e)
    
#Start of fifth guardian
def wardelemental5(e):
    value = (dice(1, 30, 0))
    if value == 1:
        fight5(e)
    elif value == 5:
        trap(e)

def fight5(e):
    combat5Ret = combat(e, [("Air Elemental", 50, 0, 10)])
    if (combat5Ret == 1):
        wonCombat5(e)
    elif (combat5Ret == 2):
        ranaway5(e)
    else:
        lostCombat(e)

def wonCombat5(e):
    setTag(e, "TotEWard2", 6)
    
def ranaway5(e):
    showMessage(e, ["You find that there is no escape."])
    fight5(e)
    
#Start of sixth guardian
def wardelemental6(e):
    value = (dice(1, 30, 0))
    if value == 1:
        fight6(e)
    elif value == 5:
        trap(e)

def fight6(e):
    combat6Ret = combat(e, [("Air Elemental", 60, 0, 10)])
    if (combat6Ret == 1):
        wonCombat6(e)
    elif (combat6Ret == 2):
        ranaway6(e)
    else:
        lostCombat(e)

def wonCombat6(e):
    setTag(e, "TotEWard2", 7)
    
def ranaway6(e):
    showMessage(e, ["You find that there is no escape."])
    fight6(e)
    
def wardguardian(e):
    value = (dice(1, 30, 0))
    if value == 1:
        fightg(e)
    elif value == 5:
        trap(e)

def fightg(e):
    combatgRet = combat(e, [("Super Golem", 100, 0, 10)])
    if (combatgRet == 1):
        wonCombatg(e)
    elif (combatgRet == 2):
        ranawayg(e)
    else:
        lostCombat(e)

def wonCombatg(e):
    setTag(e, "TotEWard2", 10)
    showMessage(e, ["When you kill the last golem, the wind dies down."])
    
def ranawayg(e):
    showMessage(e, ["You find that there is no escape."])
    fightg(e)
