local timers = require("level.timer")
thisLevel = nil
player = nil
son = nil
cwCollisionGroup = nil
ccwCollisionGroup = nil
shakeCollisionGroup = nil
rotateObj_CCW = nil
shakeObj = nil
local bOnGround, ClimbPath_A, ClimbPath_B, emitterMedalionRotate
local LD = require("design.LevelDesignLibrary")
local uiCalls = require("ui.uicalls")
local bPathActive_A = false
local bPathActive_B = true
local bKratosOnA = false
local bKratosOnB = false
function OnScriptLoaded(level, obj)
  print("//////////////////// WTFOMGBBQ")
  thisLevel = level
  player = game.Player.FindPlayer()
  son = game.AI.FindSon()
  cwCollisionGroup = obj:FindSingleGOByName("Collision_RotateCW")
  ccwCollisionGroup = obj:FindSingleGOByName("Collision_RotateCCW")
  shakeCollisionGroup = obj:FindSingleGOByName("collision_center")
  cwCollisionGroup.LuaObjectScript.RegisterHitCallback(RotateClockwise)
  ccwCollisionGroup.LuaObjectScript.RegisterHitCallback(RotateCounterClockwise)
  shakeCollisionGroup.LuaObjectScript.RegisterHitCallback(ShakeIt)
  rotateObj_CCW = obj:FindSingleGOByName("RotateGroup_CCW")
  shakeObj = obj:FindSingleGOByName("ShakeGroup")
  ClimbPath_A = obj:FindSingleGOByName("TraversePath_medallion")
  ClimbPath_B = obj:FindSingleGOByName("TraversePath_Alt")
  emitterMedalionRotate = GameObjects.medalion_grp.Child:FindSingleSoundEmitterByName("snd_MedalionRotate")
  game.SubObject.Sleep(obj)
end
function SetVarKratosOnA_True()
  bKratosOnA = true
end
function SetVarKratosOnA_False()
  bKratosOnA = false
end
function SetVarKratosOnB_True()
  bKratosOnB = true
end
function SetVarKratosOnB_False()
  bKratosOnB = false
end
function SetVarGround_On()
  bOnGround = true
end
function SetVarGround_Off()
  bOnGround = false
end
function HideTraversalPaths()
  ClimbPath_A:HideTraversePath()
  ClimbPath_B:HideTraversePath()
end
function ShowTraversePathA()
  if bOnGround == false then
    ClimbPath_A:ShowTraversePath()
    ClimbPath_B:HideTraversePath()
  end
end
function ShowTraversePathB()
  if bOnGround == false then
    ClimbPath_B:ShowTraversePath()
    ClimbPath_A:HideTraversePath()
  end
end
function ShowActivePath()
  if bPathActive_A == true and bKratosOnA == true then
    ShowTraversePathA()
  elseif bPathActive_A == false and bKratosOnA == true then
    HideTraversalPaths()
  elseif bPathActive_B == true and bKratosOnB == true then
    ShowTraversePathB()
  elseif bPathActive_B == false and bKratosOnB == true then
    HideTraversalPaths()
  end
end
function ShowActivePathPostSpin()
  timers.StartLevelTimer(1.5, function()
    ShowActivePath()
  end)
end
local CheckAxe = function()
  if player.Axe.ThrowOutStatus == tweaks.tThrowOutStatus.eThrownWeaponStatus.kTOSInFlightReturn or player.Axe.ThrowOutStatus == tweaks.tThrowOutStatus.eThrownWeaponStatus.kTOSSuspended or player.Axe.ThrowOutStatus == tweaks.tThrowOutStatus.eThrownWeaponStatus.kTOSFalling then
    return false
  end
  return true
end
function RotateClockwise()
  if CheckAxe() == false then
    return
  end
  HideTraversalPaths()
  if rotateObj_CCW.AnimFrame == 120 or rotateObj_CCW.AnimFrame == 0 then
    rotateObj_CCW:JumpAnimToFrame(240)
    rotateObj_CCW:PauseAnim()
  elseif rotateObj_CCW.AnimFrame == 30 then
    rotateObj_CCW:JumpAnimToFrame(150)
    rotateObj_CCW:PauseAnim()
  elseif rotateObj_CCW.AnimFrame == 60 then
    rotateObj_CCW:JumpAnimToFrame(180)
    rotateObj_CCW:PauseAnim()
  elseif rotateObj_CCW.AnimFrame == 90 then
    rotateObj_CCW:JumpAnimToFrame(210)
    rotateObj_CCW:PauseAnim()
  end
  if rotateObj_CCW.AnimFrame == 240 then
    rotateObj_CCW:PlayAnimToFrame(210, -1)
    ShakeIt()
    rotateAudio()
    bPathActive_A = true
    bPathActive_B = false
    ShowActivePathPostSpin()
  elseif rotateObj_CCW.AnimFrame == 210 then
    rotateObj_CCW:PlayAnimToFrame(180, -1)
    ShakeIt()
    rotateAudio()
    bPathActive_A = false
    bPathActive_B = true
    ShowActivePathPostSpin()
  elseif rotateObj_CCW.AnimFrame == 180 then
    rotateObj_CCW:PlayAnimToFrame(150, -1)
    ShakeIt()
    rotateAudio()
    bPathActive_A = true
    bPathActive_B = false
    ShowActivePathPostSpin()
  elseif rotateObj_CCW.AnimFrame == 150 then
    rotateObj_CCW:PlayAnimToFrame(120, -1)
    ShakeIt()
    rotateAudio()
    bPathActive_A = false
    bPathActive_B = true
    ShowActivePathPostSpin()
  end
end
function RotateCounterClockwise()
  if CheckAxe() == false then
    return
  end
  HideTraversalPaths()
  if rotateObj_CCW.AnimFrame == 120 or rotateObj_CCW.AnimFrame == 240 then
    rotateObj_CCW:JumpAnimToFrame(0)
    rotateObj_CCW:PauseAnim()
  elseif rotateObj_CCW.AnimFrame == 150 then
    rotateObj_CCW:JumpAnimToFrame(30)
    rotateObj_CCW:PauseAnim()
  elseif rotateObj_CCW.AnimFrame == 180 then
    rotateObj_CCW:JumpAnimToFrame(60)
    rotateObj_CCW:PauseAnim()
  elseif rotateObj_CCW.AnimFrame == 210 then
    rotateObj_CCW:JumpAnimToFrame(90)
    rotateObj_CCW:PauseAnim()
  end
  if rotateObj_CCW.AnimFrame == 0 then
    rotateObj_CCW:PlayAnimToFrame(30)
    ShakeIt()
    rotateAudio()
    bPathActive_A = true
    bPathActive_B = false
    ShowActivePathPostSpin()
  elseif rotateObj_CCW.AnimFrame == 30 then
    rotateObj_CCW:PlayAnimToFrame(60)
    ShakeIt()
    rotateAudio()
    bPathActive_A = false
    bPathActive_B = true
    ShowActivePathPostSpin()
  elseif rotateObj_CCW.AnimFrame == 60 then
    rotateObj_CCW:PlayAnimToFrame(90)
    ShakeIt()
    rotateAudio()
    bPathActive_A = true
    bPathActive_B = false
    ShowActivePathPostSpin()
  elseif rotateObj_CCW.AnimFrame == 90 then
    rotateObj_CCW:PlayAnimToFrame(120)
    ShakeIt()
    rotateAudio()
    bPathActive_A = false
    bPathActive_B = true
    ShowActivePathPostSpin()
  end
end
function ShakeIt()
  shakeObj:JumpAnimToFrame(0)
  shakeObj:PlayAnimToEnd(1)
  shakeAudio()
end
function rotateAudio()
  LD.PlaySound(emitterMedalionRotate, "SND_MECH_Blade_Relic_Stn350_Turn")
end
function shakeAudio()
  LD.PlaySound(emitterMedalionRotate, "SND_MECH_Blade_Relic_Stn350_Hit_Wood")
end
