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


---------------------------
---------------------------
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("-[Phoenix Helmet]-\n[Grow Points]".. (inst.level))
inst:RemoveTag("levelup")
end
if inst.level >=0 and inst.level <10 then
inst.components.talker:Say("-[PrincessArmor] \nNext:[10]\n[Grow Points]".. (inst.level))
inst:AddTag("level1")
elseif inst.level >=10 and inst.level <30 then
inst.components.talker:Say("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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("-[Phoenix Helmet] \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 Phoenix Helmet]\nArmor (1)\nDurability (1)\nSpeed up(0)")
    if inst.task then inst.task:Cancel() inst.task = nil end
end

local function UpgradeArmor(inst)
if inst:HasTag("broken") then
    inst.components.armor:InitCondition(9999999999999999999999999999999999999999999999999999999999999, 0)
	inst.components.talker:Say("-[Broken Phoenix Helmet]\nArmor (0)\nDurability (0)")

   end

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

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, fname_override)
   inst:AddTag("talkf")
    UpgradeArmor(inst)
inst.components.fueled:StartConsuming()        

if inst:HasTag("maskon") then
        owner.AnimState:OverrideSymbol("swap_hat", "hat_mphoenix", "swap_hat")
        owner.AnimState:Show("HAT")
        owner.AnimState:Hide("HAT_HAIR")
        owner.AnimState:Hide("HAIR_NOHAT")
        owner.AnimState:Hide("HAIR")
            owner.AnimState:Hide("HEAD")
            owner.AnimState:Show("HEAD_HAIR")
elseif not inst:HasTag("maskon") then
        owner.AnimState:OverrideSymbol("swap_hat", "hat_mphoenix2", "swap_hat")
        owner.AnimState:Show("HAT")
        owner.AnimState:Hide("HAT_HAIR")
        owner.AnimState:Hide("HAIR_NOHAT")
        owner.AnimState:Hide("HAIR")
            owner.AnimState:Hide("HEAD")
            owner.AnimState:Show("HEAD_HAIR")
        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.gasfn = function(attacked, data)
local other = data.attacker 
local gaschance1 = 0.45
local gaschance2 = 0.3
local gaschance3 = 0.15
local gaschance4 = 0.05
local player = GetPlayer()

        if data and data.attacker and data.attacker.components.sleeper and inst:HasTag("maskon") and math.random() < gaschance1 then
            data.attacker.components.sleeper:AddSleepiness(1, 12)
	local gas = SpawnPrefab("small_puff")
	local pos = Vector3(other.Transform:GetWorldPosition())
	gas.Transform:SetPosition(pos:Get())
	gas.Transform:SetScale(0.65,0.65,0.65)
        elseif data and data.attacker and data.attacker.components.sleeper and inst:HasTag("maskon") and math.random() < gaschance2 then
            data.attacker.components.sleeper:AddSleepiness(1, 18)
	local gas = SpawnPrefab("small_puff")
	local pos = Vector3(other.Transform:GetWorldPosition())
	gas.Transform:SetPosition(pos:Get())
	gas.Transform:SetScale(1,1,1)
        elseif data and data.attacker and data.attacker.components.sleeper and inst:HasTag("maskon") and math.random() < gaschance3 then
            data.attacker.components.sleeper:AddSleepiness(1, 26)
	local gas = SpawnPrefab("small_puff")
	local pos = Vector3(other.Transform:GetWorldPosition())
	gas.Transform:SetPosition(pos:Get())
	gas.Transform:SetScale(1.25,1.25,1.25)

        elseif data and data.attacker and data.attacker.components.sleeper and inst:HasTag("maskon") and math.random() < gaschance4 then
	player.components.talker:Say("Gas! Gas! Gas !")
            data.attacker.components.sleeper:AddSleepiness(1, 100)
	local gas = SpawnPrefab("small_puff")
	local pos = Vector3(other.Transform:GetWorldPosition())
	gas.Transform:SetPosition(pos:Get())
	gas.Transform:SetScale(1.25,1.25,1.25)

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

end

    local function onunequip(inst, owner)
   inst:RemoveTag("talkf")
    UpgradeArmor(inst)
inst.components.fueled:StopConsuming()        
	inst:RemoveTag("maskon") 
    inst:RemoveEventCallback("attacked", inst.gasfn, owner)
    inst:RemoveEventCallback("attacked", inst.expfn, owner)
    if inst.task then inst.task:Cancel() inst.task = nil end

        owner.AnimState:Hide("HAT")
        owner.AnimState:Hide("HAT_HAIR")
        owner.AnimState:Show("HAIR_NOHAT")
        owner.AnimState:Show("HAIR")

        if owner:HasTag("player") then
            owner.AnimState:Show("HEAD")
            owner.AnimState:Hide("HEAD_HAIR")
        end
    end

local function consume(inst, owner)
if not inst:HasTag("broken") then
inst.components.fueled:DoDelta(-50000)
end
end
local function health(inst, owner)
local player = GetPlayer()
if owner.components.health and owner.components.health:IsHurt() and not inst:HasTag("broken")  then
        owner.components.health:DoDelta(1,false)
end
end

  local function maskon(inst, data, owner, fname_override)
local player = GetPlayer()
        local owner = inst.components.inventoryitem.owner
if owner and inst:HasTag("maskon") then
	inst:RemoveTag("maskon") 
	player.components.talker:Say("mask off !")
	inst.components.talker:Say("-[Phoenix Helmet]\nWarm up(MED)\nSpeed up(10)")
    inst.components.equippable.walkspeedmult = 1.1
    inst.components.equippable.runspeedmult = 1.1
    inst.components.equippable.dapperness = 0
    inst.components.insulator.insulation = TUNING.INSULATION_SMALL
    if inst.task then inst.task:Cancel() inst.task = nil end
    if inst.health then inst.health:Cancel() inst.health= nil end

        owner.AnimState:OverrideSymbol("swap_hat", "hat_mphoenix2", "swap_hat")
        owner.AnimState:Show("HAT")
        owner.AnimState:Hide("HAT_HAIR")
        owner.AnimState:Hide("HAIR_NOHAT")
        owner.AnimState:Hide("HAIR")
            owner.AnimState:Hide("HEAD")
            owner.AnimState:Show("HEAD_HAIR")
        inst.components.useableitem:StopUsingItem()

elseif owner and not inst:HasTag("maskon") then
	inst:AddTag("maskon") 
	player.components.talker:Say("mask on !")
	inst.components.talker:Say("-[Phoenix Helmet]\nWarm up(Large)\nSanity regen\nHealth regen\nSleep gas\nSpeed down")
   inst.components.equippable.walkspeedmult =0.8
   inst.components.equippable.runspeedmult = 0.8
    inst.components.equippable.dapperness = TUNING.DAPPERNESS_LARGE
   inst.components.insulator.insulation = TUNING.INSULATION_LARGE
    inst.task = inst:DoPeriodicTask(1, function() consume(inst, owner) end)
    inst.health = inst:DoPeriodicTask(10, function() health(inst, owner) end)

        owner.AnimState:OverrideSymbol("swap_hat", "hat_mphoenix", "swap_hat")
        owner.AnimState:Show("HAT")
        owner.AnimState:Hide("HAT_HAIR")
        owner.AnimState:Hide("HAIR_NOHAT")
        owner.AnimState:Hide("HAIR")
            owner.AnimState:Hide("HEAD")
            owner.AnimState:Show("HEAD_HAIR")
        inst.components.useableitem:StopUsingItem()
end
end

	
local function fn(Sim)
        local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)
    
    inst:AddTag("hat")

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

    inst:AddTag("metal")

     inst:AddComponent("useableitem")
     inst.components.useableitem:SetOnUseFn(maskon)

    inst:AddComponent("armor")
        inst:AddComponent("equippable")
        inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
        inst.components.equippable:SetOnEquip( onequip )
        inst.components.equippable:SetOnUnequip( onunequip )
	inst:RemoveTag("maskon") 
   inst.components.equippable.walkspeedmult =0.8
  inst.components.equippable.runspeedmult = 0.8

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

     inst:AddComponent("insulator")
     inst.components.insulator.insulation = TUNING.INSULATION_LARGE


    inst:AddComponent("talker")
    inst.components.talker.fontsize = 19
    inst.components.talker.font = TALKINGFONT
    inst.components.talker.colour = Vector3(1, 0.8, 0.65, 1)
    inst.components.talker.offset = Vector3(-200,-220,0)
    inst.components.talker.symbol = "swap_object"

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

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

    return inst
end
---------------------------------
return Prefab( "common/inventory/hat_mphoenix", fn, assets) 
