local assets=
{
	Asset("ANIM", "anim/backpack.zip"),
	Asset("ANIM", "anim/swap_frostback.zip"),
	Asset("ANIM", "anim/ui_chest_frosthammer2.zip")

}


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

for y = 0, 4 do
	table.insert(slotpos, Vector3(-162, -y*58 + 124 ,0))
	table.insert(slotpos, Vector3(-162 +75, -y*58 + 124 ,0))
end

local function itemtest(inst, item, slot)
	if not item:HasTag("tstoneback") then
			return true
end
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("-[Frost Armor II]-\n[Grow Points]".. (inst.level))
inst:RemoveTag("levelup")
end
if inst.level >=0 and inst.level <10 then
inst.components.talker:Say("-[Frost Armor II] \nNext:[10]\n[Grow Points]".. (inst.level))
inst:AddTag("level1")
elseif inst.level >=10 and inst.level <30 then
inst.components.talker:Say("-[Frost Armor II] \nNext:[30]\n[Grow Points]".. (inst.level))
inst:AddTag("level2")
inst:RemoveTag("level1")
elseif inst.level >=30 and inst.level <60 then
inst.components.talker:Say("-[Frost Armor II] \nNext:[60]\n[Grow Points]".. (inst.level))
inst:AddTag("level3")
inst:RemoveTag("level1")
inst:RemoveTag("level2")
elseif inst.level >=60 and inst.level <100 then
inst.components.talker:Say("-[Frost Armor II] \nNext:[100]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[150]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[200]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[250]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[300]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[350]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[450]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[600]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[700]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[800]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[900]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[1000]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[1100]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[1200]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[1300]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[1400]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[1500]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[1600]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[1800]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[2000]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[2200]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[2400]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[2600]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[2800]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[3000]\n[Grow Points]".. (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("-[Frost Armor II] \nNext:[4000]\n[Grow Points]".. (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("-[Frost Armor II] \n[MAX]")
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.01)
inst.components.talker:Say("-[Broken FrostArmor II]\nArmor (1)\nDurability (1)\nSpeed up(0)")
end

--------
local function UpgradeArmor(inst)
if inst:HasTag("broken") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.01)
inst.components.talker:Say("-[Broken FrostArmor II]\nArmor (1)\nDurability (0)\nSpeed up (0)")
    inst.components.equippable.walkspeedmult = 1
    inst.components.equippable.runspeedmult = 1
            inst.components.fueled:StopConsuming()        
   end
if not inst:HasTag("broken") then
        if inst:HasTag("level1") then
    inst.components.equippable.walkspeedmult = 1.04
    inst.components.equippable.runspeedmult = 1.04
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.05)
	inst.components.talker:Say("-[FrostArmor II (LV 1)]\nArmor (5)\nFreeze(5)\nSpeed up (4)")
        elseif inst:HasTag("level2") then
inst.components.equippable.walkspeedmult = 1.04
    inst.components.equippable.runspeedmult = 1.04
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.1)
	inst.components.talker:Say("-[FrostArmor II (LV 2)]\nArmor (10)\nFreeze(10)\nSpeed up (4)")
        elseif inst:HasTag("level3") then
inst.components.equippable.walkspeedmult = 1.04
    inst.components.equippable.runspeedmult = 1.04
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.15)
	inst.components.talker:Say("-[FrostArmor II (LV 3)]\nArmor (15)\nFreeze(15)\nSpeed up (4)")
        elseif inst:HasTag("level4") then
inst.components.equippable.walkspeedmult = 1.04
    inst.components.equippable.runspeedmult = 1.04
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.2)
	inst.components.talker:Say("-[FrostArmor II (LV 4)]\nArmor (20)\nFreeze(20)\nSpeed up (4)")
        elseif inst:HasTag("level5") then
inst.components.equippable.walkspeedmult = 1.04
    inst.components.equippable.runspeedmult = 1.04
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.25)
	inst.components.talker:Say("-[FrostArmor II (LV 5)]\nArmor (25)\nFreeze(25)\nSpeed up (4)")
        elseif inst:HasTag("level6") then
inst.components.equippable.walkspeedmult = 1.04
    inst.components.equippable.runspeedmult = 1.04
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.24)
	inst.components.talker:Say("-[FrostArmor II (LV 6)]\nArmor (24)\nFreeze(24)\nSpeed up (4)")
        elseif inst:HasTag("level7") then
inst.components.equippable.walkspeedmult = 1.04
    inst.components.equippable.runspeedmult = 1.04
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.28)
	inst.components.talker:Say("-[FrostArmor II (LV 7)]\nArmor (28)\nFreeze(28)\nSpeed up (4)")
        elseif inst:HasTag("level8") then
inst.components.equippable.walkspeedmult = 1.04
    inst.components.equippable.runspeedmult = 1.04
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.32)
	inst.components.talker:Say("-[FrostArmor II (LV 8)]\nArmor (32)\nFreeze(32)\nSpeed up (4)")
        elseif inst:HasTag("level9") then
inst.components.equippable.walkspeedmult = 1.04
    inst.components.equippable.runspeedmult = 1.04
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.36)
	inst.components.talker:Say("-[FrostArmor II (LV 9)]\nArmor (36)\nFreeze(36)\nSpeed up (8)")
        elseif inst:HasTag("level10") then
inst.components.equippable.walkspeedmult = 1.08
    inst.components.equippable.runspeedmult = 1.08
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.4)
	inst.components.talker:Say("-[FrostArmor II (LV 10)]\nArmor (40)\nFreeze(40)\nSpeed up (8)")
        elseif inst:HasTag("level11") then
inst.components.equippable.walkspeedmult = 1.08
    inst.components.equippable.runspeedmult = 1.08
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.43)
	inst.components.talker:Say("-[FrostArmor II (LV 11)]\nArmor (43)\nFreeze(43)\nSpeed up (8)")
        elseif inst:HasTag("level12") then
inst.components.equippable.walkspeedmult = 1.08
    inst.components.equippable.runspeedmult = 1.08
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.46)
	inst.components.talker:Say("-[FrostArmor II (LV 12)]\nArmor (46)\nFreeze(46)\nSpeed up (8)")
        elseif inst:HasTag("level13") then
inst.components.equippable.walkspeedmult = 1.08
    inst.components.equippable.runspeedmult = 1.08
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.49)
	inst.components.talker:Say("-[FrostArmor II (LV 13)]\nArmor (49)\nFreeze(49)\nSpeed up (8)")
        elseif inst:HasTag("level14") then
inst.components.equippable.walkspeedmult = 1.08
    inst.components.equippable.runspeedmult = 1.08
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.52)
	inst.components.talker:Say("-[FrostArmor II (LV 14)]\nArmor (52)\nFreeze(52)\nSpeed up (8)")
        elseif inst:HasTag("level15") then
inst.components.equippable.walkspeedmult = 1.08
    inst.components.equippable.runspeedmult = 1.08
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.55)
	inst.components.talker:Say("-[FrostArmor II (LV 15)]\nArmor (55)\nFreeze(55)\nSpeed up (8)")
        elseif inst:HasTag("level16") then
inst.components.equippable.walkspeedmult = 1.08
    inst.components.equippable.runspeedmult = 1.08
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.57)
	inst.components.talker:Say("-[FrostArmor II (LV 16)]\nArmor (57)\nFreeze(57)\nSpeed up (8)")
        elseif inst:HasTag("level17") then
inst.components.equippable.walkspeedmult = 1.08
    inst.components.equippable.runspeedmult = 1.08
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.59)
	inst.components.talker:Say("-[FrostArmor II (LV 17)]\nArmor (59)\nFreeze(59)\nSpeed up (8)")
        elseif inst:HasTag("level18") then
inst.components.equippable.walkspeedmult = 1.08
    inst.components.equippable.runspeedmult = 1.08
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.61)
	inst.components.talker:Say("-[FrostArmor II (LV 18)]\nArmor (61)\nFreeze(61)\nSpeed up (8)")
        elseif inst:HasTag("level19") then
inst.components.equippable.walkspeedmult = 1.08
    inst.components.equippable.runspeedmult = 1.08
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.63)
	inst.components.talker:Say("-[FrostArmor II (LV 19)]\nArmor (63)\nFreeze(63)\nSpeed up (12)")
        elseif inst:HasTag("level20") then
inst.components.equippable.walkspeedmult = 1.12
    inst.components.equippable.runspeedmult = 1.12
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.65)
	inst.components.talker:Say("-[FrostArmor II (LV 20)]\nArmor (65)\nFreeze(65)\nSpeed up (12)")
        elseif inst:HasTag("level21") then
inst.components.equippable.walkspeedmult = 1.12
    inst.components.equippable.runspeedmult = 1.12
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.67)
	inst.components.talker:Say("-[FrostArmor II (LV 21)]\nArmor (67)\nFreeze(67)\nSpeed up (12)")
        elseif inst:HasTag("level22") then
inst.components.equippable.walkspeedmult = 1.12
    inst.components.equippable.runspeedmult = 1.12
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.69)
	inst.components.talker:Say("-[FrostArmor II (LV 22)]\nArmor (69)\nFreeze(69)\nSpeed up (12)")
        elseif inst:HasTag("level23") then
inst.components.equippable.walkspeedmult = 1.12
    inst.components.equippable.runspeedmult = 1.12
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.71)
	inst.components.talker:Say("-[FrostArmor II (LV 23)]\nArmor (71)\nFreeze(71)\nSpeed up (12)")
        elseif inst:HasTag("level24") then
inst.components.equippable.walkspeedmult = 1.12
    inst.components.equippable.runspeedmult = 1.12
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.73)
	inst.components.talker:Say("-[FrostArmor II (LV 24)]\nArmor (73)\nFreeze(73)\nSpeed up (12)")
        elseif inst:HasTag("level25") then
inst.components.equippable.walkspeedmult = 1.12
    inst.components.equippable.runspeedmult = 1.12    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.75)
	inst.components.talker:Say("-[FrostArmor II (LV 25)]\nArmor (75)\nFreeze(75)\nSpeed up (12)")
        elseif inst:HasTag("level26") then
inst.components.equippable.walkspeedmult = 1.12
    inst.components.equippable.runspeedmult = 1.12
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.77)
	inst.components.talker:Say("-[FrostArmor II (LV 26)]\nArmor (77)\nFreeze(77)\nSpeed up (12)")
        elseif inst:HasTag("level27") then
inst.components.equippable.walkspeedmult = 1.12
    inst.components.equippable.runspeedmult = 1.12
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.79)
	inst.components.talker:Say("-[FrostArmor II (LV 27)]\nArmor (79)\nFreeze(79)\nSpeed up (12)")
        elseif inst:HasTag("level28") then
inst.components.equippable.walkspeedmult = 1.12
    inst.components.equippable.runspeedmult = 1.12
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.81)
	inst.components.talker:Say("-[FrostArmor II (LV 28)]\nArmor (81)\nFreeze(81)\nSpeed up (12)")
        elseif inst:HasTag("level29") then
inst.components.equippable.walkspeedmult = 1.12
    inst.components.equippable.runspeedmult = 1.12
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.83)
	inst.components.talker:Say("-[FrostArmor II (LV 29)]\nArmor (83)\nFreeze(83)\nSpeed up (12)")
        elseif inst:HasTag("level30") then
inst.components.equippable.walkspeedmult = 1.15
    inst.components.equippable.runspeedmult = 1.15
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0.85)
	inst.components.talker:Say("-[FrostArmor II (LV 30)]\nArmor (85)\nFreeze(85)\nSpeed up (15)")
end
end
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("Lucky Points ! +(2)\n[Grow Points]".. (inst.level))
    elseif  math.random() < expchance2 and inst.level <= 4005 then
	inst.level = inst.level + 5
	levelexp(inst)
	inst.components.talker:Say("Lucky Points ! +(5)\n[Grow Points]".. (inst.level))
	elseif  math.random() < expchance3 and inst.level <= 4005 then
	inst.level = inst.level + 8
	levelexp(inst)
	inst.components.talker:Say("Lucky Points ! +(8)\n[Grow Points]".. (inst.level))
	elseif  math.random() < expchance0 and inst.level <= 4005 then
	inst.level = inst.level + 1
	levelexp(inst)
    end
end

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

--------

local function onequip(inst, owner) 
   inst:AddTag("talkf")
    UpgradeArmor(inst)
inst.components.fueled:StartConsuming()        

    owner.AnimState:OverrideSymbol("swap_body", "swap_frostback", "backpack")
    owner.AnimState:OverrideSymbol("swap_body", "swap_frostback", "swap_body")
    owner.components.inventory:SetOverflow(inst)
    inst.components.container:Open(owner)

    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 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)

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

end

local function onopen(inst)
  inst.SoundEmitter:PlaySound("dontstarve/common/gem_shatter")
end

local function onclose(inst)
  inst.SoundEmitter:PlaySound("dontstarve/common/fireOut")
end

local function fn(Sim)
	local inst = CreateEntity()
    
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
  	inst.entity:AddSoundEmitter()
    MakeInventoryPhysics(inst)
    
    local minimap = inst.entity:AddMiniMapEntity()
    minimap:SetIcon("frostback.tex")

    inst.AnimState:SetBank("backpack1")
    inst.AnimState:SetBuild("swap_frostback")
    inst.AnimState:PlayAnimation("anim")
    
    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/frostback.xml"

   inst.components.inventoryitem.cangoincontainer = false

    inst.components.inventoryitem.foleysound = "dontstarve/movement/foley/krampuspack"

    inst:AddComponent("armor")

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

        inst:AddTag("fridge")

    inst:AddComponent("container")
    inst.components.container.itemtestfn = itemtest
    inst.components.container:SetNumSlots(#slotpos)
    inst.components.container.widgetslotpos = slotpos
    inst.components.container.widgetanimbank = "ui_backpack_2x4"
    inst.components.container.widgetanimbuild = "ui_chest_frosthammer2"
    inst.components.container.widgetpos = Vector3(-5,-70,0)
    inst.components.container.side_widget = true
    inst.components.container.type = "pack"

    inst.components.container.onopenfn = onopen
    inst.components.container.onclosefn = onclose

inst:AddTag("level1")
    inst.OnLoad = OnLoad

    inst:AddComponent("talker")
    inst.components.talker.fontsize = 19
    inst.components.talker.font = TALKINGFONT
    inst.components.talker.colour = Vector3(0.7, 0.85, 1, 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/frostback", fn, assets) 
