local assets=
{
    Asset("ANIM", "anim/yuyi_sack1.zip"),
    Asset("ANIM", "anim/swap_yuyi_sack1.zip"),
    Asset("ANIM", "anim/yuyi_sack2.zip"),
    Asset("ANIM", "anim/swap_yuyi_sack2.zip"),
    Asset("ANIM", "anim/yuyi_sack3.zip"),
    Asset("ANIM", "anim/swap_yuyi_sack3.zip"),
    Asset("ANIM", "anim/ui_thatchpack_1x4.zip"),

    Asset("IMAGE", "images/inventoryimages/yuyi_sack1.tex"),
    Asset("ATLAS","images/inventoryimages/yuyi_sack1.xml"),
    Asset("IMAGE", "images/inventoryimages/yuyi_sack2.tex"),
    Asset("ATLAS","images/inventoryimages/yuyi_sack2.xml"),
    Asset("IMAGE", "images/inventoryimages/yuyi_sack3.tex"),
    Asset("ATLAS","images/inventoryimages/yuyi_sack3.xml"),
}

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

local function GETDIFFICULTY1(inst)
if	TUNING.YIYUISOPEN == 1 then
	inst.components.armor:SetAbsorption(0.60+(1-TUNING.DIFFICULTY_YUYI)/10)
	end
end

local function GETDIFFICULTY2(inst)
if	TUNING.YIYUISOPEN == 1 then
	inst.components.armor:SetAbsorption(0.70+(1-TUNING.DIFFICULTY_YUYI)/10)
	end
end

local function Removebackpack(inst)
	inst.components.container:DropEverything()
	GetPlayer().components.talker:Say(STRINGS.YUYI_SACK1)
	if inst.prefab == "yuyi_sack1" then
		inst:Remove()
	elseif inst.prefab == "yuyi_sack2" then
		inst:Remove()
		c_give("dragon_scales",1)
	elseif inst.prefab == "yuyi_sack3" then
		inst:Remove()
		c_give("dragon_scales",1)
		c_give("bearger_fur",1)
	end
end

local function task_yuyisack(inst)
	local yuyi_sack1num = c_countprefabs("yuyi_sack1", true) or 0
	local yuyi_sack2num = c_countprefabs("yuyi_sack2", true) or 0
	local yuyi_sack3num = c_countprefabs("yuyi_sack3", true) or 0
	if inst.yuyiweapon_upgrade and inst.yuyiweapon_upgrade < 0 then
		inst.yuyiweapon_upgrade = 0
	end
	if inst.armor_godbless and inst.armor_godbless == 0 then
		inst:DoTaskInTime(3, function() Removebackpack(inst) end)
	end
	if yuyi_sack1num and yuyi_sack1num > 2 then
    local yuyi_sack1near = TheSim:FindFirstEntityWithTag("yuyi_sack1")
		if yuyi_sack1near and yuyi_sack1near.weapon_upgrade == 0 then
			yuyi_sack1near.components.container:DropEverything()
			yuyi_sack1near:Remove()
			c_give("goldnugget",10)
			c_give("armorwood",1)
		end
	end
	if yuyi_sack2num and yuyi_sack2num > 2 then
    local yuyi_sack2near = TheSim:FindFirstEntityWithTag("yuyi_sack2")
		if yuyi_sack2near and yuyi_sack2near.weapon_upgrade == 0 then
			yuyi_sack2near.components.container:DropEverything()
			yuyi_sack2near:Remove()
			c_give("purplegem",1)
			c_give("dragon_scales",1)
			c_give("yuyi_sack1",1)
		end
	end
	if yuyi_sack3num and yuyi_sack3num > 1 then
    local yuyi_sack3near = TheSim:FindFirstEntityWithTag("yuyi_sack3")
		if yuyi_sack3near and yuyi_sack3near.weapon_upgrade == 0 then
			yuyi_sack3near.components.container:DropEverything()
			yuyi_sack3near:Remove()
			c_give("purplegem",1)
			c_give("bearger_fur",1)
			c_give("yuyi_sack2",1)
		end
	end
end

local slotpos_1x4 = {}
for y = 0, 3 do
	table.insert(slotpos_1x4, Vector3(-162 +(75/2), -y*75 + 114 ,0))
end

local slotpos = {}
for y = 0, 3 do
	table.insert(slotpos, Vector3(-162, -y*75 + 114 ,0))
	table.insert(slotpos, Vector3(-162 +75, -y*75 + 114 ,0))
end

local slotpos_2x5 = {}
for y = 0, 4 do
	table.insert(slotpos_2x5, Vector3(-162, -y*75 + 115 ,0))
	table.insert(slotpos_2x5, Vector3(-162 +75, -y*75 + 115 ,0))
end

local slotpos_2x6 = {}
for y = 0, 5 do
	table.insert(slotpos_2x6, Vector3(-162, -y*75 + 170 ,0))
	table.insert(slotpos_2x6, Vector3(-162 +75, -y*75 + 170 ,0))
end

local slotpos_2x8 = {}
for y = 0, 6 do
	table.insert(slotpos_2x8, Vector3(-162, -y*75 + 240 ,0))
	table.insert(slotpos_2x8, Vector3(-162 +75, -y*75 + 240 ,0))
end

local function yuyitest(inst, item, slot)
    if item.prefab == "chester_eyebone" or item.prefab == "packim_fishbone" or item.prefab == "yiyu_apple" or item == inst then
    return false
    end
	return true
end

local function OnDropped(inst)
    inst.AnimState:PlayAnimation("anim")
end

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

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

local function ShouldAcceptItem(inst, item)
	if item.prefab == "nightmarefuel" then return true else return false end
end

local function onequipyuyisack1(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_body", "swap_yuyi_sack1", "yuyi_sack1")
    owner.AnimState:OverrideSymbol("swap_body", "swap_yuyi_sack1", "swap_body")
    owner.components.inventory:SetOverflow(inst)
    inst.components.container:Open(owner)
end
	
local function onunequipyuyisack1(inst, owner)
    owner.AnimState:ClearOverrideSymbol("swap_body")
    owner.AnimState:ClearOverrideSymbol("yuyi_sack1")
    owner.components.inventory:SetOverflow(nil)
    inst.components.container:Close(owner)
end

local function onequipyuyisack2(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_body", "swap_yuyi_sack2", "yuyi_sack2")
    owner.AnimState:OverrideSymbol("swap_body", "swap_yuyi_sack2", "swap_body")
    owner.components.inventory:SetOverflow(inst)
    inst.components.container:Open(owner)
    if owner.components.health then
        owner.components.health.fire_damage_scale = 0
    end
end

local function onunequipyuyisack2(inst, owner)
    owner.AnimState:ClearOverrideSymbol("swap_body")
    owner.AnimState:ClearOverrideSymbol("yuyi_sack2")
    owner.components.inventory:SetOverflow(nil)
    inst.components.container:Close(owner)
    if owner.components.health then
        owner.components.health.fire_damage_scale = 1
    end
end

local function onequipyuyisack3(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_body", "swap_yuyi_sack3", "yuyi_sack3")
    owner.AnimState:OverrideSymbol("swap_body", "swap_yuyi_sack3", "swap_body")
    owner.components.inventory:SetOverflow(inst)
    inst.components.container:Open(owner)
    if owner.components.health then
        owner.components.health.fire_damage_scale = 0
    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.corselet_yiyu then
		owner.corselet_yiyu = inst.armor_corselet
		owner.components.health.absorb = owner.corselet_yiyu + owner.helmet_yiyu
	end
	if owner.components.freezable then
		owner.corselet_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.corselet_yiyu_winter = inst.armor_winter_temp
	owner.corselet_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.corselet_yiyu_dodge = inst.armor_dodge
	owner.dodge_yiyu = owner.corselet_yiyu_dodge+owner.helmet_yiyu_dodge
	end
	if owner.drop_yiyu then
	owner.corselet_yiyu_drop = inst.armor_drop
	owner.drop_yiyu = owner.corselet_yiyu_drop+owner.helmet_yiyu_drop
	end
	if owner.thorns_yiyu then
	owner.corselet_yiyu_thorns = inst.armor_thorns
	owner.thorns_yiyu = owner.corselet_yiyu_thorns+owner.helmet_yiyu_thorns
	end
end

local function onunequipyuyisack3(inst, owner)
    owner.AnimState:ClearOverrideSymbol("swap_body")
    owner.AnimState:ClearOverrideSymbol("yuyi_sack3")
    owner.components.inventory:SetOverflow(nil)
    inst.components.container:Close(owner)
    if owner.components.health then
        owner.components.health.fire_damage_scale = 1
    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.corselet_yiyu then
		owner.corselet_yiyu = 0
		owner.components.health.absorb = owner.corselet_yiyu + owner.helmet_yiyu
	end

	if owner.components.freezable then
		owner.corselet_yiyu_cold = 0
		owner.components.freezable.resistance = owner.corselet_yiyu_cold+owner.helmet_yiyu_cold+3
--		owner.components.freezable:SetResistance(owner.corselet_yiyu_cold+owner.helmet_yiyu_cold+2)
	end
	if owner.components.temperature then
	owner.corselet_yiyu_winter = 0
	owner.corselet_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.corselet_yiyu_dodge = 0
	owner.dodge_yiyu = owner.corselet_yiyu_dodge+owner.helmet_yiyu_dodge
	end
	if owner.drop_yiyu then
	owner.corselet_yiyu_drop = 0
	owner.drop_yiyu = owner.corselet_yiyu_drop+owner.helmet_yiyu_drop
	end
end

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

local function yuyi_sack_updata1(inst, dofx)
    inst.components.container:SetNumSlots(#slotpos_2x5)
    inst.components.container.widgetslotpos = slotpos_2x5
	inst.components.container.widgetanimbank = "ui_krampusbag_2x5"
	inst.components.container.widgetanimbuild = "ui_krampusbag_2x5"
    inst.components.container.widgetpos = Vector3(-5,-80,0)
    inst.components.container.itemtestfn = yuyitest
    inst.components.container.side_widget = true
    inst.components.container.type = "pack"
end

local function yuyi_sack_updata2(inst, dofx)
    inst.components.container:SetNumSlots(#slotpos_2x6)
    inst.components.container.widgetslotpos = slotpos_2x6
	inst.components.container.widgetanimbank = "ui_piggyback_2x6"
	inst.components.container.widgetanimbuild = "ui_piggyback_2x6"
    inst.components.container.widgetpos = Vector3(-5,-90,0)
    inst.components.container.itemtestfn = yuyitest
    inst.components.container.side_widget = true
    inst.components.container.type = "pack"
end


local function yuyi_sack_updata3(inst, dofx)
    inst.components.container:SetNumSlots(#slotpos_2x8)
    inst.components.container.widgetslotpos = slotpos_2x8
	inst.components.container.widgetanimbank = "ui_krampusbag_2x8"
	inst.components.container.widgetanimbuild = "ui_krampusbag_2x8"
    inst.components.container.widgetpos = Vector3(-5,-120,0)
    inst.components.container.itemtestfn = yuyitest
    inst.components.container.side_widget = true
    inst.components.container.type = "pack"
end

local function OnPutInInventory(inst)
    if inst.weapon_upgrade >= 15 then
		yuyi_sack_updata3(inst)
	elseif inst.weapon_upgrade >= 10 then
		yuyi_sack_updata2(inst)
	elseif inst.weapon_upgrade >= 5 then
		yuyi_sack_updata1(inst)
    end
end
----------------

local function onpreload(inst, data)
	if data and data.weapon_upgrade then
	inst.weapon_upgrade = data.weapon_upgrade
	inst.armor_godbless = data.armor_godbless
	end
	if data.armor_dodge then
	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_thorns = data.armor_thorns
	inst.weapon_hunger = data.weapon_hunger
	inst.armor_absorb = data.armor_absorb
    if inst.weapon_upgrade >= 15 then
		yuyi_sack_updata3(inst)
	elseif inst.weapon_upgrade >= 10 then
		yuyi_sack_updata2(inst)
	elseif inst.weapon_upgrade >= 5 then
		yuyi_sack_updata1(inst)
    end
	end
end

local function onsave(inst, data)
	if inst and inst.weapon_upgrade then
	data.weapon_upgrade = inst.weapon_upgrade
	data.armor_godbless = inst.armor_godbless
	end
	if inst and inst.armor_dodge then
	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_thorns = inst.armor_thorns
	data.weapon_hunger = inst.weapon_hunger
	end
end

local function OnLoad(inst, data)
	if data and data.weapon_upgrade then
	inst.weapon_upgrade = data.weapon_upgrade
	inst.armor_godbless = data.armor_godbless
	end
	if data.armor_dodge then
	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_thorns = data.armor_thorns
	inst.weapon_hunger = data.weapon_hunger
	inst.armor_absorb = data.armor_absorb
    if inst.weapon_upgrade >= 15 then
		yuyi_sack_updata3(inst)
	elseif inst.weapon_upgrade >= 10 then
		yuyi_sack_updata2(inst)
	elseif inst.weapon_upgrade >= 5 then
		yuyi_sack_updata1(inst)
    end
	end
end
----------------

local function yuyi_sack1fn(Sim)
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.AnimState:SetBank("yuyi_sack1")
	inst.AnimState:SetBuild("swap_yuyi_sack1")
	inst.AnimState:PlayAnimation("anim")
	MakeInventoryPhysics(inst)
	inst.entity:AddTransform():SetScale(1.75, 1.75, 1.75)

	inst.weapon_upgrade = 0--强化
	inst.armor_godbless = 1 --神佑
	inst.armor_absorb = 0
	inst.entity:AddMiniMapEntity()
	inst.MiniMapEntity:SetIcon( "yuyi_sack1.tex" )

	inst:AddTag("yuyi_sack1")
    inst:AddComponent("inspectable")
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.cangoincontainer = true
    inst.components.inventoryitem.imagename = "yuyi_sack1"
    inst.components.inventoryitem:SetOnDroppedFn(OnDropped)
    inst.components.inventoryitem.atlasname = "images/inventoryimages/yuyi_sack1.xml"
    inst.components.inventoryitem.foleysound = "dontstarve/movement/foley/krampuspack"
	inst.components.inventoryitem.keepondeath = true

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

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

	inst:AddComponent("characterspecific")
    inst.components.characterspecific:SetOwner("yuyi")
	
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.BODY
    inst.components.equippable:SetOnEquip( onequipyuyisack1 )
    inst.components.equippable:SetOnUnequip( onunequipyuyisack1 )

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

    inst:AddComponent("container")
    inst.components.container:SetNumSlots(#slotpos_1x4)
    inst.components.container.widgetslotpos = slotpos_1x4
    inst.components.container.widgetanimbank = "ui_thatchpack_1x4"
    inst.components.container.widgetanimbuild = "ui_thatchpack_1x4"
    inst.components.container.widgetpos = Vector3(-5,-70,0)
    inst.components.container.itemtestfn = yuyitest
    inst.components.container.side_widget = true
    inst.components.container.type = "pack"

    inst.components.container.onopenfn = function(inst) GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold") end
    inst.components.container.onclosefn = function(inst) GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold") end
	inst:DoTaskInTime(0.5, function() GETDIFFICULTY1(inst) end)
	inst.task_yuyisack = inst:DoPeriodicTask(1, function() task_yuyisack(inst) end)
    inst.OnLoad = OnLoad
    inst.OnSave = onsave
    inst.OnPreLoad = onpreload
    return inst
end

local function yuyi_sack2fn(Sim)
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.AnimState:SetBank("yuyi_sack2")
	inst.AnimState:SetBuild("swap_yuyi_sack2")
	inst.AnimState:PlayAnimation("anim")
	MakeInventoryPhysics(inst)
	inst.entity:AddTransform():SetScale(1.75, 1.75, 1.75)

	inst.weapon_upgrade = 0--强化
	inst.armor_absorb = 0
	inst.armor_fire_resistance = 1--火焰抗性
	inst.armor_godbless = 1 --神佑
	inst.entity:AddMiniMapEntity()
	inst.MiniMapEntity:SetIcon( "yuyi_sack2.tex" )

    inst.OnLoad = OnLoad
    inst.OnSave = onsave
    inst.OnPreLoad = onpreload

	inst:AddTag("yuyi_sack2")
    inst:AddComponent("inspectable")
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.cangoincontainer = true
    inst.components.inventoryitem.imagename = "yuyi_sack2"
    inst.components.inventoryitem:SetOnDroppedFn(OnDropped)
    inst.components.inventoryitem:SetOnPutInInventoryFn(OnPutInInventory)
    inst.components.inventoryitem.atlasname = "images/inventoryimages/yuyi_sack2.xml"
    inst.components.inventoryitem.foleysound = "dontstarve/movement/foley/krampuspack"
	inst.components.inventoryitem.keepondeath = true

    inst:AddComponent("armor")
    inst.components.armor:InitCondition(3600, 0.70+(1-TUNING.DIFFICULTY_YUYI)/10)
    inst:AddComponent("fueled")
    inst.components.fueled.fueltype = "NIGHTMARE"
    inst.components.fueled:InitializeFuelLevel(3600)
    inst.components.fueled.ontakefuelfn = TakeItems
    inst.components.fueled.accepting = true
    inst.components.fueled:StopConsuming()
	inst:ListenForEvent("percentusedchange", PercentChanged)
	
	inst:AddComponent("characterspecific")
    inst.components.characterspecific:SetOwner("yuyi")
	
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.BODY
    inst.components.equippable:SetOnEquip( onequipyuyisack2 )
    inst.components.equippable:SetOnUnequip( onunequipyuyisack2 )

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

    inst:AddComponent("container")
    inst.components.container:SetNumSlots(#slotpos)
    inst.components.container.widgetslotpos = slotpos
	inst.components.container.widgetanimbank = "ui_backpack_2x4"
	inst.components.container.widgetanimbuild = "ui_backpack_2x4"
    inst.components.container.widgetpos = Vector3(-5,-70,0)
    inst.components.container.itemtestfn = yuyitest
    inst.components.container.side_widget = true
    inst.components.container.type = "pack"
	
    inst.components.container.onopenfn = function(inst) GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold") end
    inst.components.container.onclosefn = function(inst) GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold") end
	inst:DoTaskInTime(0.5, function() GETDIFFICULTY2(inst) end)
	inst.task_yuyisack = inst:DoPeriodicTask(1, function() task_yuyisack(inst) end)

    return inst
end

local function yuyi_sack3fn(Sim)
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.AnimState:SetBank("yuyi_sack3")
	inst.AnimState:SetBuild("swap_yuyi_sack3")
	inst.AnimState:PlayAnimation("anim")
	MakeInventoryPhysics(inst)
	inst.entity:AddTransform():SetScale(1.75, 1.75, 1.75)

	inst.yuyiweapon_upgrade = 0--强化
	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.weapon_hunger = 0--饥饿速率

	inst.armor_godbless = 1 --神佑
	inst.armor_fire_resistance = 1--火焰抗性
	inst.armor_cold_resistance = 0 --冰冻抗性
	inst.armor_winter_temp = 0--保暖
	inst.armor_summer_temp = 0--隔热

    inst.OnPreLoad = onpreload
    inst.OnLoad = OnLoad
    inst.OnSave = onsave


	inst.entity:AddMiniMapEntity()
	inst.MiniMapEntity:SetIcon( "yuyi_sack3.tex" )
	inst:AddTag("fridge")
	inst:AddTag("yuyi_sack3")
    inst:AddComponent("inspectable")
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.cangoincontainer = true
    inst.components.inventoryitem.imagename = "yuyi_sack3"
    inst.components.inventoryitem:SetOnDroppedFn(OnDropped)
    inst.components.inventoryitem:SetOnPutInInventoryFn(OnPutInInventory)
    inst.components.inventoryitem.atlasname = "images/inventoryimages/yuyi_sack3.xml"
    inst.components.inventoryitem.foleysound = "dontstarve/movement/foley/krampuspack"
	inst.components.inventoryitem.keepondeath = true

    inst:AddComponent("armor")
    inst.components.armor:InitCondition(3600, 0.80+(1-TUNING.DIFFICULTY_YUYI)/10)
    inst:AddComponent("fueled")
    inst.components.fueled.fueltype = "NIGHTMARE"
    inst.components.fueled:InitializeFuelLevel(3600)
    inst.components.fueled.ontakefuelfn = TakeItems
    inst.components.fueled.accepting = true
    inst.components.fueled:StopConsuming()
	inst:ListenForEvent("percentusedchange", PercentChanged)
	
	inst:AddComponent("characterspecific")
    inst.components.characterspecific:SetOwner("yuyi")
	
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.BODY
    inst.components.equippable:SetOnEquip( onequipyuyisack3 )
    inst.components.equippable:SetOnUnequip( onunequipyuyisack3 )

	if not IsDLCEnabled(REIGN_OF_GIANTS) then
    MakeInventoryFloatable(inst, "idle_water", "anim")
    inst.components.equippable.poisonblocker = true
	end

    inst:AddComponent("container")
    inst.components.container:SetNumSlots(#slotpos)
    inst.components.container.widgetslotpos = slotpos
	inst.components.container.widgetanimbank = "ui_backpack_2x4"
	inst.components.container.widgetanimbuild = "ui_backpack_2x4"
    inst.components.container.widgetpos = Vector3(-5,-70,0)
    inst.components.container.itemtestfn = yuyitest
    inst.components.container.side_widget = true
    inst.components.container.type = "pack"
	
    inst.components.container.onopenfn = function(inst) GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold") end
    inst.components.container.onclosefn = function(inst) GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold") end
	inst:DoTaskInTime(0.5, function() GETDIFFICULTY(inst) end)
	inst.task_yuyisack = inst:DoPeriodicTask(1, function() task_yuyisack(inst) end)
    return inst
end

return	Prefab( "common/inventory/yuyi_sack1", yuyi_sack1fn, assets),
		Prefab( "common/inventory/yuyi_sack2", yuyi_sack2fn, assets),
		Prefab( "common/inventory/yuyi_sack3", yuyi_sack3fn, assets) 

