local assets=
{
	Asset("ANIM", "anim/icebombactive.zip"),

	

}

local prefabs =
{
    "explode_small",
}

local function OnIgniteFn(inst)


  inst._fx = SpawnPrefab("coldfirefire")
    inst._fx.entity:SetParent(inst.entity)
            inst._fx.entity:AddFollower()
            inst._fx.Follower:FollowSymbol(inst.GUID, "icebombactive", 0, 0, 0)
			
   SpawnPrefab("ice_splash").Transform:SetPosition(inst.Transform:GetWorldPosition())
end

local function OnExtinguishFn(inst)
    inst.SoundEmitter:KillSound("hiss")
end

local function freeze(inst)
if inst:HasTag("epic") or inst:HasTag("player") then
   inst.components.freezable:AddColdness(1)
        inst.components.freezable:SpawnShatterFX()
else
   inst.components.freezable:AddColdness(3)
        inst.components.freezable:SpawnShatterFX()
end
end

local function OnExplodeFn(inst)
 	local x, y, z = inst.Transform:GetWorldPosition()
	local fx = SpawnPrefab("groundpoundring_fx")
	fx.Transform:SetPosition(x, y, z)
		fx.Transform:SetScale(0.5, 0.5, 0.5)
	
    inst.SoundEmitter:KillSound("hiss")
   SpawnPrefab("chester_transform_fx").Transform:SetPosition(inst.Transform:GetWorldPosition())
	   SpawnPrefab("mining_ice_fx").Transform:SetPosition(inst.Transform:GetWorldPosition())
	     SpawnPrefab("ice_splash").Transform:SetPosition(inst.Transform:GetWorldPosition())
	   SpawnPrefab("icespike_fx_4").Transform:SetPosition(inst.Transform:GetWorldPosition())
	               inst.SoundEmitter:PlaySound("dontstarve_DLC001/common/iceboulder_smash")
	   
	   
	local x,y,z = inst.Transform:GetWorldPosition()
            local ents = TheSim:FindEntities(x,y,z, 4, {"freezable"}, {"FX", "NOCLICK", "DECOR","INLIMBO"}) 
            for i,v in pairs(ents) do
             if v and v.components.freezable then
	local bomb = inst		 
						-- v.components.health:DoDelta(-50)
						
						--	v.Transform:SetScale(0.1, 0.1, 0.1)
						  if v.components.burnable ~= nil then
        if v.components.burnable:IsBurning() then
            v.components.burnable:Extinguish()
        elseif v.components.burnable:IsSmoldering() then
            v.components.burnable:SmotherSmolder()
        end
    end


    if v.components.freezable ~= nil then
     v:DoTaskInTime(0.1, freeze)

    end
						
						
else
-- v.components.combat:GetAttacked(bomb, 50, bomb, "wind")
	end
	end
end


local function Explode(inst)
    inst.SoundEmitter:KillSound("hiss")
  inst.components.explosive:OnBurnt()
end





	
local function fn(Sim)
    local inst = CreateEntity()
	local trans = inst.entity:AddTransform()
	local anim = inst.entity:AddAnimState()
	inst.entity:AddSoundEmitter()

	inst.entity:AddNetwork()
    MakeInventoryPhysics(inst)
    
    anim:SetBank("icebombactive")
    anim:SetBuild("icebombactive")
    anim:PlayAnimation("idle",true)
        inst:AddTag("explosive")
				        inst:AddTag("SCARYTOPREY")
		
      inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

	


        inst:AddComponent("explosive")
    inst.components.explosive:SetOnExplodeFn(OnExplodeFn)
    inst.components.explosive.explosivedamage = 75
			  	      inst.components.explosive.buildingdamage = 0
	  inst.components.explosive.lightonexplode = false
		  inst.components.explosive.explosiverange = 4
	
  inst._light = nil

		  inst:DoTaskInTime(0, OnIgniteFn)
	  inst:DoTaskInTime(0, Explode)



	


	 




    
    return inst
end

return Prefab( "common/inventory/icebombactive", fn, assets) 
