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

local function onfinished(inst)
	inst:Remove()
end

local function onequip(inst, owner)
	owner.AnimState:OverrideSymbol("swap_object", "swap_tututoy", "swap_tututoy")
	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 ShouldAcceptItem(inst, item)
  if item.components.edible and  item.components.edible.foodtype == "VEGGIE" then
  return true
  end
end

local function OnGetItemFromPlayer(inst, giver, item)
	if item.prefab == "carrot" then
		inst.components.finiteuses:Use(-50)
	else
		inst.components.finiteuses:Use(-10)	
	end
end

local function usechange(inst)
	if inst.components.weapon and inst.components.finiteuses then
		if inst.components.finiteuses.current <=0 then
			inst.components.weapon:SetDamage(0)
		else
			inst.components.weapon:SetDamage(60)	
		end
	end
end


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

	MakeInventoryPhysics(inst)
	
	inst.AnimState:SetBuild("tututoy")
	inst.AnimState:SetBank("tututoy")
	inst.AnimState:PlayAnimation("idle")
	inst:AddTag("tutu")

	inst:AddComponent("inspectable")
	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/venus_tututoy.xml"
	
    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(200)
    inst.components.finiteuses:SetUses(200)
    
	inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(60)
	
	inst:AddComponent("equippable")
	inst.components.equippable:SetOnEquip( onequip )
	inst.components.equippable:SetOnUnequip( onunequip )
	
	inst:AddComponent("trader")
    inst.components.trader:SetAcceptTest(ShouldAcceptItem)
    inst.components.trader.onaccept = OnGetItemFromPlayer
	
	usechange(inst)
	inst:ListenForEvent("finiteusesdchange", usechange)

	
	return inst
end

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