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




local function onAttackfutou(inst, owner, target)



end

--将耐久余额转化为燃料数值
local function PercentChanged(inst, data)
local percent = inst.components.finiteuses.current/inst.components.finiteuses.total
local tosofutoupercent = 3600*percent
	inst.components.finiteuses.current = tosofutoupercent
end

--检测
local function OnDurabilityRmtools(inst, data)
	inst:AddTag("brokenfutou")
    inst:RemoveComponent("tool")
	inst.components.talker:Say("斧子钝了")
end
--更新组件
local function TakeItem(inst, item, data)

local player = GetPlayer()
local tosofutouf = inst.components.finiteuses.current + 360
if tosofutouf <= 3600 then
    inst.components.finiteuses:SetUses(tosofutouf)
	inst.components.finiteuses.current = tosofutouf
else
    inst.components.finiteuses:SetUses(3600)
	inst.components.finiteuses.current = 3600
end
	inst.components.fueled:DoDelta(12)
  if inst:HasTag("brokenfutou") then
    inst:RemoveComponent("tool") 
  else
    inst:AddComponent("tool")
    --inst.components.tool:SetAction(ACTIONS.HACK,3)
    inst.components.tool:SetAction(ACTIONS.CHOP, 5)
    inst.components.tool:SetAction(ACTIONS.MINE, 2)
  end
	inst:RemoveTag("brokenfutou")
end

--接受外来锻造物
local function ShouldAcceptItem(inst, item)
    if item.prefab == "flint" then
       return true
    end
    return false
end

local function OnGetItemFromPlayer(inst, giver, item)
	 if item.prefab == "flint" then
       inst.components.fueled.currentfuel = inst.components.fueled.currentfuel + inst.components.fueled.maxfuel *0.1
    end
    if inst.components.fueled.currentfuel > inst.components.fueled.maxfuel then
       inst.components.fueled.currentfuel = inst.components.fueled.maxfuel
    end
end

local function OnRefuseItem(inst, giver, item)
	if item.prefab ~= "flint" then
		inst.components.talker:Say("需要燧石来磨锋利!")
	end
end
--装备
local function onequip(inst, owner)

    owner.AnimState:OverrideSymbol("swap_object", "swap_futou", "swap_futou")
    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 fn()
    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    --inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)
	
    inst.AnimState:SetBank("futou")
    inst.AnimState:SetBuild("futou")
    inst.AnimState:PlayAnimation("idle")
	inst.entity:AddMiniMapEntity()
	inst.MiniMapEntity:SetIcon( "futou.tex" )    
	--inst:AddTag("shadow")
	--inst:AddTag("feng")
    inst:AddTag("sharp")
    inst:AddTag("weapon_sword")
    --inst:AddTag("extinguisher")
	


    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(13)

    -------
    inst.components.weapon:SetRange(0.5)
    inst.components.weapon:SetOnAttack(onAttackfutou)


	
    inst:AddComponent("inspectable")
	

    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.imagename = "futou"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/futou.xml"
	--inst.components.inventoryitem.nobounce = true
	inst.components.inventoryitem.keepondeath = true

	inst:AddComponent("fueled")
    --inst.components.fueled.fueltype = "NIGHTMARE"
    inst.components.fueled:InitializeFuelLevel(3600)
    inst.components.fueled:SetDepletedFn(OnDurabilityRmtools)
    inst.components.fueled.ontakefuelfn = TakeItem
    --inst.components.fueled.accepting = true
    inst.components.fueled:StopConsuming()
	
    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(3600)
    inst.components.finiteuses:SetUses(3600)
	if inst.components.finiteuses.current < 0 then
       inst.components.finiteuses.current = 0
    end

	inst:AddComponent("trader")
    inst.components.trader.onaccept = OnGetItemFromPlayer
    inst.components.trader:SetAcceptTest(ShouldAcceptItem)
    inst.components.trader.onrefuse = OnRefuseItem
	
	inst:AddComponent("talker")
    inst.components.talker.fontsize = 36
    inst.components.talker.font = TALKINGFONT
    inst.components.talker.colour = Vector3(.9, .4, .4)
    inst.components.talker.offset = Vector3(0, 0, 0)
    inst.components.talker.symbol = "swap_object"
	inst.Transform:SetScale(1.5,1.5,1.5)
	
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)
    --inst.components.equippable.dapperness = 20/60
    inst:AddComponent("tool")
    --inst.components.tool:SetAction(ACTIONS.HACK,3)
    inst.components.tool:SetAction(ACTIONS.CHOP, 5)
    inst.components.tool:SetAction(ACTIONS.MINE, 2)
    --inst.components.tool:SetAction(ACTIONS.HAMMER)

 
	
    return inst
end

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