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

local function onequip(inst, owner)
	if not owner:HasTag("toso") then
		inst:RemoveTag("nightvision")
	else 
		inst:AddTag("nightvision")
	end
	

	owner.AnimState:OverrideSymbol("swap_hat", "hat_eyeshade", "swap_hat")
	owner.AnimState:Show("HAT")
	owner.AnimState:Hide("HAT_HAIR")
	owner.AnimState:Show("HAIR_NOHAT")
	owner.AnimState:Show("HAIR")
	
	if inst.components.fueled then
		inst.components.fueled:StartConsuming()        
	end
end

local function onunequip(inst, owner)
	owner.AnimState:Hide("HAT")
	owner.AnimState:Hide("HAT_HAIR")
	owner.AnimState:Show("HAIR_NOHAT")
	owner.AnimState:Show("HAIR")


	if inst.components.fueled then
		inst.components.fueled:StopConsuming()        
	end
end

--第一形态专属，非第一形态则卸下物品
local function isplant(inst,data)
	if data and data.owner  then
		local owner = data.owner
		local slot = inst.components.equippable.equipslot
		if not owner:HasTag("samansha") or owner:HasTag("flower") then
			inst:DoTaskInTime(0,function ()
			owner.components.inventory:DropItem(inst) 
			owner.components.inventory:GiveItem(inst)		
			end)
			owner.components.talker:Say("无法装备")
		end
	end
end



local function fn()
	local inst = CreateEntity()
---基本代码
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
	
 
	
    inst.AnimState:SetBank("earmuffshat")
    inst.AnimState:SetBuild("hat_eyeshade")
    inst.AnimState:PlayAnimation("anim")

	--可检查和可放入物品栏
    inst:AddComponent("inspectable")
    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/hat_eyeshade.xml"
	
	--可装备
	inst:AddComponent("equippable")
	inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
	inst.components.equippable:SetOnEquip(onequip)
	inst.components.equippable:SetOnUnequip(onunequip)
	--耐久度
	inst:AddComponent("fueled")
	inst.components.fueled.fueltype = "NIGHTMARE"
	inst.components.fueled:InitializeFuelLevel(10000)
	inst.components.fueled:SetDepletedFn(inst.Remove)
	--夜视
	inst:AddTag("nightvision")
	--监测是否是第一状态，不是则卸下物品。
	--inst:ListenForEvent("equipped",isplant)
	return inst
end
	
	
return Prefab( "common/inventory/hat_eyeshade", fn, assets, prefabs)