forked from GitBraK/SRL-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem Database.simba
More file actions
288 lines (262 loc) · 9.28 KB
/
Item Database.simba
File metadata and controls
288 lines (262 loc) · 9.28 KB
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
{$IFDEF SRL5}
{$i SRL/SRL.simba}
{$ELSE}
{$i SRL/SRL.scar}
{$ENDIF}
type
TGEItem = record
ID, Price : Integer;
Name : string;
BMP : Integer;
BlackCount : Integer;
AverageColor : Integer;
end;
{*******************************************************************************
function CashStringToInt(S : string) : Integer;
by: TomTuff
Description: Takes a string amount, and returns the Integer equivalent.
*******************************************************************************}
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;
{*******************************************************************************
function DownloadFile(FileLink, Path : string) : Boolean;
by: Home
Description: Downloads a file to a specified path
*******************************************************************************}
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;
{*******************************************************************************
function GEItemExists(ID : Integer) : Boolean;
by: Home
Description: Checks the local item DB to see if the item being requested exists
*******************************************************************************}
function GEItemExists(ID : Integer) : Boolean;
begin
Result := FileExists(AppPath + 'Includes\db\' + ToStr(ID) + '.ini');
end;
{*******************************************************************************
function ReadGEItemINI(ID : Integer) : TGEItem;
by: Home
Description: Reads the items .INI file and returns a TGEItem record
*******************************************************************************}
function ReadGEItemINI(ID : Integer) : TGEItem;
var
Path : string;
begin
if(not(GEItemExists(ID)))then Exit;
Path := AppPath + 'Includes\db\' + ToStr(ID) + '.ini';
try
with Result do
begin
ID := StrToIntDef(ReadINI(ToStr(ID), 'ID', Path), -1);
Price := StrToIntDef(ReadINI(ToStr(ID), 'Price', Path), -1);
Name := ReadINI(ToStr(ID), 'Name', Path);
BMP := BitmapFromString(32, 32, ReadINI(ToStr(ID), 'BMP', Path));
BlackCount := StrToIntDef(ReadINI(ToStr(ID), 'BlackCount', Path), -1);
AverageColor := StrToIntDef(ReadINI(ToStr(ID), 'AverageColor', Path), -1);
end;
except
end;
end;
{*******************************************************************************
procedure WriteGEItemINI(Item : TGEItem);
by: Home
Description: Writes a .INI file for the TGEItem that is passed in
*******************************************************************************}
procedure WriteGEItemINI(Item : TGEItem);
var
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);
WriteINI(ToStr(ID), 'BlackCount', ToStr(BlackCount), Path);
WriteINI(ToStr(ID), 'AverageColor', ToStr(AverageColor), Path);
end;
except
end;
end;
{*******************************************************************************
function GetGEItemBMPFromID(ID : Integer) : Integer;
by: Home
Description: Retrieves the .gif image from the GE
*******************************************************************************}
function GetGEItemBMPFromID(ID : 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(ID), AppPath + 'Includes\DB\' + ToStr(ID) + '.gif') then
begin
Target := GetImageTarget;
BMP := LoadBitmap(AppPath + 'Includes\DB\' + ToStr(ID) + '.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;
{*******************************************************************************
function CreateGEItemFromIDEx(ID : Integer; Force : Boolean) : TGEItem;
by: Home
Description: 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
*******************************************************************************}
function CreateGEItemFromIDEx(ID : Integer; Force : Boolean) : TGEItem;
var
S : string;
Target, W, H, I : Integer;
BoxTPA, TPA : TPointArray;
FilterColors : TIntegerArray;
begin
if(GEItemExists(ID) and (not(Force)))then
begin
Result := ReadGEItemINI(ID);
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(ID));
Result.ID := ID;
with Result do
begin
Name := Replace(Between('<h5>', '</h5>', S), #10, '');
Price := CashStringToInt(Between('<td>', '<', Between('Current guide price', '/td>', S)));
BMP := GetGEItemBMPFromID(ID);
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);
FindColors(TPA, srl_outline_black, 0, 0, W-1, H-1);
BlackCount := Length(TPA);
AverageColor := AverageTIA(GetColors(BoxTPA));
FreeTarget(GetImageTarget);
SetImageTarget(Target);
end;
WriteGEItemINI(Result);
end;
{*******************************************************************************
function CreateGEItemFromID(ID : Integer) : TGEItem;
by: Home
Description: Creates an TGEItem for the ID passed in, and disables Force
*******************************************************************************}
function CreateGEItemFromID(ID : Integer) : TGEItem;
begin
Result := CreateGEItemFromIDEx(ID, False);
end;
{*******************************************************************************
function LoadGEItemFromID(ID : Integer) : TGEItem;
by: Home
Description: Loads an TGEItem record from the local DB of items
*******************************************************************************}
function LoadGEItemFromID(ID : Integer) : TGEItem;
begin
if(GEItemExists(ID))then
Result := ReadGEItemINI(ID)
end;
{*******************************************************************************
function FindGEItem(var X, Y : Integer; ID : Integer) : Boolean;
by: Home
Description: Searches the Inventory for the item and set the X, Y variables to
the coordinates if found
*******************************************************************************}
function FindGEItem(var X, Y : Integer; ID : Integer) : Boolean;
var
Acc : Extended;
Item : TGEItem;
P : TPoint;
begin
Result := False;
Item := LoadGEItemFromID(ID);
// BlackCount, AverageColor, etc...
{ClearDebugImg;
DrawBitmapDebugImg(Item.BMP);}
// Use this as last resort IMO
if(FindDeformedBitmapToleranceIn(Item.BMP, P.X, P.Y, MIX1, MIY1, MIX2, MIY2, 25, 0, True, Acc))then
if(Acc > 0.80)then
begin
Result := True;
FreeBitmap(Item.BMP);
P := ItemCoords(CoordsToItem(P.X, P.Y));
X := P.X; Y := P.Y;
Exit;
end;{ else
WriteLn(Acc); }
end;
{//////////////////////////////////////////////////////////////////////////////}
// TESTING //
{//////////////////////////////////////////////////////////////////////////////}
var
Item : TGEItem;
x, y : Integer;
begin
SetupSRL;
MouseSpeed := 12;
Item := CreateGEItemFromIDEx(1381, True);
WriteLn(Item);
if(FindGEItem(X, Y, Item.ID))then
MMouse(X-5, Y-5, 10, 10)
else
WriteLn('Did not find item');
FreeBitmap(Item.BMP);
end.