#Chapel alter
from eventAPI import *
from APIUtils import *

rtchapelAlter=0
rtHedgeFountainFlag=0

def fireEvent(e):
   global rtchapelAltar
   global rtHedgeFountainFlag
   rtchapelAltar = getTag(e, "rtchapelAltar")
   rtHedgeFountainFlag = getTag(e, "rtHedgeFountainFlag")
   if (rtchapelAltar == 3):
      return 1
   elif (rtchapelAltar == 2):
      crossReturned(e)
   elif (rtchapelAltar == 1):
      returnVisit(e)
   else:
      firstVisit(e)
   if ((rtHedgeFountainFlag == 0) or (rtHedgeFountainFlag == 3)):
      return 1
   else:
      return 0

def firstVisit(e):
   global rtchapelAltar
   global rtHedgeFountainFlag
   rtHedgeFountainFlag = getTag(e, "rtHedgeFountainFlag")
   if (rtHedgeFountainFlag == 0):
      return 1
   else:
      showMessage(e, ["As You approach the altar you feel a chill permeate the air.", "", "A ghost appears before you and you recognize it as the same spirit that appeared to you at the fountain."], optionInput)
   showPicture(e, "Stone_Cleric")
   showMessage(e, ["\"Welcome!  I have long prayed that one such as yourself would come.\"", "", "I am sorry for the abruptness of my earlier message, but it is difficult to leave the halls of this castle for even a short time.", "", "\"Please, sit with me awhile and we shall speak of things both past and future.\""])
   showMessage(e, ["\"This castle, as you may have guessed, is cursed.  Even in death, we who served our beloved king cannot escape.  The tale of how this came to pass is long and my time here is limited.  I ask that you would visit the library to read the full account of all that has transpired here.\""])
   showMessage(e, ["\"There is a task that I would set you to, if you would but help us.  There is a holy artifact that was taken from this chapel by those in service to the Lord of the Great Eastern Keep.  A golden cross that was both blessed and powerful.  It was taken as spoil during one of the many raids that the Lords did execute in days past.  However, as none of us can now leave this castle there is none that can retrieve it, save you.\""])
   showMessage(e, ["\"If you would return this artifact here and place it upon the hidden altar behind this chapel, then I might pray there and remove one of the barriers to the throne room above.\""])
   showMessage(e, ["The image of the ghost wavers.", "", "\"I must rest for a time.  Return the cross if you are able.  I will pray for your success.\""])
   rtchapelAltar=1
   setTag(e, "rtchapelAltar", rtchapelAltar)

def returnVisit(e):
   showMessage(e, ["The ghost appears before you.  It seems more translucent than before."], optionInput)
   showPicture(e, "Stone_Cleric")
   if (firstHasItem(e, "Golden Cross") >= 0):
      showMessage(e, ["\"Please, place the cross upon the hidden altar behind this chapel.\""])
   else:
      showMessage(e, ["\"When you return the cross, the barrier will be removed.  Until then I must rest.\""])

def crossReturned(e):
   global rtchapelAltar
   showPicture(e, "Stone_Cleric")
   showMessage(e, ["\"Thank you for your kind work.  The third barrier within the throne room has been removed.  There is little that I can give you in return.  However, I can give you a blessing so that your future journey will be easier.\""])
   for partyIdx in range(getPartyCount(e)):
      modifyXP(e, partyIdx, 100000)
   showMessage(e, ["Each member of the party recieves an experience bonus."])
   clearPicture(e)
   showMessage(e, ["The spirit fades completely away.  You hope that he is now able to rest in peace."])
   rtchapelAltar = 3
   setTag(e, "rtchapelAltar", rtchapelAltar)
