#castle librarian
from eventAPI import *
from APIUtils import *

rtcastleLibrary=0

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



def librarian(e):
   showMessage(e, ["While searching the stacks of books, you feel a sudden chill in the air.", "", "A ghost appears and begins to speak."], optionInput)
   showPicture(e, "Aldorik")
   showMessage(e, ["\"My goodness!  It has been so long since anyone has visited.\"", "", "The ghost appears to chuckle to itself.", "", "\"I had thought that perhaps the world had forgotten how to read.\""])
   showMessage(e, ["\"Do not be alarmed.  I am just an old librarian.  Perhaps my current visage does cause some concern among the living, but my only concern anymore is the knowledge within these books.\""])
   showMessage(e, ["\"Oh, but we have a wonderful library here.\"", "", "\"I have spent many long hours cataloging everything.  All you need do is request a volume from the master index and I will bring to you.\""])
   showMessage(e, ["The spirit of the librarian wavers slightly.  You think that this may be a sign of distress."])
   showMessage(e, ["\"Are you at all familiar with the history of this castle?\"", "", "\"Perhaps you would take time to read of the great and tragic history of the Lord Mercer and his sons?\""])
   showMessage(e, ["\"It is not a happy tale, but it is one that you must read for both your sake and mine.\""])
   showMessage(e, ["The spirit returns to cataloging the books."])
   rtcastleLibrary=1
   setTag(e, "rtcastleLibrary", rtcastleLibrary)
   return 1


def returnVisit(e):
   rtcastleLab=0
   rtalchemyBook=0
   rtcastleLab = getTag(e, "rtcastleLab")
   rtalchemyBook = getTag(e, "rtalchemyBook")
   showPicture(e, "Aldorik")
   showMessage(e, ["The ghost appears to be cataloging the many books found within this library.", "", "As you approach, the librarian looks in your direction and gives you a slight smile."])
   if ((firstHasItem(e, "Alchemy Textbook") >= 0) and (rtcastleLab >= 2) and (rtalchemyBook == 0)):
      showMessage(e, ["You hand the worn alchemy textbook to the librarian.", "", "\"Hmm, a first year edition?  Not in good shape either.  Use this second edition.  It is much more informative.\""])
      showMessage(e, ["The librarian takes from you the old, worn textbook and pulls a much newer looking volume from the shelf.  The title reads 'Beginner Metalurgical Alchemy, Second edition.'"])
      rtalchemyBook=1
      setTag(e, "rtalchemyBook", rtalchemyBook)
   else:
      showMessage(e, ["\"Please, just request any volume from the master index and I will be most happy to retrieve it for you.\""])
   return 1
