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

}
--------------
local function close(inst)
--inst.components.resurrector.active = true
end

local function far(inst)
--inst.components.resurrector.active = false
end

local function makeused5(inst)
	inst.AnimState:PlayAnimation("debris")
end

local function doresurrect5(inst, dude)
    dude.entity:AddLight()
	dude.Light:SetRadius(3)
    dude.Light:SetFalloff(10)
    dude.Light:SetIntensity(.5)
    dude.Light:SetColour(15/255,165/255,165/255)
	dude.Light:Enable(true)

	inst:AddTag("busy")	
	inst.persists = false
    if inst.Physics then
		RemovePhysicsColliders(inst)
    end
    --dude:Hide()
    if dude.HUD then
        dude.HUD:Hide()
    end
    if dude.components.playercontroller then
        dude.components.playercontroller:Enable(false)
    end

    inst:RemoveComponent("inspectable")
    dude:ClearBufferedAction()
------
    scheduler:ExecuteInTime(2, function()
        dude:Show()
       -- inst:Hide()

inst.AnimState:PlayAnimation("debris")
-------
        dude.sg:GoToState("amulet_rebirth")
        dude:DoTaskInTime(4, function() 

            if dude.HUD then
                dude.HUD:Show()
            end
            if dude.components.health then
				dude.components.health:RecalculatePenalty()
                dude.components.health:Respawn(120)
                dude.components.health:SetInvincible(true)
            end
          if dude.components.sanity then
			    dude.components.sanity:SetPercent(1)
            end
          if dude.components.hunger then
                dude.components.hunger:SetPercent(1)
            end
        if dude.components.playercontroller then
                dude.components.playercontroller:Enable(true)
            end
            inst:RemoveTag("busy")
            dude.components.health:SetInvincible(false)
	dude.Light:Enable(false)

 end)
	inst:Show()

 end)
	if inst.components.container then 
	inst.components.container:DropEverything() 
    end
	local dark2 = SpawnPrefab("statue_transition_2")
	local pos = Vector3(inst.Transform:GetWorldPosition())
dark2.Transform:SetPosition(pos:Get())
	local armor = SpawnPrefab("armor_mushaa")
	local pos = Vector3(inst.Transform:GetWorldPosition())
crown.Transform:SetPosition(pos:Get())

	inst:Remove()
            end
----------------

local function OnOpen(inst)
    inst.SoundEmitter:PlaySound("dontstarve/wilson/lighter_on")
end 

local function OnClose(inst) 
    inst.SoundEmitter:PlaySound("dontstarve/wilson/lighter_on")
end 

local slotpos = {}

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

--[[
local slotpos = {}

for y = 0, 6 do
	table.insert(slotpos, Vector3(-162, -y*75 + 240 ,0))
	table.insert(slotpos, Vector3(-162 +75, -y*75 + 240 ,0))
end
]]
--------------
local function healowner(inst, owner)
    if (owner.components.health and owner.components.health:IsHurt())
    and (owner.components.hunger and owner.components.hunger.current > 160 and owner.components.health:GetPercent() > 0.6)then
        owner.components.health:DoDelta(2,false)
elseif (owner.components.health and owner.components.health:IsHurt())
    and (owner.components.hunger and owner.components.hunger.current < 160 and owner.components.hunger and owner.components.hunger.current > 60  )then
        owner.components.health:DoDelta(1,false)
        owner.components.sanity:DoDelta(1,false)
elseif (owner.components.health and owner.components.health:IsHurt())
    and (owner.components.hunger and owner.components.hunger.current < 60 )then
        owner.components.sanity:DoDelta(2,false)
    end
end
--[[
local function OnBlocked(owner) 
    owner.SoundEmitter:PlaySound("dontstarve/wilson/hit_armour") 
end
]]--
---------------------------
local function levelexp(inst,data)

	local max_exp = 4100
	local exp = math.min(inst.level, max_exp)

if inst.level <= 4000 then
inst.components.talker:Say("-[公主的盔甲]-\n[成长点数]".. (inst.level))
inst:RemoveTag("levelup")
end
if inst.level >=0 and inst.level <10 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[10]\n[成长点数]".. (inst.level))
inst:AddTag("level1")
elseif inst.level >=10 and inst.level <30 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[30]\n[成长点数]".. (inst.level))
inst:AddTag("level2")
inst:RemoveTag("level1")
elseif inst.level >=30 and inst.level <60 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[60]\n[成长点数]".. (inst.level))
inst:AddTag("level3")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
elseif inst.level >=60 and inst.level <100 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[100]\n[成长点数]".. (inst.level))
inst:AddTag("level4")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
elseif inst.level >=100 and inst.level <150 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[150]\n[成长点数]".. (inst.level))
inst:AddTag("level5")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
elseif inst.level >=150 and inst.level <200 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[200]\n[成长点数]".. (inst.level))
inst:AddTag("level6")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
elseif inst.level >=200 and inst.level <250 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[250]\n[成长点数]".. (inst.level))
inst:AddTag("level7")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
elseif inst.level >=250 and inst.level <300 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[300]\n[成长点数]".. (inst.level))
inst:AddTag("level8")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
elseif inst.level >=300 and inst.level <350 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[350]\n[成长点数]".. (inst.level))
inst:AddTag("level9")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
elseif inst.level >=350 and inst.level <450 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[450]\n[成长点数]".. (inst.level))
inst:AddTag("level10")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
elseif inst.level >=450 and inst.level <600 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[600]\n[成长点数]".. (inst.level))
inst:AddTag("level11")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
elseif inst.level >=600 and inst.level <700 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[700]\n[成长点数]".. (inst.level))
inst:AddTag("level12")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
elseif inst.level >=700 and inst.level <800 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[800]\n[成长点数]".. (inst.level))
inst:AddTag("level13")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
elseif inst.level >=800 and inst.level <900 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[900]\n[成长点数]".. (inst.level))
inst:AddTag("level14")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
elseif inst.level >=900 and inst.level <1000 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[1000]\n[成长点数]".. (inst.level))
inst:AddTag("level15")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
elseif inst.level >=1000 and inst.level <1100 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[1100]\n[成长点数]".. (inst.level))
inst:AddTag("level16")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
elseif inst.level >=1100 and inst.level <1200 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[1200]\n[成长点数]".. (inst.level))
inst:AddTag("level17")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
elseif inst.level >=1200 and inst.level <1300 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[1300]\n[成长点数]".. (inst.level))
inst:AddTag("level18")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
elseif inst.level >=1300 and inst.level <1400 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[1400]\n[成长点数]".. (inst.level))
inst:AddTag("level19")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
elseif inst.level >=1400 and inst.level <1500 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[1500]\n[成长点数]".. (inst.level))
inst:AddTag("level20")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
inst:RemoveTag("level19")
elseif inst.level >=1500 and inst.level <1600 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[1600]\n[成长点数]".. (inst.level))
inst:AddTag("level21")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
inst:RemoveTag("level19")
inst:RemoveTag("level20")
elseif inst.level >=1600 and inst.level <1800 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[1800]\n[成长点数]".. (inst.level))
inst:AddTag("level22")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
inst:RemoveTag("level19")
inst:RemoveTag("level20")
inst:RemoveTag("level21")
elseif inst.level >=1800 and inst.level <2000 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[2000]\n[成长点数]".. (inst.level))
inst:AddTag("level23")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
inst:RemoveTag("level19")
inst:RemoveTag("level20")
inst:RemoveTag("level21")
inst:RemoveTag("level22")
elseif inst.level >=2000 and inst.level <2200 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[2200]\n[成长点数]".. (inst.level))
inst:AddTag("level24")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
inst:RemoveTag("level19")
inst:RemoveTag("level20")
inst:RemoveTag("level21")
inst:RemoveTag("level22")
inst:RemoveTag("level23")
elseif inst.level >=2200 and inst.level <2400 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[2400]\n[成长点数]".. (inst.level))
inst:AddTag("level25")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
inst:RemoveTag("level19")
inst:RemoveTag("level20")
inst:RemoveTag("level21")
inst:RemoveTag("level22")
inst:RemoveTag("level23")
inst:RemoveTag("level24")
elseif inst.level >=2400 and inst.level <2600 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[2600]\n[成长点数]".. (inst.level))
inst:AddTag("level26")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
inst:RemoveTag("level19")
inst:RemoveTag("level20")
inst:RemoveTag("level21")
inst:RemoveTag("level22")
inst:RemoveTag("level23")
inst:RemoveTag("level24")
inst:RemoveTag("level25")
elseif inst.level >=2600 and inst.level <2800 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[2800]\n[成长点数]".. (inst.level))
inst:AddTag("level27")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
inst:RemoveTag("level19")
inst:RemoveTag("level20")
inst:RemoveTag("level21")
inst:RemoveTag("level22")
inst:RemoveTag("level23")
inst:RemoveTag("level24")
inst:RemoveTag("level25")
inst:RemoveTag("level26")
elseif inst.level >=2800 and inst.level <3000 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[3000]\n[成长点数]".. (inst.level))
inst:AddTag("level28")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
inst:RemoveTag("level19")
inst:RemoveTag("level20")
inst:RemoveTag("level21")
inst:RemoveTag("level22")
inst:RemoveTag("level23")
inst:RemoveTag("level24")
inst:RemoveTag("level25")
inst:RemoveTag("level26")
inst:RemoveTag("level27")
elseif inst.level >=3000 and inst.level <4000 then
inst.components.talker:Say("-[公主的盔甲] \n下一级:[4000]\n[成长点数]".. (inst.level))
inst:AddTag("level29")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
inst:RemoveTag("level19")
inst:RemoveTag("level20")
inst:RemoveTag("level21")
inst:RemoveTag("level22")
inst:RemoveTag("level23")
inst:RemoveTag("level24")
inst:RemoveTag("level25")
inst:RemoveTag("level26")
inst:RemoveTag("level27")
inst:RemoveTag("level28")
elseif inst.level >=4000 then
inst.components.talker:Say("-[公主的盔甲] \n[满级]")
inst:AddTag("level30")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
inst:RemoveTag("level3")
inst:RemoveTag("level4")
inst:RemoveTag("level5")
inst:RemoveTag("level6")
inst:RemoveTag("level7")
inst:RemoveTag("level8")
inst:RemoveTag("level9")
inst:RemoveTag("level10")
inst:RemoveTag("level11")
inst:RemoveTag("level12")
inst:RemoveTag("level13")
inst:RemoveTag("level14")
inst:RemoveTag("level15")
inst:RemoveTag("level16")
inst:RemoveTag("level17")
inst:RemoveTag("level18")
inst:RemoveTag("level19")
inst:RemoveTag("level20")
inst:RemoveTag("level21")
inst:RemoveTag("level22")
inst:RemoveTag("level23")
inst:RemoveTag("level24")
inst:RemoveTag("level25")
inst:RemoveTag("level26")
inst:RemoveTag("level27")
inst:RemoveTag("level28")
inst:RemoveTag("level29")
end
end


local function onpreload(inst, data)
	if data then
		if data.level then
		inst.level = data.level
			levelexp(inst)
end
	end
		end
local function onsave(inst, data)
	data.level = inst.level
	data.charge_time = inst.charge_time
end


local function OnDurability(inst, data)
inst:AddTag("broken")
inst.components.fueled:StopConsuming()        
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0)
inst.components.talker:Say("-[残破的 公主的盔甲]\n护甲值 (0)\n耐久度 (0)")
end

local function UpgradeArmor(inst)
if inst:HasTag("broken") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.01)
   end
if not inst:HasTag("broken") then
        if inst:HasTag("level1") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.6)
	inst.components.talker:Say("-[公主的盔甲(1级)]\n护甲值 (60)\n冻结(5)")
        elseif inst:HasTag("level2") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.62)
	inst.components.talker:Say("-[公主的盔甲(2级)]\n护甲值 (62)\n冻结(10)")
        elseif inst:HasTag("level3") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.63)
	inst.components.talker:Say("-[公主的盔甲(3级)]\n护甲值 (63)\n冻结(15)")
        elseif inst:HasTag("level4") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.64)
	inst.components.talker:Say("-[公主的盔甲(4级)]\n护甲值 (64)\n冻结(20)")
        elseif inst:HasTag("level5") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.65)
	inst.components.talker:Say("-[公主的盔甲(5级)]\n护甲值 (65)\n冻结(25)")
        elseif inst:HasTag("level6") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.66)
	inst.components.talker:Say("-[公主的盔甲(6级)]\n护甲值 (66)\n冻结(24)")
        elseif inst:HasTag("level7") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.67)
	inst.components.talker:Say("-[公主的盔甲(7级)]\n护甲值 (67)\n冻结(28)")
        elseif inst:HasTag("level8") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.68)
	inst.components.talker:Say("-[公主的盔甲(8级)]\n护甲值 (68)\n冻结(32)")
        elseif inst:HasTag("level9") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.69)
	inst.components.talker:Say("-[公主的盔甲(9级)]\n护甲值 (69)\n冻结(36)")
        elseif inst:HasTag("level10") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.7)
	inst.components.talker:Say("-[公主的盔甲(10级)]\n护甲值 (70)\n冻结(40)")
        elseif inst:HasTag("level11") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.71)
	inst.components.talker:Say("-[公主的盔甲(11级)]\n护甲值 (71)\n冻结(43)")
        elseif inst:HasTag("level12") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.72)
	inst.components.talker:Say("-[公主的盔甲(12级)]\n护甲值 (72)\n冻结(46)")
        elseif inst:HasTag("level13") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.73)
	inst.components.talker:Say("-[公主的盔甲(13级)]\n护甲值 (73)\n冻结(49)")
        elseif inst:HasTag("level14") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.74)
	inst.components.talker:Say("-[公主的盔甲(14级)]\n护甲值 (74)\n冻结(52)")
        elseif inst:HasTag("level15") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.75)
	inst.components.talker:Say("-[公主的盔甲(15级)]\n护甲值 (75)\n冻结(55)")
        elseif inst:HasTag("level16") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.76)
	inst.components.talker:Say("-[公主的盔甲(16级)]\n护甲值 (76)\n冻结(57)")
        elseif inst:HasTag("level17") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.77)
	inst.components.talker:Say("-[公主的盔甲(17级)]\n护甲值 (77)\n冻结(59)")
        elseif inst:HasTag("level18") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.78)
	inst.components.talker:Say("-[公主的盔甲(18级)]\n护甲值 (78)\n冻结(61)")
        elseif inst:HasTag("level19") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.79)
	inst.components.talker:Say("-[公主的盔甲(19级)]\n护甲值 (79)\n冻结(63)")
        elseif inst:HasTag("level20") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.8)
	inst.components.talker:Say("-[公主的盔甲(20级)]\n护甲值 (80)\n冻结(65)")
        elseif inst:HasTag("level21") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.81)
	inst.components.talker:Say("-[公主的盔甲(21级)]\n护甲值 (81)\n冻结(67)")
        elseif inst:HasTag("level22") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.82)
	inst.components.talker:Say("-[公主的盔甲(22级)]\n护甲值 (82)\n冻结(69)")
        elseif inst:HasTag("level23") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.83)
	inst.components.talker:Say("-[公主的盔甲(23级)]\n护甲值 (83)\n冻结(71)")
        elseif inst:HasTag("level24") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.84)
	inst.components.talker:Say("-[公主的盔甲(24级)]\n护甲值 (84)\n冻结(73)")
        elseif inst:HasTag("level25") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.85)
	inst.components.talker:Say("-[公主的盔甲(25级)]\n护甲值 (85)\n冻结(75)")
        elseif inst:HasTag("level26") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.86)
	inst.components.talker:Say("-[公主的盔甲(26级)]\n护甲值 (86)\n冻结(77)")
        elseif inst:HasTag("level27") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.87)
	inst.components.talker:Say("-[公主的盔甲(27级)]\n护甲值 (87)\n冻结(79)")
        elseif inst:HasTag("level28") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.88)
	inst.components.talker:Say("-[公主的盔甲(28级)]\n护甲值 (88)\n冻结(81)")
        elseif inst:HasTag("level29") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.89)
	inst.components.talker:Say("-[公主的盔甲(29级)]\n护甲值 (89)\n冻结(83)")
        elseif inst:HasTag("level30") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.9)
	inst.components.talker:Say("-[公主的盔甲(满级30级)]\n护甲值 (90)\n冻结(85)")
end
end
end

local function OnLoad(inst, data)
    UpgradeArmor(inst)
end

--------
-------- --------
local function TakeItem(inst, item, data)
local expchance0 = 1
local expchance1 = 0.3
local expchance2 = 0.2
local expchance3 = 0.12
	inst.components.fueled:DoDelta(5000000)
	SpawnPrefab("splash").Transform:SetPosition(inst:GetPosition():Get())
inst:RemoveTag ("broken")     
UpgradeArmor(inst)
   if math.random() < expchance1 and inst.level <= 4005 then
	inst.level = inst.level + 2
	levelexp(inst)
	inst.components.talker:Say("幸运点数 ! +(2)\n[成长点数]".. (inst.level))
    elseif  math.random() < expchance2 and inst.level <= 4005 then
	inst.level = inst.level + 5
	levelexp(inst)
	inst.components.talker:Say("幸运点数 ! +(5)\n[成长点数]".. (inst.level))
	elseif  math.random() < expchance3 and inst.level <= 4005 then
	inst.level = inst.level + 8
	levelexp(inst)
	inst.components.talker:Say("幸运点数 ! +(8)\n[成长点数]".. (inst.level))
	elseif  math.random() < expchance0 and inst.level <= 4005 then
	inst.level = inst.level + 1
	levelexp(inst)
    end
end

local function onequip(inst, owner) 
   inst:AddTag("talkf")
    UpgradeArmor(inst)
inst.components.fueled:StartConsuming()        
    owner.AnimState:OverrideSymbol("swap_body", "armor_mushab", "swap_body")
    owner.components.inventory:SetOverflow(inst)
    inst.components.container:Open(owner)

    inst.task = inst:DoPeriodicTask(12, function() healowner(inst, owner) end)

    inst.expfn = function(attacked, data)
local expchance = 0.5
local damagedur1 = 0.2
local damagedur2 = 0.5
local damagedur3 = 0.7
local damagedur4 = 1

if data and data.attacker and math.random() < damagedur1 then
inst.components.fueled:DoDelta(-150000)
elseif data and data.attacker and math.random() < damagedur2 then
inst.components.fueled:DoDelta(-100000)
elseif data and data.attacker and math.random() < damagedur3 then
inst.components.fueled:DoDelta(-50000)
elseif data and data.attacker and math.random() < damagedur4 then
inst.components.fueled:DoDelta(-50000)

end
if data and data.attacker and math.random() < expchance and inst.level < 4010 then
	inst.components.fueled:DoDelta(-50000)
	inst.level = inst.level + 1
			levelexp(inst)

        end 
	end 

    inst.freezefn = function(attacked, data)
        if data and data.attacker and data.attacker.components.freezable and inst:HasTag("level1") then
            data.attacker.components.freezable:AddColdness(0.05)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level2") then
            data.attacker.components.freezable:AddColdness(0.1)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level3") then
            data.attacker.components.freezable:AddColdness(0.15)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level4") then
            data.attacker.components.freezable:AddColdness(0.2)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level5") then
            data.attacker.components.freezable:AddColdness(0.25)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level6") then
            data.attacker.components.freezable:AddColdness(0.24)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level7") then
            data.attacker.components.freezable:AddColdness(0.28)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level8") then
            data.attacker.components.freezable:AddColdness(0.32)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level9") then
            data.attacker.components.freezable:AddColdness(0.36)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level10") then
            data.attacker.components.freezable:AddColdness(0.4)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level11") then
            data.attacker.components.freezable:AddColdness(0.43)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level12") then
            data.attacker.components.freezable:AddColdness(0.46)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level13") then
            data.attacker.components.freezable:AddColdness(0.49)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level14") then
            data.attacker.components.freezable:AddColdness(0.52)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level15") then
            data.attacker.components.freezable:AddColdness(0.55)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level16") then
            data.attacker.components.freezable:AddColdness(0.57)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level17") then
            data.attacker.components.freezable:AddColdness(0.59)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level18") then
            data.attacker.components.freezable:AddColdness(0.61)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level19") then
            data.attacker.components.freezable:AddColdness(0.63)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level20") then
            data.attacker.components.freezable:AddColdness(0.65)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level21") then
            data.attacker.components.freezable:AddColdness(0.67)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level22") then
            data.attacker.components.freezable:AddColdness(0.69)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level23") then
            data.attacker.components.freezable:AddColdness(0.71)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level24") then
            data.attacker.components.freezable:AddColdness(0.73)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level25") then
            data.attacker.components.freezable:AddColdness(0.75)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level26") then
            data.attacker.components.freezable:AddColdness(0.77)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level27") then
            data.attacker.components.freezable:AddColdness(0.79)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level28") then
            data.attacker.components.freezable:AddColdness(0.81)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level29") then
            data.attacker.components.freezable:AddColdness(0.83)
            data.attacker.components.freezable:SpawnShatterFX()
        elseif data and data.attacker and data.attacker.components.freezable and inst:HasTag("level30") then
            data.attacker.components.freezable:AddColdness(0.85)
            data.attacker.components.freezable:SpawnShatterFX()
        end 
    end

    inst:ListenForEvent("attacked", inst.freezefn, owner)
    inst:ListenForEvent("attacked", inst.expfn, owner)
end

local function onunequip(inst, owner) 
inst.components.fueled:StopConsuming()        
   inst:RemoveTag("talkf")
    UpgradeArmor(inst)
    owner.AnimState:ClearOverrideSymbol("swap_body")
    owner.AnimState:ClearOverrideSymbol("backpack")
    owner.components.inventory:SetOverflow(nil)
    inst.components.container:Close(owner)

    if inst.task then inst.task:Cancel() inst.task = nil end

    inst:RemoveEventCallback("attacked", inst.freezefn, owner)
    inst:RemoveEventCallback("attacked", inst.expfn, owner)

end

local function onfinished(inst)
    inst:Remove()
end

local function fn(Sim)
	local inst = CreateEntity()
  	inst.entity:AddSoundEmitter()
  
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    
   -- inst.AnimState:SetBank("armor_mushab")
    inst.AnimState:SetBank("armor_wood")
    inst.AnimState:SetBuild("armor_mushab")
    inst.AnimState:PlayAnimation("anim")
    
    inst:AddTag("metal")
    
    inst:AddComponent("inspectable")

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.foleysound = "dontstarve/movement/foley/jewlery"
	inst.components.inventoryitem.atlasname = "images/inventoryimages/armor_mushab.xml"
---resurrect
        inst:AddComponent("playerprox")
    inst:AddComponent("resurrector")
   -- inst.components.resurrector.active = true
	inst.components.resurrector.doresurrect = doresurrect5
	inst.components.resurrector.makeusedfn = makeused5
    inst.components.playerprox:SetDist(10, 11)
    inst.components.playerprox:SetOnPlayerNear(close)
    inst.components.playerprox:SetOnPlayerFar(far)

----------------------
    inst:AddComponent("container")
    inst.components.container:SetNumSlots(#slotpos)
    inst.components.container.widgetslotpos = slotpos
    --ui_krampusbag_2x8
    inst.components.container.widgetanimbank = "ui_piggyback_2x6"
    inst.components.container.widgetanimbuild = "ui_piggyback_2x6"
    inst.components.container.widgetpos = Vector3(-140,-75,0)
	inst.components.container.side_widget = true    

 -------------------------   
    inst:AddComponent("armor")
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.BODY
    
    inst.components.equippable:SetOnEquip( onequip )
    inst.components.equippable:SetOnUnequip( onunequip )
    
inst:AddTag("level1")
    inst.OnLoad = OnLoad

    inst:AddComponent("talker")
    inst.components.talker.fontsize = 19
    inst.components.talker.font = TALKINGFONT
    inst.components.talker.colour = Vector3(1, 0.8, 0.95, 1)
    inst.components.talker.offset = Vector3(0,100,0)
    inst.components.talker.symbol = "swap_object"

	inst.level = 0
inst:ListenForEvent("levelup", levelexp)
	inst.OnSave = onsave
	inst.OnPreLoad = onpreload

        inst:AddComponent("fueled")
       inst.components.fueled.fueltype = "CHEMICAL"
        inst.components.fueled:InitializeFuelLevel(25000000)
       inst.components.fueled:SetDepletedFn(OnDurability)
        inst.components.fueled.ontakefuelfn = TakeItem
        inst.components.fueled.accepting = true
inst.components.fueled:StartConsuming()        

    return inst
end

return Prefab( "common/inventory/armor_mushab", fn, assets) 
