dofile_once("data/scripts/lib/utilities.lua")

local entity_id    = GetUpdatedEntityID()
local pos_x, pos_y, radians = EntityGetTransform( entity_id )
 
SetRandomSeed( GameGetFrameNum(), pos_x + pos_y + entity_id )

local ca = math.cos(radians)
local sa = math.sin(radians)

pos_x = (pos_x + Random(-8, 8)) - (ca * 20)
pos_y = (pos_y + Random(-8, 8)) - (sa * 20)

local components = EntityGetComponent( entity_id, "VariableStorageComponent" )

local spirits_remaining = 0

for key,comp_id in pairs(components) do 
    local var_name = ComponentGetValue( comp_id, "name" )

    if(var_name == "rock_spirits_remaining")then
        local value =  ComponentGetValue( comp_id, "value_string" ) 
        
        spirits_remaining = tonumber(value)

        ComponentSetValue(comp_id, "value_string", tostring(spirits_remaining - 1))
    end
end
if(spirits_remaining > 0)then
    local projectile = shoot_projectile_from_projectile( entity_id, "mods/spellbound_bundle/files/entities/enemies/small_pebble.xml", pos_x, pos_y, 0, 0 )
end