#keep level 4 fight #2
from eventAPI import *
from APIUtils import *

rtKeep4Flag2=0

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

def firstVisit(e):
   showMessage(e, ["You find a lone goblin hiding up here."], optionInput)
   showPicture(e, "Goblin")
   showMessage(e, ["\"No!  No hurt!  I no fight you!\""])
   showMessage(e, ["\"I escape from cages below.  Run up here to hide from ghosts.  No hurt, I just hide.\""])
   if (poseYesNo(e, ["Will you spare this creature?"])):
      giveMessage(e)
   else:
      showMessage(e, ["The Goblin wails at the top of it lungs.", "", "\"I said no hurt!\""])
      showMessage(e, ["As it continues it's wailing it grows to an enormous size."], optionInput)
      fightThem(e)

def giveMessage(e):
   global rtKeep4Flag2
   showMessage(e, ["\"Oh good!  I so happy I not hurt!\"", "", "\"I tell you secret now, make you happy, too.\""])
   showMessage(e, ["\"I see other place down in ground.  They think it locked, but I know secret magic!\""])
   showMessage(e, ["\"Here, you take this.  It tell secret word.  Go say word and you can go down into ground.\""])
   showMessage(e, ["The goblin hands you a faded and rather sticky note."])
   showMessage(e, ["\"You nice and you get reward!  You get one hunderrrr...  one hunnnnderrrerrr...\""])
   showMessage(e, ["\"You gets lots of experience reward!\""])
   showMessage(e, ["the goblin scurries away.  Probably off to find a new hiding place."])
   for partyIdx in range(getPartyCount(e)):
      modifyXP(e, partyIdx, 100000)
   giveItems(e, ["Goblin Note"])
   rtKeep4Flag2 = 1
   setTag(e, "rtKeep4Flag2", rtKeep4Flag2)

def fightThem(e):
   combatRet = combat(e, [("Giant Goblin", 1, 0, 10)])
   if (combatRet == 1):
      wonFight(e)
   elif (combatRet == 3):
      lostFight(e)
   else:
      ranAwayFight(e)

def wonFight(e):
   global rtKeep4Flag2
   showMessage(e, ["The giant goblin gives one final wail and collapses."])
   showMessage(e, ["On the corpse you find a faded and rather sticky note."])
   giveItems(e, ["Goblin Note"])
   rtKeep4Flag2 = 1
   setTag(e, "rtKeep4Flag2", rtKeep4Flag2)

def lostFight(e):
   showMessage(e, ["Mercy is often its own reward."])

def ranAwayFight(e):
   global rtKeep4Flag2
   showMessage(e, ["\"NO!  YOU TRY HURT!  I SMASH YOU!\""], optionInput)
   fightThem(e)
