Advertisement
Guest User

Magitek Flan Farming v1.4

a guest
May 7th, 2015
792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 9.94 KB | None | 0 0
  1. // # Magitek Flan Farming v1.4
  2. // # by /u/Dystaxia
  3. // #
  4. // # New in this version...
  5. // # - Enhanced logging to let you know exactly what's going on.              
  6. // # - Active detection of characters being ready to attack.
  7. // # - Some important values used for detecting the Hard button were corrected.
  8. // #
  9. // # Setup
  10. // # - This script was designed for Bluestacks in fullscreen mode.
  11. // # - Drag the crosshair (right-most button on the toolbar) to BlueStacks.
  12. // # - Keep Bladeblitz or Dragon in a character's first ability slot.
  13. // # - Ensure your inventory has some free space (no handling for that).
  14. // # - Click the event so that the Easy, Normal, Hard select menu is shown.
  15. // # - Click the play button on the toolbar or hit F9 to run.
  16. // # - Ctrl+F4 while the SCAR window is focused will stop execution.
  17. // #
  18. // # Enjoy!      
  19.  
  20. program MagitekFlanFarm;
  21. var countFlans, countTotal, countStamina: integer;
  22. var colorHard, colorGo, colorFlan, colorBattle, colorPart, colorNext, colorStamina: integer;
  23. var x1Hard, y1Hard, x2Hard, y2Hard, tolHard: integer;
  24. var x1Go, y1Go, x2Go, y2Go, tolGo: integer;
  25. var x1Part1, y1Part1, x2Part1, y2Part1, tolPart1: integer;
  26. var x1Part2, y1Part2, x2Part2, y2Part2, tolPart2: integer;
  27. var x1Flan, y1Flan, x2Flan, y2Flan, tolFlan: integer;
  28. var x1Battle, y1Battle, x2Battle, y2Battle, tolBattle: integer;
  29. var x1Next, y1Next, x2Next, y2Next, tolNext: integer;
  30. var x1Stamina, y1Stamina, x2Stamina, y2Stamina, tolStamina: integer;
  31. var xBegin, yBegin, xRetreat1, xRetreat2, yRetreat1, yRetreat2: integer;
  32. var xCamp, yCamp, xAbility, yAbility, xDefend, yDefend: integer;
  33. var xStamBack, yStamBack, timeWait: integer;
  34. var windowWidth, windowHeight: integer;
  35. var x, y: integer;
  36.  
  37. procedure InitSettings;
  38. begin
  39.  
  40.   timeWait := 720000; // Default: 720000 ms (12 minutes)
  41.  
  42. // # Below this are the colors that are used to search for various buttons.
  43. // # If you are having parrticular trouble, you can sample your own colors.
  44. // # Use the eye dropper on the toolbar to choose a color and change the value.
  45.  
  46.   colorHard := 987428; // Default: 987428
  47.   colorGo := 16777215; // Default: 16777215
  48.   colorPart := 7214848; // Default: 7214848
  49.   colorFlan := 15119703; // Default: 15119703
  50.   colorBattle := 16777215; // Default: 16777215
  51.   colorNext := 16716032; // Default: 16716032
  52.   colorStamina := 15778; // Default: 15778
  53.  
  54. // # Below this are tolerance values for the color finding procedures.
  55. // # If you are having trouble finding a color, perhaps increase the tolerance.
  56. // # This may produce unexpected results.
  57.  
  58.   tolHard := 0; // Default: 0
  59.   tolGo := 0; // Default: 0
  60.   tolPart1 := 0; // Default: 0
  61.   tolPart2 := 0; // Default: 0
  62.   tolFlan := 5; // Default: 5
  63.   tolBattle := 0; // Default: 0
  64.   tolNext := 0; // Default: 0
  65.   tolStamina := 0; // Default: 0
  66.  
  67. // # Below this are the values that define the bounding box used to restrict the
  68. // # color search to a specific area. Widening the search area can solve issues
  69. // # where the target is not within the bounds of the search.
  70.  
  71.   x1Hard := 0;
  72.   y1Hard := 700 * windowHeight div 1080;
  73.   x2Hard := windowWidth;
  74.   y2Hard := 800 * windowHeight div 1080;
  75.  
  76.   x1Go := 200 * windowWidth div 674;
  77.   y1Go := 790 * windowHeight div 1080;
  78.   x2Go := 475 * windowWidth div 674;  
  79.   y2Go := 900 * windowHeight div 1080;
  80.      
  81.   x1Part1 := 0;
  82.   y1Part1 := 400 * windowHeight div 1080;
  83.   x2Part1 := windowWidth;
  84.   y2Part1 := 500 * windowHeight div 1080;  
  85.  
  86.   x1Part2 := 0;
  87.   y1Part2 := 500 * windowHeight div 1080;  
  88.   x2Part2 := windowWidth;
  89.   y2Part2 := 600 * windowHeight div 1080;
  90.  
  91.   x1Flan := 100 * windowWidth div 674;
  92.   y1Flan := 350 * windowHeight div 1080;
  93.   x2Flan := 250 * windowWidth div 674;
  94.   y2Flan := 450 * windowHeight div 1080;
  95.  
  96.   xBegin := 477 * windowWidth div 674;
  97.   yBegin := 759 * windowHeight div 1080;
  98.  
  99.   x1Battle := 50 * windowWidth div 674;
  100.   y1Battle := 850 * windowHeight div 1080;
  101.   x2Battle := 400 * windowWidth div 674;  
  102.   y2Battle := 1000 * windowHeight div 1080;
  103.    
  104.   x1Next := 0;
  105.   y1Next := 0;
  106.   x2Next := 320 * windowWidth div 674;
  107.   y2Next := windowHeight;
  108.  
  109.   x1Stamina := 0;
  110.   y1Stamina := 565 * windowHeight div 1080;
  111.   x2Stamina := windowWidth;
  112.   y2Stamina := 650 * windowHeight div 1080;
  113.  
  114. // # Below this are values of fixed coordinates that do not rely on color to be pressed.
  115.  
  116.   xBegin := 460 * windowWidth div 674;
  117.   yBegin := 780 * windowHeight div 1080;
  118.   xRetreat1 := 550 * windowWidth div 674;
  119.   yRetreat1 := 900 * windowHeight div 1080;
  120.   xRetreat2 := 550 * windowWidth div 674;
  121.   yRetreat2 := 750 * windowHeight div 1080;
  122.   xCamp := 590 * windowWidth div 674;
  123.   yCamp := 215 * windowHeight div 1080;
  124.   xAbility := 300 * windowWidth div 674;
  125.   yAbility := 900 * windowHeight div 1080;
  126.   xDefend := 200 * windowWidth div 674;
  127.   yDefend := 900 * windowHeight div 1080;
  128.   xStamBack := 333 * windowWidth div 674;
  129.   yStamBack := 770 * windowHeight div 1080;  
  130.  
  131. end;
  132.  
  133. // # Below this are the routines of the script. You shouldn't have to modify
  134. // # anything below this line to get things working.
  135.  
  136. procedure ClickGo;
  137. begin
  138.   if FindColorTol(x, y, colorGo, x1Go, y1Go, x2Go, y2Go, tolGo) = true then
  139.   begin
  140.     WriteLn('#   - GO! located at ('+IntToStr(x)+','+IntToStr(y)+').');
  141.     Wait(1000);
  142.     ClickMouse(x, y, false);
  143.   end;
  144. end;
  145.  
  146. procedure ClickPartOne;
  147. begin
  148.   WriteLn('#   Awaiting Part 1 button. Searching for GO!...');
  149.   while FindColorTol(x, y, colorPart, x1Part1, y1Part1, x2Part1, y2Part1, tolPart1) = false do    
  150.   begin
  151.     ClickGo;
  152.     Wait(1000);
  153.   end;
  154.   WriteLn('#   - Part 1 button located at ('+IntToStr(x)+','+IntToStr(y)+').');
  155.   Wait(1000);
  156.   ClickMouse(x+100, y, false);
  157. end;
  158.  
  159. function CheckPartTwo: boolean;
  160. begin
  161.   Result := false;
  162.   if FindColorTol(x, y, colorPart, x1Part2, y1Part2, x2Part2, y2Part2, tolPart2) then
  163.   begin
  164.     WriteLn('#   - Part 2 button located at ('+IntToStr(x)+','+IntToStr(y)+').');
  165.     Result := true;
  166.   end;
  167. end;
  168.  
  169. function CheckFlan: boolean;
  170. begin
  171.   Result := false;
  172.   if FindColorTol(x, y, colorFlan, x1Flan, y1Flan, x2Flan, y2Flan, tolFlan) then
  173.   begin
  174.     countFlans := countFlans + 1;
  175.     WriteLn('#   Flan located at ('+IntToStr(x)+','+IntToStr(y)+'). ('+IntToStr(countFlans)+'/'+IntToStr(countTotal-countStamina)+')');
  176.     Result := true;
  177.   end;
  178. end;
  179.  
  180. procedure ClickAbilities;
  181. begin
  182.   if FindColorTol(x, y, colorBattle, x1Battle, y1Battle, x2Battle, y2Battle, tolBattle) = true then
  183.   begin
  184.     WriteLn('#   - Readied character detected at ('+IntToStr(x)+','+IntToStr(y)+').');
  185.     Wait(1000);
  186.     ClickMouse(xAbility, yAbility, false);
  187.     Wait(500);
  188.     ClickMouse(xDefend, yDefend, false);
  189.   end;
  190. end;
  191.  
  192. function CheckNext: boolean;
  193. begin
  194.   Result := false;
  195.   if FindColorTol(x, y, colorNext, x1Next, y1Next, x2Next, y2Next, tolNext) then
  196.   begin
  197.     WriteLn('#   - Next button located at ('+IntToStr(x)+','+IntToStr(y)+').');
  198.     Wait(1000);
  199.     ClickMouse(x, y, false);
  200.     Result := true;
  201.   end;
  202. end;
  203.  
  204. function CheckHard: boolean;
  205. begin
  206.   Result := false;
  207.   if FindColorTol(x, y, colorHard, x1Hard, y1Hard, x2Hard, y2Hard, 0) then
  208.   begin
  209.     WriteLn('#   - Hard button located at ('+IntToStr(x)+','+IntToStr(y)+').');
  210.     Result := true;
  211.   end;
  212. end;
  213.  
  214. procedure Retreat;
  215. begin
  216.   ClickMouse(xRetreat1, yRetreat1, false);
  217.   Wait(1000);
  218.   ClickMouse(xRetreat2, yRetreat2, false);
  219.   Wait(1000);
  220.   WriteLn('#   Awaiting Hard button. Searching for Next...');
  221.   while CheckHard = false do
  222.   begin
  223.     Wait(2000);
  224.     CheckNext;
  225.   end;
  226. end;
  227.  
  228. procedure CampRetreat;
  229. begin
  230.   ClickMouse(xCamp, yCamp, false);
  231.   WriteLn('#   - Camp button has been clicked at ('+IntToStr(xCamp)+','+IntToStr(yCamp)+').');
  232.   Wait(2000);
  233.   Retreat;
  234. end;
  235.  
  236. function CheckStamina: boolean;
  237. begin
  238.   Result := false;
  239.   if FindColorTol(x, y, colorStamina, x1Stamina, y1Stamina, x2Stamina, y2Stamina, tolStamina) then
  240.   begin
  241.     countStamina := countStamina + 1;
  242.     WriteLn('#   Out of stamina screen detected at ('+IntToStr(x)+','+IntToStr(y)+'). ('+IntToStr(countStamina)+')');
  243.     Result := true;
  244.   end;
  245. end;
  246.  
  247. begin
  248. countTotal := 0;
  249. countStamina := 0;
  250. countFlans := 0;
  251. ClickMouse(1, 1, false);
  252. Wait(500);
  253. GetWindowSize(GetActiveWindow, windowWidth, windowHeight);
  254. WriteLn('');
  255. WriteLn('# Window size determined. (W: '+IntToStr(windowWidth)+', H: '+IntToStr(windowHeight)+')');
  256. InitSettings;
  257. while 1 <> 2 do
  258. begin
  259.   countTotal := countTotal + 1;
  260.   WriteLn('');
  261.   WriteLn('# Run ' + IntToStr(countTotal) + ' initiating.');
  262.   WriteLn('#   Searching for Hard button...');
  263.   while CheckHard = false do
  264.   begin
  265.     Wait(1000);
  266.   end;
  267.   Wait(1000);
  268.   ClickMouse(x, y, false);
  269.   ClickPartOne;
  270.   Wait(2000);
  271.   if CheckFlan then
  272.   begin
  273.     Wait(1000);
  274.     WriteLn('#   - Engaging...');
  275.     ClickMouse(xBegin, yBegin, false);      
  276.     Wait(4000);
  277.     while CheckNext = false do
  278.     begin
  279.       ClickAbilities;
  280.       Wait(2000);
  281.     end;
  282.     WriteLn('#   - Battle complete.');
  283.     WriteLn('#   Awaiting Part 2 button. Searching for Next...');
  284.     while CheckPartTwo = false do
  285.     begin
  286.       CheckNext;
  287.       Wait(1000);
  288.     end;
  289.     Wait(1000);
  290.     WriteLn('#   Retreating...');
  291.     CampRetreat;
  292.     WriteLn('# Run '+IntToStr(countTotal)+' completed.');
  293.   end else
  294.   begin
  295.     if CheckStamina = false then
  296.     begin
  297.       WriteLn('#   Flan was not found. ('+IntToStr(countTotal-countStamina-countFlans)+'/'+IntToStr(countTotal-countStamina)+')');
  298.       WriteLn('#   - Retreating...');
  299.       Wait(2000);
  300.       Retreat;
  301.       WriteLn('# Run '+IntToStr(countTotal)+' completed.');
  302.     end else
  303.       begin
  304.         ClickMouse(xStamBack, yStamBack, false);      
  305.         Wait(500);
  306.         WriteLn('#   - Retreating...');
  307.         CampRetreat;                                            
  308.          WriteLn('# Run '+IntToStr(countTotal)+' completed.');
  309.         WriteLn('');
  310.         WriteLn('# Waiting'+IntToStr(timeWait div 60000)+' minutes.');
  311.         Wait(timeWait);      
  312.       end;
  313.   end;
  314. end;
  315. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement