#plane of fire Flame encounter
from eventAPI import *
from APIUtils import *

rtPOFFlame1 = 0

def fireEvent(e):
   global rtPOFFlame1
   rtPOFFlame1 = getTag(e, "rtPOFFlame1")
   if ((rtPOFFlame1 == 0) or (rtPOFFlame1 == 2)):
      return 1
   else:
      firstVisit(e)
   return 1

def firstVisit(e):
   showMessage(e, ["You follow Flame to the southern end of the rocky plateau.  There, Flame directs you to a small pile of treasure.", "", "These items only still exist because they would not immediatly burn from Flame's touch."])
   showPicture(e, "Fire_Elemental")
   showMessage(e, ["#4\"Take the stone which contains the very heart of elemental force, but take only the stone.  The rest is mine.\""])
   showMessage(e, ["You reach to take the object, and suddenly realize that Flame has blocked your exit from this area.", "", "You turn to face flame and he laughs at his betrayal."])
   showMessage(e, ["#4\"Did you think I would give you what is mine?  You have only given yourself to me!  Now you shall fuel MY desires!\""])
   hasEye = 0
   if (firstHasItem(e,"Kraken Eye") >= 0):
      hasEye = 1
   if (hasEye):
      fightThem(e)
   else:
      showMessage(e, ["Laughing, Flame directs his wrath towards you."])
      showMessage(e, ["You are unable to withstand the intense heat from Flame, and you perish in fire."])
      partyIdx = 0
      while (partyIdx < getPartyCount(e)):
         modifyHP(e, partyIdx, -30000)
         partyIdx += 1
      return 1


def fightThem(e):
   showPicture(e, "Fire_Elemental")
   showMessage(e, ["Flame directs his wrath towards you, but the fires do not consume your flesh.", "", "The eye of the kraken begins to smolder and steam, absorbing the fires that would surely kill you otherwise."])
   showMessage(e, ["#4\"Curse Ocean, she has protected you!  You have released Wind from his prison and raised Ocean to aid you, but you shall still feel my wrath!\""])
   combatRet = combat(e, [("Flame", 1, 0, 10)])
   if (combatRet == 1):
      wonFight(e)
   elif (combatRet == 3):
      lostFight(e)
   else:
      ranAwayFight(e)


def wonFight(e):
   showMessage(e, ["With a final blow, the fire being disappears.", "", "The great heat disipates and the fires lessen, but do not extinguish."])
   showMessage(e, ["The eye of the Kraken has been consumed by the fires, but it has protected you from Flame's wrath.  You brush the remaining ashes from you hands.", "", "You have defeated Flame, but you have not destroyed him.  There is no doubt that he will someday return."])
   showMessage(e, ["The treasure here has been destroyed in the battle, but the elemental stone remains."])
   clearPicture(e)
   holder = firstHasItem(e, "Kraken Eye")
   removeItem(e, holder, "Kraken Eye")
   giveItems(e, ["Elemental Heart"])
   showMessage(e, ["You grasp the elemental object carefully.  It is still searing to unprotected skin and you carefully pack it away for your return to the empty space where the strange man awaits."])
   rtPOFFlame1 = 2
   setTag(e, "rtPOFFlame1", rtPOFFlame1)

def lostFight(e):
   showMessage(e, ["The eye of the kraken is now completely consumed by the fires.  With your protection gone, you are destroyed by the power of Flame."])

def ranAwayFight(e):
   showMessage(e, ["You escape has been blocked by Flame.  The kracken eye continues to smolder and will eventually be consumed.  You must defeat Flame before it is too late."])
   fightThem(e)
