#castle basement switch #5 - master switch
from eventAPI import *
from APIUtils import *

rtcastle0switch1 = 0
rtcastle0switch2 = 0
rtcastle0switch3 = 0
rtcastle0switch4 = 0
rtcastle0North = 0
rtcastle0West = 0
rtcastle0South = 0
rtcastle0East = 0
rtcastle0complete = 0

def fireEvent(e):
   global rtcastle0switch1
   global rtcastle0switch2
   global rtcastle0switch3
   global rtcastle0switch4
   rtcastle0switch1 = getTag(e, "rtcastle0switch1")
   rtcastle0switch2 = getTag(e, "rtcastle0switch2")
   rtcastle0switch3 = getTag(e, "rtcastle0switch3")
   rtcastle0switch4 = getTag(e, "rtcastle0switch4")
   if (poseYesNo(e, ["The floor beneath your feet contains a white orb which gives slightly when you step on it.", "", "Do you push the floor switch?"])):
      checkSwitch(e)
   return 0

def checkSwitch(e):
   if ((rtcastle0switch1 == 0) and (rtcastle0switch2 == 0) and (rtcastle0switch3 == 5) and (rtcastle0switch4 == 4)):
      northopen(e)
   elif ((rtcastle0switch1 == 0) and (rtcastle0switch2 == 4) and (rtcastle0switch3 == 8) and (rtcastle0switch4 == 0)):
      eastopen(e)
   elif ((rtcastle0switch1 == 6) and (rtcastle0switch2 == 4) and (rtcastle0switch3 == 9) and (rtcastle0switch4 == 9)):
      westopen(e)
   elif ((rtcastle0switch1 == 1) and (rtcastle0switch2 == 1) and (rtcastle0switch3 == 1) and (rtcastle0switch4 == 5)):
      southopen(e)
   elif ((rtcastle0switch1 == 0) and (rtcastle0switch2 == 0) and (rtcastle0switch3 == 0) and (rtcastle0switch4 == 0)):
      openall(e)
   else:
      showMessage(e, ["Nothing happens."], optionInput)


def eastopen(e):
   rtcastle0North = 0
   rtcastle0West = 0
   rtcastle0South = 0
   rtcastle0East = 1
   setTag(e, "rtcastle0North", rtcastle0North)
   setTag(e, "rtcastle0West", rtcastle0West)
   setTag(e, "rtcastle0South", rtcastle0South)
   setTag(e, "rtcastle0East", rtcastle0East)
   showMessage(e, ["CLICK"], optionInput)

def westopen(e):
   rtcastle0North = 0
   rtcastle0West = 1
   rtcastle0South = 0
   rtcastle0East = 0
   setTag(e, "rtcastle0North", rtcastle0North)
   setTag(e, "rtcastle0West", rtcastle0West)
   setTag(e, "rtcastle0South", rtcastle0South)
   setTag(e, "rtcastle0East", rtcastle0East)
   showMessage(e, ["CLICK"], optionInput)


def northopen(e):
   rtcastle0North = 1
   rtcastle0West = 0
   rtcastle0South = 0
   rtcastle0East = 0
   setTag(e, "rtcastle0North", rtcastle0North)
   setTag(e, "rtcastle0West", rtcastle0West)
   setTag(e, "rtcastle0South", rtcastle0South)
   setTag(e, "rtcastle0East", rtcastle0East)
   showMessage(e, ["CLICK"], optionInput)


def southopen(e):
   rtcastle0North = 0
   rtcastle0West = 0
   rtcastle0South = 1
   rtcastle0East = 0
   setTag(e, "rtcastle0North", rtcastle0North)
   setTag(e, "rtcastle0West", rtcastle0West)
   setTag(e, "rtcastle0South", rtcastle0South)
   setTag(e, "rtcastle0East", rtcastle0East)
   showMessage(e, ["CLICK"], optionInput)


def openall(e):
   global rtcastle0altar1
   global rtcastle0altar2
   global rtcastle0altar3
   global rtcastle0altar4
   global rtcastle0complete
   rtcastle0altar1 = getTag(e, "rtcastle0altar1")
   rtcastle0altar2 = getTag(e, "rtcastle0altar2")
   rtcastle0altar3 = getTag(e, "rtcastle0altar3")
   rtcastle0altar4 = getTag(e, "rtcastle0altar4")
   if ((rtcastle0altar1 == 2) and (rtcastle0altar2 == 2) and (rtcastle0altar3 == 2) and (rtcastle0altar4 == 2)):
      rtcastle0North = 1
      rtcastle0West = 1
      rtcastle0South = 1
      rtcastle0East = 1
      setTag(e, "rtcastle0North", rtcastle0North)
      setTag(e, "rtcastle0West", rtcastle0West)
      setTag(e, "rtcastle0South", rtcastle0South)
      setTag(e, "rtcastle0East", rtcastle0East)
      showMessage(e, ["CLICK", "CLICK", "CLICK", "CLICK", "", "There is a humming noise for only a moment and then there is silence."])
      rtcastle0complete = 1
      setTag(e, "rtcastle0complete", rtcastle0complete)
      setExit(e, "maps/rtcastle0b.cfg", 15, 18, 0)
      return 0
   else:
      showMessage(e, ["A humming noise fills your ears.  It lasts for only a second before dying."], optionInput)
