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

	

}

local prefabs =
{
    "explode_small",
}

local function OnIgniteFn(inst)
  inst._fx = SpawnPrefab("torchfire")
    inst._fx.entity:SetParent(inst.entity)
            inst._fx.entity:AddFollower()
            inst._fx.Follower:FollowSymbol(inst.GUID, "stickybomb", 0, 0, 0)
    inst.SoundEmitter:PlaySound("dontstarve/common/blackpowder_fuse_LP", "hiss")
end

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


local function turnoffspeed(inst)

	inst.components.locomotor.externalspeedmultiplier = 1
inst:RemoveTag("slowed")
    end

local function OnExplodeFn(inst)
local x, y, z = inst.Transform:GetWorldPosition()
local ents = TheSim:FindEntities(x, y, z, 3)
		 for i, v in ipairs(ents) do
		 

 if v.components.pinnable ~= nil then
            v.components.pinnable:Stick()
        end
		  
		     if v ~= nil and v:IsValid() and v.components.locomotor ~= nil and not v:HasTag("epic") then
	v.components.locomotor.externalspeedmultiplier = 0.10
					v:AddTag("slowed")
			v:DoTaskInTime(4, turnoffspeed)
end			 
			
	
end
inst.SoundEmitter:PlaySound("dontstarve/creatures/spat/spit")
  local cloud = SpawnPrefab("chester_transform_fx")
  
  
    cloud.Transform:SetPosition(x, y, z)
	cloud.entity:AddAnimState()
	    cloud.AnimState:SetMultColour(0, 2, 0, 0.8)
	
	inst.SoundEmitter:PlaySound("dontstarve/creatures/spat/spit_hit")
		SpawnPrefab("spat_splash_fx_full").Transform:SetPosition(inst.Transform:GetWorldPosition())
		SpawnPrefab("spat_splat_fx").Transform:SetPosition(inst.Transform:GetWorldPosition())
    inst.SoundEmitter:KillSound("hiss")

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("stickybombactive")
    anim:SetBuild("stickybombactive")
    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 = 100
	  inst.components.explosive.lightonexplode = false
	  		  	      inst.components.explosive.buildingdamage = 0
	
  inst._light = nil

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



	


	 




    
    return inst
end

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