#castle level 3 fight #1

from eventAPI import *
from APIUtils import *

rtCastle3Flag1=0
returnValue=1

def fireEvent(e):
   global rtCastle3Flag1
   global returnValue
   rtCastle3Flag1 = getTag(e, "rtCastle3Flag1")
   if (rtCastle3Flag1 == 4):
      return 1
   elif (rtCastle3Flag1 == 3):
      tooLate(e)
   elif (rtCastle3Flag1 == 2):
      lookClosely(e)
   elif (rtCastle3Flag1 == 1):
      returnVisit(e)
   else:
      firstVisit(e)
   return returnValue

def firstVisit(e):
   global rtCastle3Flag1
   global returnValue
   if (poseYesNo(e, ["There is a painting of a strange creature here.  You feel that as you walk past, the creature is watching your movement.", "", "Do you examine the painting?"])):
      rtCastle3Flag1 = 2
      setTag(e, "rtCastle3Flag1", rtCastle3Flag1)
      returnValue=0
   else:
      rtCastle3Flag1 = 1
      setTag(e, "rtCastle3Flag1", rtCastle3Flag1)

def returnVisit(e):
   global returnValue
   if (poseYesNo(e, ["You catch movement out of the corner of your eye, but there does not appear to be anything there.  Just that grotesque painting.", "", "Do you take a closer look at the painting?"])):
      rtCastle3Flag1 = 2
      setTag(e, "rtCastle3Flag1", rtCastle3Flag1)
      returnValue=0
   else:
      returnValue=1

def lookClosely(e):
   global rtCastle3Flag1
   global returnValue
   showMessage(e, ["You see nothing out of the ordinary.  It is just a painting of a gigantic lizard... err... bird creature.  Obviously a creation of the painter's dark imagination."])
   rtCastle3Flag1 = 3
   setTag(e, "rtCastle3Flag1", rtCastle3Flag1)
   returnValue=1

def tooLate(e):
   showMessage(e, ["You feel a slight movement and realize to your horror that you are inside the painting!", "", "This creature looks much worse up close and personal."])
   fightThem(e)

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

def wonFight(e):
   global rtCastle3Flag1
   showMessage(e, ["You have defeated the basilisk and escaped the magical trap!  You no longer feel that the creature is watching you.  From now on, this will only be an ordinary painting."])
   rtCastle3Flag1 = 4
   setTag(e, "rtCastle3Flag1", rtCastle3Flag1)

def lostFight(e):
   showMessage(e, ["Unable to escape the trap within this painting, you are now a permanent fixture for others to gaze upon."])

def ranAwayFight(e):
   showMessage(e, ["You struggle to escape the trap.  Though you can almost break free, the magic of the painting draws you back in."])
   fightThem(e)
