#castle south tower guardian
from eventAPI import *
from APIUtils import *

rtcTowerSouthFlag = 0
rtcBarrierFlag1=0

def fireEvent(e):
   global rtcTowerSouthFlag
   rtcTowerSouthFlag = getTag(e, "rtcTowerSouthFlag")
   if (rtcTowerSouthFlag == 2):
      return 1
   elif (rtcTowerSouthFlag == 1):
      returnVisit(e)
   else:
      firstVisit(e)
   if (rtcTowerSouthFlag == 2):
      return 1
   else:
      return 0

def firstVisit(e):
   showPicture(e, "stalker")
   showMessage(e, ["The tower guardian strides out of the shadows.", "", "It looks like an ordinary man.  Wholly unremarkable."], optionInput)
   fightThem(e)

def returnVisit(e):
   showPicture(e, "stalker")
   showMessage(e, ["As you approach, the guardian walks out of the shadows to challenge you."])
   fightThem(e)

def fightThem(e):
   combatRet = combat(e, [("Alchemist's Construct", 1, 0, 10)])
   if (combatRet == 1):
      wonFight(e)
   elif (combatRet == 3):
      lostFight(e)
   else:
      ranAwayFight(e)

def wonFight(e):
   global rtcTowerSouthFlag
   global rtcBarrierFlag1
   showMessage(e, ["As the guardian collapses it dissolves into a pile of sand and glass."])
   rtcTowerSouthFlag = 2
   rtcBarrierFlag1 = 1
   setTag(e, "rtcTowerSouthFlag", rtcTowerSouthFlag)
   setTag(e, "rtcBarrierFlag1", rtcBarrierFlag1)

def lostFight(e):
   showMessage(e, ["You prove no match for the guardian.  It shows no emotion as it ends your life."])

def ranAwayFight(e):
   global rtcTowerSouthFlag
   showMessage(e, ["The guardian does not bother to chase you.  It moves back to it's place in the shadows to wait."])
   rtcTowerSouthFlag = 1
   setTag(e, "rtcTowerSouthFlag", rtcTowerSouthFlag)
