<?xml version="1.0" encoding="utf-8"?>
<!--
	The Andor Training Range event
-->
<waypoints>
	<onLoad>
		<![CDATA[
			id_kate		= 121035
			id_magelly	= 120687
			
			id_zone		= 360
			
			id_tortoise	= 106881
			id_newt		= 106882
			id_armored	= 106883
			id_rabbit	= 106884
			id_ammo		= 106885
			
			-- Table of mobs in KILL order
			obj_table 	= {id_newt, id_tortoise, id_armored, id_rabbit, id_ammo}
			
			-- Move to Kate Wesker and enter
			player:target_NPC(id_kate)
			ChoiceOptionByName("Transport to Andor Training Range"); yrest(1000)
			waitForLoadingScreen()
			
			-- Move to Magelly Basac
			player:target_NPC(id_magelly)
			
			-- Check if we already completed
			ChoiceOptionByName("Register for timed training"); yrest(1000)
			--ChoiceOptionByName("Register for arena training"); yrest(1000)		-- Select based on what reward we already have?
			ChoiceOptionByName("Participate in training"); yrest(1000)
			ChoiceOptionByName("Confirm"); yrest(1000)
			
			
			-- Repeat until we fail
			repeat
			
				-- Wait for mobs to spawn
				cprintf(cli.lightblue, "Reading in mobs\n")
				player:sleep()
				
				-- Read in objects
				local killTable = {}
				local objectList = CObjectList()
	
				-- Read in all mobs in table while making table
				objectList:update()			
				for i = 0,objectList:size() do
					local obj = objectList:getObject(i)
					if( obj ~= nil ) then
						for __, _objid in pairs(obj_table) do
							if( obj.Address ~= ignore and obj.Id ==  _objid) then
								table.insert(killTable, obj)
							end
						end
					end
				end
				
				-- Wait for adds to move
				cprintf(cli.lightblue, "Killing mobs, %d in list\n", #killTable)
				player:sleep()
				
				-- Training...kill mobs in order	
				for __,objid in pairs(obj_table) do
					cprintf(cli.lightblue, "\tKilling %d\n", objid)
					for k,obj in pairs(killTable) do
						if( obj.Id ==  objid) then
							player:target(obj)
							RoMScript("UseExtraAction(1)")
							yrest(1000)
							objectList:update()
						end
					end
				end
				
			until false
		]]>
	</onLoad>
</waypoints>
