/
stats.simba
377 lines (270 loc) · 7.6 KB
/
stats.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
(*
Gametab Stats
=============
The Gametab Stats file holds functions and procedures that are used in the runescape Stats gametab.
The source for this file can be found `here <https://github.com/SRL/SRL-6/blob/master/lib/interfaces/gametabs/stats.simba>`_.
*)
{$f-}
(*
Consts, Types, Vars
~~~~~~~~~~~~~~~~~~~
The following constants, types and variables are used throughout the chatBox methods.
**const Skill type**
Constants that represent the two different stats types for a skill. When
reading a skill level, there is either a static skill level or a dynamic skill
level. The dynamic skill level is the level that changes when you boost a skill.
* SKILL_STATIC
* SKILL_DYNAMIC
*)
const
SKILL_STATIC = 1;
SKILL_DYNAMIC = 0;
{*
const Internal
~~~~~~~~~~~~~~
Internal constants. Constants that represent the color of the skill text.
*}
const
{$IFNDEF CODEINSIGHT}
__COLOR_STATS = 36095;
{$ENDIF}
(*
**const Skill Info Type**
Constants that represent the different skill info types. These are used
when reading the skill XP.
* INFO_CURRENT_XP
* INFO_REMAINDER
* INFO_NEXT_LEVEL
* INFO_BONUS_XP
*)
const
INFO_CURRENT_XP = 'Current';
INFO_REMAINDER = 'Remainder';
INFO_NEXT_LEVEL = 'Next level';
INFO_BONUS_XP = 'Bonus';
(*
**type TRSTabStats**
.. code-block:: pascal
type
TRSTabStats = type TRSInterface;
A type that stores the stats tab interface properties.
*)
type
TRSTabStats = record(TRSInterface)
tabIndex: integer;
end;
(*
**var tabStats**
.. code-block:: pascal
var
tabStats: TRSTabStats;
A variable through which scripters can access the TRSTabStats type methods.
*)
var
tabStats: TRSTabStats;
(*
TRSTabStats methods
~~~~~~~~~~~~~~~~~~~
The following methods should be called through the **tabStats** variable.
Example:
.. code-block:: pascal
if tabStats.isOpen() then
writeln('It''s open!');
*)
{*
__init
------
.. code-block:: pascal
procedure TRSTabStats.__init();
Initializes the TRSTabStats.
.. note::
- by Olly
- Last Updated: 14 September 2013 by Olly
Example:
.. code-block:: pascal
tabStats.__init();
*}
{$IFNDEF CODEINSIGHT}
procedure TRSTabStats.__init();
begin
with self do
begin
name := 'RS Stats tab';
ID := ID_INTERFACE_TAB_STATS;
tabIndex := TAB_STATS;
parentID := -1;
static := true;
end;
end;
{$ENDIF}
(*
isOpen
------
.. code-block:: pascal
function TRSTabStats.isOpen(): boolean;
Returns true if the stats gametab is open.
.. note::
- by Olly
- Last Updated: 14 September 2013 by Olly
Example:
.. code-block:: pascal
if tabStats.isOpen() then
writeln('The stats tab is currently open!');
*)
function TRSTabStats.isOpen(): boolean;
const
BAR_COLOR = 7056896;
begin
result := (gameTabs.isTabActive(self.tabIndex));
if (not result) then
result := (getColor(gameTabs.tabArea.x1 + 95, gameTabs.tabArea.y2 -27) = 7056896);
end;
(*
open
----
.. code-block:: pascal
function TRSTabStats.open(): boolean;
Returns true if the stats gametab is successfully opened.
.. note::
- by Olly
- Last Updated: 14 September 2013 by Olly
Example:
.. code-block:: pascal
if tabStats.open() then
writeln('We opened the stats tab');
*)
function TRSTabStats.open(): boolean;
begin
result := self.isOpen();
if (not result) then
result := gameTabs.openTab(self.tabIndex);
end;
(*
getSkillBox
-----------
.. code-block:: pascal
function TRSTabStats.getSkillBox(skill: integer): TBox;
Returns a TBox around the skill information. The **skill** is one of the skill
constants found in `globals.simba <https://github.com/SRL/SRL-6/blob/master/lib/core/globals.simba>`_.
.. note::
- by Olly
- Last Updated: 14 September 2013 by Olly
Example:
.. code-block:: pascal
var
b: TBox;
begin
b := tabStats.getSkillBox(SKILL_ATTACK);
end;
*)
function TRSTabStats.getSkillBox(skill: integer): TBox;
var
offSet: TPoint;
begin
if gameTabs.areMultiOpen() then
offset := [0, 45]
else
offset := [15, 17];
result := gridBox(skill, 3, 9, 58, 24, 65, 27, point(gameTabs.tabArea.x1 + 38 + offset.x, gameTabs.tabArea.y1 + offset.y));
end;
(*
getSkillLevel
-------------
.. code-block:: pascal
function TRSTabStats.getSkillLevel(skill: integer; skillType: integer = SKILL_STATIC): integer;
Returns the skill level of **skill*, if unsuccesfull it will return -1.
* **skill** : The skill level to get (skill constants are found in `globals.simba <https://github.com/SRL/SRL-6/blob/master/lib/core/globals.simba>`_).
* **skillType** : Which skill level to read (either SKILL_STATIC or SKILL_DYNAMIC) *(default = SKILL_STATIC)*
.. note::
- by Olly
- Last Updated: 14 September 2013 by Olly
Example:
.. code-block:: pascal
writeln(tabStats.getSkillLevel(SKILL_ATTACK));
// To get the dymanic (boosted or weakened) skill
writeln(tabStats.getSkillLevel(SKILL_ATTACK, SKILL_DYNAMIC));
*)
function TRSTabStats.getSkillLevel(skill: integer; skillType: integer = SKILL_STATIC): integer;
var
tpa: TPointArray;
atpa: T2DPointArray;
b: TBox;
s: string;
begin
result := -1;
if (not self.open()) then
exit();
b := self.getSkillBox(skill);
if (b.x1 <> -1) then
begin
b.x1 := b.x1 + 23; // get rid of the skill iron
findColors(tpa, __COLOR_STATS, b);
atpa := tpa.split(10, 2);
atpa.sortFromMidPoint([b.x1, b.y2]);
if (length(atpa) <> 2) then
begin
print('tabStats.getSkillLevel(): Found too much or too little color', TDebug.ERROR);
exit();
end;
s := getTextAtEx(atpa[skillType].getBounds(), 0, 3, 3, __COLOR_STATS, 0, statChars, numbers);
result := strToIntDef(s, -1);
print('tabStats.getSkillLevel('+toStr(skill)+'): result = ' + intToStr(result));
end else
print('tabStats.getSkillLevel(): Was unable to get the skill box', TDebug.ERROR);
end;
(*
getSkillInfo
------------
.. code-block:: pascal
function TRSTabStats.getSkillInfo(skill: integer; infoType: string): integer;
Returns the XP information about the skill **skill**.
* **skill** - The skill XP to get (skill constants are found in `globals.simba <https://github.com/SRL/SRL-6/blob/master/lib/core/globals.simba>`_).
* **infoType** - What XP information to get. SKill into type constants are found at top of this page.
.. note::
- by Olly
- Last Updated: 2 August 2015 by The Mayor
Example:
.. code-block:: pascal
var
bonusXP, currXP, remXP, nextLvl: Integer;
begin
currXP := tabStats.getSkillInfo(SKILL_ATTACK, INFO_CURRENT_XP);
bonusXP := tabStats.getSkillInfo(SKILL_ATTACK, INFO_BONUS_XP);
remXP := tabStats.getSkillInfo(SKILL_ATTACK, INFO_REMAINDER);
nextLvl := tabStats.getSkillInfo(SKILL_ATTACK, INFO_NEXT_LEVEL);
end;
*)
function TRSTabStats.getSkillInfo(skill: integer; infoType: string): integer;
var
b: TBox;
i, p: integer;
s: string;
boxArr: TBoxArray;
tesseractFilter: TTesseractFilter = [3, 3, [true, 40, TM_Mean]];
begin
result := -1;
if (not self.open()) then
exit();
if infoType = INFO_BONUS_XP then tesseractFilter := [2, 2, [true, 10, TM_Mean]];
mouseBox(tabStats.getSkillBox(skill));
if isMouseOverMenuOpen(b, 1000 + random(100)) then
begin
boxArr := b.split(b.getWidth(), 14);
wait(200 + random(300));
for i := 0 to high(boxArr) do
begin
s := tesseract_GetText(boxArr[i], tesseractFilter);
p := pos(infoType, s);
if (p > 0) then
begin
result := strToIntDef(extractFromStr(s, numbers), -1);
break();
end;
end;
end;
print('TRSTabStats.getSkillInfo(): result = '+intToStr(result), TDebug.SUB);
end;
begin
tabStats.__init();
end;
{$f+}