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

local prefabs = {
}

---------------------------------------------
local function GETDIFFICULTY(inst)
if	TUNING.YIYUISOPEN == 1 then
	if inst.prefab == "yuyi_hat2" then
		inst.components.armor:SetAbsorption(0.80+(1-TUNING.DIFFICULTY_YUYI)/10+inst.armor_absorb)
	elseif inst.prefab == "yuyi_hat3" then
		inst.components.armor:SetAbsorption(0.80+(1-TUNING.DIFFICULTY_YUYI)/10+inst.armor_absorb)
	end
end
end

local function SpawnEffect(inst)
    local pt = inst:GetPosition()
    local fx = SpawnPrefab("small_puff")
    fx.Transform:SetPosition(pt.x, pt.y, pt.z)
    fx.Transform:SetScale(0.5,0.5,0.5)
end

local function getitem(musician, item)
    SpawnEffect(item)
    if item.components.stackable then
        item = item.components.stackable:Get()
    end
    if item.components.trap and item.components.trap:IsSprung() then
        item.components.trap:Harvest(musician)
        return
    end
    musician.components.inventory:GiveItem(item)
end

local function pickup(inst, musician)
    local pt = musician:GetPosition()
    local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, 5)
    for k,v in pairs(ents) do
        if v.components.inventoryitem and v.components.inventoryitem.canbepickedup and v.components.inventoryitem.cangoincontainer and not
            v.components.inventoryitem:IsHeld() and v.prefab ~= "yiyutrap" and v.prefab ~= "powcake" and v.components.stackable then
            if not musician.components.inventory:IsFull() then
				if inst.components.fueled and inst.components.fueled.currentfuel > 50 then
					inst.components.armor.condition = inst.components.armor.condition -10
					inst.components.fueled:DoDelta(-10)
					getitem(musician, v)
				end
                return
            elseif v.components.stackable then
                local stack = musician.components.inventory:FindItem(function(item) return (item.prefab == v.prefab and not item.components.stackable:IsFull()
                    and item ~= musician.components.inventory.activeitem) end)
                if stack then
					if inst.components.fueled and inst.components.fueled.currentfuel > 50 then
						inst.components.armor.condition = inst.components.armor.condition -10
						inst.components.fueled:DoDelta(-10)
						getitem(musician, v)
					end
                    return
                end
            end
        end
    end
end

local function onuseyuyihats(inst)
	local player = GetPlayer()
	if player.taskmagic then player.taskmagic:Cancel() player.taskmagic = nil end
	if player:HasTag("yiyuflute") then
		player:RemoveTag("yiyuflute")
	elseif not player:HasTag("yiyuflute") then
		player:AddTag("yiyuflute")
	end
	player.taskmagic = player:DoPeriodicTask(0.2 , function() if player:HasTag("yiyuflute") then pickup(inst, player) end end)
end

local function onuseyuyihats2(inst)
	local player = GetPlayer()
	if player:HasTag("yiyu_light") then
		player:RemoveTag("yiyu_light")
		inst.Light:Enable(false)
		if inst.task_yuyilight then inst.task_yuyilight:Cancel() inst.task_yuyilight = nil end
	elseif not player:HasTag("yiyu_light") then
		player:AddTag("yiyu_light")
		local light = inst.entity:AddLight()
		light:SetIntensity(0.7)
		light:SetRadius(10)
		light:SetFalloff(0.7)
		light:SetColour(180/255,195/255,150/255)
		light:Enable(true)

		inst.task_yuyilight = inst:DoPeriodicTask(1, function()
			if inst.components.fueled and inst.components.fueled.currentfuel > 30 then
				inst.components.armor.condition = inst.components.armor.condition -3
				inst.components.fueled:DoDelta(-3)
			elseif inst.components.fueled and inst.components.fueled.currentfuel <= 30 then
				if inst.task_yuyilight then inst.task_yuyilight:Cancel() inst.task_yuyilight = nil end
				player:RemoveTag("yiyu_light")
				light:Enable(false)
			end
		end)
	end
end


local function PercentChanged(inst, data)
local percent = inst.components.armor.condition/inst.components.armor.maxcondition
local yiyufpercent = 1800*percent
	inst.components.fueled.currentfuel = yiyufpercent
end

local function TakeItems(inst, item, data)
local player = GetPlayer()
local yiyuarmor = inst.components.armor.condition + 180
if yiyuarmor <= 1800 then
    inst.components.armor:SetCondition(yiyuarmor)
	inst.components.fueled.currentfuel = yiyuarmor
else
    inst.components.armor:SetCondition(1800)
	inst.components.fueled.currentfuel = 1800
end
end

---------------------------------------------

local function onequipyuyi_hat1(inst, owner, data)
    owner.AnimState:OverrideSymbol("swap_hat", "yuyi_hat1", "swap_hat")
    owner.AnimState:Show("HAT")
    owner.AnimState:Hide("HAIR_NOHAT")
    owner.AnimState:Hide("HAIR")
end

local function onunequipyuyi_hat1(inst, owner)
    owner.AnimState:Hide("HAT")
    owner.AnimState:Show("HAIR_NOHAT")
    owner.AnimState:Show("HAIR")
	local player = GetPlayer()
	player:RemoveTag("yiyuflute")
	if player.taskmagic then player.taskmagic:Cancel() player.taskmagic = nil end
end

-------------------------------------------------------

local function onequip_yuyi_hat2(inst, owner, data)
	owner.AnimState:OverrideSymbol("swap_hat", "yuyi_hat2", "swap_hat")
	owner.AnimState:Show("HAT")
    owner.AnimState:Hide("HAIR_NOHAT")
    owner.AnimState:Hide("HAIR")
	local health_percent = owner.components.health:GetPercent()
    if owner.components.health and inst.armor_health and inst.armor_health > 0 then
		owner.components.health.maxhealth = owner.components.health.maxhealth + inst.armor_health
		owner.components.health:SetPercent(health_percent)
	end
	if owner.helmet_yiyu then
		owner.helmet_yiyu = 0
		owner.components.health.absorb = owner.corselet_yiyu + owner.helmet_yiyu
	end
	if owner.components.health then
		owner.helmet_yiyu_fire = inst.armor_fire_resistance
		local all_yiyu_fire = owner.corselet_yiyu_fire + owner.helmet_yiyu_fire
		if all_yiyu_fire > 1 then all_yiyu_fire = 1 end
		owner.components.health.fire_damage_scale = 1-all_yiyu_fire--TUNING.ARMORDRAGONFLY_FIRE_RESIST
	end
	if owner.components.freezable then
		owner.helmet_yiyu_cold = inst.armor_cold_resistance
		owner.components.freezable.resistance = owner.corselet_yiyu_cold+owner.helmet_yiyu_cold+3
	end
	if owner.components.temperature then
	owner.helmet_yiyu_winter = inst.armor_winter_temp
	owner.helmet_yiyu_summer = inst.armor_summer_temp
	owner.components.temperature.inherentinsulation = owner.corselet_yiyu_winter+owner.helmet_yiyu_winter
	owner.components.temperature.inherentsummerinsulation = owner.corselet_yiyu_summer+owner.helmet_yiyu_summer
	end
	if owner.dodge_yiyu then
	owner.helmet_yiyu_dodge = inst.armor_dodge
	owner.dodge_yiyu = owner.corselet_yiyu_dodge + owner.helmet_yiyu_dodge
	end
	if owner.drop_yiyu then
	owner.helmet_yiyu_drop = inst.armor_drop
	owner.drop_yiyu = owner.corselet_yiyu_drop+owner.helmet_yiyu_drop
	end
end

local function onunequip_yuyi_hat2(inst, owner)
	owner.AnimState:Hide("HAT")
	owner.AnimState:Hide("HAT_HAIR")
	owner.AnimState:Show("HAIR_NOHAT")
	owner.AnimState:Show("HAIR")
	local player = GetPlayer()
	player:RemoveTag("yiyuflute")
	if player.taskmagic then player.taskmagic:Cancel() player.taskmagic = nil end
	local health_percent = owner.components.health:GetPercent()
    if owner.components.health and inst.armor_health and inst.armor_health > 0 then
		owner.components.health.maxhealth = owner.components.health.maxhealth - inst.armor_health
		owner.components.health:SetPercent(health_percent)
	end
	if owner.helmet_yiyu then
		owner.helmet_yiyu = inst.armor_corselet
		owner.components.health.absorb = owner.corselet_yiyu + owner.helmet_yiyu
	end
	if owner.components.health then
		owner.helmet_yiyu_fire = 0
		local all_yiyu_fire = owner.corselet_yiyu_fire + owner.helmet_yiyu_fire
		if all_yiyu_fire > 1 then all_yiyu_fire = 1 end
		owner.components.health.fire_damage_scale = 1-all_yiyu_fire--TUNING.ARMORDRAGONFLY_FIRE_RESIST
	end
	if owner.components.freezable then
		owner.helmet_yiyu_cold = 0
		owner.components.freezable.resistance = owner.corselet_yiyu_cold+owner.helmet_yiyu_cold+3
	end
	if owner.components.temperature then
	owner.helmet_yiyu_winter = 0
	owner.helmet_yiyu_summer = 0
	owner.components.temperature.inherentinsulation = owner.corselet_yiyu_winter+owner.helmet_yiyu_winter
	owner.components.temperature.inherentsummerinsulation = owner.corselet_yiyu_summer+owner.helmet_yiyu_summer
	end
	if owner.dodge_yiyu then
	owner.helmet_yiyu_dodge = 0
	owner.dodge_yiyu = owner.corselet_yiyu_dodge + owner.helmet_yiyu_dodge
	end
	if owner.drop_yiyu then
	owner.helmet_yiyu_drop = 0
	owner.drop_yiyu = owner.corselet_yiyu_drop+owner.helmet_yiyu_drop
	end
end

-------------------------------------------------------

local function onequip_yuyi_hat3(inst, owner, data)
	owner.AnimState:OverrideSymbol("swap_hat", "yuyi_hat3", "swap_hat")
	owner.AnimState:Show("HAT")
    owner.AnimState:Hide("HAIR_NOHAT")
    owner.AnimState:Hide("HAIR")
	local health_percent = owner.components.health:GetPercent()
    if owner.components.health and inst.armor_health and inst.armor_health > 0 then
		owner.components.health.maxhealth = owner.components.health.maxhealth + inst.armor_health
		owner.components.health:SetPercent(health_percent)
	end
	if owner.helmet_yiyu then
		owner.helmet_yiyu = inst.armor_corselet
		owner.components.health.absorb = owner.corselet_yiyu + owner.helmet_yiyu
	end
	if owner.components.health then
		owner.helmet_yiyu_fire = inst.armor_fire_resistance
		local all_yiyu_fire = owner.corselet_yiyu_fire + owner.helmet_yiyu_fire
		if all_yiyu_fire > 1 then all_yiyu_fire = 1 end
		owner.components.health.fire_damage_scale = 1-all_yiyu_fire--TUNING.ARMORDRAGONFLY_FIRE_RESIST
	end
	if owner.components.freezable then
		owner.helmet_yiyu_cold = inst.armor_cold_resistance
		owner.components.freezable.resistance = owner.corselet_yiyu_cold+owner.helmet_yiyu_cold+3
	end
	if owner.components.temperature then
	owner.helmet_yiyu_winter = inst.armor_winter_temp
	owner.helmet_yiyu_summer = inst.armor_summer_temp
	owner.components.temperature.inherentinsulation = owner.corselet_yiyu_winter+owner.helmet_yiyu_winter
	owner.components.temperature.inherentsummerinsulation = owner.corselet_yiyu_summer+owner.helmet_yiyu_summer
	end
	if owner.dodge_yiyu then
	owner.helmet_yiyu_dodge = inst.armor_dodge
	owner.dodge_yiyu = owner.corselet_yiyu_dodge + owner.helmet_yiyu_dodge
	end
	if owner.drop_yiyu then
	owner.helmet_yiyu_drop = inst.armor_drop
	owner.drop_yiyu = owner.corselet_yiyu_drop+owner.helmet_yiyu_drop
	end
end

local function onunequip_yuyi_hat3(inst, owner)
    owner.AnimState:Hide("HAT")
    owner.AnimState:Show("HAIR_NOHAT")
    owner.AnimState:Show("HAIR")
	local player = GetPlayer()
	player:RemoveTag("yiyu_light")
	if inst.Light then inst.Light:Enable(false) end
	if inst.task_yuyilight then inst.task_yuyilight:Cancel() inst.task_yuyilight = nil end

	if player.taskmagic then player.taskmagic:Cancel() player.taskmagic = nil end
	local health_percent = owner.components.health:GetPercent()
    if owner.components.health and inst.armor_health and inst.armor_health > 0 then
		owner.components.health.maxhealth = owner.components.health.maxhealth - inst.armor_health
		owner.components.health:SetPercent(health_percent)
	end
	if owner.components.health then
		owner.helmet_yiyu_fire = 0
		local all_yiyu_fire = owner.corselet_yiyu_fire + owner.helmet_yiyu_fire
		if all_yiyu_fire > 1 then all_yiyu_fire = 1 end
		owner.components.health.fire_damage_scale = 1-all_yiyu_fire--TUNING.ARMORDRAGONFLY_FIRE_RESIST
	end
	if owner.components.freezable then
		owner.helmet_yiyu_cold = 0
		owner.components.freezable.resistance = owner.corselet_yiyu_cold+owner.helmet_yiyu_cold+3
	end
	if owner.components.temperature then
	owner.helmet_yiyu_winter = 0
	owner.helmet_yiyu_summer = 0
	owner.components.temperature.inherentinsulation = owner.corselet_yiyu_winter+owner.helmet_yiyu_winter
	owner.components.temperature.inherentsummerinsulation = owner.corselet_yiyu_summer+owner.helmet_yiyu_summer
	end
	if owner.dodge_yiyu then
	owner.helmet_yiyu_dodge = 0
	owner.dodge_yiyu = owner.corselet_yiyu_dodge + owner.helmet_yiyu_dodge
	end
	if owner.drop_yiyu then
	owner.helmet_yiyu_drop = 0
	owner.drop_yiyu = owner.corselet_yiyu_drop+owner.helmet_yiyu_drop
	end
end

----------------

local function onpreload(inst, data)
	if data then
	inst.weapon_upgrade = data.weapon_upgrade
	inst.armor_health = data.weapon_upgrade
	inst.armor_fire_resistance = data.armor_fire_resistance
	inst.armor_cold_resistance = data.armor_cold_resistance
	inst.armor_winter_temp = data.armor_winter_temp
	inst.armor_summer_temp = data.armor_summer_temp
	inst.armor_dodge = data.armor_dodge
	inst.armor_drop = data.armor_drop
	inst.armor_godbless = data.armor_godbless
	inst.armor_absorb = data.armor_absorb
	inst.armor_thorns = data.armor_thorns
	inst.weapon_hunger = data.weapon_hunger
	if data.armor_absorb then
		if inst.prefab == "yuyi_hat1" then
		inst.components.armor:SetAbsorption(0.65+data.armor_absorb)
		elseif inst.prefab == "yuyi_hat2" then
		inst.components.armor:SetAbsorption(0.80+(1-TUNING.DIFFICULTY_YUYI)/10+data.armor_absorb)
		elseif inst.prefab == "yuyi_hat3" then
		inst.components.armor:SetAbsorption(0.80+(1-TUNING.DIFFICULTY_YUYI)/10+data.armor_absorb)
		end
	end
	end
end

local function onsave(inst, data)
	data.weapon_upgrade = inst.weapon_upgrade
	data.armor_health = inst.armor_health
	data.armor_absorb = inst.armor_absorb
	data.armor_fire_resistance = inst.armor_fire_resistance
	data.armor_cold_resistance = inst.armor_cold_resistance
	data.armor_winter_temp = inst.armor_winter_temp
	data.armor_summer_temp = inst.armor_summer_temp
	data.armor_dodge = inst.armor_dodge
	data.armor_drop = inst.armor_drop
	data.armor_godbless = inst.armor_godbless
	data.armor_thorns = inst.armor_thorns
	data.weapon_hunger = inst.weapon_hunger
end

local function OnLoad(inst, data)
	if data then
	inst.weapon_upgrade = data.weapon_upgrade
	inst.armor_health = data.weapon_upgrade
	inst.armor_fire_resistance = data.armor_fire_resistance
	inst.armor_cold_resistance = data.armor_cold_resistance
	inst.armor_winter_temp = data.armor_winter_temp
	inst.armor_summer_temp = data.armor_summer_temp
	inst.armor_dodge = data.armor_dodge
	inst.armor_drop = data.armor_drop
	inst.armor_godbless = data.armor_godbless
	inst.armor_absorb = data.armor_absorb
	inst.armor_thorns = data.armor_thorns
	inst.weapon_hunger = data.weapon_hunger
	if data.armor_absorb then
		if inst.prefab == "yuyi_hat1" then
		inst.components.armor:SetAbsorption(0.65+data.armor_absorb)
		elseif inst.prefab == "yuyi_hat2" then
		inst.components.armor:SetAbsorption(0.80+(1-TUNING.DIFFICULTY_YUYI)/10+data.armor_absorb)
		elseif inst.prefab == "yuyi_hat3" then
		inst.components.armor:SetAbsorption(0.80+(1-TUNING.DIFFICULTY_YUYI)/10+data.armor_absorb)
		end
	end
	end
end

----------------

local function yuyi_hat1()
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("beehat")
	inst.AnimState:SetBuild("yuyi_hat1")
	inst.AnimState:PlayAnimation("anim")

	inst.entity:AddMiniMapEntity()
	inst.MiniMapEntity:SetIcon( "yuyi_hat1.tex" )

	inst:AddTag("hat")
	inst:AddComponent("tradable")
	inst:AddComponent("inspectable")
	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/yuyi_hat1.xml"
	inst:AddComponent("armor")
	inst.components.armor:InitCondition(1800, 0.65)

	inst:AddComponent("equippable")
	inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
	inst.components.equippable:SetOnEquip( onequipyuyi_hat1 )
	inst.components.equippable:SetOnUnequip( onunequipyuyi_hat1 )
    inst.components.equippable.runspeedmult = TUNING.CANE_SPEED_MULT - 0.1
    inst.components.equippable.walkspeedmult = TUNING.CANE_SPEED_MULT - 0.1

	inst:AddComponent("characterspecific")
	inst.components.characterspecific:SetOwner("yuyi")

if not IsDLCEnabled(REIGN_OF_GIANTS) then
	MakeInventoryFloatable(inst, "idle_water", "anim")
end

    return inst
end


local function yuyi_hat2()

	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("beehat")
	inst.AnimState:SetBuild("yuyi_hat2")
	inst.AnimState:PlayAnimation("anim")

	inst.weapon_upgrade = 0--强化
	inst.armor_health = 0--生命上限
	inst.armor_absorb = 0--伤害减免
	inst.armor_corselet = 0--伤害吸收
	inst.armor_fire_resistance = 0--火焰抗性
	inst.armor_cold_resistance = 0 --冰冻抗性
	inst.armor_winter_temp = 0--保暖
	inst.armor_summer_temp = 0--隔热
	inst.armor_dodge = 0 --闪避
	inst.armor_drop = 0 --卸甲
	inst.armor_godbless = 0 --神佑
	inst.armor_thorns = 0--荆棘
	inst.weapon_hunger = 0--饥饿速率

	inst.entity:AddMiniMapEntity()
	inst.MiniMapEntity:SetIcon( "yuyi_hat2.tex" )

	inst:AddTag("hat")
	inst:AddComponent("inspectable")

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/yuyi_hat2.xml"
	
	inst:AddComponent("equippable")
	inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
	inst.components.equippable:SetOnEquip( onequip_yuyi_hat2 )
	inst.components.equippable:SetOnUnequip( onunequip_yuyi_hat2 )
    inst.components.equippable.runspeedmult = TUNING.CANE_SPEED_MULT - 0.1
    inst.components.equippable.walkspeedmult = TUNING.CANE_SPEED_MULT - 0.1

    inst:AddComponent("fueled")
    inst.components.fueled.fueltype = "NIGHTMARE"
    inst.components.fueled:InitializeFuelLevel(1800)
    inst.components.fueled.ontakefuelfn = TakeItems
    inst.components.fueled.accepting = true
    inst.components.fueled:StopConsuming()
	inst:ListenForEvent("percentusedchange", PercentChanged)

	inst:AddComponent("useableitem")
	inst.components.useableitem:SetOnUseFn(onuseyuyihats)
    inst.components.useableitem:SetCanInteractFn(function() if inst.components.equippable:IsEquipped() then return true end end)

	inst:AddComponent("characterspecific")
    inst.components.characterspecific:SetOwner("yuyi")

	inst:AddComponent("armor")
	inst.components.armor:InitCondition(1800, 0.80+(1-TUNING.DIFFICULTY_YUYI)/10)

if not IsDLCEnabled(REIGN_OF_GIANTS) then
	MakeInventoryFloatable(inst, "idle_water", "anim")
end

    inst.OnLoad = OnLoad
    inst.OnSave = onsave
    inst.OnPreLoad = onpreload
	inst:DoTaskInTime(0.75, function() GETDIFFICULTY(inst) end)
    return inst
end


local function yuyi_hat3()

	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("beehat")
	inst.AnimState:SetBuild("yuyi_hat3")
	inst.AnimState:PlayAnimation("anim")

	inst.weapon_upgrade = 0--强化
	inst.armor_health = 0--生命上限
	inst.armor_absorb = 0--伤害减免
	inst.armor_corselet = 0--伤害吸收
	inst.armor_dodge = 0 --闪避
	inst.armor_drop = 0 --卸甲
	inst.armor_thorns = 0--荆棘
	inst.armor_fire_resistance = 0--火焰抗性
	inst.armor_cold_resistance = 0 --冰冻抗性
	inst.armor_winter_temp = 0--保暖
	inst.armor_summer_temp = 0--隔热
	inst.armor_godbless = 0 --神佑
	inst.weapon_hunger = 0--饥饿速率

	inst.entity:AddMiniMapEntity()
	inst.MiniMapEntity:SetIcon( "yuyi_hat3.tex" )

	inst:AddTag("hat")
	inst:AddComponent("inspectable")

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.imagename = "yuyi_hat3"
	inst.components.inventoryitem.atlasname = "images/inventoryimages/yuyi_hat3.xml"

	inst:AddComponent("equippable")
	inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
	inst.components.equippable:SetOnEquip( onequip_yuyi_hat3 )
	inst.components.equippable:SetOnUnequip( onunequip_yuyi_hat3 )
    inst.components.equippable.runspeedmult = TUNING.CANE_SPEED_MULT - 0.1
    inst.components.equippable.walkspeedmult = TUNING.CANE_SPEED_MULT - 0.1

    inst:AddComponent("fueled")
    inst.components.fueled.fueltype = "NIGHTMARE"
    inst.components.fueled:InitializeFuelLevel(1800)
    inst.components.fueled.ontakefuelfn = TakeItems
    inst.components.fueled.accepting = true
    inst.components.fueled:StopConsuming()
	inst:ListenForEvent("percentusedchange", PercentChanged)

	inst:AddComponent("useableitem")
	inst.components.useableitem:SetOnUseFn(onuseyuyihats2)
    inst.components.useableitem:SetCanInteractFn(function() if inst.components.equippable:IsEquipped() then return true end end)

	inst:AddComponent("characterspecific")
    inst.components.characterspecific:SetOwner("yuyi")

	inst:AddComponent("armor")
	inst.components.armor:InitCondition(1800, 0.80+(1-TUNING.DIFFICULTY_YUYI)/10)

	if not IsDLCEnabled(REIGN_OF_GIANTS) then
	MakeInventoryFloatable(inst, "idle_water", "anim")
	end

    inst.OnLoad = OnLoad
    inst.OnSave = onsave
    inst.OnPreLoad = onpreload
	inst:DoTaskInTime(1, function() GETDIFFICULTY(inst) end)
    return inst
end

return  Prefab( "common/inventory/yuyi_hat1", yuyi_hat1, assets, prefabs),
		Prefab( "common/inventory/yuyi_hat2", yuyi_hat2, assets, prefabs),
		Prefab( "common/inventory/yuyi_hat3", yuyi_hat3, assets, prefabs)