#eastern keep lord
from eventAPI import *
from APIUtils import *

rtkeepLordFlag = 0
rtcastleLordFlag = 0

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

def getCrown(e):
   global rtkeepLordFlag
   showMessage(e, ["You approach the throne."], optionInput)
   showPicture(e, "Landvaettir")
   showMessage(e, ["You find yourself before an ancient and pitiful figure."])
   showMessage(e, ["\"So, he has sent you to do what he can no longer do himself.\""])
   showMessage(e, ["\"He does not understand.  I cannot be slain by your hand.  Now, only he has the power to do so.  Yet, he cannot leave his castle and I cannot leave mine.  We are both bound, never to be freed from this curse.\""])
   showMessage(e, ["The lich reaches up and removes the crown from his head."])
   showMessage(e, ["\"In my arrogance, I sought to cure death itself.  He could not be made to understand my ambition.  Even I did not fully understand that which I sought.\""])
   showMessage(e, ["You can feel the sorrow emanating from the figure.  If it were possible, you know that it would be crying"])
   showMessage(e, ["\"He will want this.\"", "", "The lich king hands you his crown", "", "\"I no longer want it.  I only wish for him to forgive me.  I searched for life and found only misery and regret.  He has sealed away his emotions and now it is too late.  His only thought is to punish me for my crimes.  I have cursed the both of us forever.\""])
   showMessage(e, ["\"Take this and go.  I wish to be left alone in my misery.\""])
   giveItems(e, ["Lich Crown"])
   rtkeepLordFlag = 1
   setTag(e, "rtkeepLordFlag", rtkeepLordFlag)

def returnVisit(e):
   showPicture(e, "Landvaettir")
   showMessage(e, ["You approach the thone of the lord of the keep.", "", "\"Go away.  For my betrayal I deserve to be alone.\""], optionInput)

def lastVisit(e):
   global rtkeepLordFlag
   showMessage(e, ["You once again approach the throne of the Lich King."], optionInput)
   showPicture(e, "Landvaettir")
   showMessage(e, ["\"I did not expect this.\"", "", "The ancient figure shows you a cracked smile.", "", "\"Was it the thought of my death that finally broke him?\""])
   showMessage(e, ["\"I believed that he had removed all of his emotion for me.  I only longed to tell him that I had been wrong.  Now, I think that he would have forgiven me had I been able to speak to him again.\""], optionInput)
   showMessage(e, ["\"You have helped us both.  I think that now I will choose to join with my brother again.  We were not meant to live forever.  That is the truth that I discovered.\""], optionInput)
   showMessage(e, ["With a final breath, the ancient king settles back onto the throne.  The corpse crumbles to dust."], optionInput)
   for partyIdx in range(getPartyCount(e)):
      modifyXP(e, partyIdx, 100000)
   showMessage(e, ["Each member of the party recieves an experience bonus."])
   rtkeepLordFlag = 2
   setTag(e, "rtkeepLordFlag", rtkeepLordFlag)
