#dwarves and elemental fight
from eventAPI import *
from APIUtils import *

rtfollowdwarf=0

def fireEvent(e):
   global rtfollowdwarf
   rtfollowdwarf = getTag(e, "rtfollowdwarf")
   if (rtfollowdwarf == 4):
      getReady(e)
   else:
      return 1

def getReady(e):
   showMessage(e, ["You stop near the entrance to a large cavern."])
   showPicture(e, "Dwarf_Male03")
   showMessage(e, ["\"We are near the portal.  I can sense it.\""])
   showPicture(e, "Dwarf_Male04")
   showMessage(e, ["Bron looks ahead into the cavern.", "", "\"Too many in the way.  We'd never survive a run straight to the portal.  Nothing left to do but fight.\""])
   clearPicture(e)
   showMessage(e, ["You peer into the room to get a good count of your opposition.  The cavern seems empty until you notice the hundreds of large rocks scattered about.  Each one is an elemental and some are quite large."])
   showMessage(e, ["\"Gred and I will try to hold as many of them back as possible while you get the ones that make it through.  Uh, Sten, you do whatever it is that you do.\""])
   showPicture(e, "Dwarf_Male03")
   showMessage(e, ["\"It's magic, Bron.  Try not to stand directly in front of me this time.\""])
   clearPicture(e)
   showMessage(e, ["Bron gives a quick signal then he and Gred charge into the room.  The elementals do not appear surprised and they immediately respond.", "", "Sten chants and a number of fireballs zip past you and into the room."])
   showPicture(e, "Dwarf_Male04")
   showMessage(e, ["\"Here they come.\" says Bron.", "", "Elemetals crash into the dwarves while fireballs continue to zip into the room, destroying many of the rock beasts."])
   clearPicture(e)
   showMessage(e, ["Finally the numbers are too great and elementals run past the dwarves to confront you."])
   fightThem(e)

def fightThem(e):
   combatRet = combat(e, [("Stone Beast", 40, 10, 10), ("Earth Elemental", 10, 10, 20), ("Stone Golem", 34, 10,10)])
   if (combatRet == 1):
      wonFight(e)
   elif (combatRet == 3):
      lostFight(e)
   else:
      ranAwayFight(e)

def wonFight(e):
   showMessage(e, ["Finally the elemental beasts have had enough and the remaining foes flee into the rocks."])
   showPicture(e, "Dwarf_Male02")
   showMessage(e, ["\"I think I lost another tooth!\", complains Gred."])
   showPicture(e, "Dwarf_Male04")
   showMessage(e, ["\"Not a bad fight, I think I may have beaten my old record!\"", "", "Bron claps you on the back and smiles.", "", "\"Excellent work.  You have the makings of a fine dwarf!\""])
   showMessage(e, ["\"There's the portal ahead, just as it should be.\"", "", "\"Thank ye for yer help.  We could not possibly have made it out of here without ye.\""])
   showMessage(e, ["Everyone takes turns shaking hands and saying goodbyes then the dwarves turn to leave.", "", "They move to a spot near the back of the caven and pause briefly to wave goodbye one last time.", "", "Stepping forward, they disappear into thin air."])
   rtfollowdwarf = 5
   setTag(e, "rtfollowdwarf", rtfollowdwarf)

def lostFight(e):
   showMessage(e, ["An unstoppable army of elementals crush you undernearth."])

def ranAwayFight(e):
   showMessage(e, ["You turn to run, but there are far too many of the elementals for you to escape."])
   fightThem(e)

