/
lodestone.simba
446 lines (330 loc) · 9.82 KB
/
lodestone.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
(*
Lodestone
=========
The lodestone file holds functions and procedures that are used in the
Runescape lodestone-teleport screen.
The source for this file can be found `here <https://github.com/SRL/SRL-6/blob/master/lib/interfaces/lodestone.simba>`_.
*)
{$f-}
(*
const Locations
~~~~~~~~~~~~~~~
All possible locations to teleport on the lodestone network.
Example:
.. code-block:: pascal
lodestoneScreen.teleportTo(LOCATION_LUNAR_ISLE);
*)
const
LOCATION_LUNAR_ISLE = 0;
LOCATION_EAGLES_PEAK = 1;
LOCATION_TIRANNWN = 2;
LOCATION_FREMENNIK = 3;
LOCATION_SEERS_VILLAGE = 4;
LOCATION_ARDOUGNE = 5;
LOCATION_YANILLE = 6;
LOCATION_OOGLOG = 7;
LOCATION_BURTHORPE = 8;
LOCATION_CATHERBY = 9;
LOCATION_TAVERLEY = 10;
LOCATION_TRAVERLEY = 10;
LOCATION_KARAMJA = 11;
LOCATION_WILDERNESS = 12;
LOCATION_EDGEVILLE = 13;
LOCATION_FALADOR = 14;
LOCATION_PORT_SARIM = 15;
LOCATION_VARROCK = 16;
LOCATION_DRAYNOR_VILLAGE = 17;
LOCATION_LUMBRIDGE = 18;
LOCATION_BANDIT_CAMP = 19;
LOCATION_AL_KHARID = 20;
LOCATION_CANIFIS = 21;
LOCATION_ASHDALE = 22;
LOCATION_PRIFDDINAS = 23;
LOCATION_PREVIOUS = 1337;
(*
type TRSLodestoneScreen
~~~~~~~~~~~~~~~~~~~~~~~~
A type that stores the lodestone interface properties.
*)
type
TRSLodestoneScreen = type TRSInterface;
(*
var lodestoneScreen
~~~~~~~~~~~~~~~~~~~~
Variable that stores functions and properties of the Runescape lodestone interface.
Example:
.. code-block:: pascal
if (lodestoneScreen.isOpen() then
writeln('Lodestone screen is open!');
*)
var
lodestoneScreen: TRSLodestoneScreen;
{*
TRSLodestoneScreen.__init
~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
procedure TRSLodestoneScreen.__init();
Initializes the TRSLodestoneScreen.
.. note::
- by Olly
- Last Updated: 16 November 2013 by Olly
Example:
.. code-block:: pascal
TRSLodestoneScreen.__init();
*}
{$IFNDEF CODEINSIGHT}
procedure TRSLodestoneScreen.__init();
begin
with (self) do
begin
name := 'RS Production Screen';
ID := ID_INTERFACE_LODESTONE;
parentID := -1;
static := false;
end;
end;
{$ENDIF}
(*
TRSLodestoneScreen.__find
~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSLodestoneScreen.__find(): boolean;
Returns true if the lodestone screen is detected, and sets the bounds
.. note::
- by Ashaman88
- Last Updated: 27 February 2014 by Ashaman88
Example:
.. code-block:: pascal
if (LodestoneScreen.__find()) then
writeln('bounds are set!');
*)
function TRSLodestoneScreen.__find(): boolean;
const
TOP_COLOR = 855595; //red color behind lodestone
MENU_LENGTH = 165; //length of large red background
MENU_OFFSET_COLOR = 5333103; //p2p offset color on map
MENU_OFFSET_COLOR_FTP = 6250064; //f2p offset color on map
var
tpa : TPointArray;
atpa : T2DPointArray;
i, hh: integer;
b: TBox;
begin
result := false;
if (not findColors(tpa, TOP_COLOR, getClientBounds())) then
exit();
atpa := tpa.cluster(5);
hh := high(atpa);
for i := 0 to hh do
if (length(atpa[i]) = MENU_LENGTH) then
begin
b := getTPABounds(atpa[i]);
if (getColor(b.x2, b.y2 + 5) = MENU_OFFSET_COLOR) or (getColor(b.x2, b.y2 + 5) = MENU_OFFSET_COLOR_FTP) then
begin
self.setBounds([b.x1 - 13, b.y1 - 14, b.x2 + 304, b.y2 + 297]);
exit(true);
end;
end;
end;
(*
TRSLodestoneScreen.isOpen
~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSLodestoneScreen.isOpen(waitTime: integer = 0): boolean;
Returns true if the lodestone sceen is open, has a optional parameter 'waitTime'
which is the max time of how long we will wait for the screen to appear.
.. note::
- by Olly
- Last Updated: 16 November 2013 by Olly
Example:
.. code-block:: pascal
if (lodestoneScreen.isOpen() then
writeln('Lodestone screen is open!');
*)
function TRSLodestoneScreen.isOpen(waitTime: integer = 0): boolean;
var
cts: integer;
t : LongWord;
begin
t := (getSystemTime() + waitTime);
cts := getToleranceSpeed();
setColorToleranceSpeed(1);
repeat
result := self.__find();
wait(20 + random(20));
until (getSystemTime() >= t) or (result);
setColorToleranceSpeed(cts);
end;
(*
TRSLodestoneScreen.close
~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSLodestoneScreen.close(): boolean;
Closes the lodestone screen.
.. note::
- by Olly
- Last Updated: 16 November 2013 by Olly
Example:
.. code-block:: pascal
lodestoneScreen.close();
*)
function TRSLodestoneScreen.close(): boolean;
var
t: longWord;
begin
result := false;
t := (getSystemTime() + randomRange(6000, 8000));
if (self.isOpen()) then
begin
mouseCircle(self.x2 - 4, self.y1 + 8, 4, MOUSE_LEFT);
while (t > getSystemTime()) do
begin
if (not self.isOpen()) then
begin
result := true;
break;
end;
wait(50 + random(50));
end;
end else
result := true;
if (result) then
print('TRSLodestoneScreen.close(): Closed lodestone screen', TDebug.SUB)
else
print('TRSLodestoneScreen.close(): Failed to close lodestone screen', TDebug.WARNING);
end;
{*
TRSLodestoneScreen._isLocationVaild
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSLodestoneScreen._isLocationVaild(location: integer): boolean;
Returns true if the location is vaild.
.. note::
- by Olly
- Last Updated: 16 November 2013 by Olly
Example:
.. code-block:: pascal
if (lodestoneScreen._isLocationVaild(LOCATION_LUNAR_ISLE)) then
writeln('vaild.');
*}
function TRSLodestoneScreen._isLocationVaild(location: integer): boolean;
begin
result := inRange(location, LOCATION_LUNAR_ISLE, LOCATION_PRIFDDINAS);
if (not result) then
print('TRSLodestoneScreen._isLocationVaild(): Location isn''t vaild!');
end;
{*
TRSLodestoneScreen._getTeleportBox
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSLodestoneScreen._getTeleportBox(location: integer): TBox;
Returns the TBox of the location.
.. note::
- by Olly
- Last Updated: 16 November 2013 by Olly
Example:
.. code-block:: pascal
b := lodestoneScreen._getTeleportBox(LOCATION_CANIFIS);
*}
function TRSLodestoneScreen._getTeleportBox(location: integer): TBox;
const
pnts: TPointArray = [[26, 48], [94, 117], [71, 194], [183, 53], [165, 100], [156, 144], [147, 209], [139, 262], [239, 87], [198, 130], [230, 124], [198, 198], [298, 60], [281, 99], [261, 146], [262, 188], [336, 131], [299, 162], [310, 199], [310, 243], [351, 193], [393, 105], [84, 298], [51, 139]];
var
p: TPoint;
begin
result := [-1, -1, -1, -1];
if (self._isLocationVaild(location)) then
begin
p := pnts[location];
p.offset([self.x1, self.y1]);
result := [p.x -8, p.y -8, p.x +8, p.y +8];
end;
end;
(*
TRSLodestoneScreen._isLocked
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSLodestoneScreen._isLocked(location: integer): boolean;
Checks if the lodestone is unlocked (actually locked or members only).
This is only used internally in lodestoneScreen.teleportTo(location).
.. note::
- by The Mayor
- Last Updated: 16 December 2014 by The Mayor
Example:
.. code-block:: pascal
if (lodestoneScreen._isLocked(LOCATION_VARROCK) then
writeln('You need to activate the Varrock loadstone!');
*)
function TRSLodestoneScreen._isLocked(location: integer): boolean;
var
x, y, i: integer;
b: TBox;
DTMs: array[0..1] of integer;
begin
DTMs := [DTMFromString('mbQAAAHicY2VgYKiA4mogrofiQEYGBm8gdoXSIP6kHccZppy+zbDu1lMwDeLzA9WiY0YsGAwA0uoPRA=='),
DTMFromString('mWAAAAHicY2FgYHgNxC+B+B0QvwHiZUA8B4oXAfFvIP7/3Ifh/2c/MJsfDTOiYRAAAOaoDNs=')];
b := self._getTeleportBox(location);
b.expand(5);
for i := 0 to high(DTMs) do
if findDTM(DTMs[i], x, y, b) then
result := true;
freeDTMs(DTMs);
if result then
print('TRSLodestoneScreen._isLocked(): lodestone ' + toStr(location) + ' is not activated', TDebug.ERROR)
end;
(*
TRSLodestoneScreen.teleportTo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSLodestoneScreen.teleportTo(location: integer): boolean;
Will teleport to location 'location'. Use integer constants at the top of the file.
.. note::
- by Olly
- Last Updated: 16 December 2014 by The Mayor
Example:
.. code-block:: pascal
if (lodestoneScreen.teleportTo(LOCATION_LUMBRIDGE) then
writeln('We just teleported to Lumbrodge');
*)
function TRSLodestoneScreen.teleportTo(location: integer): boolean;
var
b: TBox;
begin
result := false;
if (not self.isOpen()) then
begin
mouseCircle(minimap.button[MM_BUTTON_LODESTONE].center.x, minimap.button[MM_BUTTON_LODESTONE].center.y,
minimap.button[MM_BUTTON_LODESTONE].radius, MOUSE_MOVE);
if (location = LOCATION_PREVIOUS) then
begin
fastclick(MOUSE_RIGHT);
result := chooseOption.select(['Previous dest', 'estination', 'evious']);
if (result) then
print('TRSLodestoneScreen.teleportTo(): Succesfully teleported to previous destination', TDebug.SUB)
else
print('TRSLodestoneScreen.teleportTo(): Failed teleport to previous destination (ChooseOption must have failed)', TDebug.SUB);
exit();
end;
end;
if (not self.isOpen()) then
fastClick(MOUSE_LEFT);
if (self.isOpen(4000 + random(1500))) then
begin
if not self._isLocked(location) then
begin
b := self._getTeleportBox(location);
if (b.x1 <> -1) then
begin
mouseBox(b, MOUSE_LEFT);
result := true;
print('TRSLodestoneScreen.teleportTo(): result = true', TDebug.SUB);
end;
end else
self.close();
end else
print('TRSLodestoneScreen.teleportTo(): lodestone screen never appeared', TDebug.ERROR);
end;
begin
lodestoneScreen.__init();
end;
{$f+}