#defend fight #4
from eventAPI import *
from APIUtils import *

rtDefendFight4=0

def fireEvent(e):
   global rtDefendFight4
   rtDefendFight4 = getTag(e, "rtDefendFight4")
   if (rtDefendFight4 == 2):
      return 1
   elif (rtDefendFight4 == 1):
      showMessage(e, ["Kobolds pound upon the temple doors. The wood splinters and the kobolds howl in anticipation."])
   else:
      showMessage(e, ["The temple is under attack! Kobolds pound upon the temple doors while the priests inside try desperately to hold them off. If the priests are slain the city will be without healing. You must help them!"], optionInput)
   fightThem(e)
   if (rtDefendFight4 == 2):
      return 1
   else:
      return 0

def fightThem(e):
   combatRet = combat(e, [("Kobold", 6, 1, 10), ("Goblin", 1, 0, 20)])
   if (combatRet == 1):
      wonFight(e)
   elif (combatRet == 3):
      lostFight(e)
   else:
      ranAwayFight(e)

def wonFight(e):
   global rtDefendFight4
   showMessage(e, ["You have saved the priests within the temple. Grateful for your help, the priests heal you."])
   rtDefendFight4 = 2
   setTag(e, "rtDefendFight4", rtDefendFight4)
   partyIdx = 0
   while (partyIdx < getPartyCount(e)):
      modifyHP(e, partyIdx, +2000)
      partyIdx += 1

def lostFight(e):
   showMessage(e, ["You have fought bravely, but your battle is now over."])

def ranAwayFight(e):
   global rtDefendFight4
   showMessage(e, ["You are able to flee from your foes, but this will not stop their destructive rampage."])
   rtDefendFight4 = 1
   setTag(e, "rtDefendFight4", rtDefendFight4)
