#The dark one
from eventAPI import *
from APIUtils import *

rtDarkOne = 0

def fireEvent(e):
   global rtDarkOne
   rtDarkOne = getTag(e, "rtDarkOne")
   if (rtDarkOne != 1):
      return 1
   else:
      fightThem(e)
   return 1

def fightThem(e):
   global rtencounterCount
   global returnValue
   rtencounterCount = getTag(e, "rtencounterCount")
   if ((rtencounterCount >= 8) and ((gameTimeHour(getGameTime(e)) <= 5) or (gameTimeHour(getGameTime(e)) >= 19))):
      showPicture(e, "wolfman")
      showMessage(e, ["A familiar growling sound sends a chill down your spine.  You turn to find the beast from the keep staring you down."], optionInput)
      combatRet = combat(e, [("Dark One", 1, 0, 10)])
      if (combatRet == 1):
         wonFight(e)
   else:
      rtencounterCount+=1
      setTag(e, "rtencounterCount", rtencounterCount)


def wonFight(e):
   global rtDarkOne
   setTag(e, "rtDarkOne", rtDarkOne)
   showMessage(e, ["You are victorious in battle against the strange beast."], optionInput)
   hasStaff = 0
   if (firstHasItem(e,"Redwood Staff") >= 0):
      hasStaff = 1
   if (hasStaff):
      showMessage(e, ["Something strange is happening.  Instead of springing to life as before, the creature appears somehow caught between life and death.", "", "You notice that the Redwood Staff that you obtained from the Plane of Fire is producing a slight humming sound."], optionInput)
      if (poseYesNo(e, ["Perhaps striking the beast with the staff will finally destroy it", "", "Will you use the staff on the unconcious beast?"])):
         destroyDarkOne(e)
      else:
         showPicture(e, "wolfman")
         showMessage(e, ["Suddenly, the corpse of the slain beast stirs and it comes back to life!", "", "The beast again growls at you and flees into the hedge maze."])
         playSpecAudio(e, "Howl")
         showMessage(e, ["You can hear the creature howling as it runs away."])
         rtencounterCount = 1
         setTag(e, "rtencounterCount", rtencounterCount)
   else:
      showPicture(e, "wolfman")
      showMessage(e, ["Suddenly, the corpse of the slain beast stirs and it comes back to life!", "", "The beast again growls at you and flees into the hedge maze."], optionInput)
      clearPicture(e)
      playSpecAudio(e, "Howl")
      showMessage(e, ["You can hear the creature howling as it runs away."], optionInput)
      rtencounterCount = 1
      setTag(e, "rtencounterCount", rtencounterCount)

def destroyDarkOne(e):
   showPicture(e, "wolfman")
   showMessage(e, ["You stab the beast with the tip of the staff.", "", "The Redwood Staff seems to absorb the essence of the creature and the color of the wood deepends to a dark red.", "", "The remaining corpse turns into a pile of ash."], optionInput)
   clearPicture(e)
   rtDarkOne = 2
   setTag(e, "rtDarkOne", rtDarkOne)
   holder = firstHasItem(e,"Redwood Staff")
   removeItem(e, holder, "Redwood Staff")
   giveItems(e, ["Dark Redwood Staff"])
