Skip to content

Commit ff8a01e

Browse files
committed
feat(TRSItem): added TRSItem.Spread()
- spreads items with "(a..b)" into a TRSItemArray for each quantity from `a` to `b`. - time contants were all missing a 0.... oops. This caused a ton of issues, notably with antiban
1 parent 0a30b14 commit ff8a01e

File tree

5 files changed

+155
-70
lines changed

5 files changed

+155
-70
lines changed

osrs/antiban/antibantasks.simba

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ begin
6464

6565
b := RSClient.Bounds.Expand(150);
6666

67-
for i := 1 to Trunc(GaussRand(1, 6)) do
67+
for i := 1 to Trunc(Abs(GaussRand(1, 6))) do
6868
begin
6969
if Random() < 0.30 then
7070
Mouse.Move(b, True, EMouseDistribution.GAUSS)
@@ -152,7 +152,7 @@ begin
152152
Exit;
153153
end;
154154

155-
Self.OpenSkill(Self.Skills.Random(), Trunc(GaussRand(1000, 10000)), RandomBoolean(0.5));
155+
Self.OpenSkill(Self.Skills.Random(), Biometrics.RandomModeInteger(3000, 1000, 8000), RandomBoolean(0.5));
156156
end;
157157

158158

osrs/finders/itemfinder.simba

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,20 @@ end;
261261
function TRSItemFinder.FindAll(items: TRSItemArray; boxes: TBoxArray; maxToFind: Integer = 0): TImageMatchArray;
262262
var
263263
item: TRSItem;
264+
spread: TRSItemArray;
264265
img: TImage;
265266
i: Integer;
266267
skip: TBooleanArray;
267268
match: Single;
268269
begin
269270
SetLength(skip, Length(boxes));
270271

272+
for item in items do
273+
spread += item.Spread();
274+
271275
Target.FreezeImage();
272276

273-
for item in items do
277+
for item in spread do
274278
begin
275279
item := LowerCase(item);
276280
Self.ImageCompare.Filter := @Self.GetFilter(item);
@@ -301,6 +305,7 @@ end;
301305
function TRSItemFinder.FindAll(items: TRSItemArray; boxes: TBoxArray; out matches: TImageMatchArray): Boolean; overload;
302306
var
303307
item: TRSItem;
308+
spread: TRSItemArray;
304309
results: TImageMatchArray;
305310
i: Integer;
306311
img: TImage;
@@ -309,9 +314,12 @@ var
309314
begin
310315
SetLength(skip, Length(boxes));
311316

317+
for item in items do
318+
spread += item.Spread();
319+
312320
Target.FreezeImage();
313321

314-
for item in items do
322+
for item in spread do
315323
begin
316324
item := LowerCase(item);
317325
Self.ImageCompare.Filter := @Self.GetFilter(item);
@@ -352,6 +360,7 @@ end;
352360
function TRSItemFinder.Find(items: TRSItemArray; boxes: TBoxArray; out match: TImageMatch): Boolean;
353361
var
354362
item: TRSItem;
363+
spread: TRSItemArray;
355364
img: TImage;
356365
i: Integer;
357366
similarity: Single;
@@ -361,6 +370,9 @@ begin
361370
Target.FreezeImage();
362371

363372
for item in items do
373+
spread += item.Spread();
374+
375+
for item in spread do
364376
begin
365377
item := LowerCase(item);
366378
Self.ImageCompare.Filter := @Self.GetFilter(item);

osrs/interfaces/gametabs/worldswitcher.simba

Lines changed: 95 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ WriteLn WorldSwitcher.IsLoading();
149149
*)
150150
function TRSWorldSwitcher.IsLoading(): Boolean;
151151
begin
152-
Result := not Target.HasColor(RSFonts.ORANGE, 0, 1, Self.CurrentWorldBounds);
152+
Result := not Target.HasColor(RSFonts.ORANGE, 0, 50, Self.CurrentWorldBounds);
153153
end;
154154

155155
(*
@@ -189,9 +189,9 @@ WriteLn WorldSwitcher.Open();
189189
function TRSWorldSwitcher.Open(waitLoad: Boolean = True): Boolean;
190190
begin
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);
195195
end;
196196

197197

@@ -247,23 +247,6 @@ begin
247247
end;
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);
384367
end;
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;
396376
begin
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;
404396
end;
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

415413
Example:
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;
421445
var
422446
current, next: Integer;
423-
available: TRSWorldArray;
424-
world: TRSWorld;
425447
begin
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);
452483
end;
453484

485+
454486
var
455487
(*
456488
## WorldSwitcher variable

utils/item.simba

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,47 @@ begin
235235
Result := Self.EndsWith(')', True);
236236
end;
237237

238+
(*
239+
## TRSItem.Spread
240+
```pascal
241+
function TRSItem.Spread(): TRSItemArray;
242+
```
243+
Checks if the `TRSItem` has `(a..b)` in it's name and will spread it into a
244+
`TRSItemArray`.
245+
246+
Example:
247+
```pascal
248+
item := 'prayer potion(1..4)';
249+
WriteLn item.Spread(); ['prayer potion(1)', 'prayer potion(2)', 'prayer potion(3)'. 'prayer potion(4)']
250+
item := 'prayer potion(2..1)';
251+
WriteLn item.Spread(); ['prayer potion(2)', 'prayer potion(1)']
252+
```
253+
*)
254+
function TRSItem.Spread(): TRSItemArray;
255+
var
256+
parts: TStringArray;
257+
first, last, i: Integer;
258+
name: String;
259+
begin
260+
parts := Self.Split('..');
261+
if Length(parts) <= 1 then
262+
Exit([Self]);
263+
264+
first := StrToInt(parts[0].Last);
265+
last := StrToInt(parts[1].First);
266+
name := parts[0].CopyRange(1, parts[0].Length-1);
267+
268+
if first < last then
269+
begin
270+
for i := first to last do
271+
Result += name + ToStr(i) + ')';
272+
Exit;
273+
end;
274+
275+
for i := first downto last do
276+
Result += name + ToStr(i) + ')';
277+
end;
278+
238279
(*
239280
## TRSItem.SimplifyName
240281
```pascal

utils/time.simba

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Time related misc functions and variables
77
const
88
TICK: Integer = 600;
99
ONE_SECOND: Integer = 1000;
10-
ONE_MINUTE: Integer = 6000;
11-
ONE_HOUR: Integer = 360000;
12-
ONE_DAY: Integer = 8640000;
10+
ONE_MINUTE: Integer = 60000;
11+
ONE_HOUR: Integer = 3600000;
12+
ONE_DAY: Integer = 86400000;
1313
TIME_FORMAL: String = 'h \ho\ur\s, m \min\ute\s and s \second\s';
1414
MINUTES_FORMAL: String = 'm \min\ute\s and s \second\s';
1515
FILE_TIME_FORMAT: String = 'YYYY-MM-DD_hh-mm-ss-ms';

0 commit comments

Comments
 (0)