<?xml version="1.0" encoding="utf-8"?><waypoints>
<onLoad>
	--***	Siege Reward Package Tier Stone script by NoobBotter	***--
	--***					Version 0.2 beta								***--
	--***	
	--***	This script will take keyboard commands from a menu	to process Seige Victory Reward Packages,				
	--***	open Superior Equipment Packages, buy fusion stones, and build Mana stones, all with a single character.							
	--***	
	--***		Will process 9 at a time, making a T8 each round.					
	--***		3 rounds makes a T9 stone (27 reward packages).
	--***		9 rounds will make a T10 using 81 reward packages.					
	--***		
	--***		If you have a lot of Siege Victory Reward packages, you can really burn through
	--***		your Arcane Transmutor charges, as well as your Phirius Token Coins to buy more charges. 
	--***		This script will detect and use (when required) any charges you have purchased 
	--***		or picked up from minigames that may be in your inventory or item shop backpack (but not 
	--***		in your house item shop bank slot). If you run out of charges while running the script 
	--***		(and you don't have Phirius Token Coins to buy more) it will pause and allow you to acquire more before continuing.
	--***		
	--***			
	--***			
	--***	REQUIREMENTS:
	--***	
	--***			WARNING 	WARNING 	WARNING		WARNING	 	WARNING		WARNING		WARNING		WARNING		WARNING:
	--***		REMOVE ANY MANA STONES FROM YOUR BAGS THAT YOU USE FOR STATTING GEAR BECAUSE THEY MAY GET FUSED INTO DIRTY STONES 
	--***		DURING THIS SCRIPT IF THEY REMAIN IN YOUR BAGS. PUT THEM IN YOUR BANK BEFORE YOU START.
	--***	
	--***		Character running this should be Level 95. I don't know if level 94 Superior equipment packages will always give
	--***		high enough level blue equipment to result in T6 stones. If you want to try it, change the minCharLevel variable 
	--***		to 94 (or whatever level you want to try). This variable specifies minimum level to run the script.
	--***	
	--***		Uses bags1 and 2 of your inventory. Bag 1 must be clean and bag 2 must have at least 6 free slots.
	--***		As you process more and more tier stones (running multiple rounds) the requirement for available space in bag 2
	--***		will go up because each time it opens the Siege Rewards Packages, you receive Exp orbs, which only stack to 20.
	--***		I would recommend if you plan on making a T10 stone to have at least 12 available slots in bag 2.
	--***	
	--***		Each round will use 13 Arcane Transmutor Charges. If you don't have enough charges in inventory to run the 
	--***		number of rounds you plan to run, be prepared to have this script use your P-token coins to buy more.
	--***		If you have lots of spare Ptoken coins, this is a good way to use them. A T10 stone (9 rounds) will use 121 charges.
	--***		If you don't have any charges, that equates to spending 1300 P-token coins to buy them.
	--***	
	--***	
	--***	ADDON/USERFUNCTION REQUIREMENTS:
	--***		Fusion Addon Version 2.0 or later
	--***		Rock5's travelTo Userfunciton
	--***		Rock5's Fusion Control Functions
	--***		
	--***		
	--***	INSTRUCTIONS:	
	--***		1. Edit this script, user variables section, and set mySecondPassword to your secondary password so the bot can purchase AT Charges if needed.
	--***		2. Ensure bag 1 is empty and bag to has at least 6 empty spaces, and you have Siege Victory Reward Packages in your bag inventory.
	--***		3. REMOVE ANY MANA STONES FROM YOUR BAGS THAT YOU USE FOR STATTING because they may get fused into dirty stones 
	--***			during this script if they remain in your bags.
	--***		4. You can start script from any Snoop/Transporter, or in Varanas West at Odely Prole (Varanas Fusion Stone Merchant).
	--***		5. After starting, provied requirements are met, MM window will provide a menu:
	--***			1... Open Rewards			Will open 9 siege reward packages (minus number of Superior Equipment packages and blue lvl 94+ gear in bag1)
	--***			2... Open Equipment			Will open 9 Superior equipment packages (minus number of blue lvl 94+ gear in bag1)
	--***			3... Buy Stones				Will purchase Random Fusion Stones (and buy charges if needed)
	--***			4... Fuse Stones			Will use Fusion to create Tier stones. Should process 9 creating a T8 stone.
	--***			9... All Steps for 1 round with 1 Click		Will do all 4 steps for 1 round (open items, buy stones, fuse items to create a T8).
	--***	
	--***			Select a number on your numpad (similar to creating waypoints) to activate that menu item. 
	--***			You can do this with the game screen as the active window. Menu will reappear after each step.
	--***	
	--***		6. As you perform multiple rounds, the script will process higher level stones when they are available.
	--***			For example, after running menu item 9 three times, it will have created a T9 stone.
	--***			Running it 9 times will have created a T10 stone.
	--***		

	--***	User Variables:	***--
	local mySecondPassword = "password" 	--need to set to your secondary password for use with item shop so the bot can buy AT Charges with Phirius Token Coins.
	local minCharLevel = 95					-- Minimum player level allowed to run this script. You can change it BUT IT MAY RESULT IN LOWER LEVEL TIER STONES.
	
	--*************************************************--
	-- Local Variables... do not change these:
	local highClassEquipment = 206772
	local rewardPackages = 206770
	local currentHighClassEquipmentPackages = 0
	local currentGear = 0
	local emptySlots = 0
	local chargesNeeded = 0
	local goldNeeded = 0
	local charges = 0
	local currentStones = 0
		
	--*****  Function to check if we have enough charges or can buy them. ***********************************--
	function checkCharges()
		charges = RoMScript("GetMagicBoxEnergy()")
		if 15 > charges then
			repeat
				charges = RoMScript("GetMagicBoxEnergy()")
				chargesNeeded = 15 - charges
				if inventory:itemTotalCount(203487) > 0 then	--1 charge
					inventory:useItem(203487)
					print("Added single Arcane Transmutor Charge to Magic Box from inventory.\n")
				elseif inventory:itemTotalCount(208932) > 0 then	--5 charges
					inventory:useItem(208932)
					print("Added 5 Arcane Transmutor Charges to Magic Box from inventory.\n")
				elseif inventory:itemTotalCount(202928) > 0 then	--10 charges
					inventory:useItem(202928)
					print("Added 10 Arcane Transmutor Charges to Magic Box from inventory.\n")
				elseif inventory:itemTotalCount(203577) > 0 then	--10 charges
					inventory:useItem(203577)
					print("Added 10 Arcane Transmutor Charges to Magic Box from inventory.\n")
				elseif inventory:itemTotalCount(208778) > 0 then	--10 charges
					inventory:useItem(208778)
					print("Added 10 Arcane Transmutor Charges to Magic Box from inventory.\n")
				elseif inventory:itemTotalCount(202929) > 0 then	--50 charges
					inventory:useItem(202929)
					print("Added 50 Arcane Transmutor Charges to Magic Box from inventory.\n")
				elseif inventory:itemTotalCount(203578) > 0 then	--50 charges
					inventory:useItem(203578)
					print("Added 50 Arcane Transmutor Charges to Magic Box from inventory.\n")
				elseif inventory:itemTotalCount(208777) > 0 then	--50 charges
					inventory:useItem(208777)
					print("Added 50 Arcane Transmutor Charges to Magic Box from inventory.\n")
				elseif inventory:itemTotalCount(202930) > 0 then	--100 charges
					inventory:useItem(202930)
					print("Added 100 Arcane Transmutor Charges to Magic Box from inventory.\n")
				elseif inventory:itemTotalCount(208776) > 0 then	--100 charges
					inventory:useItem(208776)
					print("Added 100 Arcane Transmutor Charges to Magic Box from inventory.\n")
				else
					local phirCoins = inventory:itemTotalCount(203038)
					printf("Running low on available charges and none in inventory... buying 10 more.\n")
					guid = FindItemShopGUID(202928,"coin")
					if phirCoins > 99 then	
						BuyFromItemShop(guid, mySecondPassword)			
					else
						print("\a\aInsufficient Phirius Token Coins to purchase required Magic Box Energy. We need an additional "..chargesNeeded.." charges. \nGet more charges then press Delete to continue.")
						player:sleep()
					end
					yrest(1000);
					print("Using 10 Arcane Transmutor Charges just purchased.\n")
					inventory:useItem(202928)
					yrest(100);
				end
				inventory:update()
			until RoMScript("GetMagicBoxEnergy()") >= 15
		end
	end
	
	--********************************************************************************************************--
	-- Check for required empty bag space first
	function prepBags()
		inventory:update()
		yrest(1000)
		currentGear = 0
		emptySlots = 0
		for i = 61,90 do
			local item = inventory.BagSlot[i]
			if (item:isType("Weapons") or item:isType("Armor")) and item.RequiredLvl >=94 and item.Quality == 2 then
				currentGear = currentGear + 1
			elseif item.Id == highClassEquipment then
				print("found highClassEquipmentPackages")
			elseif item.Id ~= 0 and item.Name ~= "Mana Stone Tier 8" and item.Name ~= "Mana Stone Tier 9" then
				item:moveTo("bag2")
				emptySlots = emptySlots + 1
				--print(emptySlots)
			elseif item.Id == 0 then
				emptySlots = emptySlots + 1
				--print("slot "..i.." was empty. now have "..emptySlots.." empty slots.")
			end
			
		end
		currentHighClassEquipmentPackages = inventory:itemTotalCount(highClassEquipment)
		if 23 > emptySlots + currentGear then 
			print("\a\aInsufficient space available in bag 1. Clear space and then press Delete to continue...")
			player:sleep()
		end
		local gold = RoMScript('GetPlayerMoney("copper");')
		if 17820 > gold then
			goldNeeded = 17820-gold
			print("Not enough gold to purchase required Random Fusion Stones. Get "..goldNeeded.." more gold then press Delete to continue.")
			player:sleep()
		end		
	end
	
	--******************************************************************************--
	-- function to open 9 Seige Reward Packages	-->
	function openRewardsPackages()
		if not RoMCode("BagFrame:IsVisible()") then 
			RoMCode("BagFrame:Show()")
		end
		prepBags()
		checkCharges()
		local toOpen = 9 - currentGear - currentHighClassEquipmentPackages
		if toOpen > inventory:itemTotalCount(rewardPackages) then
			print("\a\aInsufficient reward packages or high level gear. Get more then press Delete to continue...")
			player:sleep()
		end
		cprintf(cli.green, "Now opening "..toOpen.." Reward Packages...")
		for i = 1,toOpen do
			inventory:useItem(rewardPackages);
			yrest(2000)
		end
		inventory:update()
		yrest(1000)
		for i = 61,90 do
			local item = inventory.BagSlot[i]
			if not ((item:isType("Weapons") or item:isType("Armor")) and item.RequiredLvl >=94 and item.Quality == 2) then
				if not item.Id == highClassEquipment then
					if inventory:itemTotalCount(0, "Bag2") > 0 then
						item:moveTo("bag2")
					else
						cprintf(cli.red, "Out of space in bag 2. Please clear some space before continuing.")
						player:sleep()
					end
				end
			end
			
		end
		yrest(2000)
	end
	
	--******************************************************************************--
	-- function to open 9 High Class Equipment Packages	-->
	function openEquipmentPackages()
		-- need item ID of this item, as well as ID of everything inside it.
		local toOpen = 9 - currentGear
		if toOpen > inventory:itemTotalCount(highClassEquipment) then
			print("\a\aInsufficient High Class Equipment Packages. Get more then press Delete to continue...")
			player:sleep()
		end
		cprintf(cli.green, "Now opening "..toOpen.." Superior Equipment Packages...")
		for i = 1,toOpen do
			inventory:useItem(highClassEquipment);
			yrest(500)
		end
		RoMCode("ToggleBackpack() BagFrame:Hide()");
	end
	
	--*******************************************************************************--
	-- function to buy correct amount of fusion stones. -->
	function buyFusions()		
		local npcname = 110576 -- "Odeley Prole"
		local stonename = "Random Fusion Stone"
		local curstones = inventory:itemTotalCount(stonename,"bags")
		stonestobuy = 9
		local stonestobuy = stonestobuy-curstones
		if 0 > stonestobuy then 
			stonestobuy = 0 
		end
		if stonestobuy > 0 then
			cprintf(cli.green, "Now purchasing "..stonestobuy.." Random Fusion Stones...")
			myitem = player:findNearestNameOrId(npcname)
			if not myitem or distance(myitem, player) > 200 then
				travelTo("VaranasWest")
				player:moveTo(CWaypoint(2908,-798), true)
				player:moveTo(CWaypoint(2870,-865), true)
				player:moveTo(CWaypoint(2711,-976), true)
				player:moveTo(CWaypoint(2552,-1090), true)
				player:moveTo(CWaypoint(2454,-1160), true)
				player:moveTo(CWaypoint(2520,-1278), true)
				player:moveTo(CWaypoint(2623,-1423), true)
				player:moveTo(CWaypoint(2710,-1546), true)
				player:moveTo(CWaypoint(2762,-1620), true)
				player:moveTo(CWaypoint(2752,-1631), true)
			end
			player:openStore(npcname);
			inventory:storeBuyItem(stonename, stonestobuy)
			yrest(500)
			if RoMScript("StoreFrame:IsVisible()") then
				RoMCode("CloseWindows()");
			end
		end
	end
	
	--***************************************************************************--
	-- Fuse Function -->
	function fuseItems()
		if not RoMCode("BagFrame:IsVisible()") then 
			RoMCode("BagFrame:Show()")
		end
		--clear fuser:
		for i = 51,60 do
			local item = inventory.BagSlot[i]
			if item.Id ~= 0 then
				item:moveTo("bag2")
			end
		end
		-- first check charges:
		local charges = RoMScript("GetMagicBoxEnergy()")
		if 3 > charges then
			for i = 1, 2 do
				local phirCoins = inventory:itemTotalCount(203038)
				printf("Running low on charges... buying 10 more.\n")
				guid = FindItemShopGUID(202928,"coin")
				if phirCoins > 99 then	
					BuyFromItemShop(guid, mySecondPassword)
				else
					print("Not enough p-coins left")
				end
				yrest(1000);
				print("Using 10x arcane transmutor pack")
				inventory:useItem(202928)
				yrest(100);						
			end
		elseif 15 > charges then
			local phirCoins = inventory:itemTotalCount(203038)
			printf("Running low on charges... buying 10 more.\n")
			guid = FindItemShopGUID(202928,"coin")
			if phirCoins > 99 then	
				BuyFromItemShop(guid, mySecondPassword)			
			else
				print("Not enough p-coins left")
			end
			yrest(1000);
			print("Using 10x arcane transmutor pack")
			inventory:useItem(202928)
			yrest(100);
		end
		--setup fusion:
		Fusion_Config("Random Fusion Stones", true)
		Fusion_Config("Fusion Stones", false)
		Fusion_Config("Purified Fusion Stones", false)
		Fusion_Config("Maximum Stats", 3)
		Fusion_Config("Use Clean Items", false)
		Fusion_Config("Use Item Whitelist", false)
		Fusion_Config("Item Tier Level", 6)
		Fusion_Config("White", false)
		Fusion_Config("Green", false)
		Fusion_Config("Blue", true)
		Fusion_Config("Purple", false)
		
		Fusion_MakeMaxManaStones(10)
		yrest(1000)
		--find empty slots in bag 2 then move any Tstones from 1 to 2.
		currentStones = inventory:itemTotalCount("Mana Stone Tier 6", "Bag1")
		currentStones = currentStones + inventory:itemTotalCount("Mana Stone Tier 7", "Bag1")
		currentStones = currentStones + inventory:itemTotalCount("Mana Stone Tier 8", "Bag1")
		currentStones = currentStones + inventory:itemTotalCount("Mana Stone Tier 9", "Bag1")
		if currentStones > 0 then
			emptySlots = inventory:itemTotalCount(0, "Bag2")
			if emptySlots > 0 then
				for i = 61,90 do
					local item = inventory.BagSlot[i]
					for n = 6,10 do
						if item.Name == "Mana Stone Tier "..n then
							item:moveTo("Bag2")
						end
					end
				end
			else
				cprintf(cli.red, "Please clear a slot from bag 2")
				player:sleep()
			end
		
		end
		
		
		
		
		sendMacro("CloseWindows()")
		
	end
	
	--*******************************************************************************************--
	--***		function to do a full precheck to ensure we have enough of everything.		--
	function precheck()
		--precheck charges and phirius tokens.
		local chargeCount = 0
		charges = RoMScript("GetMagicBoxEnergy()")
		if 15 > charges then
			chargesNeeded = 15 - charges
			chargeCount = inventory:itemTotalCount(203487) 
			chargeCount = chargeCount + (inventory:itemTotalCount(208932) * 5)	--5 charges
			chargeCount = chargeCount + (inventory:itemTotalCount(202928) * 10)	--10 charges
			chargeCount = chargeCount + (inventory:itemTotalCount(203577) * 10) --10 charges
			chargeCount = chargeCount + (inventory:itemTotalCount(208778) * 10) --10 charges
			chargeCount = chargeCount + (inventory:itemTotalCount(202929) * 50) --50 charges
			chargeCount = chargeCount + (inventory:itemTotalCount(203578) * 50) --50 charges
			chargeCount = chargeCount + (inventory:itemTotalCount(208777) * 50) --50 charges
			chargeCount = chargeCount + (inventory:itemTotalCount(202930) * 100) --100 charges
			chargeCount = chargeCount + (inventory:itemTotalCount(208776) * 100) --100 charges
			chargesNeeded = chargesNeeded - chargeCount
			if 0 > chargesNeeded then 
				chargesNeeded = 0 
			end
			local phirCoins = inventory:itemTotalCount(203038)
			if chargesNeeded > 10 then
				if 200 > phirCoins then	
					cprintf(cli.red, "\a\aInsufficient Phirius Token Coins to purchase required Magic Box Energy.\n")
					cprintf(cli.red, "We need an additional "..chargesNeeded.." charges. \n")
					cprintf(cli.red, "Get more charges then press Delete to continue.\n")
					player:sleep()
				end
			elseif chargesNeeded > 0 then
				if 100 > phirCoins then	
					cprintf(cli.red, "\a\aInsufficient Phirius Token Coins to purchase required Magic Box Energy.\n")
					cprintf(cli.red, "We need an additional "..chargesNeeded.." charges.\n")
					cprintf(cli.red, "Get more charges then press Delete to continue.")
					player:sleep()
				end
			end			
		end
		-- precheck equipment packages:
		currentGear = 0
		emptySlots = 0
		for i = 61,90 do
			local item = inventory.BagSlot[i]
			if (item:isType("Weapons") or item:isType("Armor")) and item.RequiredLvl >=94 and item.Quality == 2 then
				currentGear = currentGear + 1
			elseif item.Id == highClassEquipment then
				yrest(50)
			elseif item.Id ~= 0 and item.Name ~= "Mana Stone Tier 8" and item.Name ~= "Mana Stone Tier 9" then
				item:moveTo("bag2")
				emptySlots = emptySlots + 1
				--print(emptySlots)
			elseif item.Id == 0 then
				emptySlots = emptySlots + 1
				--print("slot "..i.." was empty. now have "..emptySlots.." empty slots.")
			end
			
		end
		currentHighClassEquipmentPackages = inventory:itemTotalCount(highClassEquipment)
		if 23 > emptySlots + currentGear + currentHighClassEquipmentPackages then 
			cprintf(cli.red, "\a\aInsufficient space available in bag 1. Clear space and then press Delete to continue...\n")
			player:sleep()
		end
		local gold = RoMScript('GetPlayerMoney("copper");')
		if 17820 > gold then
			goldNeeded = 17820-gold
			cprintf(cli.red, "Not enough gold to purchase required Random Fusion Stones.\n")
			cprintf(cli.red, "Get "..goldNeeded.." more gold then press Delete to continue.\n")
			player:sleep()
		end		
		local toOpen = 9 - currentGear - currentHighClassEquipmentPackages
		if toOpen > inventory:itemTotalCount(rewardPackages) then
			cprintf(cli.red, "\a\aInsufficient reward packages or high level gear. Get more then press Delete to continue...\n")
			player:sleep()
		end
		
	end
	
	
	--*************************************************--
	-- Build Menu -->
	
	
	function SKM_ShowButtons()
		precheck()
		cprintf(cli.green, "1... Open Rewards\n")
		cprintf(cli.green, "2... Open Equipment\n")
		cprintf(cli.green, "3... Buy Stones\n")
		cprintf(cli.green, "4... Fuse Stones\n")
		print("----------------------\n")
		cprintf(cli.green, "9... All Steps for 1 round with 1 Click\n")
		print("----------------------\n")
		cprintf(cli.green, "Press Ctrl + L to exit\n")
	end
	
	function checkExistingStones()
		local ManaTable = {
			"Mana Stone Tier 6", 
			"Mana Stone Tier 7",
			"Mana Stone Tier 8",
			"Mana Stone Tier 9",
			"Mana Stone Tier 10",
			"Mana Stone Tier 11"
		}
		local foundManaStone = false
		for k,v in pairs(ManaTable) do
			local item = inventory:findItem(v,"bags")
			if item then
				foundManaStone = true
				print ("found "..item.Name.." in inventory.")
			end
		end
		if foundManaStone == true then
			cprintf(cli.red, "Found Existing Mana Stones in Inventory!!!!\n")
			cprintf(cli.red, "Be sure these are stones you are not using for Statting\n")
			cprintf(cli.red, "as they may get fused with other stones!!!!!!\n")
			player:sleep()
		end
	end
	
	--*******************************************************************************************************
	--*** start actions here ---
	if minCharLevel > player.Level then
		error("Player level does not meet the minimum required level (see the minCharLevel variable in the user variables section).")
	end
	for k,v in pairs(settings.profile.skills) do
		v.AutoUse = false
	end
	print("skills disabled.\n")
	
	__WPL:setForcedWaypointType("NORMAL")
	if RoMScript("StoreFrame:IsVisible()") then
		RoMCode("CloseWindows()");
	end
	RoMCode("ToggleBackpack() BagFrame:Hide()");
	checkExistingStones()
	SKM_ShowButtons()
	local delay = 1 -- time between key presses.
	local time = os.time()
	while(true) do
		yrest(10)
		if keyPressed(key.VK_NUMPAD1) and (os.time() - time > delay ) then
			openRewardsPackages()
			SKM_ShowButtons()
			time = os.time()
		end
		if keyPressed(key.VK_NUMPAD2) and (os.time() - time > delay ) then
			openEquipmentPackages()
			SKM_ShowButtons()
			time = os.time()
		end  
		if keyPressed(key.VK_NUMPAD3) and (os.time() - time > delay ) then
			buyFusions()
			SKM_ShowButtons()
			time = os.time()
		end 		
		if keyPressed(key.VK_NUMPAD4) and (os.time() - time > delay ) then
			fuseItems()
			SKM_ShowButtons()
			time = os.time()
		end  
		if keyPressed(key.VK_NUMPAD9) and (os.time() - time > delay ) then
			openRewardsPackages()
			openEquipmentPackages()
			buyFusions()
			fuseItems()
			SKM_ShowButtons()
			time = os.time()
		end  
	end
</onLoad>
</waypoints>