
local Assets =
{
	Asset("ANIM", "anim/goldhelm.zip"),
	Asset("IMAGE", "inventoryimages/goldhelm.tex"),
	Asset("ATLAS", "inventoryimages/goldhelm.xml"),	 
}


local function onequip(inst, owner)
	owner.AnimState:OverrideSymbol("swap_hat", "goldhelm", "swap_hat")
	owner.AnimState:Show("HAT")
	owner.AnimState:Show("HAT_HAIR")
	owner.AnimState:Hide("HAIR_NOHAT")
	owner.AnimState:Hide("HAIR")
	owner.SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold")

	if owner:HasTag("player") then
		owner.AnimState:Hide("HEAD")
		owner.AnimState:Show("HEAD_HAT")
	end

	--[[
	if inst.components.fueled ~= nil 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 owner:HasTag("player") then
		owner.AnimState:Show("HEAD")
		owner.AnimState:Hide("HEAD_HAT")
	end

	--[[
	if inst.components.fueled ~= nil then
		inst.components.fueled:StopConsuming()
	end --]]
end



local function fn(Sim)
	local inst = CreateEntity()

	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddNetwork()

	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("footballhat")
	inst.AnimState:SetBuild("goldhelm")
	inst.AnimState:PlayAnimation("anim")

	inst:AddTag("hat")
	inst:AddTag("golden")

	inst.entity:SetPristine()
	if not TheWorld.ismastersim then
		return inst
	end

	inst:AddComponent("inspectable")

	inst:AddComponent("inventoryitem")
	inst:AddComponent("tradable")
	inst.components.inventoryitem.atlasname = "inventoryimages/goldhelm.xml"
	inst:AddComponent("armor")
	inst.components.armor:InitCondition(
		TUNING.MAD_GOLDHELM.armor, --825
		TUNING.MAD_GOLDHELM.absorption --0.9 90%
	)

	inst:AddComponent("equippable")
	inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
	inst.components.equippable:SetOnEquip( onequip )
	inst.components.equippable:SetOnUnequip( onunequip )

	MakeHauntableLaunch(inst)

	return inst
end

return Prefab( "common/inventory/goldhelm", fn, Assets)
