#First Ward: Earth
from eventAPI import *
from APIUtils import *

TotEWard1 = 0

def fireEvent(e):
    if (getTag(e, "TotEplot") < 5):
#Must have solved all riddles
        showMessage(e, ["A maelstrom of pebbles forces you to go back. You're denied access to the first ward."])
        return 0
    global TotEWard1
    TotEWard1 = getTag(e, "TotEWard1")
    if (TotEWard1 == 0):
#Have not yet started the Ward
        begin(e)
    elif (TotEWard1 == 1):
#The first Ward Elemental
        wardelemental1(e)
    elif (TotEWard1 == 2):
#The second Ward Elemental
        wardelemental2(e)
    elif (TotEWard1 == 3):
#The third Ward Elemental
        wardelemental3(e)
    elif (TotEWard1 == 4):
#The fourth Ward Elemental
        wardelemental4(e)
    elif (TotEWard1 == 5):
#The fifth Ward Elemental
        wardelemental5(e)
    elif (TotEWard1 == 6):
#The sixth Ward Elemental
        wardelemental6(e)
    elif (TotEWard1 == 7):
#Guardian fight
        wardguardian(e)
    return 1

def begin(e):
    showMessage(e, ["As you pass into the first ward, you see dirt and rocks scattered across your path.  This is the Earth Ward.  Tread carefully."])
    setTag(e, "TotEWard1", 1)

 
def trap(e):
   showMessage(e, ["Without warning, you are immediately pummeled by a mass of falling rocks!"], optionInput)
   for partyIdx in range(getPartyCount(e)):
       if (not savingThrow(e, "dex", partyIdx, 0)):
           modifyHP(e, partyIdx, -dice(10, 6, 4))
           
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 == 2:
        trap(e)

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

def wonCombat1(e):
    setTag(e, "TotEWard1", 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:
        trap(e)
    elif value == 2:
        fight2(e)

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

def wonCombat2(e):
    setTag(e, "TotEWard1", 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 == 3:
        fight3(e)
    elif value == 5:
        trap(e)

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

def wonCombat3(e):
    setTag(e, "TotEWard1", 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 == 3:
        fight4(e)
    elif value == 5:
        trap(e)

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

def wonCombat4(e):
    setTag(e, "TotEWard1", 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, [("Earth Elemental", 50, 0, 10)])
    if (combat5Ret == 1):
        wonCombat5(e)
    elif (combat5Ret == 2):
        ranaway5(e)
    else:
        lostCombat(e)

def wonCombat5(e):
    setTag(e, "TotEWard1", 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, [("Earth Elemental", 60, 0, 10)])
    if (combat6Ret == 1):
        wonCombat6(e)
    elif (combat6Ret == 2):
        ranaway6(e)
    else:
        lostCombat(e)

def wonCombat6(e):
    setTag(e, "TotEWard1", 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, "TotEWard1", 10)
    showMessage(e, ["As the last golem falls, the rumble of the earth recedes."])
    
def ranawayg(e):
    showMessage(e, ["You find that there is no escape."])
    fightg(e)
