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

local entity_id = GetUpdatedEntityID()
local pos_x, pos_y, current_rotation = EntityGetTransform( entity_id )
local projectile_component = EntityGetFirstComponent( entity_id, "ProjectileComponent" )
local velocity_component = EntityGetFirstComponent( entity_id, "VelocityComponent" )

local speed = 10

local self_filename = nil


if(projectile_component ~= nil)then
    EntityLoad( "mods/spellbound_bundle/files/entities/misc/bubble_projectiles_explosion.xml", pos_x, pos_y )

    local components = EntityGetComponent( entity_id, "VariableStorageComponent" )

    local storage_index = 0

    local last_comp_id = 0

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

        if(string.match(var_name, "original_ProjectileComponent_speed_max"))then
            storage_index = storage_index + 1
            local value =  ComponentGetValue( comp_id, "value_string" ) 
            speed = tostring(value)
            
         --   print(var_name)

            last_comp_id = comp_id
        end
        if(var_name == "projectile_filename")then
            local value =  ComponentGetValue( comp_id, "value_string" ) 
            self_filename = value
        end
    end

    if(self_filename ~= nil)then
        EntityAddComponent( entity_id, "LuaComponent", 
        { 
            script_source_file="mods/spellbound_bundle/files/scripts/projectiles/shoot_projectiles_forward.lua",
            execute_every_n_frame="15",
            execute_times="10"
        } )
    end
    
end