<?xml version="1.0" encoding="utf-8"?>
<waypoints>
	<onLoad>
		-- V 3.2
		<![CDATA[
			--=== user options ===--
			-- it will stop once this score is reached, bonuses will be added afterwards though 
			-- so 4700 will probably be total score of 3100
			local requiredscore = 2700
			
			-- alter to your local language, caps sensative, in english is "Go!!!", so "Go" is enough
			local goMessage = "Go"
			
			id_kate		= 121035
			id_magelly	= 120687
						
			-- Move to Kate Wesker and enter
			if getZoneId() == 2 then
				player:target_NPC(id_kate)
				
				--ChoiceOptionByName("Transport to Andor Training Range"); 
				--yrest(1000)
				ChoiceOptionByName(getTEXT("SKWERL_MOBIUS_24")) 
				yrest(1000)
				
				waitForLoadingScreen()
			end
			-- Move to Magelly Basac
			player:target_NPC(id_magelly)
			
			-- Check if we already completed
			--ChoiceOptionByName("Register for timed training"); yrest(1000)  
			ChoiceOptionByName(getTEXT("SKWERL_MOBIUS_14")) yrest(1000)
			
			--ChoiceOptionByName("Participate in training"); yrest(1000)  
			ChoiceOptionByName(getTEXT("SKWERL_MOBIUS_25")) yrest(1000)
			
			--ChoiceOptionByName("Confirm"); yrest(1000)
			ChoiceOptionByName(getTEXT("SYS_OKAY")) yrest(1000) --(might be wrong)
			
			local round = 0
			local score = 0
			
			function tort()
				local proc = getProc()
				
				local function checkclicked(address)
					local tmp = memoryReadRepeat("int", proc, address + addresses.pawnAttackable_offset) or 0;
					if bitAnd(tmp,0x8) then
						return true
					else
						return false
					end
				end

				local function one(ID)
					--print("targeting: "..ID)
					local objectList = CObjectList();
					objectList:update();
					local objSize = objectList:size()
					for i = 0,objSize do 
						obj = objectList:getObject(i)
						obj:update()
						if (obj.Id == ID or ID == 106885) and checkclicked(obj.Address) then
							player:target(obj)
							RoMScript("UseExtraAction(1)")
							yrest(10)
							player:target(obj)
							RoMScript("UseExtraAction(1)")
							if ID == 106883 then
								yrest(10)
								player:target(obj)
								RoMScript("UseExtraAction(1)")	
							end
							yrest(100)
						end
					end
				end
				if player:findNearestNameOrId(106881,106882,106883,106884) then
					--== monitor chat
					EventMonitorStart("Tortevent", "SYSTEM_MESSAGE");
					local time, moreToCome, name, msg, _go 
					repeat
						time, moreToCome, name, msg = EventMonitorCheck("Tortevent",1)
						yrest(10)
						if name and string.find(name,goMessage) then
							_go = true
						end
					until _go == true
					EventMonitorStop("Tortevent")
					round = round + 1
					print("Wave: "..round..", Score: "..score)
					repeat
						one(106882)
						one(106882)
						one(106881)
						one(106883)
						one(106884)
					until not player:findNearestNameOrId(106881,106882,106883,106884)
				end
			end
			
			repeat
				yrest(100)
			until  player:findNearestNameOrId(106881)
			print("OK event has started")
			repeat
				tort()
				player:update()
				yrest(100)
				buffed = player:getBuff(622402)
				if buffed then score = buffed.Level end
			until not player:hasBuff(622402) or ( buffed and buffed.Level > requiredscore )
			error("Event finished, end score was "..score)
		]]>
	</onLoad>
</waypoints>
