This repository has been archived by the owner on Dec 6, 2018. It is now read-only.
forked from SRL/MSI
/
Obstacles.simba
392 lines (307 loc) · 9.04 KB
/
Obstacles.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
(*
Obstacles
=========
The Obstacles file includes all routines that are used to solve obstacles such
as climbing a ladder or climbing over a wall.
The source for can be found
`here <https://github.com/SRL/MSI/raw/master/MSI/Core/Obstacles.simba>`_.
*)
(*
MSI_GetObstacle
~~~~~~~~~~~~~~~
.. code-block:: pascal
function MSI_GetObstacle(obs: integer): TObstacle;
Returns a TObstacle record for the obstacle specified by 'obs'; 'obs' is a
constant that can be found in
`here <https://github.com/SRL/MSI/raw/master/MSI/Core/Globals.simba>`_ with the
prefix "OBS_".
.. note::
| Author: The MSI Team
| Last Updated: 23 July 2011 by Coh3n
Example:
.. code-block:: pascal
var
obs: TObstacle;
begin
obs := MSI_GetObstacle(OBS_LADDER_DOWN_MINE_GUILD);
writeln('Loaded obstacle: '+obs.name);
end;
*)
function MSI_GetObstacle(obs: integer): TObstacle;
begin
case obs of
OBS_LADDER_MG_DOWN:
with result do
begin
Name := 'OBS_LADDER_MG_DOWN';
ObjConst := LADDER_MG_DOWN;
ObjMir := LADDER_MG_UP;
ObjMirArea := intToBox(MSCX - 85, MSCY - 85, MSCX + 85, MSCY + 85);
Camera := ['n', true];
// West, South, East, North
EndTiles := [Point(3017, 9739), Point(3019, 9737),
Point(3021, 9739), Point(3019, 9741)];
end;
OBS_LADDER_MG_UP:
with result do
begin
Name := 'OBS_LADDER_MG_UP';
ObjConst := LADDER_MG_UP;
ObjMir := LADDER_MG_DOWN;
ObjMirArea := intToBox(MSCX - 85, MSCY - 85, MSCX + 85, MSCY + 85);
Camera := ['n', true];
// West, South, East, North
EndTiles := [Point(3017, 3339), Point(3019, 3337),
Point(3021, 3339), Point(3019, 3341)];
end;
OBS_WALL_FW:
with result do
begin
Name := 'OBS_WALL_FW';
ObjConst := WALL_FW;
ObjMir := WALL_FW;
ObjMirArea := intToBox(MSCX, MSY1, MSX2, MSY2); // Right half of MS;
Camera := ['w', false];
EndTiles := [Point(2940, 3355)];
end;
OBS_DOOR_CG_IN:
with result do
begin
Name := 'OBS_DOOR_CG_IN';
MirText := ['elcome', 'uild', 'aster', 'raft'];
ObjConst := DOOR_NORMAL;
ObjMir := DOOR_NORMAL;
ObjMirArea := intToBox(MSCX - 100, MSCY - 100, MSCX + 100, MSCY - 20);
Camera := ['n', true];
EndTiles := [Point(2933, 3288)];
end;
OBS_DOOR_CG_OUT:
with result do
begin
Name := 'OBS_DOOR_CG_OUT';
ObjConst := DOOR_NORMAL;
ObjMir := DOOR_NORMAL;
ObjMirArea := intToBox(MSCX - 100, MSCY, MSCX + 100, MSCY + 100);
Camera := ['n', true];
EndTiles := [Point(2933, 3289)];
end;
end;
result.constant := obs;
end;
(*
MSI_FindMirrorText
~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function MSI_FindMirrorText(obs: TObstacle): boolean;
Returns true if the obstacle's (obs) mirror text is found in the RS chat box.
.. note::
| Author: Coh3n
| Last Updated: 01 August 2011 by Coh3n
Example:
.. code-block:: pascal
if (not MSI_FindMirrorText(obs)) then
MSI_Debug('Found mirror text: ' + obs.mirText);
*)
function MSI_FindMirrorText(obs: TObstacle): boolean;
var
i, x, y: integer;
begin
if (length(obs.mirText) <= 0) then
begin
MSI_SubDebug('No text for obstacle: ' + obs.name);
exit;
end;
for i := 0 to high(obs.mirText) do
if (findText(x, y, obs.mirText[i], 'CharsNPC', MCX1, MCY1, MCX2, MCY2)) then
begin
result := true;
MSI_SubDebug('Found mirror text: ' + obs.mirText[i]);
break;
end;
end;
(*
MSI_FindMirrorObject
~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function MSI_FindMirrorObject(obs: TObstacle): boolean;
Returns true if the obstacle's (obs) mirror object is found in the record's
search area. Will move the mouse and check for uptext, just to be sure. Will
also draw the search area in blue on the main screen.
.. note::
| Author: Coh3n
| Last Updated: 01 August 2011 by Coh3n
Example:
.. code-block:: pascal
if (not MSI_FindMirrorObject(obs)) then
MSI_Debug('Found mirror object: ' + obs.name);
*)
function MSI_FindMirrorObject(obs: TObstacle): boolean;
var
mirObj: TMSObject;
begin
mirObj := MSI_GetObject(obs.objMir);
mirObj.searchArea := obs.objMirArea;
{$IFDEF SMART}
if (MSI_Settings[SETUP_DEBUG_SMART]) then
SMART_DrawBoxEx(false, mirObj.searchArea, clBlue);
{$ENDIF}
if (MSI_FindObject(mirObj, moMove)) then
begin
MSI_SubDebug('Found mirror object: ' + mirObj.name);
result := true;
end;
end;
(*
MSI_OnMirrorTile
~~~~~~~~~~~~~~~~
.. code-block:: pascal
function MSI_OnMirrorTile(obs: TObstacle): boolean;
Returns true if the player's current tile is the same as one of the obstacle's
(obs) ending tiles.
.. note::
| Author: Coh3n
| Last Updated: 23 July 2011 by Coh3n
Example:
.. code-block:: pascal
if (not MSI_OnMirrorTile(obs)) then
MSI_Debug('Player not on ending tiles');
*)
function MSI_OnMirrorTile(obs: TObstacle): boolean;
{$IFDEF REFLECTION}
var
i, h: integer;
mPos: TPoint;
{$ENDIF}
begin
if (not loggedIn) then
exit;
result := false;
{$IFDEF REFLECTION}
if (not MSI_HookBroken[HOOK_WALKING]) then
begin
mPos := getMyPos();
h := high(obs.endTiles);
// loop through end tiles comparing to player's current tile
for i := 0 to h do
if (mPos = obs.endTiles[i]) then
begin
MSI_SubDebug('Player is on end tile');
result := true;
break;
end;
end;
{$ENDIF}
end;
(*
MSI_WaitForMirror
~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function MSI_WaitForMirror(obs: TObstacle): boolean;
Returns true when an obstacles 'mirror object' has appeared. For example, if
we're climbing a ladder, the mirror obstacle would be the ladder climbing down.
If reflection is enabled, it will check to see if the player is on the end tile,
and return true if they are.
.. note::
| Author: Sir R. Magician & Coh3n
| Last Updated: 01 August 2011 by Coh3n
Example:
.. code-block:: pascal
var
obs: TObstacle;
begin
obs := MSI_GetObstacle(LADDER_MG_DOWN);
// clickObstacle isn't a real function, just an example
if (clickObstacle(obs)) then
result := MSI_WaitForMirror(obs);
end;
*)
function MSI_WaitForMirror(obs: TObstacle): boolean;
var
t: integer;
mirFound: boolean;
begin
if (not loggedIn) then
exit;
t := (getSystemTime + 30000);
repeat
mirFound := MSI_FindMirrorText(obs);
if (not mirFound) then
mirFound := MSI_FindMirrorObject(obs);
if (mirFound) then
begin
{$IFDEF REFLECTION}
if (not MSI_OnMirrorTile(obs)) then
continue;
{$ENDIF}
result := true;
end;
if (not result) then
if ((t - getSystemTime) > 10000) then // reset after 10 seconds
MSI_NotBoxes := [];
wait(randomRange(250, 500));
until(result or (getSystemTime > t));
end;
(*
MSI_SolveObstacle
~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function MSI_SolveObstacle(obs: TObstacle): boolean;
Returns true if the obstacle 'obs' is solved. Uses MSI_FindObject to find and
click the obstacle, then calls MSI_WaitForMirror to determine when the obstacle
has been passed.
.. note::
| Author: Coh3n
| Last Updated: 01 August 2011 by Coh3n
Example:
.. code-block:: pascal
var
obs: TObstacle;
begin
obs := MSI_GetObstacle(LADDER_MG_DOWN);
result := MSI_SolveObstacle(obs);
end;
*)
function MSI_SolveObstacle(obs: TObstacle): boolean;
var
{$IFDEF REFLECTION}
i: integer;
{$ENDIF}
t: integer;
obsObj: TMSObject;
begin
if (not loggedIn) then
exit;
MSI_AddHeader('MSI_SolveObstacle');
obsObj := MSI_GetObject(obs.objConst);
if ((varType(obs.camera[0]) = varString) and (obs.camera[0] = 'n')) then
clickNorth(obs.camera[1])
else begin
makeCompass(obs.camera[0]);
setAngle(obs.camera[1]);
end;
while ((not result) and (t < 5)) do
begin
inc(t);
if (MSI_FindObject(obsObj, moLeft)) then
begin
wait(randomRange(1500, 2000));
result := MSI_WaitForMirror(obs);
end else begin
// click the obstacle's tile if it's not found
{$IFDEF REFLECTION}
if (not MSI_HookBroken[HOOK_WALKING]) then
for i := 0 to high(obs.endTiles) do
if (walkToTile(obs.endTiles[i], 0, 0)) then
begin
MSI_Debug('Clicked obstacle''s tile');
wait(randomRange(500, 1000));
break;
end;
{$ENDIF}
MSI_Debug('Setting obstacle to right click only');
obsObj.rightClickOnly := true; // in case uptext is failing
MSI_NotBoxes := [];
end;
end;
MSI_CloseHeader('MSI_SolveObstacle: ' + boolToStr(result));
end;