#defend boss fight
from eventAPI import *
from APIUtils import *

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

def firstVisit(e):
   showMessage(e, ["You approach the Breach within the wall."])
   showPicture(e, "Orc")
   showMessage(e, ["There appears to be a large orc yelling orders to the goblin and kobold invaders.", "", "Beside the orc stands a pair of the ugliest ogres that you have ever seen."])
   showMessage(e, ["\"Send the reinforcements to the south eastern part of the city and push towards the gates!\""])
   showMessage(e, ["\"Errrg! Ubuk! I want you to find that elf-woman and bring me her head!\""])
   showPicture(e, "Ogre")
   showMessage(e, ["Errrg:","\"Want to eat the elf. Elf better than kobold. Kobold taste bad.\"", "", "Ubuk:", "*pfffffftttt"])
   showMessage(e, ["The ogres see you and one points a thick finger in your direction."])
   showMessage(e, ["Errrg:","\"That the elf woman?\"", "", "Ubuk:", "*pfffffftttt"])
   showPicture(e, "Orc")
   showMessage(e, ["\"No you idiots! Those are just more fools looking for a place to die.\"", "", "\"Well, what are you waiting for? Go smash them!\""])
   showPicture(e, "Ogre")
   showMessage(e, ["Errrg:","\"guh... okay!\"", "", "Ubuk:", "*pfffffftttt"])
   fightThem(e)

def fightThem(e):
   showMessage(e, ["Your enemies rush to attack you."])
   combatRet = combat(e, [("Ogre", 2, 0, 10), ("Orc", 1, 0, 10), ("Goblin", 5, 2, 10), ("Kobold", 4, 2, 10)])
   if (combatRet == 1):
      wonFight(e)
   elif (combatRet == 3):
      lostFight(e)
   else:
      ranAwayFight(e)

def wonFight(e):
   clearPicture(e)
   showMessage(e, ["Your foes fall before you."])
   showMessage(e, ["Around you, the city guard is pushing back the goblin invaders.", "", "Without their leader, the forces outside of the breach break and flee."])
   showMessage(e, ["A contingent of guards rushes into the breach to finish off the remaining enemies. The city has been saved, but you wonder at the cost."])
   showMessage(e, ["You lean against a wall to rest. Your arms are tired from the fighting and you bear numerous cuts."])
   showPicture(e, "Human_Male06")
   showMessage(e, ["\"Get those bodies cleared away and bring in the engineers! We need that hole patched before nightfall!\""])
   showMessage(e, ["You motion to the captain and he responds in kind."])
   showMessage(e, ["\"Head back to the barracks and see the priests on duty there.\"", "", "You nod at the captain, and slowly work your way back to the barracks for healing."])
   setTag(e, "rtDefendFlag1", 1)
   setExit(e, "maps/renibister.cfg", 22, 22, 270)

def lostFight(e):
   showMessage(e, ["You have fought bravely, but your battle is now over."])

def ranAwayFight(e):
   showMessage(e, ["As you flee you can see more goblins entering through the breach. The city will fall unless the goblin reinforcements can be kept out of the city."])
   setTag(e, "lFlagU", 1)