-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathItem Database.simba
1155 lines (912 loc) · 27.1 KB
/
Item Database.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
{$i SRL/SRL.simba}
{*******************************************************************************
R_BOSS Remote Based Objest Search System
by: Home, Hobbit, Kyle Undefined, Zyt3x and BraK also known as Dev Team 6
Description: System that automatically identifies and finds object in the
inventory and bank
*******************************************************************************}
{ TODO
- Check Hue/Sat
}
{//////////////////////////////////////////////////////////////////////////////}
{/// IMPORTANT REMINDER IMPORTANT ///}
{//////////////////////////////////////////////////////////////////////////////}
{/// *Don't put finding functions after the Main finder it has to be last. ///}
{/// *Edit the Main finder with your separate Find functions. ///}
{/// *Don't forget to add Docs to your created functions Explaining them. ///}
{//////////////////////////////////////////////////////////////////////////////}
type
TGEItem = record
ID, Price : Integer;
Name : string;
BMP : Integer;
BlackCount : Integer;
AverageColor : Integer;
CommonColors :TIntegerArray;
BestColor : Integer;
Tolerance : Integer;
Hue : Extended;
Sat : Extended;
BestColorCount : Integer;
end;
var
TItemArray : Array of TGEItem;
//Temp function til simba gets the bug fixed.
function FixedSumIntegerArray(const Ints : TIntegerArray): Int64;
var
I, H: Integer;
begin
Result := 0;
H := High(Ints);
for I := 0 to H do
Result := Result + Ints[I];
end;
//Temp function til simba gets the bug fixed.
function FixedAverageTIA(const tI : TIntegerArray): Int64;
begin
try Result := (FixedSumIntegerArray(tI) div Length(tI)); except Result := 0; end;
end;
(*
CommonColorsBMP
~~~~~~~~~~~~~~~
.. code-block:: pascal
function GetColorsBMP(BMP : Integer; BadColors : TIntegerArray) : TIntegerArray;
Takes 3 best colors for given BMP.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
CommonColors := GetColorsBMP(BMP, [2171169, 526344, 460551, 0]);
*)
function GetColorsBMP(BMP : Integer; BadColors : TIntegerArray) : TIntegerArray;
var
W, H, I, J, C : Integer;
ColArr, CountArr : TIntegerArray;
begin
GetBitmapSize(BMP, W, H);
ColArr := GetColorsBox(0, 0, W-1, H-1, True);
ClearSameIntegers(ColArr);
for I := High(ColArr) downto 0 do
if InIntArray(BadColors, ColArr[I]) then
DeleteValueInIntArray(ColArr, I);
SetLength(CountArr, Length(ColArr));
for I := High(CountArr) downto 0 do
CountArr[I] := CountColor(ColArr[I], 0, 0, W-1, H-1);
QuickSort(CountArr);
InvertTIA(CountArr);
SetLength(Result, Length(ColArr));
for I := High(ColArr) downto 0 do
for J := High(CountArr) downto 0 do
if CountColor(ColArr[I], 0, 0, W-1, H-1) = CountArr[J] then
begin
Result[C] := ColArr[I];
Inc(C);
DeleteValueInIntArray(CountArr, J);
Break;
end;
SetLength(Result, 3);
end;
(*
ModifyColors
~~~~~~~~~~~~
.. code-block:: pascal
procedure ModifyColors(Colors : TIntegerArray; var Color, Tol : Integer; var Hue, Sat : Extended);
Takes an array of colors and returns the CTS2 Information.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
ModifyColors(CommonColors, BestColor, Tolerance, Hue, Sat);
*)
procedure ModifyColors(Colors : TIntegerArray; var Color, Tol : Integer; var Hue, Sat : Extended);
var
I,II : integer;
HSLColor : Array[1..3] of Extended;
HSL : Array[0..1] of Array[1..3] of Extended;
begin
for I := 1 to 3 do
HSL[0][i] := 255;
for I := 0 to High(Colors) do
begin;
ColortoHSL(Colors[i],HSLColor[1],HSLColor[2],HSLColor[3]);
for II := 1 to 3 do
begin
HSL[0][II] := MinE(HSLColor[II],HSL[0][II]);
HSL[1][II] := MaxE(HSLColor[II],HSL[1][II]);
end;
Color := HSLToColor((HSL[1][1] + HSL[0][1]) div 2,(HSL[1][2] + HSL[0][2]) div 2,(HSL[1][3] + HSL[0][3]) div 2);
Tol := Ceil((HSL[1][3])) - Ceil((HSL[1][3] + HSL[0][3]) div 2) + 2;
try
Hue := (HSL[1][1] - HSL[0][1]) / (HSL[1][3] - HSL[0][3]);
except end;
try
Sat := (HSL[1][2] - HSL[0][2]) / (HSL[1][3] - HSL[0][3]);
except end;
end;
end;
(*
CashStringToInt
~~~~~~~~~~~~~~~
.. code-block:: pascal
function CashStringToInt(S : string) : Integer;
Takes a string amount, and returns the Integer equivalent.
.. note::
Author: TomTuff
Last Modified: Unknown
Example:
.. code-block:: pascal
Price := CashStringToInt(Between('<td>', '<', Between('Current guide price', '/td>', S)));
*)
function CashStringToInt(S : string) : Integer;
var
i, ii : Integer;
Numbs : TStringArray;
Temp : string;
begin
Temp := '';
Numbs := ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'k', 'm', 'b'];
for i := 1 to High(S) do
for ii := 0 to High(Numbs) do
if(S[i] = Numbs[ii])then
case ii of
0..9: Temp := Temp + Numbs[ii];
10..12:
begin
Result := StrToInt(Temp);
case ii of
10: Result := Result * 100; //Since price is given to 1 decimal,
11: Result := Result * 100000; //instead of multiplying by the entire
12: Result := Result * 100000000; //factor, you must multiply by factor/10
end;
end;
end;
if(Result = 0)then
try
Result := StrToInt(Temp);
except end;
end;
(*
DownloadFile
~~~~~~~~~~~~
.. code-block:: pascal
function DownloadFile(FileLink, Path : string) : Boolean;
Downloads a file to a specified path.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
if DownloadFile('http://services.runescape.com/m=itemdb_rs/g=runescape/obj_sprite.gif?id=' + ToStr(itemID), AppPath + 'Includes\DB\' + ToStr(itemID) + '.gif') then
*)
function DownloadFile(FileLink, Path : string) : Boolean;
var
PageString: string;
iFile: Integer;
begin
Result := False;
try
PageString := GetPage(FileLink);
if(PageString = '')then Exit;
iFile := RewriteFile(Path, False);
Result := WriteFileString(iFile, PageString);
CloseFile(iFile);
except
end;
end;
(*
GEItemExists
~~~~~~~~~~~~
.. code-block:: pascal
function GEItemExists(itemID : Integer) : Boolean;
Checks the local item DB to see if the item being requested exists.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
if(GEItemExists(itemID))then
*)
function GEItemExists(itemID : Integer) : Boolean;
begin
Result := FileExists(AppPath + 'Includes\db\' + ToStr(itemID) + '.ini');
end;
(*
ReadGEItemINI
~~~~~~~~~~~~~
.. code-block:: pascal
function ReadGEItemINI(itemID : Integer) : TGEItem;
Reads the items .INI file and returns a TGEItem record.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
Result := ReadGEItemINI(itemID);
*)
function ReadGEItemINI(itemID : Integer) : TGEItem;
var
I : Integer;
Path : string;
begin
if(not(GEItemExists(itemID)))then Exit;
SetArrayLength(result.CommonColors, 3);
Path := AppPath + 'Includes/db/' + ToStr(itemID) + '.ini';
try
Result.ID := StrToIntDef(ReadINI(ToStr(itemID), 'ID', Path), -1);
Result.Price := StrToIntDef(ReadINI(ToStr(itemID), 'Price', Path), -1);
Result.Name := ReadINI(ToStr(itemID), 'Name', Path);
Result.BMP := BitmapFromString(32, 32, ReadINI(ToStr(itemID), 'BMP', Path));
Result.BlackCount := StrToIntDef(ReadINI(ToStr(itemID), 'BlackCount', Path), -1);
Result.AverageColor := StrToIntDef(ReadINI(ToStr(itemID), 'AverageColor', Path), -1);
for I := 0 to 2 do
Result.CommonColors[i] := StrToIntDef(ReadINI(ToStr(itemID), 'CommonColors' + Inttostr(i), Path), -1);
Result.BestColor := StrToIntDef(ReadINI(ToStr(itemID), 'BestColor', Path), -1);
Result.Tolerance := StrToIntDef(ReadINI(ToStr(itemID), 'Tolerance', Path), -1);
Result.Hue := StrToFloatDef(ReadINI(ToStr(itemID), 'Hue', Path), -1);
Result.Sat := StrToFloatDef(ReadINI(ToStr(itemID), 'Sat', Path), -1);
Result.BestColorCount := StrToIntDef(ReadINI(ToStr(itemID), 'BestColorCount', Path), -1);
except
end;
end;
(*
WriteGEItemINI
~~~~~~~~~~~~~~
.. code-block:: pascal
procedure WriteGEItemINI(Item : TGEItem);
Writes a .INI file for the TGEItem that is passed in.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
WriteGEItemINI(Result);
*)
procedure WriteGEItemINI(Item : TGEItem);
var
I : Integer;
Path : string;
begin
if(not(DirectoryExists(AppPath + 'Includes\DB')))then
CreateDirectory(AppPath + 'Includes\DB');
Path := AppPath + 'Includes\DB\' + ToStr(Item.ID) + '.ini';
try
with Item do
begin
WriteINI(ToStr(ID), 'ID', ToStr(ID), Path);
WriteINI(ToStr(ID), 'Price', ToStr(Price), Path);
WriteINI(ToStr(ID), 'Name', Name, Path);
WriteINI(ToStr(ID), 'BMP', CreateBitmapString(BMP), Path);
if Item.BlackCount > 0 then
WriteINI(ToStr(ID), 'BlackCount', ToStr(BlackCount), Path);
WriteINI(ToStr(ID), 'AverageColor', ToStr(AverageColor), Path);
for I := 0 to 2 do
WriteINI(ToStr(ID), 'CommonColors' + inttostr(i), ToStr(CommonColors[i]), Path);
WriteINI(ToStr(ID), 'BestColor', ToStr(BestColor), Path);
WriteINI(ToStr(ID), 'Tolerance', ToStr(Tolerance), Path);
WriteINI(ToStr(ID), 'Hue', ToStr(Hue), Path);
WriteINI(ToStr(ID), 'Sat', ToStr(Sat), Path);
WriteINI(ToStr(ID), 'BestColorCount', ToStr(BestColorCount), Path);
end;
except
end;
end;
(*
GetGEItemBMPFromID
~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function GetGEItemBMPFromID(itemID : Integer) : Integer;
Retrieves the .gif image from the GE. Exits if it fails to get a proper Image.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
BMP := GetGEItemBMPFromID(itemID);
*)
function GetGEItemBMPFromID(itemID : Integer) : Integer;
var
I, J, W, H, BMP : Integer;
TPA : TPointArray;
Target : Integer;
FilterColors, FilterColorsTo : TIntegerArray;
begin
// URL to .gif of the item from runescape's GE
if DownloadFile('http://services.runescape.com/m=itemdb_rs/g=runescape/obj_sprite.gif?id=' + ToStr(itemID), AppPath + 'Includes\DB\' + ToStr(itemID) + '.gif') then
begin
Debugln('Bitmap #' + IntToStr(BMP));
Target := GetImageTarget;
BMP := LoadBitmap(AppPath + 'Includes\DB\' + ToStr(itemID) + '.gif');
SetTargetBitmap(BMP);
GetBitmapSize(BMP, W, H);
FilterColors := [2171169, 526344, 460551];
FilterColorsTo := [0, srl_outline_black, srl_outline_black];
for I := High(FilterColors) downto 0 do
if(FindColors(TPA, FilterColors[I], 0, 0, W - 1, H - 1))then
for J := 0 to High(TPA) do
FastSetPixel(BMP, TPA[J].X, TPA[J].Y, FilterColorsTo[I]);
Result := BitmapFromClient(0, 0, W-1, H-1);
FreeTarget(GetImageTarget);
FreeBitmap(BMP);
SetImageTarget(Target);
end;
end;
(*
CreateGEItemFromIDEx
~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function CreateGEItemFromIDEx(itemID : Integer; force : Boolean) : TGEItem;
Creates an TGEItem for the ID that is passed in. if force is set to True, the
current .gif image and .INI files will be rewriten.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
Result := CreateGEItemFromIDEx(itemID, False);
*)
function CreateGEItemFromIDEx(itemID : Integer; force : Boolean) : TGEItem;
var
S : string;
TmpCTS, Target, W, H, I : Integer;
BoxTPA, TPA : TPointArray;
FilterColors : TIntegerArray;
begin
if(GEItemExists(itemID) and (not(force)))then
begin
Result := ReadGEItemINI(itemID);
Exit;
end;
// URL to the item from runescape's GE
S := GetPage('http://services.runescape.com/m=itemdb_rs/g=runescape/viewitem.ws?obj=' + ToStr(itemID));
with Result do
begin
ID := itemID;
Name := Replace(Between('<h5>', '</h5>', S), #10, '');
Price := CashStringToInt(Between('<td>', '<', Between('Current guide price', '/td>', S)));
BMP := GetGEItemBMPFromID(itemID);
Target := GetImageTarget;
SetTargetBitmap(BMP);
GetBitmapSize(BMP, W, H);
FilterColors := [0, 2171169];
BoxTPA := TPAFromBox(IntToBox(0, 0, W-1, H-1));
for I := High(FilterColors) downto 0 do
if(FindColors(TPA, FilterColors[I], 0, 0, W-1, H-1))then
BoxTPA := ClearTPAFromTPA(BoxTPA, TPA);
AverageColor := FixedAverageTIA(GetColors(BoxTPA)); // Added as a temp fix till simba gets it fixed
CommonColors := GetColorsBMP(BMP, [2171169, 526344, 460551, 0]);
ModifyColors(CommonColors, BestColor, Tolerance, Hue, Sat);
TmpCTS := GetColorToleranceSpeed
SetColorToleranceSpeed(2);
SetColorspeed2Modifiers(Hue, Sat);
FindColorsTolerance(TPA, BestColor, 0, 0, W - 1, H - 1, Tolerance);
BestColorCount := Length(TPA);
FreeTarget(GetImageTarget);
SetImageTarget(Target);
end;
WriteGEItemINI(Result);
end;
(*
CreateGEItemFromID
~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function CreateGEItemFromID(itemID : Integer) : TGEItem;
Creates an TGEItem for the ID passed in, and disables force.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
item[i] := CreateGEItemFromID(IDArray[I]);
*)
function CreateGEItemFromID(itemID : Integer) : TGEItem;
begin
Result := CreateGEItemFromIDEx(itemID, False);
end;
(*
LoadGEItemFromID
~~~~~~~~~~~~~~~~
.. code-block:: pascal
function LoadGEItemFromID(itemID : Integer) : TGEItem;
Loads an TGEItem record from the local DB of items.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
Item := LoadGEItemFromID(itemID);
*)
function LoadGEItemFromID(itemID : Integer) : TGEItem;
begin
if(GEItemExists(itemID))then
Result := ReadGEItemINI(itemID)
end;
(*
FindItemBMP
~~~~~~~~~~~
.. code-block:: pascal
function FindItemBMP(var X, Y : Integer; ItemBMP : Integer; Inv : Boolean) : Boolean;
Searches for the item and sets the X, Y variables to the coordinates if found.
Use True to search the Inventory and False to search the Bank.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
Result := FindItemBMP(X, Y, Item.BMP, Inv);
*)
function FindItemBMP(var X, Y : Integer; ItemBMP : Integer; Inv : Boolean) : Boolean;
var
Acc : Extended;
TB : TBox;
P : TPoint;
begin
if Inv then
TB := IntToBox(MIX1, MIY1, MIX2, MIY2)
else
TB := IntToBox(MBX1, MBY1, MBX2, MBY2);
if(FindDeformedBitmapToleranceIn(ItemBMP, P.X, P.Y, TB.X1, TB.Y1, TB.X2, TB.Y2, 25, 0, True, Acc))then
if(Acc > 0.80)then
begin
Result := True;
FreeBitmap(ItemBMP);
P := ItemCoords(CoordsToItem(P.X, P.Y));
X := P.X; Y := P.Y;
DebugLn('Item found using Bitmaps.');
Exit;
end;
end;
(*
GetItemBL
~~~~~~~~~
.. code-block:: pascal
function GetItemBL(var Box : TBox) : Integer;
Gets the Blacklist count for the specified TBox.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
Result := GetItemBL(TB);
*)
function GetItemBL(var Box : TBox) : Integer;
begin
Result := CountColor(131072, Box.X1, Box.Y1 + 17, Box.X2, Box.Y2);
end;
(*
FindItemBL
~~~~~~~~~~
.. code-block:: pascal
function FindItemBL(Var X, Y : Integer; Count : Integer; Inv : Boolean) : Boolean;
Searches the screen for the item with the correct BL count and returns the x, y
coordinates of the Item. Use True to search the Inventory and False to search the Bank.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
Result := FindItemBL(X, Y, Item.BlackCount, Inv);
*)
function FindItemBL(Var X, Y : Integer; Count : Integer; Inv : Boolean) : Boolean;
var
I, NumberSlots : Integer;
TB : TBox;
P : TPoint;
begin
if Inv then
NumberSlots := 28
else
NumberSlots := 50;
for I := 1 to NumberSlots do
begin
if Inv then
TB := InvBox(I)
else
TB := BankIndexToMSBox(I);
if Count = GetItemBL(TB) then
begin
Result := True;
P := MiddleTPA(TPAFromBox(TB));
X := P.X; Y := P.Y;
DebugLn('Item found using Black List.');
Break;
end;
end;
end;
(*
GetBLFromPoint
~~~~~~~~~~~~~~
.. code-block:: pascal
function GetBLFromPoint(x, y : Integer) : Integer;
Finds the Slot for X, Y coordinates if found. It outputs the blacklist data for the Item.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
Item.BlackCount := GetBLFromPoint(x, y);
*)
function GetBLFromPoint(x, y : Integer) : Integer;
var
I : Integer;
TB : TBox;
begin
if PointInBox(Point(x, y), IntToBox(MIX1, MIY1, MIX2, MIY2)) then
begin
for I := 1 to 28 do
if PointInBox(Point(x, y), InvBox(i)) then
begin
TB := InvBox(i);
Result := GetItemBL(TB);
Break;
end;
end else
for I := 1 to 50 do
if PointInBox(Point(x, y), IntToBox(MBX1, MBY1, MBX2, MBY2)) then
begin
TB := BankIndexToMSBox(i);
Result := GetItemBL(TB);
Break;
end;
end;
(*
SortTIAFrom
~~~~~~~~~~~
.. code-block:: pascal
function SortTIAFrom(TIA : TIntegerArray; From : Integer) : TIntegerArray;
Sorts a color array to the closest color.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
CloseCountArr := SortTIAFrom(CountArr, Item.BestColorCount);
*)
function SortTIAFrom(TIA : TIntegerArray; From : Integer) : TIntegerArray;
var
TPA : TPointArray;
Hi, I : Integer;
begin
Hi := Length(TIA);
for I := 0 to Hi - 1 do
begin
SetLength(TPA, I + 1);
TPA[I].X := 0;
TPA[I].Y := TIA[I];
end;
SortTPAFrom(TPA, Point(0, From));
for I := 0 to Hi - 1 do
TIA[I] := TPA[I].Y;
Result := TIA;
end;
(*
GetBankScrollPos
~~~~~~~~~~~~~~~~
.. code-block:: pascal
function GetBankScrollPos : Integer;
Gets the position of the bank scroll bar.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
if (GetBankScrollPos = 1) then
*)
function GetBankScrollPos : Integer;
var
cts : Integer;
begin
Result := 1;
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
if SimilarColors(GetColor(490, 104), 4610402, 3) or SimilarColors(GetColor(490, 104), 2830904, 3) then
Result := 0
else if SimilarColors(GetColor(490, 274), 3951700, 3) then
Result := 2;
ColorToleranceSpeed(cts);
end;
(*
SetBankScrollPos
~~~~~~~~~~~~~~~~
.. code-block:: pascal
procedure SetBankScrollPos(Top : Boolean);
Sets the position of the bank scroll bar.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
SetBankScrollPos(True);
*)
procedure SetBankScrollPos(Top : Boolean);
begin
if Top and (GetBankScrollPos <> 0) then
Mouse(482, 104, 12, 6, True)
else if (not Top) and (GetBankScrollPos <> 2) then
Mouse(482, 266, 12, 6, True)
else
Exit;
Wait(750 + Random(200));
end;
(*
BankBox
~~~~~~~
.. code-block:: pascal
function BankBox(Index : Integer): TBox;
Returns the box coords of a given bank slot.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
TB := BankBox(i);
*)
function BankBox(Index : Integer): TBox;
begin
with Result do
begin
if (GetBankScrollPos = 1) then
SetBankScrollPos(True);
case GetBankScrollPos of
0: Y1 := 92;
1: Exit;
2: Y1 := 116;
end;
X1 := 38 + (((Index - 1) mod 10) * 44);
Y1 := Y1 + (((Index - 1) div 10) * 44);
X2 := X1 + 35;
Y2 := Y1 + 31;
end;
end;
(*
CoordsToBank
~~~~~~~~~~~~
.. code-block:: pascal
function CoordsToBank(X, Y : Integer): Integer;
Takes a X/Y coord and converts them into a bank slot
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
ItemBox := BankBox(CoordsToBank(MP.X, MP.Y));
*)
function CoordsToBank(X, Y : Integer): Integer;
var
tmpBox : TBox;
begin
if not PointInBox(Point(X, Y), IntToBox(MBX1, MBY1, MBX2, MBY2)) then exit;
for Result := 1 to 10 do
begin
tmpBox := BankBox(result);
if InRange(X, tmpBox.x1, tmpBox.x2) then break;
end;
while (not InRange(Y, tmpBox.y1, tmpBox.y2)) do
begin
IncEx(Result, 10);
if (Result > 50) then
Break;
tmpBox := BankBox(Result);
end;
if (not PointInBox(Point(X, Y), tmpBox)) then
Result := 0;
end;
(*
FindItemCC
~~~~~~~~~~
.. code-block:: pascal
function FindItemCC(var X, Y : Integer; colors : TIntegerArray; Inv : Boolean) : Boolean;
Searches either your bank or inventory for the common colors that are created
from the GE image at runtime, and returns the X, Y coords if the tem was found.
.. note::
Author: Dev Team 6
Last Modified: Unknown
Example:
.. code-block:: pascal
Result := FindItemCC(x, y, Item.CommonColors, Inv);
*)
function FindItemCC(var X, Y : Integer; colors : TIntegerArray; Inv : Boolean) : Boolean;
var
i, a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
Box, ItemBox : TBox;
begin
if(Inv)then
Box := IntToBox(MIX1, MIY1, MIX2, MIY2)
else
Box := IntToBox(MSX1, MSY1, MSX2, MSY2);
DebugLn('FindItemCC.Inv := ' + BoolToStr(Inv));
DebugLn('FindItemCC.Box := ' + IntToStr(Box.X1) + ', ' + IntToStr(Box.Y1) + ', ' + IntToStr(Box.X2) + ', ' + IntToStr(Box.Y2));
for i := 0 to High(colors) do
begin
DebugLn('FindItemCC.colors[' + IntToStr(i) + '] := ' + IntToStr(colors[i]));
if(FindColors(TPA, colors[i], Box.X1, Box.Y1, Box.X2, Box.Y2))then
begin
DebugLn('FindItemCC.FindColors.TPA.LengtAverageColor := FixedAverageTIA(GetColors(BoxTPA));h := ' + IntToStr(Length(TPA)));
ATPA := TPAtoATPAEx(TPA, 7, 7);
DebugLn('FindItemCC.FindColors.TPA.ATPA.Length := ' + IntToStr(Length(ATPA)));
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
DebugLn('FindItemCC.FindColors.TPA.ATPA.MP.X := ' + IntToStr(MP.X));
DebugLn('FindItemCC.FindColors.TPA.ATPA.MP.Y := ' + IntToStr(MP.Y));
if(Inv)then
ItemBox := InvBox(CoordsToItem(MP.X, MP.Y))
else
ItemBox := BankBox(CoordsToBank(MP.X, MP.Y));
FindColors(TPA, colors[i], ItemBox.X1, ItemBox.Y1, ItemBox.X2, ItemBox.Y2);
DebugLn('FindItemCC.FindColors.TPA.ATPA.MP.FindColors.TPA.Length := ' + IntToStr(Length(TPA)));
if(Length(TPA) > 0)then
begin
X := MP.X; Y := MP.Y;
Result := True;
DebugLn('Item found using Common Colors.');
Exit;
end;
end;
end;
end;
end;
function TestItem(itemID : Integer) : Boolean;
var
Item : TGEItem;
ItemBox : TBox;
MiddlePoint : TPoint;
CloseCountArr, CountArr : TIntegerArray;
T, I : Integer;
TPA : TPointArray;
aTPA : T2DPointArray;
begin
Result := False;
Item := CreateGEItemFromIDEx(itemID, True);
//Item := LoadGEItemFromID(itemID);
WriteLn(Item);
SetColorToleranceSpeed(2);
SetColorspeed2Modifiers(Item.Hue, Item.Sat);
MarkTime(T);
FindColorsTolerance(TPA, Item.BestColor, MIX1, MIY1, MIX2, MIY2, Item.Tolerance)
aTPA := TPAtoATPAEx(TPA, 7, 7);
Writeln(Length(aTPA));
for I := 0 to High(aTPA) do
begin
MiddlePoint := MiddleTPA(aTPA[I]);
ItemBox := InvBox(CoordsToItem(MiddlePoint.X, MiddlePoint.Y));
FindColorsTolerance(TPA, Item.BestColor, ItemBox.X1, ItemBox.Y1, ItemBox.X2, ItemBox.Y2, Item.Tolerance)
Writeln(Length(TPA));
SetLength(CountArr, I + 1);
CountArr[I] := Length(TPA);
end;
CloseCountArr := SortTIAFrom(CountArr, Item.BestColorCount);
for I := 0 to High(aTPA) do
begin
MiddlePoint := MiddleTPA(aTPA[I]);
ItemBox := InvBox(CoordsToItem(MiddlePoint.X, MiddlePoint.Y));
FindColorsTolerance(TPA, Item.BestColor, ItemBox.X1, ItemBox.Y1, ItemBox.X2, ItemBox.Y2, Item.Tolerance)
if Length(TPA) = CloseCountArr[0] then
MMouse(MiddlePoint.X, MiddlePoint.Y, 0, 0);