local assets =
{
    Asset("ANIM", "anim/downvest_pink77.zip"),  --对应在anim里面的文件 加载动画文件
	Asset("ATLAS", "inventoryimages/downvest_pink77.xml"), --加载物品栏贴图
    Asset("IMAGE", "inventoryimages/downvest_pink77.tex"),
}
local function armorhealing(inst, owner)
	local owner = inst.components.inventoryitem.owner
	if inst.components.inventoryitem == nil or owner.components.inventory == nil then
        return
    end
	if owner and owner.components.health ~= 0 and owner.components.health:IsHurt() and inst.heal_time == 1 then
		owner.components.health.currenthealth = owner.components.health.currenthealth+1
		owner.components.health:ForceUpdateHUD()
		owner.player_classified.issleephealing:set(true)
	end
end

local function OnBlocked(owner, data)
    owner.SoundEmitter:PlaySound("dontstarve/wilson/hit_armour")
end

local function onequip(inst, owner) --装备
	owner.AnimState:OverrideSymbol("swap_body", "downvest_pink77", "swap_body")
  inst.heal_time = 1
	if inst.heal_time == 1 then
	   inst.task = inst:DoPeriodicTask(1, function() armorhealing(inst, 2) end)
	end
	owner.player_classified.issleephealing:set(true)
	owner:AddTag("downvested")
  inst:ListenForEvent("blocked", OnBlocked, owner)
end

local function onunequip(inst, owner)  --脱下
    owner.AnimState:ClearOverrideSymbol("swap_body")
    inst.heal_time = 0
  	if inst.task ~= nil then
          inst.task:Cancel()
          inst.task = nil
    end
  	owner.player_classified.issleephealing:set(false)
  	owner:RemoveTag("downvested")
    inst:RemoveEventCallback("blocked", OnBlocked, owner)
end

local function fn()
    local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("downvest_pink77") --动画
    inst.AnimState:SetBuild("downvest_pink77")
    inst.AnimState:PlayAnimation("anim")	--丢地上的动画

    inst:AddTag("wood")

    inst.foleysound = "dontstarve/movement/foley/logarmour"

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("inspectable") --可悲检查组件

    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "inventoryimages/downvest_pink77.xml"  --加载物品栏贴图 mod物品必须有

	inst:AddComponent("waterproofer")  --防雨组件  （括号里面可以直接填数字）
    inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_ABSOLUTE)

	inst:AddComponent("insulator") --温度隔绝组件（括号里可以直接天数字就是保温多少秒）
    inst.components.insulator:SetInsulation(240)

	inst:AddComponent("fuel")--燃料 组件
    inst.components.fuel.fuelvalue = TUNING.LARGE_FUEL

    MakeSmallBurnable(inst, TUNING.SMALL_BURNTIME) --燃烧有关
    MakeSmallPropagator(inst)

    inst:AddComponent("armor")--护甲组件
    inst.components.armor:InitCondition(1500,0.5) --耐久度和减伤（90%）
    inst.components.armor:AddWeakness("beaver", TUNING.BEAVER_WOOD_DAMAGE)

    inst:AddComponent("equippable") --装备组件
    inst.components.equippable.equipslot = EQUIPSLOTS.BODY --装备的部位是身体
    inst.components.equippable.walkspeedmult = 1.25--這是裝備後可以加速

    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)

    MakeHauntableLaunch(inst)

    return inst
end

return Prefab("downvest_pink77", fn, assets) --生成这个预设物  代码为 downvest_gray77
