local function MakeVesan(name)
	local assets=
	{
		Asset("ANIM", "anim/vesan.zip"),
		Asset("ANIM", "anim/swap_"..name..".zip"),
		Asset("ATLAS", "images/inventoryimages/"..name..".xml"),
	}
	
	-- local function levelrespawn(inst)
	-- local prefab = SpawnPrefab("vesan"..inst.level)
	-- GetPlayer().components.inventory:GiveItem(prefab)
	-- inst.Remove()
	-- end
	
	local function onequip(inst, owner) 
		owner.AnimState:OverrideSymbol("swap_object", "swap_"..inst.hao, "swap_vesan")
		owner.AnimState:Show("ARM_carry") 
		owner.AnimState:Hide("ARM_normal") 
		print("power:",inst.power)
		if inst.power >= 50 then
			if inst.prefab == "vsz" then inst.a = TheInput:AddKeyDownHandler(KEY_R, function()
			owner.components.talker:Say("Skill Start!")
			inst.components.weapon:SetDamage(78)
			inst:DoTaskInTime(10,function()inst.components.weapon:SetDamage(47) end)
			inst.power = inst.power - 10
			end) end
			if inst.prefab == "vsx" then inst.a = TheInput:AddKeyDownHandler(KEY_R, function()
			inst:DoTaskInTime(0.1, function()
			owner.components.talker:Say("Skill Start!")
			owner.components.combat:SetAreaDamage(2)
			inst:DoTaskInTime(10,function()owner.components.combat:SetAreaDamage(nil,nil) end)
			inst.power = inst.power - 10
			
			end) end)
			end
		end
	end

	local function onunequip(inst, owner) 
		owner.AnimState:Hide("ARM_carry") 
		owner.AnimState:Show("ARM_normal") 
		if inst.a ~= nil then
		inst.a:Remove()
		end
	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 fn(Sim)
		local inst = CreateEntity()
		local trans = inst.entity:AddTransform()
		local anim = inst.entity:AddAnimState()
		local sound = inst.entity:AddSoundEmitter()
		inst.power = 0
		inst.hao = name or ""
		MakeInventoryPhysics(inst)
    
		inst.AnimState:SetBank("vesan")
		inst.AnimState:SetBuild("vesan")
		inst.AnimState:PlayAnimation("idle"..inst.hao,true)
    
		inst:AddTag("sharp")

		inst:AddComponent("weapon")
		inst.components.weapon.onattack = function()
			inst.power = inst.power + 1
				if inst.hao == "vsz" then
					if inst.power >= 500 then 
					--GetPlayer().components.inventory:GiveItem(SpawnPrefab("vsx"))
					GetPlayer().components.inventory:Equip(SpawnPrefab("vsx"))
					inst:Remove() end
				end
				if inst.hao == "vsx" then
					if inst.power >= 500 then 
					--GetPlayer().components.inventory:GiveItem(SpawnPrefab("vsz"))
					GetPlayer().components.inventory:Equip(SpawnPrefab("vsz"))
					inst:Remove() end
				end
		end
    
    -------
    

		inst:AddComponent("inspectable")
    
		inst:AddComponent("inventoryitem")

		
		inst:AddComponent("equippable")
		inst.components.equippable:SetOnEquip( onequip )
		inst.components.equippable:SetOnUnequip( onunequip )
     
		inst.components.weapon:SetDamage(47)

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

	return Prefab( "common/inventory/"..name, fn, assets) 
end
return MakeVesan("vsz"),MakeVesan("vsx")