#dungeon guardian
from eventAPI import *
from APIUtils import *

rtkDungeonFlag = 0

def fireEvent(e):
   global rtkDungeonFlag
   rtkDungeonFlag = getTag(e, "rtkDungeonFlag")
   if (rtkDungeonFlag == 1):
      return 1
   elif (rtkDungeonFlag == 2):
      showMessage(e, ["Once again, You come face to face with the dread knight."])
   else:
      showMessage(e, ["A skeletal knight steps forward to challenge you."], optionInput)
   showPicture(e, "Skeleton")
   showMessage(e, ["\"Flee if you can, for I shall grant the living no mercy.\""], optionInput)
   fightThem(e)
   if (rtkDungeonFlag == 1):
      return 1
   else:
      return 0

def fightThem(e):
   combatRet = combat(e, [("Dread Knight", 1, 0, 10)])
   if (combatRet == 1):
      wonFight(e)
   elif (combatRet == 3):
      lostGuardianFight(e)
   else:
      ranAwayGuardianFight(e)

def wonFight(e):
   global rtkDungeonFlag
   showMessage(e, ["The skeleton finally collapses.", "", "Among the possessions you find a golden cross."])
   giveItems(e, ["Golden Cross"])
   rtkDungeonFlag = 1
   setTag(e, "rtkDungeonFlag", rtkDungeonFlag)

def lostGuardianFight(e):
   showMessage(e, ["True to his word, the dread knight grants you no mercy."])

def ranAwayGuardianFight(e):
   global rtkDungeonFlag
   showMessage(e, ["As you flee the battle you can hear the knight laughing at your cowardice."])
   rtkDungeonFlag = 2
   setTag(e, "rtkDungeonFlag", rtkDungeonFlag)
