local function MakeVesan(hao)
	local assets=
	{
		Asset("ANIM", "anim/vesan.zip"),
		Asset("ANIM", "anim/swap_vesan"..hao..".zip"),
		Asset("ATLAS", "images/inventoryimages/vesan"..hao..".xml"),
	}
	
	-- local function levelrespawn(inst)
	-- local prefab = SpawnPrefab("vesan"..inst.level)
	-- GetPlayer().components.inventory:GiveItem(prefab)
	-- inst.Remove()
	-- end
	
	local function trylevel(inst)
	if TheVera.hardmode then
			if inst.power >= 350 + inst.level*20 and inst.level < 3 then 
			inst.level = inst.level + 1
			local prefab = SpawnPrefab("vesan"..inst.level)
			--GetPlayer().components.health.penalty = GetPlayer().components.health.penalty + 1
			GetPlayer().components.health:DoDelta(0)
			GetPlayer().components.inventory:GiveItem(prefab)
			--GetPlayer().components.inventory:Equip(prefab)
			inst:Remove()
		end
	else
		if inst.power >= 300 + inst.level*10 and inst.level < 3 then 
			inst.level = inst.level + 1
			local prefab = SpawnPrefab("vesan"..inst.level)
			--GetPlayer().components.health.penalty = GetPlayer().components.health.penalty + 1
			--GetPlayer().components.inventory:GiveItem(prefab)
			GetPlayer().components.health:DoDelta(0)
			GetPlayer().components.inventory:Equip(prefab)
			inst:Remove()
		end
	end end
	local function onattack(inst,owner,target)
		inst.power = inst.power +1
		trylevel(inst)
	end

	local function onequip(inst, owner) 
		owner.AnimState:OverrideSymbol("swap_object", "swap_vesan"..inst.hao, "swap_vesan")
		owner.AnimState:Show("ARM_carry") 
		owner.AnimState:Hide("ARM_normal") 
	end

	local function onunequip(inst, owner) 
		owner.AnimState:Hide("ARM_carry") 
		owner.AnimState:Show("ARM_normal") 
		print("power:",inst.power)
	end
	
	local function onpreload(inst, data)
		if data then
		inst.power = data.power
	end end 
	
	local function onload(inst, data)
		if data then
		inst.power = data.power
	end 
	 end

	local function onsave(inst, data)
		data.power = inst.power
	end

	local function spell(inst,target,pos)

		SpawnPrefab("yangliu").Transform:SetPosition(pos.x+1, 0, pos.z-1)
		SpawnPrefab("yangliu").Transform:SetPosition(pos.x-2, 0, pos.z+math.random(3))
		SpawnPrefab("yangliu").Transform:SetPosition(pos.x, 0, pos.z+2)
		SpawnPrefab("yangliu").Transform:SetPosition(pos.x+3, 0, pos.z-2)
		SpawnPrefab("yangliu").Transform:SetPosition(pos.x-math.random(3), 0, pos.z-3)
		inst.power = inst.power - 20
		inst:StartThread(function()
			for k = 1, 5 do
				local ents = TheSim:FindEntities(pos.x,pos.y,pos.z,3)
				for k,v in ipairs(ents) do 
					if v.components.combat and v ~= GetPlayer() then
						v.components.combat:GetAttacked(inst,10.6)
					end end
				Sleep(1)end end)
	end
	
	local function sts(inst,player,target,pos)
		if inst.power >= 100 and pos and pos.x and pos.y and pos.z then 
		return true end
		return false
	end
	
	local function fn(Sim)
		local inst = CreateEntity()
		local trans = inst.entity:AddTransform()
		local anim = inst.entity:AddAnimState()
		local sound = inst.entity:AddSoundEmitter()
		inst.level = tonumber(hao) or 1
		inst.power = 0
		inst.hao = hao or "1"
		MakeInventoryPhysics(inst)
    
		inst.AnimState:SetBank("vesan")
		inst.AnimState:SetBuild("vesan")
		inst.AnimState:PlayAnimation("idle"..hao,true)
    
		inst:AddTag("sharp")

		inst:AddComponent("weapon")
		inst.components.weapon.onattack = onattack
    
    -------
    

		inst:AddComponent("inspectable")
    
		inst:AddComponent("inventoryitem")
		
		if inst.level == 3 then
		inst:AddComponent("spellcaster")
		local scer = inst.components.spellcaster
		scer.canusefrominventory = false
		scer.canuseontargets = true
		scer.canuseonpoint = true
		scer:SetSpellFn(spell)
		scer:SetSpellTestFn(sts)
		end
		
		inst:AddComponent("equippable")
		inst.components.equippable:SetOnEquip( onequip )
		inst.components.equippable:SetOnUnequip( onunequip )
     
		inst.components.weapon:SetDamage(26.5+ inst.level * 9)

		inst.components.inventoryitem.atlasname = "images/inventoryimages/vesan"..inst.hao..".xml"
	
		inst.OnSave = onsave
		inst.OnLoad = onload
		inst.OnPreLoad = onpreload
		return inst
	end 

	return Prefab( "common/inventory/vesan"..hao, fn, assets) 
end
return MakeVesan("1"),MakeVesan("2"),MakeVesan("3")