#plane of water - the kraken
from eventAPI import *
from APIUtils import *

rtpowaterFlag1 = 0
rtPOWOcean1 = 0

def fireEvent(e):
   global rtpowaterFlag1
   global rtPOWOcean1
   rtpowaterFlag1 = getTag(e, "rtpowaterFlag1")
   rtPOWOcean1 = getTag(e, "rtPOWOcean1")
   if (rtpowaterFlag1 == 1):
      return 1
   elif (rtPOWOcean1 == 3):
      callStorm(e)
   else:
      return 1


def callStorm(e):
   showMessage(e, ["You stare out over the southern peninsula and across the endless waters.  Here is where Ocean has told you to speak her daughter's name."])
   answer = stringInput(e, ["What is the word that you will speak?"])
   if(answer.lower() != "storm"):
      wrongAnswer(e)
   else:
      correctAnswer(e)

def wrongAnswer(e):
   showMessage(e, ["Nothing happens.  Perhaps you spoke incorrectly."])
   return 0

def correctAnswer(e):
   playSpecAudio(e, "Thunder")
   showMessage(e, ["As you speak the name of Storm, there is a clash of thunder and the waters begin to churn violently."])
   showPicture(e, "Beholder")
   showMessage(e, ["A great beast appears from the water."])
   fightThem(e)

def fightThem(e):
   stopSpecAudio(e)
   combatRet = combat(e, [("Kraken", 1, 0, 10)])
   if (combatRet == 1):
      wonFight(e)
   elif (combatRet == 3):
      lostGuardianFight(e)
   else:
      ranAwayGuardianFight(e)

def wonFight(e):
   global rtpowaterFlag1
   showMessage(e, ["With a quick cut, you remove one of the fallen beast's eyes."])
   giveItems(e, ["Kraken Eye"])
   showMessage(e, ["The beast appears to still be alive, though wounded.", "", "The Kraken sinks back into the water to escape you."])   
   rtpowaterFlag1 = 1
   setTag(e, "rtpowaterFlag1", rtpowaterFlag1)

def lostGuardianFight(e):
   showMessage(e, ["You are unable to defeat the Kraken and it drags you to your death in the cold water."])

def ranAwayGuardianFight(e):
   showMessage(e, ["You are able to escape, but feel ashamed at your cowardice."])
