local assets=
{
    Asset("ANIM", "anim/knife.zip"),
    Asset("ANIM", "anim/swap_knife.zip"),
  
    Asset("ATLAS", "images/inventoryimages/knife.xml"),
    Asset("IMAGE", "images/inventoryimages/knife.tex"),
}

--local function onattack(inst,target)
   
 --   local pt = owner:GetPosition()
 --  if target.components.health then
   --    target.Transform:SetPosition(pt.x+10, pt.y, pt.z)
 --   end
 -- inst:DoTaskInTime(0.1, function() 
  -- target.components.health:DoDelta(-100)
  --  end)
--local x, y, z = attacker.Transform:GetWorldPosition()
   -- local range = 10

-- local ents = TheSim:FindEntities(x, y, z, range)
   -- for i, v in ipairs(ents) do
    --    if v.components.health and  v:HasTag("companion") then
     --       v.components.health:DoDelta(-100)
      --  elseif v:HasTag("smashable") then
      --      v.components.health:Kill()
      --  elseif v.components.workable ~= nil and v.components.workable.workleft > 0 then
       --     SpawnPrefab("collapse_small").Transform:SetPosition(v.Transform:GetWorldPosition())
      --      v.components.workable:Destroy(inst)
       -- end
   -- end
--return true

--end

local function onattack(inst, attacker, data)
    if attacker then
        SpawnPrefab("statue_transition").Transform:SetPosition(inst:GetPosition():Get())
        SpawnPrefab("fire").Transform:SetPosition(inst:GetPosition():Get())
        -- SpawnPrefab("collapse_big").Transform:SetPosition(inst:GetPosition():Get())
       --  SpawnPrefab("caster_ring_fx").Transform:SetPosition(inst:GetPosition():Get())
    end
   
   --if attacker.components.sanity > 300 then
   --if not skipsanity and attacker ~= nil and attacker.components.sanity ~= nil then
    --attacker.components.sanity:DoDelta(-1)
    --attacker.components.health:DoDelta(-1)

    local x, y, z = attacker.Transform:GetWorldPosition()
    local range =20
    --inst.components.finiteuses:Use(1)

    local ents = TheSim:FindEntities(x, y, z, range)
    for i, v in ipairs(ents) do
        if v.components.health and  v:HasTag("summonedbyplayer")then
            v.components.health:DoDelta(-1000)
        elseif v:HasTag("smashable") then
            v.components.health:Kill()
        --elseif v.components.workable ~= nil and v.components.workable.workleft > 0 then
           -- SpawnPrefab("collapse_small").Transform:SetPosition(v.Transform:GetWorldPosition())
         --   v.components.workable:Destroy(inst)
        end
    end
    --and not v:HasTag("player") 
--elseif attacker.components.health ~= nil then
  --  attacker.components.health:DoDelta(-10)
--end
return true

end


local function OnEquip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_knife", "swap_knife")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
end
  
local function OnUnequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
end

local function linkToBuilder(inst, builder)
	-- sound and anim reactions
	if builder then
		SpawnPrefab("mossling_spin_fx").Transform:SetPosition(inst:GetPosition():Get())
	end
end
 
local function fn()
  
    local inst = CreateEntity()
 
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
     
    MakeInventoryPhysics(inst)   
      
    inst.AnimState:SetBank("knife")
    inst.AnimState:SetBuild("knife")
    inst.AnimState:PlayAnimation("idle")
 
    inst:AddTag("sharp")
 
    if not TheWorld.ismastersim then
        return inst
    end
 
    inst.entity:SetPristine()
     
    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(0)
    inst.components.weapon:SetOnAttack(onattack)
	  
    inst:AddComponent("inspectable")
      
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "knife"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/knife.xml"
	
    inst:AddComponent("perishable")
    inst.components.perishable:SetPerishTime(1.5*30*16*2)
    inst.components.perishable:StartPerishing()
    inst.components.perishable:SetOnPerishFn(inst.Remove)
      
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
	
	inst.OnBuilt = linkToBuilder
	
    return inst
end
return  Prefab("common/inventory/archer_knife", fn, assets) 