
dofile( "../../Assets/Scripts/util_math.lua" )


Global:StatTrack( 1, true )

local ASSETS_XML_ISLANDS = "../../Assets/Xml/island_parts/"
local Aster = Player:gAster()
local myData = Entity:Data()
local file


local ringHook = Global:FindEntityByName( "ringhook02", false )
local ringHookPos = ringHook:SHR_gPosition()
local ringHookRot = ringHook:SHR_gRotation()

file = "circ10.xml"
local circ10   = Global:CreateEntityAt( ASSETS_XML_ISLANDS .. file, ringHookPos.x + 41, ringHookPos.y + -82, ringHookPos.z + 21, 0, 0, 0 )
-- Hackiest hack in the history of hacks
Editor:AttachToIsland( 0, circ10:GetMyPointer(), ASSETS_XML_ISLANDS .. file )

file = "circ05.xml"
local circ05   = Global:CreateEntityAt( ASSETS_XML_ISLANDS .. file, ringHookPos.x - 55, ringHookPos.y + -106, ringHookPos.z -13, 0, 0, 0 )
-- Hackiest hack in the history of hacks
Editor:AttachToIsland( 0, circ05:GetMyPointer(), ASSETS_XML_ISLANDS .. file )

local circ10Pos = circ10:SHR_gPosition()
local circ10Rot = circ10:SHR_gRotation()
local circ05Pos = circ05:SHR_gPosition()
local circ05Rot = circ05:SHR_gRotation()
                 
                                        
local HIGH_DIF = 35
local HORZ_DIF = ( ( ringHookPos.x ) - ( ringHookPos.x - 55 ) ) / HIGH_DIF
local ROTATION_DIF = 360 / HIGH_DIF
local OK_GO = -1
local PLAYER_DIST = 330


local ringHookAltPos = ringHookPos
local ringHookAltRot = ringHookRot
ringHookAltPos.y = ringHookAltPos.y - HIGH_DIF
local circ10AltPos = circ10Pos
local circ10AltRot = circ10Rot
local circ05AltPos = circ05Pos
local circ05AltRot = circ05Rot


while( 1 ) 
do
  ringHook:SHR_sPosition( ringHookAltPos.x, ringHookAltPos.y, ringHookAltPos.z )
  circ10:SHR_sPosition( circ10AltPos.x, circ10AltPos.y, circ10AltPos.z )
  circ05:SHR_sPosition( circ05AltPos.x, circ05AltPos.y, circ05AltPos.z )
  coroutine.yield()
  
  if( vec3.magnitude( vec3.subtract( Aster:SHR_gPosition(), ringHookPos ) ) < PLAYER_DIST ) and
    ( OK_GO < 0 )
  then
    Global:StatTrack( 1, false )
    OK_GO = 0
  
  end
  
  if( OK_GO >= 0 and OK_GO < HIGH_DIF )
  then
    local time = Global:TimeElapsed() / 300
    OK_GO = OK_GO + ( time )
    
    ringHookAltRot.y = ringHookAltRot.y + ( ROTATION_DIF * time )
    ringHookAltPos.y = ringHookAltPos.y + ( time )
    ringHook:SHR_sRotation( ringHookAltRot.x, ringHookAltRot.y, ringHookAltRot.z )
    
    circ10AltRot.y = circ10AltRot.y + ( ROTATION_DIF * time )
    circ10AltPos.y = circ10AltPos.y + ( -time )
    circ10:SHR_sRotation( circ10AltRot.x, circ10AltRot.y, circ10AltRot.z )
    
    circ05AltRot.y = circ05AltRot.y + ( ROTATION_DIF * time )
    circ05AltPos.x = circ05AltPos.x + ( time * HORZ_DIF )
    circ05:SHR_sRotation( circ05AltRot.x, circ05AltRot.y, circ05AltRot.z )
  
  else
    ringHook:SHR_sRotation( ringHookRot.x, ringHookRot.y, ringHookRot.z )
    circ10:SHR_sRotation( circ10Rot.x, circ10Rot.y, circ10Rot.z )
    circ05:SHR_sRotation( circ05Rot.x, circ05Rot.y, circ05Rot.z )
  
  end

end