PageRenderTime 66ms CodeModel.GetById 59ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/gametab/gametab.simba

http://github.com/Drags111/Reflection_Dev
Unknown | 387 lines | 298 code | 89 blank | 0 comment | 0 complexity | 0f6966a7aa5b813bf34fe855e3b1a4e3 MD5 | raw file
  1(*
  2GameTab
  3=======
  4
  5All the routines regarding game tab switching, world map, minimap levels, and
  6things of that nature.
  7
  8{Gametab constants}
  9  RTAB_FRIENDSLIST = 99;
 10  RTAB_CHAT = 100;
 11  RTAB_CLANCHAT = 101;
 12  RTAB_OPTIONS = 102;
 13  RTAB_EMOTES = 103;
 14  RTAB_MUSIC = 104;
 15  RTAB_NOTES = 105;
 16  RTAB_COMBAT = 128;
 17  RTAB_TASKS = 129;
 18  RTAB_STATS = 130;
 19  RTAB_QUESTS = 131;
 20  RTAB_INVENTORY = 132;
 21  RTAB_EQUIPMENT = 133;
 22  RTAB_PRAYER = 134;
 23  RTAB_SPELLBOOK = 135;
 24
 25*)
 26
 27(*
 28R_CurrentGameTab
 29~~~~~~~~~~~~~~~~
 30
 31.. code-block:: pascal
 32
 33    function R_CurrentGameTab: Integer;
 34
 35Returns the gametab index (one of the constants) of the active game tab.
 36
 37.. note::
 38
 39  by Drags111
 40
 41*)
 42function R_CurrentGameTab: Integer;
 43var
 44  GameTabs: TIntegerArray;
 45  I, Child, TextureID: Integer;
 46begin
 47  Result := -1;
 48  GameTabs := [RTAB_FRIENDSLIST, RTAB_CHAT, RTAB_CLANCHAT, RTAB_OPTIONS,
 49               RTAB_EMOTES, RTAB_MUSIC, RTAB_NOTES, RTAB_COMBAT, RTAB_TASKS,
 50               RTAB_STATS, RTAB_QUESTS, RTAB_INVENTORY, RTAB_EQUIPMENT,
 51               RTAB_PRAYER, RTAB_SPELLBOOK];
 52  for I := 0 to High(GameTabs)do
 53  begin
 54    Child := R_GetInterfaceChildRef(INTERFACE_GAMETAB, GameTabs[I]);
 55    TextureID := SmartGetFieldInt(Child, hook_interface_TextureID);
 56    SmartFreeObject(Child);
 57    if(TextureID = 1836)then
 58    begin
 59      Result := GameTabs[I];
 60      Exit;
 61    end;
 62  end;
 63end;
 64
 65(*
 66R_GameTab
 67~~~~~~~~~
 68
 69.. code-block:: pascal
 70
 71    function R_GameTab(Tab: Integer): Boolean;
 72
 73Clicks the specified GameTab (see constants.simba for a list of valid
 74GameTab constants).
 75
 76.. note::
 77
 78  by Drags111
 79
 80*)
 81function R_GameTab(Tab: Integer): Boolean;
 82var
 83  ChildObj, TextureID, T: Integer;
 84  GameTabs: TIntegerArray;
 85  Child: TInterfaceChild;
 86begin
 87  Result := False;
 88  GameTabs := [RTAB_FRIENDSLIST, RTAB_CHAT, RTAB_CLANCHAT, RTAB_OPTIONS,
 89               RTAB_EMOTES, RTAB_MUSIC, RTAB_NOTES, RTAB_COMBAT, RTAB_TASKS,
 90               RTAB_STATS, RTAB_QUESTS, RTAB_INVENTORY, RTAB_EQUIPMENT,
 91               RTAB_PRAYER, RTAB_SPELLBOOK];
 92  if not InIntArray(GameTabs, Tab)then
 93  begin
 94    R_Debug('Invalid tab number', 'R_GameTab');
 95    Exit;
 96  end;
 97
 98  if(R_CurrentGameTab = Tab)then
 99  begin
100    Result := True;
101    Exit;
102  end;
103
104  if not R_ValidInterface(INTERFACE_GAMETAB)then
105    Exit;
106
107  ChildObj := R_GetInterfaceChildRef(INTERFACE_GAMETAB, Tab);
108  TextureID := SmartGetFieldInt(ChildObj, hook_interface_TextureID);
109  SmartFreeObject(ChildObj);
110
111  if(TextureID = 1836)then
112  begin
113    Result := True;
114    Exit;
115  end;
116
117  Child := R_GetInterfaceChild(INTERFACE_GAMETAB, Tab);
118
119  R_ClickInterface(Child, 1);
120  MarkTime(T);
121  while(TimeFromMark(T) < 2000)do
122  begin
123    Wait(50+RandoM(25));
124    Child := R_GetInterfaceChild(INTERFACE_GAMETAB, Tab);
125    if(Child.TextureID = 1836)then
126      Break;
127  end;
128
129  Result := (TimeFromMark(T) < 2000);
130end;
131
132(*
133R_GetMMLevels
134~~~~~~~~~~~~~
135
136.. code-block:: pascal
137
138    function R_GetMMLevels(Which: string): Integer;
139
140Returns the current value at the designated minimap level.
141
142.. note::
143
144  by lordsaturn, Drags111
145
146*)
147function R_GetMMLevels(Which: string): Integer;
148begin
149  Result := -1;
150  case LowerCase(Which) of
151    'hitpoints', 'hp', 'lp', 'lifepoints': Result := StrToInt(R_GetInterfaceText(INTERFACE_HITPOINTS, 8));
152    'prayer', 'pp'   : Result := StrToInt(R_GetInterfaceText(INTERFACE_PRAYER, 4));
153    'run', 'energy'  : Result := StrToInt(R_GetInterfaceText(INTERFACE_RUN, 5));
154    'sum', 'summoning': Result := StrToInt(R_GetInterfaceText(INTERFACE_SUMMONING, 5));
155    else R_Debug('Invaild string.', 'R_GetMMLevels');
156  end;
157end;
158
159(*
160R_ClickNorth
161~~~~~~~~~~~~
162
163.. code-block:: pascal
164
165    procedure R_ClickNorth;
166
167Clicks the compass icon next to the minimap to face the compass north.
168
169.. note::
170
171  by Drags111
172
173*)
174procedure R_ClickNorth;
175var
176  Compass: TInterfaceChild;
177begin
178  if not R_ValidInterface(INTERFACE_GAMETAB)then
179    Exit;
180  Compass := R_GetInterfaceChild(INTERFACE_GAMETAB, INTERFACE_GAMETAB_FACENORTH);
181  R_ClickInterface(Compass, 1);
182end;
183
184(*
185R_IsRunning
186~~~~~~~~~~~
187
188.. code-block:: pascal
189
190    function R_IsRunning: boolean;
191
192Returns true if you are running.
193
194.. note::
195
196  by Drags111
197
198*)
199function R_IsRunning: boolean;
200begin
201  Result := R_GetSetting(SETTING_RUN) = 1;
202end;
203
204(*
205R_SetRun
206~~~~~~~~
207
208.. code-block:: pascal
209
210    procedure R_SetRun(Run: Boolean);
211
212Sets the run to the condition specified.
213
214.. note::
215
216  by Drags111
217
218*)
219procedure R_SetRun(Run: Boolean);
220var
221  Button: TInterfaceChild;
222  T: Integer;
223begin
224  if not R_ValidInterface(INTERFACE_RUN)then
225    Exit;
226  if(Run = R_IsRunning)then
227    Exit;
228
229  Button := R_GetInterfaceChild(INTERFACE_RUN, 1);
230  R_ClickInterface(Button, 1);
231
232  MarkTime(T);
233  while(TimeFromMark(T) < 1000)do
234  begin
235    Wait(25+Random(50));
236    if(Run = R_IsRunning)then
237      Break;
238  end;
239end;
240
241(*
242R_IsResting
243~~~~~~~~~~~
244
245.. code-block:: pascal
246
247    function R_IsResting: boolean;
248
249Returns true if your player is performing the resting animation.
250
251.. note::
252
253  by Drags111
254
255*)
256function R_IsResting: boolean;
257var
258  Animations: TIntegerArray;
259begin
260  SetLength(Animations, 5);
261  Animations := [12108, 2033, 2716, 11786, 5713];
262  Result := InIntArray(Animations, R_GetAnimation);
263end;
264
265(*
266R_Rest
267~~~~~~
268
269.. code-block:: pascal
270
271    function R_Rest(MaxEnergy: integer): boolean;
272
273Uses the rest ability until the desired energy is reached.
274
275.. note::
276
277  by Drags111
278
279*)
280function R_Rest(MaxEnergy: integer): boolean;
281var
282  T, MT, Energy: integer;
283  RunIcon: TInterfaceChild;
284begin
285  Result := True;
286  MarkTime(MT);
287  Energy := R_GetMMLevels('Run');
288
289  if(Energy >= MaxEnergy)then
290    Exit;
291
292  Result := R_IsResting;
293  while(not Result)do
294  begin
295    if not LoggedIn or (TimeFromMark(MT) > 9000)then
296      Exit;
297    RunIcon := R_GetInterfaceChild(INTERFACE_RUN, 1);
298    R_ClickInterface(RunIcon, 2);
299    Wait(25+Random(50));
300    Result := R_ChooseOption('Rest');
301    if(Result)then
302    begin
303      MarkTime(T);
304      while((not R_IsResting) and (TimeFromMark(T) < 3000))do
305        wait(100+Random(100));
306      Result := (R_IsResting);
307    end;
308  end;
309
310  Energy := R_GetMMLevels('run');
311  while(Energy < MaxEnergy)do
312  begin
313    case Random(50) of
314      0..5: SleepAndMoveMouse(Random(1000));
315      else wait(100+Random(400));
316    end;
317    Energy := R_GetMMLevels('run');
318  end;
319end;
320
321(*
322R_WorldMapOpen
323~~~~~~~~~~~~~~
324
325.. code-block:: pascal
326
327    function R_WorldMapOpen : Boolean;
328
329Returns true if the World Map is open.
330
331.. note::
332
333  by Drags111
334
335*)
336function R_WorldMapOpen : Boolean;
337var
338  Map: TInterfaceChild;
339begin
340  Result := R_ValidInterface(755);
341  if not Result then
342    Exit;
343  Map := R_GetInterfaceChild(INTERFACE_WORLDMAP, 0);
344  Result := (Map.Width <> 0);
345end;
346
347(*
348R_CloseWorldMap
349~~~~~~~~~~~~~~~
350
351.. code-block:: pascal
352
353    function R_CloseWorldMap : Boolean;
354
355Closes the World Map. Returns true if it is successful.
356
357.. note::
358
359  by Drags111
360
361*)
362function R_CloseWorldMap : Boolean;
363var
364  T: Integer;
365  Button: TInterfaceChild;
366begin
367  Result := False;
368  if not R_WorldMapOpen then
369  begin
370    Result := True;
371    Exit;
372  end;
373
374  Button := R_GetInterfaceChild(INTERFACE_WORLDMAP, INTERFACE_WORLDMAP_CLOSE);
375  R_ClickInterface(Button, 1);
376
377  MarkTime(T);
378  while(TimeFromMark(T) < 5000)do
379  begin
380    wait(50+Random(50));
381    if not R_WorldMapOpen then
382      Break;
383  end;
384  Result := (TimeFromMark(T) < 5000);
385end;
386
387