local DL = require("design.DesignerLibrary")
local shield
local phase = 0
local currentTimer = 0
local lightningStrike
function OnScriptLoaded(level, go)
  if shield == nil then
    for weapon in game.Player.FindPlayer():IterateActiveWeapons() do
      if weapon ~= nil and weapon.Weapon ~= nil and weapon.Weapon:GetName() == "kratosshield00" then
        shield = weapon.Weapon
        break
      end
    end
  end
end
function OnUpdate(level, go)
  if phase == 0 then
    if 0.15 < currentTimer then
      local player = game.Player.FindPlayer()
      lightningStrike = game.FX.Spawn("Sky_lightning", level)
      lightningStrike:SetWorldPosition(DL.GetWorldJointPositionByName(shield, "zerojoint"))
      lightningStrike:SetWorldFacing((player:GetWorldForward() * -30 + engine.Vector.New(0, 30, 0)):Normalized())
      phase = 1
    end
  elseif phase == 1 then
    lightningStrike:SetWorldPosition(DL.GetWorldJointPositionByName(shield, "zerojoint"))
    if 0.5 < currentTimer then
      game.Player.FindPlayer():TriggerMoveEvent("kLE_DefBlockSonShockArrow")
      phase = 2
    end
  elseif 1.5 < currentTimer then
    if lightningStrike ~= nil then
      lightningStrike:Destroy()
    end
    go:Destroy()
  end
  currentTimer = currentTimer + level:GetUnitTime()
end
