-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBank.simba
1199 lines (1018 loc) · 27.4 KB
/
Bank.simba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{$include_once Internal/Reflection.simba}
{$include_once Constants.simba}
{$include_once Mainscreen.simba}
{$include_once Menu.simba}
{$include_once Inventory.simba}
{$include_once Mouse.simba}
{$include_once Timing.simba}
const
R_BANK_ITEM_SLOT_INDEX = 11;
VARBIT_CURRENT_BANK_TAB = 4150;
VARBIT_BANK_TAB_COUNT_1 = 4171;
VARBIT_BANK_TAB_COUNT_2 = 4172;
VARBIT_BANK_TAB_COUNT_3 = 4173;
VARBIT_BANK_TAB_COUNT_4 = 4174;
VARBIT_BANK_TAB_COUNT_5 = 4175;
VARBIT_BANK_TAB_COUNT_6 = 4176;
VARBIT_BANK_TAB_COUNT_7 = 4177;
VARBIT_BANK_TAB_COUNT_8 = 4178;
VARBIT_BANK_TAB_COUNT_9 = 4179;
type
TRSBankItem = record
ID: Int32;
Amount: Int32;
Slot: Int32;
Tab: Int32;
Name: String;
Bounds: TBox;
end;
TBankLocation = (
LUMBRIDGE,
DRAYNOR,
VARROCK_WEST,
VARROCK_EAST,
GRAND_EXCHANGE,
FALADOR_WEST,
FALADOR_EAST,
EDGEVILLE,
CAMELOT,
ARDOUGNE_NORTH,
ARDOUGNE_SOUTH,
AL_KHARID,
DUEL_ARENA,
CASTLE_WARS,
YANILLE,
PORT_KHAZARD,
BLAST_FURNACE,
WOODCUTTING_GUILD
);
{$scopedenums on}
type
TRSBankQuantity = (ONE, FIVE, TEN, X, ALL);
{$scopedenums off}
{*
R__GetBankTiles
~~~~~~~~~~~~~~~
Utility function that returns the tiles of the booths.
*}
Function R__GetBankTiles(Location: TBankLocation): TPointArray;
begin
case Location of
TBankLocation.LUMBRIDGE:
Result := [[3208, 3221], [3209, 3221]];
TBankLocation.DRAYNOR:
Result := [[3091, 3245], [3091, 3243], [3091, 3242]];
TBankLocation.VARROCK_WEST:
Result := [[3186, 3444], [3186, 3442], [3186, 3440], [3186, 3438], [3186, 3436]];
TBankLocation.VARROCK_EAST:
Result := [[3251, 3419], [3252, 3419], [3253, 3419], [3254, 3419], [3255, 3419], [3256, 3419]];
TBankLocation.GRAND_EXCHANGE:
Result := [[3162, 3490], [3162, 3489], [3167, 3489], [3167, 3490]];
TBankLocation.FALADOR_WEST:
Result := [[2945, 3367], [2946, 3367], [2947, 3367], [2948, 3367], [2949, 3367]];
TBankLocation.FALADOR_EAST:
Result := [[3015, 3354], [3014, 3354], [3013, 3354], [3012, 3354], [3011, 3354], [3010, 3354]];
TBankLocation.EDGEVILLE:
Result := [[3098, 3493], [3096, 3493], [3095, 3491], [3095, 3489]];
TBankLocation.CAMELOT:
Result := [[2721, 3494], [2722, 3494], [2724, 3494], [2727, 3494], [2728, 3494], [2729, 3494]];
TBankLocation.ARDOUGNE_NORTH:
Result := [[2619, 3331], [2618, 3331], [2615, 3331]];
TBankLocation.ARDOUGNE_SOUTH:
Result := [[2656, 3286], [2656, 3283], [2656, 3280]];
TBankLocation.AL_KHARID:
Result := [[3268, 3169], [3268, 3168], [3268, 3166], [3268, 3164]];
TBankLocation.DUEL_ARENA:
Result := [[3382, 3270], [3381, 3269]];
TBankLocation.CASTLE_WARS:
Result := [[2444, 3083]];
TBankLocation.YANILLE:
Result := [[2614, 3094], [2614, 3092], [2614, 3091]];
TBankLocation.PORT_KHAZARD:
Result := [[2661, 3163]];
TBankLocation.BLAST_FURNACE:
Result := [[1948, 4956]];
TBankLocation.WOODCUTTING_GUILD:
Result := [[1592, 3475]];
end;
end;
{*
R__GetBankIDs
~~~~~~~~~~~~~
Utility function that returns the IDs of the booths.
*}
Function R__GetBankIDs(Location: TBankLocation): TIntegerArray;
begin
case Location of
TBankLocation.LUMBRIDGE:
Result := [18491, 27291];
TBankLocation.VARROCK_WEST,
TBankLocation.VARROCK_EAST:
Result := [10583, 34810];
TBankLocation.GRAND_EXCHANGE:
Result := [10060, 30389];
TBankLocation.FALADOR_WEST,
TBankLocation.FALADOR_EAST:
Result := [24101, 27253];
TBankLocation.DRAYNOR,
TBankLocation.EDGEVILLE,
TBankLocation.AL_KHARID:
Result := [10355];
TBankLocation.CAMELOT:
Result := [25808, 27264];
TBankLocation.ARDOUGNE_NORTH,
TBankLocation.ARDOUGNE_SOUTH:
Result := [10355, 10356];
TBankLocation.DUEL_ARENA:
Result := [3194];
TBankLocation.CASTLE_WARS:
Result := [4483];
TBankLocation.YANILLE:
Result := [10356, 10355];
TBankLocation.PORT_KHAZARD,
TBankLocation.BLAST_FURNACE:
Result := [26707];
TBankLocation.WOODCUTTING_GUILD:
Result := [28861];
end;
end;
{*
R__GetBankType
~~~~~~~~~~~~~~
Utility function that returns the RSObjectType of the booth.
*}
Function R__GetBankType(Location: TBankLocation): RSObjectType;
begin
case Location of
TBankLocation.GRAND_EXCHANGE:
Result := BOUNDARY_OBJECT;
TBankLocation.LUMBRIDGE,
TBankLocation.DRAYNOR,
TBankLocation.CAMELOT,
TBankLocation.EDGEVILLE,
TBankLocation.AL_KHARID,
TBankLocation.DUEL_ARENA,
TBankLocation.CASTLE_WARS,
TBankLocation.PORT_KHAZARD,
TBankLocation.YANILLE,
TBankLocation.FALADOR_WEST,
TBankLocation.FALADOR_EAST,
TBankLocation.VARROCK_WEST,
TBankLocation.VARROCK_EAST,
TBankLocation.ARDOUGNE_NORTH,
TBankLocation.ARDOUGNE_SOUTH,
TBankLocation.ARDOUGNE_SOUTH,
TBankLocation.BLAST_FURNACE,
TBankLocation.WOODCUTTING_GUILD:
Result := GAME_OBJECT;
end;
end;
{*
R__GetBankUptext
~~~~~~~~~~~~~~~~
Utility function that returns the strings included in the name of the booth.
*}
Function R__GetBankUptext(Location: TBankLocation): Array of String;
begin
case Location of
TBankLocation.GRAND_EXCHANGE:
Result := ["Bank Grand Exchange booth"];
TBankLocation.LUMBRIDGE,
TBankLocation.DRAYNOR,
TBankLocation.CAMELOT,
TBankLocation.EDGEVILLE,
TBankLocation.AL_KHARID,
TBankLocation.YANILLE,
TBankLocation.FALADOR_WEST,
TBankLocation.FALADOR_EAST,
TBankLocation.VARROCK_WEST,
TBankLocation.VARROCK_EAST,
TBankLocation.ARDOUGNE_NORTH,
TBankLocation.ARDOUGNE_SOUTH:
Result := ["Bank Bank booth"];
TBankLocation.DUEL_ARENA:
Result := ["Bank Open chest"];
TBankLocation.CASTLE_WARS,
TBankLocation.PORT_KHAZARD,
TBankLocation.BLAST_FURNACE,
TBankLocation.WOODCUTTING_GUILD:
Result := ["Use Bank chest"];
end;
end;
{*
R_BankScreen
~~~~~~~~~~~~
Returns true if Bank Screen is open.
Example:
if R_BankScreen then
...
*}
Function R_BankScreen: Boolean;
begin
Result := RSWidget.IsValid(R_BANK_CONTAINER.Group, R_BANK_CONTAINER.Child);
end;
{*
R_WaitBankScreen
~~~~~~~~~~~~~~~~
Returns once Bank Screen is open, otherwise it waits for the timeout.
Example:
if R_WaitBankScreen(1000) then
...
*}
Function R_WaitBankScreen(timeout: UInt32): Boolean;
begin
Result := WaitUntil(R_Bankscreen, 50, timeout);
end;
{*
R_OpenBank
~~~~~~~~~~
Opens the specified bank by interacting with the booths. Returns true if Bank
Screen is open.
Example:
if R_OpenBank(EDGEVILLE) then
...
*}
Function R_OpenBank(Location: TBankLocation):boolean;
var
Me: RSPlayer;
I: Integer;
T: Timer;
Pnt: TPoint;
Box: TBox;
Booths, Bounds: TPointArray;
IDs: TIntegerArray;
BoothType: RSObjectType;
BoothUptext: Array of String;
Obj: RSObject;
begin
if (R_BankScreen) then
Exit(True);
Me := RSPlayer.Me;
Booths := R__GetBankTiles(Location);
IDs := R__GetBankIDs(Location);
BoothType := R__GetBankType(Location);
BoothUptext := R__GetBankUptext(Location);
Booths.Sort([Me.Tile.X, Me.Tile.Y]);
for I := 0 to High(Booths) do
begin
Obj := RSObject.Get(BoothType, Booths[I].X, Booths[I].Y);
if (IDs.Find(Obj.ID) <> -1) then
begin
Bounds := Obj.ClickArea;
Box := Bounds.MinAreaRect.Bounds;
while not SRL.PointInPoly(Pnt, Bounds) do
Pnt := TSRL.RandomPoint(Box);
if not R_MainscreenBounds.Contains(Pnt) then
Continue;
Mouse.Move(Pnt, 20, False);
if (R_WaitUpText(BoothUptext, False, randomRange(80, 214))) then
begin
Mouse.Click(MOUSE_LEFT);
if R_DidRedClick then
begin
T.Start;
While (Not R_Bankscreen) and (Not R_ClickToContinueIsOpen) and (T.ElapsedTime < 25000) do
wait(RandomRange(80, 176));
end;
end;
Obj.Free;
Exit(R_BankScreen);
end;
end;
end;
{*
R_PinScreen
~~~~~~~~~~~
Returns true if Pin Screen is open.
Example:
if R_PinScreen then
...
*}
Function R_PinScreen: Boolean;
begin
Result := RSWidget.IsValid(R_BANK_PIN_CONTAINER.Group, R_BANK_PIN_CONTAINER.Child);
end;
{*
R_WaitPinScreen
~~~~~~~~~~~~~~~
Returns once Pin Screen is open, otherwise it waits for the timeout.
Example:
if R_WaitPinScreen(1000) then
...
*}
Function R_WaitPinScreen(timeout: UInt32): Boolean;
begin
Result := WaitUntil(R_PinScreen, 50, timeout);
end;
{*
R_DepositBox
~~~~~~~~~~~~
Returns true if Deposit Screen is open.
Example:
if R_DepositBox then
...
*}
Function R_DepositBox: Boolean;
begin
Result := RSWidget.IsValid(R_DEPOSITBOX_CONTAINER.Group, R_DEPOSITBOX_CONTAINER.Child);
end;
{*
R_WaitDepositBox
~~~~~~~~~~~~~~~~
Returns once Deposit Screen is open, otherwise it waits for the timeout.
Example:
if R_WaitDepositBox(1000) then
...
*}
Function R_WaitDepositBox(timeout: UInt32): Boolean;
begin
Result := WaitUntil(R_DepositBox, 50, timeout);
end;
{*
R_CurrentBankTab
~~~~~~~~~~~~~~~~
Returns the current open bank tab.
Example:
if (R_CurrentBankTab <> 4) then
...
*}
Function R_CurrentBankTab: Int32;
begin
Result := RSClient.getVarbit(VARBIT_CURRENT_BANK_TAB);
end;
{*
R_BankTabCount
~~~~~~~~~~~~~~
Counts the number of items in a bank tab.
Example:
if (R_BankTabCount(4) < 10) then
...
*}
Function R_BankTabCount(Index: Int32): Int32;
var
TabVarbits: Array of Int32;
begin
if (Index < 0) or (Index > 8) then
Exit(-1);
TabVarbits := [VARBIT_BANK_TAB_COUNT_1, VARBIT_BANK_TAB_COUNT_2,
VARBIT_BANK_TAB_COUNT_3, VARBIT_BANK_TAB_COUNT_4,
VARBIT_BANK_TAB_COUNT_5, VARBIT_BANK_TAB_COUNT_6,
VARBIT_BANK_TAB_COUNT_7, VARBIT_BANK_TAB_COUNT_8,
VARBIT_BANK_TAB_COUNT_9];
Result := RSClient.getVarbit(TabVarbits[Index]);
end;
{*
R_BankSlotToTab
~~~~~~~~~~~~~~~
Returns the tab containing your global bank slot.
Example:
BankTab := R_BankSlotToTab(135)
*}
Function R_BankSlotToTab(Slot: Int32): Int32;
var
I: Int32;
TabCount, Total: Int32;
begin
Result := 0;
TabCount := 0;
for I := 0 to 8 do
begin
TabCount := R_BankTabCount(I);
if TabCount = 0 then
continue;
Total += TabCount;
if Slot < Total then
Exit(I + 1);
end;
end;
{*
R_BankSlotToTabSlot
~~~~~~~~~~~~~~~~~~~
Returns the tab slot containing your global bank slot.
Example:
BankTab := R_BankSlotToTabSlot(135)
*}
Function R_BankSlotToTabSlot(Slot: Int32): Int32;
var
I: Int32;
TabCount, Total: Int32;
begin
Result := 0;
TabCount := 0;
for I := 0 to 8 do
begin
TabCount := R_BankTabCount(I);
if TabCount = 0 then
continue;
Total += TabCount;
if Slot < Total then
begin
Exit(TabCount - (Total - Slot)); //Exit(0 - (Total - Slot - TabCount));
end;
end;
Result := Slot - Total;
end;
{*
R_SelectBankTab
~~~~~~~~~~~~~~~
Opens the specified bank tab.
Example:
R_SelectBankTab(4);
*}
Function R_SelectBankTab(Index: Int32): Boolean;
var
TabWidget: RSWidget;
T: Timer;
begin
if (Index < 0) or (Index > 8) then
Exit(False);
if not R_BankScreen then
Exit;
if R_CurrentBankTab = Index then
Exit(True);
TabWidget := RSWidget.Get(R_BANK_TAB_CONTAINER.Group, R_BANK_TAB_CONTAINER.Child, Index);
if TabWidget.ref = nil then
Exit(False);
Mouse.Click(TabWidget.Bounds, MOUSE_LEFT, True);
TabWidget.Free;
T.Start;
while R_CurrentBankTab <> Index do
begin
if T.ElapsedTime > 1000 then
Exit(False);
Wait(50, Random(50));
end;
Result := R_CurrentBankTab = Index;
end;
{*
R_BankSlotVisible
~~~~~~~~~~~~~~~~~
Returns true if the bank slot is visible on the screen.
Example:
R_BankSlotVisible(40);
*}
Function R_BankSlotVisible(Index: Int32): Boolean;
var
TabContainer: RSWidget;
TabWidget: RSWidget;
BankBounds: TBox;
begin
if not R_BankScreen then
Exit(False);
TabContainer := RSWidget.Get(R_BANK_ITEM_CONTAINER.Group, R_BANK_ITEM_CONTAINER.Child);
if TabContainer.ref = nil then
Exit(False);
TabWidget := TabContainer.Child(Index);
if TabWidget.ref = nil then
begin
TabContainer.Free;
Exit(False);
end;
BankBounds := TabContainer.Bounds;
TabContainer.Free;
Result := BankBounds.Contains(TabWidget.Bounds);
TabWidget.Free;
end;
{*
R_BankSlotToBox
~~~~~~~~~~~~~~~
Returns the mainscreen bounds of the bank slot.
Example:
R_BankSlotToBox(40);
*}
Function R_BankSlotToBox(Index: Int32): TBox;
var
ItemContainer: RSWidget;
begin
if not R_BankScreen then
Exit(Box(-1, -1, -1, -1));
ItemContainer := RSWidget.Get(R_BANK_ITEM_CONTAINER.Group, R_BANK_ITEM_CONTAINER.Child, Index);
if ItemContainer.ref = nil then
Exit(Box(-1, -1, -1, -1));
Result := ItemContainer.Bounds;
ItemContainer.Free;
end;
{*
R_ScrollToBankSlot
~~~~~~~~~~~~~~~~~~
Scrolls to the specified bank slot if it is not on screen.
Possible scroll methods:
- RSScroll.SCROLLWHEEL: Emulates the mouse scroll wheel.
- RSScroll.SCROLLBAR: Drags the scroll bar to the desired location.
- RSScroll.SCROLLARROWS: Uses the up/down arrows.
Example:
R_ScrollToBankSlot(40, RSScroll.SCROLLWHEEL);
*}
Function R_ScrollToBankSlot(Index: Int32; ScrollType: RSScroll = RSScroll.SCROLLWHEEL): Boolean;
var
ScrollBar, ScrollArrow, ItemContainer: RSWidget;
ItemContainerBounds: TBox;
T: Timer;
Down: Boolean;
P: TPoint;
begin
ItemContainer := RSWidget.Get(R_BANK_CONTENT_CONTAINER.Group, R_BANK_CONTENT_CONTAINER.Child);
if ItemContainer.ref = nil then
Exit(False);
ItemContainerBounds := ItemContainer.Bounds;
ItemContainer.Free;
if ItemContainerBounds.Contains(R_BankSlotToBox(Index)) then
Exit(True);
//Gain focus on the interface
Down := ItemContainerBounds.Middle.Y < R_BankSlotToBox(Index).Middle.Y;
//Scroll the interface using the mouse-wheel
if ScrollType = RSScroll.SCROLLWHEEL then
begin
Mouse.Move(ItemContainerBounds, True);
T.Start;
while not ItemContainerBounds.Contains(R_BankSlotToBox(Index)) do
begin
if T.ElapsedTime > 5000 then
Exit(False);
Mouse.Scroll(3, Down);
end;
Exit(ItemContainerBounds.Contains(R_BankSlotToBox(Index).Middle));
end;
//Scroll the interface using the scroll-bar
if ScrollType = RSScroll.SCROLLBAR then
begin
ScrollBar := RSWidget.Get(R_BANK_SCROLLBAR_BAR.Group, R_BANK_SCROLLBAR_BAR.Child, R_BANK_SCROLLBAR_BAR.Index);
if ScrollBar.ref = nil then
Exit(False);
Mouse.Move(ScrollBar.Bounds, True);
Mouse.Click(MOUSE_LEFT);
Mouse.Hold(MOUSE_LEFT);
ScrollBar.Free;
T.Start;
while not ItemContainerBounds.Contains(R_BankSlotToBox(Index)) do
begin
if T.ElapsedTime > 5000 then
begin
Mouse.Release(MOUSE_LEFT);
Exit(False);
end;
P := Mouse.Position;
if Down then
begin
Mouse.Move(P.X + RandomRange(-3, 3), P.Y + RandomRange(5, 10));
end else
begin
Mouse.Move(P.X + RandomRange(-3, 3), P.Y - RandomRange(5, 10));
end;
end;
Mouse.Release(MOUSE_LEFT);
Exit(ItemContainerBounds.Contains(R_BankSlotToBox(Index).Middle));
end;
//Scroll the interface using the arrows
if ScrollType = RSScroll.SCROLLARROWS then
begin
if Down then
ScrollArrow := RSWidget.Get(R_BANK_SCROLLBAR_BAR_DOWN.Group, R_BANK_SCROLLBAR_BAR_DOWN.Child, R_BANK_SCROLLBAR_BAR_DOWN.Index)
else
ScrollArrow := RSWidget.Get(R_BANK_SCROLLBAR_BAR_UP.Group, R_BANK_SCROLLBAR_BAR_UP.Child, R_BANK_SCROLLBAR_BAR_UP.Index);
if ScrollArrow.ref = nil then
Exit(False);
Mouse.Move(ScrollArrow.Bounds, True);
Mouse.Click(MOUSE_LEFT);
Mouse.Hold(MOUSE_LEFT);
ScrollArrow.Free;
T.Start;
while not ItemContainerBounds.Contains(R_BankSlotToBox(Index)) do
begin
//It can take a long time to get from slot 0 to 800 (worst case) with the scroll arrows!
//Ideally, we should calculate the distance from the current slot to the target slot
//and determine how much time is necessary to get there based on scroll velocity..
if T.ElapsedTime > 30000 then
begin
Mouse.Release(MOUSE_LEFT);
Exit(False);
end;
end;
Mouse.Release(MOUSE_LEFT);
Exit(ItemContainerBounds.Contains(R_BankSlotToBox(Index).Middle));
end;
end;
{*
R_GetAllBankItems
~~~~~~~~~~~~~~~~~
Returns an array of all the items in your bank.
Example:
Writeln(R_GetAllBankItems);
*}
Function R_GetAllBankItems: Array of TRSBankItem;
var
BankItemContainer, Child: RSWidget;
ItemNodeCache: RSHashTable;
ItemNode: RSItemNode;
ItemIDs, ItemQuantities: Array of Int32;
I, J: Int32;
Garbage: RSTypeArray;
begin
if not R_BankScreen then
Exit;
BankItemContainer := RSWidget.Get(R_BANK_ITEM_CONTAINER.Group, R_BANK_ITEM_CONTAINER.Child);
if BankItemContainer.ref = nil then
Exit;
Garbage += BankItemContainer;
ItemNodeCache := RSClient.ItemNodeCache;
if ItemNodeCache.ref <> nil then
begin
Garbage += ItemNodeCache;
ItemNode.ref := ItemNodeCache.GetObject(R_BANK_ITEM_CONTAINER_ID).ref;
if ItemNode.ref <> nil then
begin
Garbage += ItemNode;
ItemIDs := ItemNode.ItemIDs;
ItemQuantities := ItemNode.ItemQuantities;
SetLength(Result, Length(ItemIDs));
for I := 0 to high(ItemIDs) do
begin
Child := BankItemContainer.Child(I);
if Child.ref <> nil then
begin
Garbage += Child;
Result[J].ID := ItemIDs[I];
Result[J].Amount := ItemQuantities[I];
Result[J].Slot := I;
Result[J].Tab := R_BankSlotToTab(I);
Result[J].Name := Child.Name;
Result[J].Bounds := Child.Bounds;
Inc(J);
end;
end;
end;
end;
SetLength(Result, J);
Garbage.Free;
end;
{*
R_FindBankItem
~~~~~~~~~~~~~~
Locates and returns information about the specified item in the bank.
Example:
Writeln(R_FindBankItem(123).Name);
*}
Function R_FindBankItem(ID: Int32): TRSBankItem;
var
BankItemContainer, Child: RSWidget;
ItemNodeCache: RSHashTable;
ItemNode: RSItemNode;
ItemIDs, ItemQuantities: Array of Int32;
I: Int32;
Garbage: RSTypeArray;
begin
Result.ID := -1;
Result.Amount := -1;
Result.Slot := -1;
Result.Tab := -1;
if not R_BankScreen then
Exit;
BankItemContainer := RSWidget.Get(R_BANK_ITEM_CONTAINER.Group, R_BANK_ITEM_CONTAINER.Child);
if BankItemContainer.ref = nil then
Exit;
Garbage += BankItemContainer;
ItemNodeCache := RSClient.ItemNodeCache;
if ItemNodeCache.ref <> nil then
begin
Garbage += ItemNodeCache;
ItemNode.ref := ItemNodeCache.GetObject(R_BANK_ITEM_CONTAINER_ID).ref;
if ItemNode.ref <> nil then
begin
Garbage += ItemNode;
ItemIDs := ItemNode.ItemIDs;
ItemQuantities := ItemNode.ItemQuantities;
for I := 0 to high(ItemIDs) do
begin
if ItemIDs[I] = ID then
begin
Child := BankItemContainer.Child(I);
if Child.ref <> nil then
begin
Garbage += Child;
Result.ID := ItemIDs[I];
Result.Amount := ItemQuantities[I];
Result.Slot := I;
Result.Tab := R_BankSlotToTab(I);
Result.Name := Child.Name;
Result.Bounds := Child.Bounds;
break;
end;
end;
end;
end;
end;
Garbage.Free;
end;
{*
R_DepositAllItems
~~~~~~~~~~~~~~~~~
Returns true if successfully deposited all inventory items.
Example:
R_DepositAllItems;
*}
Function R_DepositAllItems: Boolean;
var
Widget: RSWidget;
begin
if not R_BankScreen then
Exit;
Widget := RSWidget.Get(R_BANK_DEPOSIT_INVENTORY_ICON.Group, R_BANK_DEPOSIT_INVENTORY_ICON.Child);
if Widget.ref = nil then
Exit(False);
Mouse.Move(Widget.Bounds);
Wait(50 + RandomRange(0, 50));
Mouse.Click(MOUSE_LEFT);
Widget.Free;
Result := R_InventoryCount = 0;
end;
{*
R_DepositAllEquipment
~~~~~~~~~~~~~~~~~~~~~
Returns true if successfully deposited all equipment items.
Example:
R_DepositAllEquipment;
*}
Function R_DepositAllEquipment: Boolean;
var
Widget: RSWidget;
begin
if not R_BankScreen then
Exit;
Widget := RSWidget.Get(R_BANK_DEPOSIT_EQUIPMENT_ICON.Group, R_BANK_DEPOSIT_EQUIPMENT_ICON.Child);
if Widget.ref = nil then
Exit(False);
Mouse.Move(Widget.Bounds);
Wait(50 + RandomRange(0, 50));
Mouse.Click(MOUSE_LEFT);
Widget.Free;
Result := True;
end;
{*
R_DepositSlot
~~~~~~~~~~~~~
Returns true if deposited specified inventory slot. Accepts any amount to
deposit. Amount = 0: Deposit all items.
Example:
R_DepositSlot(12, 0);
*}
Function R_DepositSlot(Index: Int32; Amount: Int32 = 1): Boolean;
var
Item: TRSInventoryItem;
InputFull: RSWidget;
Retries: Int32;
begin
if not R_BankScreen then
Exit(False);
Item := R_GetInventorySlotItem(Index);
if Item.ID = -1 then
Exit(False);
if Amount = 0 then
begin
Mouse.Move(Item.Bounds);
if R_WaitUptext(['Deposit-All'], True, RandomRange(500, 800)) then
begin
Mouse.Click(Item.Bounds, MOUSE_LEFT);
Exit(True);
end else begin
Mouse.Click(Item.Bounds, MOUSE_RIGHT);
Wait(50 + RandomRange(50, 100));
Exit(R_ChooseOptions(['Deposit-All']));
end;
end;
Mouse.Move(Item.Bounds);
Wait(50 + RandomRange(50, 100));
if R_WaitUptext(['Deposit-' + IntToStr(Amount)], True, RandomRange(200, 300)) then
begin
Mouse.Click(Item.Bounds, MOUSE_LEFT);
Exit(True);
end;
Mouse.Click(Item.Bounds, MOUSE_RIGHT);
Wait(50 + RandomRange(50, 100));
if R_ChooseOptions(['Deposit-' + IntToStr(Amount)]) then
Exit(True);
if R_ChooseOptions(['Deposit-X']) then
begin
InputFull := RSWidget.Get(R_CHATBOX_INPUT_FULL.Group, R_CHATBOX_INPUT_FULL.Child);
if InputFull.ref = nil then
Exit(False);
while Retries < 3 do
begin
if InputFull.Text <> '*' then
begin
Keyboard.KeyDown(VK_BACK);
while InputFull.Text <> '*' do
Wait(50 + RandomRange(50, 100));
Keyboard.KeyUp(VK_BACK);
end;
Keyboard.Send(IntToStr(Amount));
Result := InputFull.Text = IntToStr(Amount) + '*';
if Result then
begin
Keyboard.PressKey(VK_ENTER);
Exit(True);
end;
Inc(Retries);
end;
end;
end;
{*
R_DepositItem
~~~~~~~~~~~~~
Returns true if deposited specified inventory item into bank.
Amount = 0: Deposit all items.
Example:
R_DepositItem(5442, 0);
*}
Function R_DepositItem(ID: Int32; Amount: Int32 = 1; RandomObject: Boolean = False): Boolean;
var
Items: Array of TRSInventoryItem;
begin
if not R_BankScreen then
Exit(False);
Items := R_GetInventoryItem(ID);
if Length(Items) < 1 then
Exit(False);
if RandomObject then
R_DepositSlot(Items[Random(0, High(Items))].Slot, Amount)
else R_DepositSlot(Items[0].Slot, Amount);
end;
{*
R_WithdrawItem
~~~~~~~~~~~~~~
Returns true if withdrawed specified bank item into inventory.
Example:
R_WithdrawItem(5442, 12);
*}