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

local entity_id    = GetUpdatedEntityID()
local x, y = EntityGetTransform( entity_id )

local parent_id = EntityGetParent( entity_id )

local target_id = 0

if ( parent_id ~= NULL_ENTITY ) then
	target_id = parent_id
else
	target_id = entity_id
end

if ( target_id ~= NULL_ENTITY ) then
	local projectile_components = EntityGetComponent( target_id, "ProjectileComponent" )
	
	if( projectile_components == nil ) then return end
    
    
	if ( #projectile_components > 0 ) then
        for k, projectile_component in pairs(projectile_components)do

            local action_id = ComponentObjectGetValue2(projectile_component, "config", "action_id")

            
            if(action_id == "MEGALASER")then
                --print("added components")
                EntityAddComponent(target_id, "BlackHoleComponent", {
                    particle_attractor_force="6",
                    damage_probability="0.05",
                    radius="5",
                })

                EntityAddComponent(target_id, "LooseGroundComponent", {
                    max_distance="80",
                    probability="0.2",
                    max_angle="3.1415926535",
                    chunk_max_angle="3.1415926535",
                    chunk_probability="0.03",
                })

                EntityAddComponent(target_id, "LuaComponent", {
                    script_source_file="mods/spellbound_bundle/files/scripts/misc/grow_blackhole.lua",
                    execute_every_n_frame="0",
                })
            end   
         end
	end
end
