#giant spider fight
from eventAPI import *
from APIUtils import *

bwspiders=0

def fireEvent(e):
   global bwspiders
   bwspiders = getTag(e, "bwspiders")
   if (bwspiders == 1):
      return 1
   else:
      showMessage(e, ["Cobwebs litter the room. Something moves in the distance."], optionInput)
   fightThem(e)
   if (bwspiders == 1):
      return 1
   else:
      return 0

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

def wonFight(e):
   global bwspiders
   showMessage(e, ["You wade through the bodies of the fallen spiders."])
   bwspiders = 1
   setTag(e, "bwspiders", bwspiders)

def lostFight(e):
   showMessage(e, ["The spiders drag your corpses away."])

def ranAwayFight(e):
   global bwspiders
   showMessage(e, ["You run as quickly as possible and escape battle."])
   bwspiders = 0
   setTag(e, "bwspiders", bwspiders)
   setExit(e, "maps/bwquadrant1.cfg", 30, 14, 0)