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

rtcTowerNorthFlag = 0
rtcBarrierFlag2 = 0

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

def firstVisit(e):
   showPicture(e, "Ubu")
   showMessage(e, ["You feel a stirring in the air.", "", "A sprite appears.  It flys nervously about and speaks to you in a tiny voice."])
   showMessage(e, ["\"Yes, yes?  New ones.  Yes I see.", "You are here to help me be free?\"", "", "\"The barrier you seek to pass?", "For it I was set to my task!\""])
   showMessage(e, ["\"Answer me this question true.", "Then at last my task is through!\""])
   showMessage(e, ["\"The master here is dead in life.", "His family gone.  No son!  No wife!\"", "", "\"Only one does keep him here.", "But his existance brings no cheer.\""])
   showMessage(e, ["\"From battle won to battle lost,", "neither one could know the cost.\"", "", "\"A curse upon them, each his own.", "Keeps them captive in their homes.\""])
   showMessage(e, ["\"A broken promise from their youth.", "Though each of them denies the truth.\"", "", "\"Love forgotten, blood is spilled.", "Each the other one must kill.\""], optionInput)
   showMessage(e, ["\"Now the wrong is old and past.", "Has redemption come at last?\"", "", "\"True forgiveness is the cure.", "Remembrance of love! The soul made pure!\""], optionInput)
   answer = stringInput(e, ["\"Free my master!  End his pain!\"", "", "\"Tell me now his brother's name?\""])
   if(answer.lower() != "nathan"):
      wrongAnswer(e)
   else:
      correctAnswer(e)

def returnVisit(e):
   showPicture(e, "Ubu")
   showMessage(e, ["You feel a stirring in the air.", "", "A sprite appears.  It flys nervously about and speaks to you in a tiny voice."], optionInput)
   answer = stringInput(e, ["\"Free my master!  End his pain!\"", "", "\"Tell me now his brother's name?\""])
   if(answer.lower() != "nathan"):
      wrongAnswer(e)
   else:
      correctAnswer(e)
   
def wrongAnswer(e):
   global rtcTowerNorthFlag
   rtcTowerNorthFlag = 1
   setTag(e, "rtcTowerNorthFlag", rtcTowerNorthFlag)
   showMessage(e, ["\"No, no no!  That is not right!", "Use your minds and not your might!\""], optionInput)
   showMessage(e, ["The sprite leaves.  She seemed disappointed with you."], optionInput)

def correctAnswer(e):
   global rtcTowerNorthFlag
   global rtcBarrierFlag2
   showMessage(e, ["\"Passage to the king you've won.", "Now I shall leave.  My work is done.\""])
   showMessage(e, ["The sprite buzzes around you a few times then disappears in a small puff of smoke."],  optionInput)
   rtcTowerNorthFlag = 2
   setTag(e, "rtcTowerNorthFlag", rtcTowerNorthFlag)
   rtcBarrierFlag2 = 1
   setTag(e, "rtcBarrierFlag2", rtcBarrierFlag2)
