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