#castle librarian
from eventAPI import *
from APIUtils import *

rtcastleLab=0

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

def firstVisit(e):
      showMessage(e, ["There is a strange man wearing a multicolored robe here.", "", "He seems surprised to see you, but he quickly recovers and assumes an air of cold detachment."], optionInput)
      showPicture(e, "Summoner")
      showMessage(e, ["\"I am a busy man.  Please state your business\"", "", "He seems less friendly and helpful than you had hoped.", "", "\"Do you even know why you are here?  Are you just stumbling around in the dark?\""])
      showMessage(e, ["\"I have no time for vistors.  I must find a way to unmake the barrier.  Kill the guardian, remove the barrier.  But I can't kill it.  Why would I even want to kill it?  After all, I'm the one who made it!\""])
      showMessage(e, ["\"Oh, first it's all 'Make something to protect the barrier' and 'Make something that will last.'  But then it's all 'Remove the barrier' and 'Help! This thing is killing us!'\""])
      showMessage(e, ["\"Well, I made it to last.  Creating a golem isn't easy you know!  You could use whatever is handy, but those will never last.  No, I created a guardian, just like I was told to do.\""])
      showMessage(e, ["\"I told them what it would be, but they never listen.  Don't listen to the crazy old man.  He's just an alchemist wasting his life away in the laboratory.  Well?  Who saved them all?  It sure wasn't the librarian!\""])
      showMessage(e, ["\"I sent it away to the top of the south tower.  It's not going anywhere now.  So you go tell them to just leave it alone until I have time to figure it all out.\""])
      showMessage(e, ["The 'alchemist' then dismisses you.  You wonder if all of his conversations are so one-sided."])
      rtcastleLab=1
      setTag(e, "rtcastleLab", rtcastleLab)

def returnVisit(e):
   if ((firstHasItem(e, "Alchemy Textbook") >= 0) and (rtcastleLab == 1)):
      giveTextbook(e)
   else:
      showPicture(e, "Summoner")
      showMessage(e, ["\"Go on, it's locked up in the south tower.  Don't blame me if it kills you.  I warned you, I did!\""])


def giveTextbook(e):
   showPicture(e, "Summoner")
   showMessage(e, ["As you approach the alchemist he frowns at you and begins to speak."])
   showMessage(e, ["You quickly show the alchemy textbook that you found in the hedge maze.  Luckily, this stops him before he begins his speech again."])
   showMessage(e, ["The alchemist casts another frown at you.", "", "\"What?  It's just an old first year textbook.\""])
   showMessage(e, ["\"Look, it's very simple and if you had ever bothered to study you would already know this.\"", "", "\"See this passage?  You can bond blackmetal to enchanted armor and weapons by using sufficient amounts of power.  We use such simple tests to grade our first year students.  You can wear the armor over dragonhide for the best protection.  The guards just love the stuff.\""])
   showMessage(e, ["\"You had better take this to the librarian and exchange it for the second edition or you won't be ready for the exams.\""])
   showMessage(e, ["And with that, you are again dismissed."])
   rtcastleLab=2
   setTag(e, "rtcastleLab", rtcastleLab)
   return 0