#The Oracle
from eventAPI import *
from APIUtils import *
from SDLKeys import *

def fireEvent(e):
   global rtoracle
   rtoracle = getTag(e, "rtoracle")
   if (rtoracle == 1):
      askOracle(e)
   else:
      firstVisit(e)
   return 0

def firstVisit(e):
   showMessage(e, ["As you approach the dragon a robed figure appears from around the corner."])
   showPicture(e, "Alnurti")
   showMessage(e, ["\"You stand before the Great Oracle.  Seer of all the lands.\"", "", "\"You may ask of anything, but be specific or else the vision cannot form.  All questions require a tribute of 100 gold.  In advance!\""])
   showPicture(e, "Dragon_oracle")
   showMessage(e, ["The robed figure then retreats to allow you passage though he stays close enough to watch you closely.", "", "The dragon now turns it's gaze upon you.", "", "\"Come forward.\", it commands."])
   showMessage(e, ["\"The fates speak much of you.  I could sense this as you entered.  If you desire, I may peer into the threads of fate to help guide you towards your destiny.\""])
   rtoracle=1
   setTag(e, "rtoracle", rtoracle)
   askOracle(e)

def askOracle(e):
   showPicture(e, "Dragon_oracle")
   choice = optionInput(e, ["You now address the oracle.", "", "", "(A)sk about something specific", "(V)iew my future", "(L)eave"], [], [SDLK_a, SDLK_v, SDLK_l])
   if (choice == SDLK_a):
      specific(e)
   elif (choice == SDLK_v):
      viewFuture(e)
   elif (choice == SDLK_l):
      return 0

def specific(e):
   partyIdx = 0
   while (partyIdx < getPartyCount(e)):
      if(modifyGold(e, partyIdx, -100)):
         paidinFull(e)
         return 0
      partyIdx += 1
   showPicture(e, "Alnurti")
   showMessage(e, ["The robed figure steps forward", "", "\"You must pay tribute before you may ask.  Begone until you can afford the price of knowledge!\""])
   return 0

def paidinFull(e):
   answer = stringInput(e, ["\"What knowledge do you seek?\""])
#
#  People
#
   if(answer.lower() == "yeodaugh"):
      showMessage(e, ["\"He knows of much and can lead you further towards your destiny.  You may trust him in your search.\""])
   elif((answer.lower() == "taireninaugh") or (answer.lower() == "taire")):
      showMessage(e, ["\"A beautiful maiden.  Her part in your destiny is small, but she leads you to one greater.\""])
   elif(answer.lower() == "rose"):
      showMessage(e, ["A tear appears within the dragon's eye.", "", "\"A name more suiting was never known.  The fates are not always kind.\""])
   elif(answer.lower() == "argent"):
      showMessage(e, ["\"His destiny lies elsewhere.  Soon he shall seek it out.\""])
   elif((answer.lower() == "asher") or (answer.lower() == "asher inorri")):
      showMessage(e, ["\"What he has created now plagues the land.  He shall be forgotten along with his dark art.  His fault was to hesitate before seeking redemption.\""])
   elif(answer.lower() == "necrolord"):
      showMessage(e, ["\"He is a leader of forces which oppose you.\""])
   elif(answer.lower() == "alnurti"):
      if (getTag(e, "AlnurtiPlt1") == 4):
         showMessage(e, ["\"He has left to seek out new power.  You will not meet again until the fates have decided his part to play.\""])
      else:
         showMessage(e, ["\"He is one who will shape your destiny.\""])
   elif(answer.lower() == "lanutri"):
      showMessage(e, ["\"Soon you will meet, yet you will know him by another name.\""])
   elif(answer.lower() == "dorukan"):
      showMessage(e, ["\"Caught in events beyond his control.\""])
   elif(answer.lower() == "olias"):
      showMessage(e, ["\"His part to play is small.  A means to an end.\""])
   elif(answer.lower() == "almara"):
      showMessage(e, ["\"A speaker for the race of dwarves.  You will cross paths but briefly.\""])
   elif(answer.lower() == "thor"):
      if (getTag(e, "AlnurtiPlt1") == 4):
         showMessage(e, ["\"One of ambition now seeks to control the power of Thor.  The fates have not yet written this part.\""])
      else:
         showMessage(e, ["\"A god of old.  His power may yet return, but to what end?\""])
   elif(answer.lower() == "wolfdeer"):
      if (getTag(e, "WolfFlag") == 1):
         showMessage(e, ["\"Another thread of destiny is complete.  You may someday see more of the Wolfdeer.\""])
      else:
         showMessage(e, ["\"Thought to be only of legend.  The beast is held captive.\""])
   elif((answer.lower() == "philibuster") or (answer.lower() == "wolfman")):
         showMessage(e, ["\"Of no import.  A simple obstacle to overcome.\""])
   elif(answer.lower() == "harold mercer"):
      showMessage(e, ["\"A great man he was, but now no more than a memory.  Perhaps his history will become known again.\""])
   elif(answer.lower() == "nathan mercer"):
      if (getTag(e, "rtcastleLordFlag") >= 2):
         showMessage(e, ["\"His soul now rests.  No longer bound by his prideful anger, he and his brother have reconciled.  Your bravery has earned you the respect of the fates.\""])
      else:
         showMessage(e, ["\"Honesty and pride were his strength and weakness respectively.  His soul seeks rest.\""])
   elif(answer.lower() == "james mercer"):
      if (getTag(e, "rtkeepLordFlag") >= 2):
         showMessage(e, ["\"Freed from his curse, his soul now rests with that of his brother.  Together they now honor the wish of their father.\""])
      else:
         showMessage(e, ["\"An intelligence not surpased in ages, yet he was blind to the world around him.  Only in death has he found true answers.\""])
   elif((answer.lower() == "melvin") or (answer.lower() == "melvin the magnificent")):
      showMessage(e, ["\"He speaks in half-truths.  Do not take this as condemnation, but rather praise for half of what he says is indeed true.\""])
   elif(answer.lower() == "mountain"):
      if (getTag(e, "rtPOEMountain1") >= 1):
         showMessage(e, ["\"I know the one of which you speak.  The voice of Mountain is that of the Earth.\"", "", "\"Listen well to Mountain.  He will always guide you towards your destiny.\""])
      else:
         showMessage(e, ["\"Of mountains there are many.  Of which one do you speak?\""])
   elif(answer.lower() == "ocean"):
      if (getTag(e, "rtPOWOcean1") >= 2):
         showMessage(e, ["\"You have stood before Ocean.  She is the giver of life.  Be respectful to her always.\""])
      else:
         showMessage(e, ["\"There is much mystery within the ocean.  Tread lightly lest you disturb the calm waters.\""])
   elif(answer.lower() == "flame"):
      if (getTag(e, "rtPOFFlame1") >= 1):
         showMessage(e, ["\"Do not trust Flame.  It can never be completely under your control.\""])
      else:
         showMessage(e, ["\"Time is the fire in which we burn.\""])
   elif(answer.lower() == "wind"):
      if (getTag(e, "rtPOAWind1") >= 1):
         showMessage(e, ["\"You have done well.  If Wind had remained prisoner then all would have been in jeopardy.  \""])
      else:
         showMessage(e, ["\"Your destiny moves with the wind.  Do not hesitate.\""])
   elif(answer.lower() == "prince of songs"):
      showMessage(e, ["\"He is more than he appears.  He speaks for Wind and for all those who love song.\""])
   elif(answer.lower() == "tarjan"):
      showMessage(e, ["The dragon's eyes widen in fear.", "", "\"I cannot speak of such.  He is listening.\""])
   elif(answer.lower() == "elbrus"):
      showMessage(e, ["\"Once of fire, now of earth.\""])
   elif(answer.lower() == "strange man"):
      if (getTag(e, "rtetherLordFlag") == 3):
         showMessage(e, ["\"His dark work is only beginning.  The threads of fate stretch tight before being cut.\""])
      elif (getTag(e, "rtetherLordFlag") >= 4):
         showMessage(e, ["\"The end has been forestalled, but it is an inevitability that cannot be overcome.\""])
      else:
         showMessage(e, ["\"He appears as such, but he is not a man.  He is the last of a host.\""])
   elif((answer.lower() == "oracle") or (answer.lower() == "great oracle") or (answer.lower() == "you")):
      showMessage(e, ["The dragon appears to smile.", "", "\"I am exactly as I appear.  No more, no less\""])
   elif(answer.lower() == "mangar"):
      showMessage(e, ["\"A wizard of the city of Skara Brae.  He attempts to wrest control, but he does not forsee his fate.\""])
   elif(answer.lower() == "kylearan"):
      showMessage(e, ["\"Manipulative, yet he can be trusted.  He seeks to test those who approach him.\""])
   elif((answer.lower() == "destiny knight") or (answer.lower() == "the destiny knight")):
      showMessage(e, ["\"One foretold.  The knight of destiny brings order by wielding chaos.\""])
   elif(answer.lower() == "xoram"):
      showMessage(e, ["\"Appearances can be deceiving, and yet many things are exactly as they appear.  What is the lie and what is the truth?\""])
   elif((answer.lower() == "sir blackwood") or (answer.lower() == "blackwood")):
      showMessage(e, ["\"A powerful warrior in this world or any other.  What kindness is given is returned tenfold.\""])
   elif(answer.lower() == "dark one"):
      showMessage(e, ["\"An ancient tribe.  All but gone.\""])
   elif((answer.lower() == "me") or (answer.lower() == "us")):
      showMessage(e, ["\"You?  Surely you know better than all others!\""])
   elif(answer.lower() == "gnav"):
      if (getTag(e, "TotEplot") == 0):
         showMessage(e, ["\"I do not see him.\""])
      elif (getTag(e, "TotEplot") == 10):
         showMessage(e, ["\"A sad end to a sad tale.\""])
      else:
         showMessage(e, ["\"Will you redeem his kin?\""])
   elif(answer.lower() == "savah"):
      if (getTag(e, "TotEplot") == 0):
         showMessage(e, ["\"I do not see her.\""])
      elif (getTag(e, "TotEplot") == 10):
         showMessage(e, ["\"She was consumed by power and greed.\""])
      else:
         showMessage(e, ["\"A lost soul. Will you free her?\""])
   elif((answer.lower() == "blackranger") or (answer.lower() == "black ranger")):
      if (getTag(e, "kssPlot") <= 6):
         showMessage(e, ["\"Who?\""])
      else:
         showMessage(e, ["\"His heart was as black as his garb.\""])
   elif((answer.lower() == "archdruid") or (answer.lower() == "arch druid")):
      if (getTag(e, "kssAD") <= 1):
         showMessage(e, ["\"Who?\""])
      elif (getTag(e, "kssAD") <= 7):
         showMessage(e, ["\"Powerful, yet craven. His end is nigh.\""])
      else:
         showMessage(e, ["\"You were his doom.\""])
#
#  Places
#
   elif(answer.lower() == "rennibister"):
      if (getTag(e, "AlnurtiPlt1") == 4):
         showMessage(e, ["\"The city of Rennibister has been cleansed of the present threat.  With this ending a new threat has arisen to which the resolution is unknown.  Your destiny does not move towards this, yet.\""])
      else:
         showMessage(e, ["\"The great city of this area.  A rotten core still resides within.  You destiny is entangled with the fate of this place.\""])
   elif(answer.lower() == "orkney"):
      showMessage(e, ["\"The land in which you travel.\""])
   elif(answer.lower() == "green bard"):
      showMessage(e, ["\"A lair of villany and alcohol.  But then, I am being redundant.\""])
   elif(answer.lower() == "arena"):
      showMessage(e, ["\"A place to test your skill if you choose to do so.\""])
   elif(answer.lower() == "guard tower"):
      if (getTag(e, "OliasPlt1") == 6):
         showMessage(e, ["\"You have already faced the dangers within the tower and have emerged triumphant.\""])
      else:
         showMessage(e, ["\"At the highest reaches you will see battle.  The coming of light will signal the end.\""])
   elif(answer.lower() == "mage tower"):
      if (getTag(e, "AlnurtiPlt1") >= 3):
         showMessage(e, ["\"You were judged worthy.  You have reached the end of the beginning.\""])
      else:
         showMessage(e, ["\"The guardians will test you.  You shall emerge with the power of old.\""])
   elif(answer.lower() == "lair"):
      if (getTag(e, "WolfFlag") == 1):
         showMessage(e, ["\"You have bested the dangers within the lair.  The pattern of your destiny begins to take shape.\""])
      else:
         showMessage(e, ["\"The lair lies south of here.  It is home to ancient beasts.\"", "", "\"From within a voice calls out to be freed.\""])
   elif(answer.lower() == "dwarf caves"):
      showMessage(e, ["\"To the east.  A group of dwarves make this their home though it is far from the splendor of their great cities.\""])
   elif(answer.lower() == "dragon caves"):
      showMessage(e, ["\"Far to the east there lies a dwelling of my kind and kin, yet they are as different from I as are you.  The dwarves and dragons vie for control of that area.\""])
   elif(answer.lower() == "ashers tomb"):
      if (getTag(e, "ArgentPlt1") >= 4):
         showMessage(e, ["\"You actions therein have done well to heal the wounds of the land.  The wounds of the heart will take still longer to heal.\""])
      else:
         showMessage(e, ["\"The forgotten tomb is upon the western edge of the world.  Dark secrets are hidden within.\""])
   elif(answer.lower() == "elemental gallery"):
      showMessage(e, ["\"Beneath the earth.  The lock and key reside therein.  A gateway to places far distant.\""])
   elif(answer.lower() == "hedge maze"):
      showMessage(e, ["\"Once a courtyard, the resident beasts now tend to it's shifting patterns.  Do not get lost within the dangerous confines of the maze.\""])
   elif(answer.lower() == "western castle"):
      showMessage(e, ["\"At its height is was the center focus for all things concerning art, science and magic.  Since that time, much that was known was lost.\""])
   elif((answer.lower() == "eastern keep") or (answer.lower() == "great eastern keep")):
      showMessage(e, ["\"The greatest minds of the former age gathered within it's halls.  Both hero and villain have walked the corridors.  The plots hatched within have affected events to this day.\""])
   elif((answer.lower() == "crystal hall") or (answer.lower() == "crystal")):
      showMessage(e, ["\"This hall was created by the ancient dragons before The Fall.  The crystals still hold some of their power.  It is my home now until such time as I grow weary.\""])
   elif(answer.lower() == "skara brae"):
      showMessage(e, ["\"Two wizards vie for control of this city.  Some seek to break the stalemate.\""])
   elif((answer.lower() == "basement") or (answer.lower() == "the basement")):
      showMessage(e, ["\"A maze of underground passages.  Deception makes it's home within.\""])
   elif(answer.lower() == "tangramayne"):
      showMessage(e, ["\"A city of the realm.\""])
   elif(answer.lower() == "ephesus"):
      showMessage(e, ["\"A city of the realm.\""])
   elif(answer.lower() == "philippi"):
      showMessage(e, ["\"A city of the realm.\""])
   elif(answer.lower() == "colosse"):
      showMessage(e, ["\"A city of the realm.\""])
   elif(answer.lower() == "corinth"):
      showMessage(e, ["\"A city of the realm.\""])
   elif(answer.lower() == "thessalonica"):
      showMessage(e, ["\"A city of the realm.\""])
   elif(answer.lower() == "fanskars castle"):
      showMessage(e, ["\"The castle lies within the wilderness.\""])
   elif(answer.lower() == "dargoths tower"):
      showMessage(e, ["\"The tower is within the city of Philippi.\""])
   elif(answer.lower() == "oscons fortress"):
      showMessage(e, ["\"The fortress is within the city of Corinth.\""])
   elif(answer.lower() == "temple"):
      if (getTag(e, "TotEplot") == 0):
         showMessage(e, ["\"There are many of them.\""])
      elif (getTag(e, "TotEplot") == 10):
         showMessage(e, ["\"The elements have been soothed, but at terrible cost!\""])
      else:
         showMessage(e, ["\"The elements rage within. You'll have to stop their rampage.\""])
   elif((answer.lower() == "crypt") or (answer.lower() == "shoppe") or (answer.lower() == "crypt shoppe")):
      if (getTag(e, "kssCrypt") < 21):
         showMessage(e, ["\"Wait and see...\""])
      elif (getTag(e, "kssCrypt") < 50):
         showMessage(e, ["\"Where can a crypt be found, I wonder ?", "", "", "It's now open:",
                         "To see their stock,", "Thrice have to run", "Around the clock.\""])
      else:
         showMessage(e, ["\"You have already found it, haven't you?\""])
#
#  Things
#
   elif((answer.lower() == "fate") or (answer.lower() == "destiny")):
      showMessage(e, ["\"All beings have a destiny, yet not all are able to achieve such.\""])
   elif(answer.lower() == "death"):
      showMessage(e, ["\"The consequence of life.\""])
   elif(answer.lower() == "life"):
      showMessage(e, ["\"The purpose of the universe.\""])
   elif(answer.lower() == "time"):
      showMessage(e, ["\"Time is the fire in which we burn.\""])
   elif(answer.lower() == "future"):
      showMessage(e, ["\"Always in motion is the future.\""])
   elif(answer.lower() == "help"):
      showMessage(e, ["\"You may gain knowledge within this hall, but it is your decision on how to use such.\""])
   elif(answer.lower() == "devil whiskey"):
      showMessage(e, ["\"Smokey with a slight medicinal aftertaste.\""])
   elif((answer.lower() == "damn") or (answer.lower() == "shit") or (answer.lower() == "fuck") or (answer.lower() == "motherfucker")  or (answer.lower() == "fuck you") or (answer.lower() == "ass") or (answer.lower() == "asshole") or (answer.lower() == "dick") or (answer.lower() == "cunt") or (answer.lower() == "shithead") or (answer.lower() == "son of a bitch") or (answer.lower() == "bitch")):
      showMessage(e, ["\"I've heard better...\""])
      choosetoDie(e)
      return 0
   elif((answer.lower() == "treasure") or (answer.lower() == "gold")):
      showMessage(e, ["\"There is much of value to be found.  Be it riches, knowledge or the respect of others.\""])
   elif(answer.lower() == "necromancy"):
      showMessage(e, ["\"A pitiful use for such great magic.  Those who practice the art have doomed themselves, though they cannot see it.\""])
   elif(answer.lower() == "dragon"):
      showMessage(e, ["\"You speak with one.\""])
   elif(answer.lower() == "elemental heart"):
      if ((getTag(e, "rtetherLordFlag") >= 3) or (getTag(e, "rtpillar") > 1)):
         showMessage(e, ["\"The power of elements is returned to it's place.\""])
      else:
         showMessage(e, ["\"Chaos trapped within order.\""])
   elif((answer.lower() == "druids challenge") or (answer.lower() == "druids") or (answer.lower() == "challenge")):
      if (getTag(e, "kssPlot") == 0):
         showMessage(e, ["The dragon appears to smile, as far as you can tell.","","\"The clue is gibberish, which is the central problem.\""])
      else:
         showMessage(e, ["\"Deception and betrayal.\""])
   elif(answer.lower() == "password"):
      if (getTag(e, "kssCrypt") < 50):
         showMessage(e, ["\"So many of them...\""])
      elif (getTag(e, "kssCrypt") < 55):
         showMessage(e, ["\"Garzz only knows; you'd have to be omniscient to discern it.\""])
      else:
         showMessage(e, ["\"It's \'Gwenhyfer\'.\""])
   elif(answer.lower() == "omniscient"):
      if (getTag(e, "kssCrypt") == 50):
         choice = optionInput(e, ["\"I am, of course.", "", "For example, I know Garzz's password, and can reveal it to you for the paltry sum of 100 000 gold.",
                                  "Are you interested?\""], ["(Y)es or (N)o"], [SDLK_y, SDLK_n])
         if (choice == SDLK_n):
            showMessage(e, ["\"My offer stands.\""])
         else:
            password(e)
      else:
         showMessage(e, ["\"I am.\""])
   else:
      showMessage(e, ["\"I have no answer for you.\""])
   askOracle(e)


def viewFuture(e):
   global futureSays
   futureSays=0
   if ((getTag(e, "rtHedgeFountainFlag") >= 1) and (getTag(e, "rtkeepLordFlag") <= 2)):
      showMessage(e, ["\"I sense that a great journey has begun in lands to the north.  You must seek to free those trapped by pride and regret.  This task will test you to the utmost, but the rewards are great.\""])
      futureSays=1
   if ((getTag(e, "rtetherLordFlag") >= 1) and (getTag(e, "rtetherLordFlag") <= 3)):
      showMessage(e, ["\"I see you travel across the realms of all the elements.\"", "", "\"Friend and foe shall find you.  Events within the hidden realms can influence those within this world.  This end I cannot see, for it is clouded by another.\""])
      futureSays=1
   if ((getTag(e, "ArgentPlt1") >= 1) and (getTag(e, "ArgentPlt1") < 4)):
      showMessage(e, ["\"Your destiny has intertwined with the flower and the earth.  The fate of one cannot be avoided, and the fate of the other is not yet foretold.  Seek the source within the tomb.\""])
      futureSays=1
   if ((getTag(e, "AlnurtiPlt1") == 0) and (getTag(e, "YeodPlt") >= 4)):
      showMessage(e, ["\"One old and wise speeds you towards a confrontation.  Tasks must be completed before entry is gained.  The threat awaits within the tower of the guards.\""])
      futureSays=1
   if ((getTag(e, "AlnurtiPlt1") >= 1) and (getTag(e, "AlnurtiPlt1") < 4)):
      showMessage(e, ["\"I see a new thread entering the pattern of your fate.  A hooded figure approaches with a request, sending you to the end of one journey and the beginning of another.  The spectres of the tower will come to you with warning.\""])
      futureSays=1
   if ((getTag(e, "a") >= 1) and (getTag(e, "bwfinal") != 9)):
      showMessage(e, ["\"A spirit has asked for vengeance.  Plots within plots.  There is a choice to be made at the end.\""])
      futureSays=1
   if (getTag(e, "WolfFlag") != 1):
      showMessage(e, ["\"Legend calls out to you from the lair to the south.  Go there and see what few others have seen.\""])
      futureSays=1
   if (getTag(e, "TotEplot") == 0):
      showMessage(e, ["\"You will meet a father and child, lost to each other. Will you reunite them?\""])
      futureSays=1
   if (getTag(e, "kssPlot") == 0):
      showMessage(e, ["\"Far to the east, mist conceals a secret. Help and betrayal await.\""])
      futureSays=1
   if (futureSays == 0):
      showMessage(e, ["\"There is naught that I can foresee at this time.\""])
   askOracle(e)


def choosetoDie(e):
   showMessage(e, ["The dragon raises it's head and draws a deep breath.", "", "As a great flame engulfs you, you reflect upon your poor choice of words."])
   partyIdx = 0
   while (partyIdx < getPartyCount(e)):
      modifyHP(e, partyIdx, -50000)
      partyIdx += 1

def password(e):
   partyIdx = 0
   while (partyIdx < getPartyCount(e)):
      if(modifyGold(e, partyIdx, -100000)):
            showMessage(e, ["\"Garzz's password is \'Gwenhyfer\'.\""])
            setTag(e, "kssCrypt", 55)
            return 0
      partyIdx += 1
   showMessage(e, ["\"Return when you can pay for valuable information.\""])
   return 0

