#castle west Lord
from eventAPI import *
from APIUtils import *
from SDLKeys import SDLK_y, SDLK_n, SDLK_l

rtcastleLordFlag = 0

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

def firstVisit(e):
   global rtcastleLordFlag
   showMessage(e, ["You approach the throne."], optionInput)
   showPicture(e, "Human_Male04")
   showMessage(e, ["As you draw near, the figure upon the throne moves.", "", "Turning his head, the lord of the castle afixes you with a cold, blue-eyed gaze."])
   showMessage(e, ["\"Who dares approach me?\"", "", "The man's voice is scratchy, as if he hasn't spoken in a long time."])
   showMessage(e, ["\"No, your names are not important. I no longer care for such formalities.\"", "", "\"Now, listen closely as I have a task for you.\""])
   showMessage(e, ["\"There is a creature of evil power within the Great Eastern Keep.  I would that you destroy it and bring me the crown that it wears upon it's foul head.\""])
   showMessage(e, ["\"Do not worry, you will be rewarded for your service.  Take whatever treasure you may find within this castle, as it is of no import to me.\""])
   showMessage(e, ["The man then rests back upon his throne and ignores your further questions."])
   rtcastleLordFlag = 1
   setTag(e, "rtcastleLordFlag", rtcastleLordFlag)

def returnVisit(e):
   showPicture(e, "Human_Male04")
   hasCrown = 0
   if (firstHasItem(e,"Lich Crown") >= 0):
      hasCrown = 1
   text = ["\"Have you returned with the crown?.\""]
   if (hasCrown):
      optionTexts = ["(Y)es", "(N)o"]
      optionsKeys = [SDLK_y, SDLK_n]
      text.extend(["", "Do you give the Lich Crown to Lord Mercer?"])
   else:
      optionTexts = ["(L)eave the Scene"]
      optionsKeys = [SDLK_l]
   if (optionInput(e, text, optionTexts, optionsKeys) == SDLK_y):
      removeCrown(e)

def removeCrown(e):
   global rtcastleLordFlag
   holder = firstHasItem(e,"Lich Crown")
   removeItem(e, holder, "Lich Crown")
   showMessage(e, ["James takes the crown from you and slowly turns it over in his hands.", "", "\"So, he is dead then?\"", "", "Though the question was asked, he does not wait for your answer."])
   showMessage(e, ["\"Finally, it is done.\"", "", "\"Oh, I thought that this would never end.  The foul demon had cursed me for so long...\""])
   showMessage(e, ["To your surprise, tears begin to form in James' eyes.", "", "\"He was...  my brother.\""])
   showMessage(e, ["Years of pent-up grief begin to overtake him and James begins to sob.", "", "\"I am sorry!  I could not forgive you!\""])
   showMessage(e, ["\"I am sorry, my brother.  Nathan, forgive me.\""])
   showMessage(e, ["\"Forgive me.\""])
   showMessage(e, ["His grief spent, Lord James turns once more to you.", "", "A small smile brightens his face.  He is no longer the cold, emotionless man you first saw.  Here is the man as he must have been long ago."])
   showMessage(e, ["\"I have locked myself away for so long.  I could not forgive him, though I knew it was the only way to free myself.  I only wish that I could have seen him again.\""])
   showMessage(e, ["Easing back in his throne, the restored Lord James Mercer submits himself to his fate.", "", "As his spirit passes, his body fades away.", "", "The crown that was upon his head clatters to the throneroom floor."])
   giveItems(e, ["Lich Crown", "Crown of Faith"])
   showMessage(e, ["With the passing of the lord of the castle the curse that was holding the ghosts prisoner here has been lifted.", "", "Although the castle is still abandoned, perhaps it can now be recovered, in time."])
   rtcastleLordFlag=2
   rtcastleLab=3
   setTag(e, "rtcastleLordFlag", rtcastleLordFlag)
   setTag(e, "rtcastleLibrary", rtcastleLordFlag)
   setTag(e, "rtcastleLab", rtcastleLab)
