Skip to content

Commit 04ebc72

Browse files
committed
feat: TWebGraph Callbacks
for teleports and what not. Can be setup as following: ```pascal WebGraphCallbacks.Setup(@Map.Position, @Map.Loader); ```
1 parent bb56b78 commit 04ebc72

File tree

5 files changed

+102
-21
lines changed

5 files changed

+102
-21
lines changed

osrs.simba

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ Summary: It includes this file until the current file is reached.
162162
{$IFNDEF WL_INVENTORY_FORM_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/handlers/inventory_form.simba}
163163
{$IFNDEF WL_PRAYER_FORM_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/handlers/prayer_form.simba}
164164
{$IFNDEF WL_CONSUMABLES_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/handlers/consumables.simba}
165+
{$IFNDEF WL_WEBGRAPH_CALLBACKS_INCLUDED} {$INCLUDE_ONCE osrs/position/map/webgraph_callbacks.simba}
166+
165167

166168
{$IFNDEF WL_ANTIBAN_TASKS_INCLUDED} {$INCLUDE_ONCE osrs/antiban/antibantasks.simba}
167169
{$IFNDEF WL_ANTIBAN_FORM_INCLUDED} {$INCLUDE_ONCE osrs/antiban/antibanform.simba}
@@ -180,4 +182,4 @@ Summary: It includes this file until the current file is reached.
180182
{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}
181183
{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}
182184
{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}{$ENDIF}
183-
{$ENDIF}
185+
{$ENDIF}{$ENDIF}

osrs/interfaces/gametabs/achievements.simba

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Helper record used to interact with the {ref]`Achievements` gametab "Diaries" ta
138138
TRSDiaryList = record
139139
Names: TStringArray;
140140
Scroll: TRSScrollBar;
141+
Cache: array [ERSAchievementDiary] of Integer;
141142
end;
142143

143144
(*
@@ -298,9 +299,8 @@ WriteLn Achievements.Diaries.GetLevel(ERSAchievementDiary.ARDOUGNE);
298299
```
299300
*)
300301
TRSAchievements = record
301-
TabsArea: TBox;
302+
TabsArea, TabTitle: TBox;
302303
Tabs: TBoxArray;
303-
304304
Summary: TRSAchievementsSummary;
305305
Quests: TRSQuestList;
306306
Diaries: TRSDiaryList;
@@ -320,6 +320,7 @@ begin
320320
with GameTab.Bounds do
321321
begin
322322
Self.TabsArea := [X1, Y1 + 5, X2, Y1 + 22];
323+
Self.TabTitle := [X1, Y1 + 25, X2, Y1 + 48];
323324

324325
Self.Summary.SetupGameTab();
325326
Self.Quests.SetupGameTab();
@@ -413,18 +414,22 @@ WriteLn Achievements.GetTab();
413414
*)
414415
function TRSAchievements.GetTab(): ERSAchievementTab;
415416
var
416-
i: Integer;
417+
title: String;
417418
begin
418419
if Self.Tabs = [] then
419420
begin
420421
if not Self.Open() then Exit;
421422
Self.SetupTabs();
422423
end;
423424

424-
for i := 0 to High(Self.Tabs) do
425-
if not Target.HasColor($48585D, 0, 100, Self.Tabs[i]) and
426-
not Target.HasColor($1E2528, 0, 100, Self.Tabs[i]) then
427-
Exit(ERSAchievementTab(i));
425+
title := OCR.Recognize(Self.TabTitle, RSFonts.BOLD_SHADOW, [RSFonts.ORANGE, $3399FF], 3);
426+
427+
case title of
428+
'Quest List': Result := ERSAchievementTab.QUESTS;
429+
'Achievement Diaries': Result := ERSAchievementTab.DIARIES;
430+
'Click here to see all': Result := ERSAchievementTab.ADVENTURE_PATHS;
431+
else Result := ERSAchievementTab.SUMMARY;
432+
end;
428433
end;
429434

430435
(*
@@ -487,13 +492,21 @@ var
487492
i: Integer;
488493
slot: TRSDiarySlot;
489494
begin
495+
if Self.Cache[diary] > 0 then
496+
Exit(Self.Cache[diary]-1);
497+
490498
if not Achievements.OpenTab(ERSAChievementTab.DIARIES) then Exit(-1);
491499
Self.ScrollTo(diary);
492500
slot := Self.GetSlot(diary);
493501

502+
if slot = Default(TRSDiarySlot) then
503+
Exit;
504+
494505
for i := 0 to 3 do
495506
begin
496507
if not Target.HasColor($14B537, 0, 1, slot.Levels[i]) then Break;
497508
Result += 1;
498509
end;
510+
511+
Self.Cache[diary] := Result+1;
499512
end;

osrs/position/map/maploader.simba

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ This is an internal type. Don't use it if you don't know what you are doing.
7878
Timeout: TCountDown;
7979
end;
8080

81+
PRSMapLoader = ^TRSMapLoader;
82+
8183
(*
8284
## Points Translation
8385
This might be the only thing you need to use from time to time from the
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
(*
2+
# WebGraph Callbacks
3+
Several callbacks to handle special webwalking nodes.
4+
*)
5+
6+
{$DEFINE WL_WEBGRAPH_CALLBACKS_INCLUDED}
7+
{$INCLUDE_ONCE WaspLib/osrs.simba}
8+
9+
type
10+
TWebGraphCallbacks = record
11+
Position: TWalkerPositionFunction;
12+
end;
13+
14+
function TWebGraphCallbacks.TeleportGrandExchange(): Boolean;
15+
begin
16+
if Magic.CastSpell(ERSSpell.VARROCK_TELEPORT, 'Grand Exchange') then
17+
Result := SleepUntil(Self.Position().InRange([8565, 36522], 60), 300, 5000);
18+
end;
19+
20+
function TWebGraphCallbacks.TeleportVarrock(): Boolean;
21+
begin
22+
if Magic.CastSpell(ERSSpell.VARROCK_TELEPORT, 'Cast') then
23+
Result := SleepUntil(Self.Position().InRange([8752, 36716], 60), 300, 5000);
24+
end;
25+
26+
27+
procedure TWebGraphCallbacks.AddTeleports(graph: PWebGraph; chunk: TPoint);
28+
begin
29+
case chunk of
30+
[49,54]:
31+
begin
32+
if Achievements.Diaries.GetLevel(ERSAchievementDiary.VARROCK) > 1 then
33+
graph^.AddTeleport([8565, 36522], @Self.TeleportGrandExchange);
34+
end;
35+
[50,53]: graph^.AddTeleport([8752, 36716], @Self.TeleportVarrock);
36+
end;
37+
end;
38+
39+
procedure TWebGraphCallbacks.Setup(position: TWalkerPositionFunction; mapLoader: PRSMapLoader);
40+
var
41+
chunk: TPoint;
42+
region: TRSMapRegion;
43+
begin
44+
Self.Position := @position;
45+
if not RSClient.IsLoggedIn() then
46+
raise GetDebugLn('WebGraphCallbacks', 'Account has to be logged in to setup TWebGraphCallbacks.');
47+
48+
for region in mapLoader^.Regions do
49+
for chunk in region.Chunks do
50+
begin
51+
Self.AddTeleports(@mapLoader^.Graph, chunk);
52+
//Self.AddShortcuts(graph, chunk);
53+
//Self.AddWhatever(graph, chunk);
54+
end;
55+
end;
56+
57+
var
58+
WebGraphCallbacks: TWebGraphCallbacks;

utils/webgraph.simba

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ Enum representing the type of nodes in a `TWebGraph`.
2929
TGraphNode = record
3030
Node: TPoint;
3131
Typ: EGraphNode;
32-
Handle: function (): Boolean;
32+
Handle: function (): Boolean of object;
3333
end;
3434

35-
function TGraphNode.Create(pt: TPoint; typ: EGraphNode = EGraphNode.NORMAL; handle: function (): Boolean = nil): TGraphNode; static;
35+
function TGraphNode.Create(pt: TPoint; typ: EGraphNode = EGraphNode.NORMAL; handle: function (): Boolean of object = nil): TGraphNode; static;
3636
begin
3737
Result.Node := pt;
3838
Result.Typ := typ;
@@ -409,7 +409,7 @@ begin
409409
end;
410410

411411

412-
procedure TWebGraph.AddLink(a, b: TPoint; typ: EGraphNode; handle: function (): Boolean);
412+
procedure TWebGraph.AddLink(a, b: TPoint; typ: EGraphNode; handle: function (): Boolean of object);
413413
var
414414
i, j, n: Integer;
415415
tpa: TPointArray;
@@ -447,7 +447,7 @@ begin
447447
end;
448448
end;
449449

450-
procedure TWebGraph.AddLink(a, b: TPoint; typ: EGraphNode; handleA, handleB: function (): Boolean); overload;
450+
procedure TWebGraph.AddLink(a, b: TPoint; typ: EGraphNode; handleA, handleB: function (): Boolean of object); overload;
451451
var
452452
i, j, n: Integer;
453453
tpa: TPointArray;
@@ -485,7 +485,7 @@ begin
485485
end;
486486
end;
487487

488-
procedure TWebGraph.AddLink(pt, a, b: TPoint; typ: EGraphNode; handle: function (): Boolean); overload;
488+
procedure TWebGraph.AddLink(pt, a, b: TPoint; typ: EGraphNode; handle: function (): Boolean of object); overload;
489489
var
490490
i, j, n: Integer;
491491
tpa: TPointArray;
@@ -521,13 +521,14 @@ begin
521521
Self.Nodes[i] := TGraphNode.Create(pt, typ, @handle);
522522
end;
523523

524-
procedure TWebGraph.AddTeleport(pt: TPoint; handle: function (): Boolean);
524+
procedure TWebGraph.AddTeleport(pt: TPoint; handle: function (): Boolean of object);
525525
var
526526
i, j, n: Integer;
527527
tpa: TPointArray;
528528
begin
529529
i := Length(Self.Nodes);
530530
Self.Nodes += [pt, EGraphNode.TELEPORT, @handle];
531+
SetLength(Self.Paths, Length(Self.Nodes));
531532

532533
tpa := Self.Tree.KNearest(pt, 12);
533534
for j := 0 to High(tpa) do
@@ -556,6 +557,7 @@ var
556557
begin
557558
i := Length(Self.Nodes);
558559
Self.Nodes += [pt, EGraphNode.FAIRYRING, nil];
560+
SetLength(Self.Paths, Length(Self.Nodes));
559561

560562
tpa := Self.Tree.KNearest(pt, 8);
561563
for j := 0 to High(tpa) do
@@ -607,8 +609,10 @@ begin
607609

608610
img.DrawColor := $00EAEA;
609611
for i := 0 to High(Self.Paths) do
610-
for j := 0 to High(Self.Paths[i]) do
611-
img.DrawLine(Self.Nodes[i].Node, Self.Nodes[Self.Paths[i, j]].Node);
612+
if Self.Nodes[i].Typ <> EGraphNode.TELEPORT then
613+
for j := 0 to High(Self.Paths[i]) do
614+
if Self.Nodes[Self.Paths[i, j]].Typ <> EGraphNode.TELEPORT then
615+
img.DrawLine(Self.Nodes[i].Node, Self.Nodes[Self.Paths[i, j]].Node);
612616

613617
for i := 0 to High(Self.Nodes) do
614618
begin
@@ -631,11 +635,13 @@ begin
631635
if Self.Nodes = [] then Exit;
632636

633637
for i := 0 to High(Self.Paths) do
634-
for j := 0 to High(Self.Paths[i]) do
635-
begin
636-
if Self.Paths[i, j] > High(Self.Nodes) then Continue;
637-
canvas.DrawLine(Self.Nodes[i].Node, Self.Nodes[Self.Paths[i, j]].Node, $00EAEA);
638-
end;
638+
if Self.Nodes[i].Typ <> EGraphNode.TELEPORT then
639+
for j := 0 to High(Self.Paths[i]) do
640+
if Self.Nodes[Self.Paths[i, j]].Typ <> EGraphNode.TELEPORT then
641+
begin
642+
if Self.Paths[i, j] > High(Self.Nodes) then Continue;
643+
canvas.DrawLine(Self.Nodes[i].Node, Self.Nodes[Self.Paths[i, j]].Node, $00EAEA);
644+
end;
639645

640646
for i := 0 to High(Self.Nodes) do
641647
begin

0 commit comments

Comments
 (0)