@@ -149,7 +149,7 @@ WriteLn WorldSwitcher.IsLoading();
149149*)
150150function TRSWorldSwitcher.IsLoading(): Boolean;
151151begin
152- Result := not Target.HasColor(RSFonts.ORANGE, 0, 1 , Self.CurrentWorldBounds);
152+ Result := not Target.HasColor(RSFonts.ORANGE, 0, 50 , Self.CurrentWorldBounds);
153153end;
154154
155155(*
@@ -189,9 +189,9 @@ WriteLn WorldSwitcher.Open();
189189function TRSWorldSwitcher.Open(waitLoad: Boolean = True): Boolean;
190190begin
191191 //overriden in TRSLogout.
192- Result := SleepUntil(not Self._IsOpen(), RandomMode(100, 50, 1500), 600 );
192+ Result := SleepUntil(not Self._IsOpen(), RandomMode(100, 50, 1500), TICK );
193193 if Result and waitLoad then
194- Self.WaitLoading();
194+ Self.WaitLoading(4*TICK );
195195end;
196196
197197
@@ -247,23 +247,6 @@ begin
247247end;
248248
249249
250- (*
251- ## WorldSwitcher.GetCurrentWorld
252- ```pascal
253- function TRSWorldSwitcher.GetCurrentWorld(): Integer;
254- ```
255- Returns the current world we are on.
256-
257- Example:
258- ```pascal
259- WriteLn WorldSwitcher.GetCurrentWorld();
260- ```
261- *)
262- function TRSWorldSwitcher.GetCurrentWorld(): Integer;
263- begin
264- Result := OCR.RecognizeNumber(Self.CurrentWorldBounds, RSFonts.BOLD, [RSFonts.ORANGE], 0);
265- end;
266-
267250(*
268251## WorldSwitcher.GetWorlds
269252```pascal
@@ -383,74 +366,123 @@ begin
383366 Result := SleepUntil(Self.IsSorted(), 50, 600);
384367end;
385368
386- (*
387- ## WorldSwitcher.WaitSwitch
388- ```pascal
389- function TRSWorldSwitcher.WaitSwitch(world: Integer; failCooldown: Boolean = True): Boolean;
390- ```
391- Exits false if "Please wait" not found, presumably due to combat.
392- Returns true if we find "Please wait" and finish world hopping successfully to
393- the specified `world`
394- *)
395- function TRSWorldSwitcher.WaitSwitch(world: Integer; failCooldown: Boolean = True): Boolean;
369+ function TRSWorldSwitcher.WaitSwitch(world: Integer; failCooldown: Boolean = True): Boolean; forward;
370+
371+ function TRSWorldSwitcher._Hop(next: Integer): Boolean;
372+ var
373+ timeout: TCountDown;
374+ available: TRSWorldArray;
375+ world: TRSWorld;
396376begin
397- if not SleepUntil(MainScreen.IsServerMessage('Please wait'), 50, 600) then
398- begin
399- if failCooldown then Self.Cooldown.Restart(0, 7000);
377+ if not Self.IsSorted() and not Self.Sort() then
400378 Exit;
401- end;
402379
403- Result := SleepUntil(Self.GetCurrentWorld() = world, 200, 10000);
380+ timeout.Start(20 * ONE_SECOND);
381+
382+ repeat
383+ available := Self.GetWorlds();
384+ if available = [] then Exit;
385+
386+ for world in available do
387+ if world.Number = next then
388+ begin
389+ Mouse.Click(world.Bounds, EMouseButton.LEFT);
390+ if Self.WaitSwitch(next) then
391+ Exit(True);
392+ end;
393+
394+ Self.Scroll.Scroll(Biometrics.RandomModeInteger(2,1,3), next > available[0].Number);
395+ until not InRange(Self.Scroll.GetLevel(), 1, 99) or timeout.IsFinished;
404396end;
405397
406398(*
407- ## WorldSwitcher.Hop
399+ ## WorldSwitcher.World
408400```pascal
409- function TRSWorldSwitcher.Hop(worlds: TIntegerArray): Boolean;
401+ property TRSWorldSwitcher.World: Integer;
402+ property TRSWorldSwitcher.World(world: Integer): Boolean;
403+ property TRSWorldSwitcher.World(worlds: TIntegerArray): Boolean;
410404```
411- Switches to a different world from the specified `worlds`. By default the
412- world switcher will sort the worlds, you can change this by passing `False` to `sort`.
413- If the `TRSWorldSwitcher.Cooldown` is still active the function will return `False`.
405+ Returns or sets the current world we are on.
406+
407+ When setting, if there's multiple worlds available we will hop to the next on
408+ the list available.
409+
410+ Setting a new world will only happen if `TRSWorldSwitcher.Cooldown` is finished,
411+ which is a cooldown that starts everytime you change worlds.
414412
415413Example:
416414```pascal
417- WriteLn WorldSwitcher.Hop([303, 304, 305]);
415+ WriteLn WorldSwitcher.World;
416+ WorldSwitcher.World := 311;
417+ WriteLn WorldSwitcher.World;
418+ WorldSwitcher.World[[311,312,313]];
419+ WriteLn WorldSwitcher.World;
418420```
419421*)
420- function TRSWorldSwitcher.Hop(worlds: TIntegerArray): Boolean;
422+ property TRSWorldSwitcher.World: Integer;
423+ begin
424+ Result := OCR.RecognizeNumber(Self.CurrentWorldBounds, RSFonts.BOLD, [RSFonts.ORANGE], 0);
425+ end;
426+
427+ property TRSWorldSwitcher.World(next: Integer): Boolean;
428+ var
429+ current: Integer;
430+ begin
431+ if not Self.Cooldown.IsFinished then
432+ Exit;
433+
434+ if not Self.Open() then
435+ Exit;
436+
437+ current := Self.World;
438+ if next = current then
439+ Exit(True);
440+
441+ Result := Self._Hop(next);
442+ end;
443+
444+ property TRSWorldSwitcher.World(worlds: TIntegerArray): Boolean;
421445var
422446 current, next: Integer;
423- available: TRSWorldArray;
424- world: TRSWorld;
425447begin
448+ if not Self.Cooldown.IsFinished or not Self.Open() then
449+ Exit;
450+
426451 if worlds = [] then
427- raise GetDebugLn('WorldSwitcher', 'worlds is empty.');
428- if not Self.Cooldown.IsFinished then Exit;
429- if not Self.Open() then Exit;
452+ raise GetDebugLn('WorldSwitcher', 'worlds parameter is empty.');
430453
431- current := Self.GetCurrentWorld() ;
432- if worlds = [current] then Exit(True);
433- if not Self.IsSorted() and not Self.Sort() then Exit ;
454+ current := Self.World ;
455+ if worlds = [current] then
456+ Exit(True) ;
434457
435458 next := worlds.IndexOf(current) + 1;
436- if next > High(worlds) then next := 0;
459+ if next > High(worlds) then
460+ next := 0;
437461
438- repeat
439- available := Self.GetWorlds();
440- if available = [] then Exit;
462+ Result := Self._Hop(next);
463+ end;
441464
442- for world in available do
443- if world.Number = next then
444- begin
445- Mouse.Click(world.Bounds, EMouseButton.LEFT);
446- if Self.WaitSwitch(next) then
447- Exit(True);
448- end;
465+ (*
466+ ## WorldSwitcher.WaitSwitch
467+ ```pascal
468+ function TRSWorldSwitcher.WaitSwitch(world: Integer; failCooldown: Boolean = True): Boolean;
469+ ```
470+ Exits false if "Please wait" not found, presumably due to combat.
471+ Returns true if we find "Please wait" and finish world hopping successfully to
472+ the specified `world`
473+ *)
474+ function TRSWorldSwitcher.WaitSwitch(world: Integer; failCooldown: Boolean = True): Boolean;
475+ begin
476+ if not SleepUntil(MainScreen.IsServerMessage('Please wait'), 50, 600) then
477+ begin
478+ if failCooldown then Self.Cooldown.Restart(0, 7000);
479+ Exit;
480+ end;
449481
450- Self.Scroll.Scroll(Biometrics.RandomModeInteger(2,1,3), next > available[0].Number);
451- until not InRange(Self.Scroll.GetLevel(), 1, 99);
482+ Result := SleepUntil(Self.World = world, 200, 10000);
452483end;
453484
485+
454486var
455487(*
456488## WorldSwitcher variable
0 commit comments