/lib/antirandoms/Sandwich.simba

http://github.com/Drags111/Reflection_Dev · Unknown · 217 lines · 190 code · 27 blank · 0 comment · 0 complexity · 23028e7d58705bcc3d47689b3a14c191 MD5 · raw file

  1. const
  2. RSandwichConst_NPCID = 8630;
  3. RSandwichConst_FoodInterface = 297;
  4. RSandwichConst_FoodAssigned = 48;
  5. var
  6. RSandwichVars_PortalIDs, RSandwichVars_ModelIDs: TIntegerArray;
  7. RSandwichVars_ModelNames, RSandwichVars_Finished: TStringArray;
  8. procedure RSandwich_SetVars;
  9. begin
  10. RSandwichVars_PortalIDs := [12731, 11373];
  11. RSandwichVars_ModelIDs := [10728, 10732, 10727, 10730, 10726, 45666, 10731];
  12. RSandwichVars_ModelNames := ['chocolate', 'triangle', 'roll', 'pie',
  13. 'baguette', 'doughnut', 'square'];
  14. RSandwichVars_Finished := ['leave', 'portal', 'exit'];
  15. end;
  16. function RSandwich_InRandom: Boolean;
  17. var
  18. SWLady: TNPC;
  19. begin
  20. Result := R_FindNPC(RSandwichConst_NPCID, True, SWLady);
  21. end;
  22. function RSandwich_HandleChat: Boolean;
  23. var
  24. Chat: String;
  25. SWLady: TNPC;
  26. begin
  27. Result := False;
  28. if R_FindNPC(RSandwichConst_NPCID, True, SWLady) then
  29. if RRandom_TalkToNPC(SWLady, False, 'Sandwich') then
  30. begin
  31. Chat := R_GetNPCChatMessage;
  32. Result := ArrInStr(RSandwichVars_Finished, R_GetNPCChatMessage);
  33. while ClickContinue(True, True) do
  34. begin
  35. if not Result then
  36. Result := ArrInStr(RSandwichVars_Finished, R_GetNPCChatMessage);
  37. Wait(500);
  38. end;
  39. if Result then
  40. R_Debug('Finished, trying to exit', 'Sandwich');
  41. end else
  42. begin
  43. R_Debug('Could not find Sandwich Lady', 'Sandwich');
  44. Exit;
  45. end;
  46. end;
  47. function RSandwich_InterfaceUp: Boolean;
  48. begin
  49. Result := R_ValidInterface(RSandwichConst_FoodInterface);
  50. end;
  51. function RSandwich_TargetString: String;
  52. begin
  53. Result := Trim(Between('Have a', 'for free!',
  54. R_GetInterfaceText(RSandwichConst_FoodInterface,
  55. RSandwichConst_FoodAssigned)));
  56. end;
  57. function RSandwich_HandleInterface: Boolean;
  58. var
  59. TargetString: String;
  60. TargetModel, i, T: Integer;
  61. TempInterface, ClickInterface: TInterfaceChild;
  62. begin
  63. if not RSandwich_InterfaceUp then Exit;
  64. TargetModel := -1;
  65. TargetString := RSandwich_TargetString;
  66. if (TargetString = '') then
  67. begin
  68. R_Debug('Unable to retrieve food string', 'Sandwich');
  69. Exit;
  70. end;
  71. for i := 0 to High(RSandwichVars_ModelNames) do
  72. if (Pos(RSandwichVars_ModelNames[i], TargetString) > 0) then
  73. begin
  74. R_Debug('Target food: ' + RSandwichVars_ModelNames[i], 'Sandwich');
  75. TargetModel := RSandwichVars_ModelIDs[i];
  76. Break;
  77. end;
  78. if (TargetModel > 0) then
  79. begin
  80. for i := 10 to 23 do
  81. begin
  82. TempInterface := R_GetInterfaceChild(RSandwichConst_FoodInterface, i);
  83. if (TargetModel = TempInterface.ModelID) then
  84. begin
  85. ClickInterface := R_GetInterfaceChild(RSandwichConst_FoodInterface, i);
  86. R_Debug('Found model match at child[' + ToStr(i) + ']', 'Sandwich');
  87. MarkTime(T);
  88. while (TimeFromMark(T) < 8000) do
  89. begin
  90. Result := not RSandwich_InterfaceUp;
  91. if Result then
  92. begin
  93. R_Debug('Clicked on Target model', 'Sandwich');
  94. Exit;
  95. end;
  96. R_ClickInterface(ClickInterface, 1);
  97. Wait(250);
  98. end;
  99. R_Debug('Clicking timed out', 'Sandwich');
  100. Exit;
  101. end;
  102. end;
  103. R_Debug('Unable to match Target model with any model', 'Sandwich');
  104. R_Debug('Trying to use child[22]', 'Sandwich');
  105. ClickInterface := R_GetInterfaceChild(RSandwichConst_FoodInterface, 22);
  106. MarkTime(T);
  107. while (TimeFromMark(T) < 8000) do
  108. begin
  109. Result := not RSandwich_InterfaceUp;
  110. if Result then
  111. begin
  112. R_Debug('Clicked on Target model', 'Sandwich');
  113. Exit;
  114. end;
  115. R_ClickInterface(ClickInterface, 1);
  116. Wait(250);
  117. end;
  118. R_Debug('Clicking timed out', 'Sandwich');
  119. Exit;
  120. end else
  121. begin
  122. R_Debug('Unable to match Target string with model ID', 'Sandwich');
  123. Exit;
  124. end;
  125. end;
  126. function RSandwich_Leave: Boolean;
  127. var
  128. Portal: TRSObject;
  129. P: TPoint;
  130. X, Y, T: Integer;
  131. begin
  132. Portal := R_GetObjectEx(RSandwichVars_PortalIDs, OBJ_INTERACTABLE, 30);
  133. if(Portal = NULL_RSOBJECT)then
  134. begin
  135. R_Debug('Unable to find portal. Go buy Portal 2..', 'Sandwich');
  136. Exit;
  137. end;
  138. if(R_DistanceFromTile(Portal.Tile) > 4)then
  139. begin
  140. if not R_WalkToTile(Portal.Tile, 1, 0)then
  141. begin
  142. R_Debug('Unable to walk to Portal.', 'Sandwich');
  143. Exit;
  144. end;
  145. Wait(300+Random(50));
  146. end;
  147. P := R_TileToMS(Portal.Tile, 0);
  148. MMouse(P.x, P.y, 10, 10);
  149. wait(25+Random(25));
  150. Result := R_OptionExists('enter');
  151. if not Result then
  152. Exit;
  153. GetMousePos(X, Y);
  154. Mouse(X, Y, 0, 0, false);
  155. wait(25+Random(25));
  156. Result := R_ChooseOption('enter');
  157. if not Result then
  158. Exit;
  159. R_WaitToMove(3000);
  160. R_Flag;
  161. MarkTime(T);
  162. while (RSandwich_InRandom and (TimeFromMark(T) < 8000)) do
  163. begin
  164. if not RSandwich_InRandom then Break;
  165. Wait(500);
  166. end;
  167. Result := not RSandwich_InRandom;
  168. end;
  169. function RSandwich_Solve: Boolean;
  170. var
  171. T: Integer;
  172. begin
  173. Result := False;
  174. RSandwich_SetVars;
  175. MarkTime(T);
  176. while RSandwich_InRandom and (TimeFromMark(T) < 240000) do
  177. begin
  178. if RSandwich_InterfaceUp then
  179. if not RSandwich_HandleInterface then
  180. begin
  181. R_Debug('Failed to handle food interface', 'Sandwich');
  182. end;
  183. if RSandwich_HandleChat then
  184. if not RSandwich_Leave then
  185. begin
  186. R_Debug('Unable to exit', 'Sandwich');
  187. end;
  188. end;
  189. Result := not RSandwich_InRandom;
  190. end;