Guest User

RuneScapeJJ Cooking Guild

a guest
Jan 14th, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 41.05 KB | None | 0 0
  1. program JJsCookingGuildCompetitionScript;
  2. {$DEFINE SMART}
  3. {$i SRL/srl.simba}
  4. {$i sps/sps.simba}
  5. //{$i SRL/SRL/misc/SmartGraphics.simba}
  6.  
  7. {* Introduction
  8. JJ's Cooking Guild Script | Made for the SRL Scripting Competition
  9. Start anywhere in RuneScape, use an account of 20+ combat to avoid the mugger
  10. from attacking you once we are in edgeville.
  11.  
  12. For the scripting competition it collects a chef's hat from scratch, and walks
  13. to the Cooking Guild. Once it is near the Cooking Guild it will collect 20+
  14. wheat and walk to the entrance. It will enter the guild and there is where the
  15. interesting part starts.
  16.  
  17. First it will fill the hopper with wheat until the
  18. flour bin is full. Once the bin is full it will start collecting the useful
  19. items in the guild. Those items are apples, jugs, empty pots and pie dishes.
  20.  
  21. Once the inventory is full it will return to the ground floor and see what it
  22. can make. It will drop the unnecessary items. It will try to make apple pie's
  23. and jug of wines if it has the ingredients. If there are any apple pie's made
  24. it will go to the 1st floor and bake it.
  25.  
  26. After that it will drop everything in the inventory and repeat the process. It
  27. will eventually run out of flour from the bin, that is why I capped it at
  28. 30 minutes of time. Due to a lack of time I didn't make it re-collect wheat.
  29.  
  30. Have fun judging this, please give it multiple tries before the final verdict
  31. is given.
  32.  
  33. Greetz,
  34.  
  35. J J.
  36.  
  37. PS: I included account details of a level 3, it might get attacked by a mugger
  38. when lodestone teleporting to edgeville.. so I would advise using your own!
  39. *}
  40.  
  41. const
  42.   GRAPE = 0;
  43.   POT = 1;
  44.   APPLE = 2;
  45.   JUG = 3;
  46.   DISH = 4;
  47.   DOUGH = 5;
  48.  
  49. type Item = record
  50.   Hue: Extended;
  51.   Sat: Extended;
  52.   Color: Integer;
  53.   Tol: Integer;
  54.   Uptext: TStringArray;
  55. end;
  56.  
  57. var
  58.   HatAttempt, Timer: Integer;
  59.   Items: Array[0..4] of Item;
  60.  
  61. procedure DeclarePlayers;
  62. begin
  63.   HowManyPlayers := 1;
  64.   NumberOfPlayers(HowManyPlayers);
  65.   CurrentPlayer := 0;
  66.   with Players[0] do
  67.   begin
  68.     Name        := '';
  69.     Pass        := '';
  70.     Pin         := '1234';
  71.     BoxRewards  := ['XP','xp','lamp'];
  72.     LampSkill   := Skill_Cooking;
  73.     Active      := True;
  74.   end;
  75. end;
  76.  
  77. {* DeclareItems
  78.  * Sets up the item record for each item
  79.  * Pretty nice stuff
  80. }
  81. procedure DeclareItems;
  82. var
  83.   i: Integer;
  84.   Hues, Sats: Array of Extended;
  85.   Colors, Tols: TIntegerArray;
  86.  
  87. begin
  88.   Hues := [0.21, 0.97, 0.40, 0.31, 0.40];
  89.   Sats := [0.94, 2.09, 0.36, 0.09, 0.36];
  90.   Colors := [6953849, 1717832, 2924866, 7500663, 2924866];
  91.   Tols := [18, 4, 14, 11, 14];
  92.  
  93.   for i:=0 to 4 do
  94.   begin
  95.     Items[i].Hue := Hues[i];
  96.     Items[i].Sat := Sats[i];
  97.     Items[i].Color := Colors[i];
  98.     Items[i].Tol := Tols[i];
  99.     case i of
  100.       0: Items[i].Uptext := ['rap', 'pes', 'Grapes'];
  101.       1: Items[i].Uptext := ['pty', 'pot', 'Empty'];
  102.       2: Items[i].Uptext := ['apple', 'ooking', 'ng ap'];
  103.       3: Items[i].Uptext := ['ug', 'Jug', 'e Ju'];
  104.       4: Items[i].Uptext := ['dish', 'Pie', 'Pie dish'];
  105.     end;
  106.   end;
  107. end;
  108.  
  109. {* FindAccurateObj
  110.  * Finds an object with great accuracy
  111.  * Uses multiple colors, tolerances and modifiers to make multiple TPA's that
  112.    store the points
  113.  * Once the points are stored it checks for nearby points in each array to
  114.    another array with a certain 'Distance'
  115.  * All nearby points are stored in a TPA. This TPA gets splitted into an ATPA
  116.  * The result is received by splitting each TPA in the ATPA, and then
  117.    calculating the middle of each TPA in the ATPA
  118. }
  119. function FindAccurateObj(Colors, Tolerances: TIntegerArray; HueMods, SatMods: TExtendedArray; Distance, X1, Y1, X2, Y2: Integer): TPointArray;
  120. var
  121.   i, j, k: Integer;
  122.   AreaCenter: TPoint;
  123.   Coords, ATPA: T2DPointArray;
  124.   TPA: TPointArray;
  125.  
  126. begin
  127.   AreaCenter := Point((X1 + X2) / 2, (Y1 + Y2) / 2);
  128.   SetLength(Coords, High(Colors)+1);
  129.   SetColorToleranceSpeed(2);
  130.  
  131.   for i:=0 to high(Colors) do
  132.   begin
  133.     SetColorspeed2Modifiers(HueMods[i], SatMods[i]);
  134.     FindColorsSpiralTolerance(AreaCenter.x, AreaCenter.y, Coords[i], Colors[i], X1, Y1, X2, Y2, Tolerances[i]);
  135.   end;
  136.  
  137.   for i:=0 to high(Coords) do
  138.     for j:=0 to high(Coords[i]) do
  139.       for k:=0 to high(Coords) do
  140.       if not(i = k) then
  141.         if NearbyPointInArray(Coords[i][j], Distance, Coords[k]) then
  142.         begin
  143.           SetLength(TPA, Length(TPA)+1);
  144.           TPA[Length(TPA)-1] := Coords[i][j];
  145.           //writeln('near coord in array: ' + ToStr(Coords[i][j]));
  146.         end;
  147.  
  148.   if Length(TPA) > 0 then
  149.   begin
  150.     SplitTPAWrap(TPA, Distance, ATPA);
  151.     SortATPASize(ATPA, true);
  152.     SetLength(Result, high(ATPA)+1);
  153.     for i:=0 to high(ATPA) do
  154.       Result[i] := MiddleTPA(ATPA[i]);
  155.   end;
  156. end;
  157.  
  158. {* FindObjByTPA
  159.  * Finds an object by using a single combination of colors/tolerances/modifiers
  160.  * Multiple handlings are used with the TPA result to get a nice result
  161.  * Returns a TPointArray with possible points
  162. }
  163. function FindObjByTPA(Color, Tolerance: Integer; HueMod, SatMod: Extended; SplitSize, X1, Y1, X2, Y2: Integer): TPointArray;
  164. var
  165.   X, Y, i: Integer;
  166.   TPA: TPointArray;
  167.   ATPA: T2DPointArray;
  168.  
  169. begin
  170.   SetColorToleranceSpeed(2);
  171.   SetColorspeed2Modifiers(HueMod, SatMod);
  172.  
  173.   if FindColorsSpiralTolerance(X, Y, TPA, Color, X1, Y1, X2, Y2, Tolerance) then
  174.   begin
  175.     ATPA := SplitTPA(TPA, SplitSize);
  176.     SortATPASize(ATPA, True);
  177.     SetLength(Result, Length(ATPA));
  178.     for i:=0 to high(ATPA) do
  179.     begin
  180.        //SMART_DrawBox(GetTPABounds(ATPA[i]));
  181.        Result[i] := MiddleTPA(ATPA[i]);
  182.     end;
  183.     //SMART_DrawDots(Result);
  184.   end;
  185. end;
  186.  
  187. ////////////////////////////////////////////////////////////////////////////////
  188. ///////////////////////// FUNCTIONS TO GET A CHEF'S HAT ////////////////////////
  189. ////////////////////////////////////////////////////////////////////////////////
  190.  
  191. {* WaitUntilNotMoving
  192.  * Waits until the player is not moving anymore
  193. }
  194. procedure WaitUntilNotMoving;
  195. begin
  196.   Wait(RandomRange(300, 600));
  197.   while (IsMoving) do
  198.     Wait(RandomRange(150, 300));
  199.   Wait(RandomRange(300, 600));
  200. end;
  201.  
  202. {* SwitchTab(Tab: Integer);
  203.  * Checks if the current tab is right, if not it changes and waits a bit
  204. }
  205. procedure SwitchTab(Tab: Integer);
  206. begin
  207.   if not(GetCurrentTab = Tab) then
  208.   begin
  209.     GameTab(Tab);
  210.     Wait(RandomRange(500, 1000));
  211.   end;
  212. end;
  213.  
  214. {* LodestoneTo(String location)
  215.  * Lodestone teleports to Lumbridge or Edgeville
  216.  * Once arrived in the desired location, it rests until more than 80% energy
  217. }
  218. function LodestoneTo(Location: String): boolean;
  219. var
  220.   X, Y, HomeTeleport, T: Integer;
  221.   S: String;
  222.  
  223. begin
  224.   SwitchTab(tab_Magic);
  225.  
  226.   HomeTeleport := DTMFromString('mbQAAAHicY2VgYFjIxsCwgA1CzwDiVUB8lomB4QgQXwPic1C878gnhrY5N1AwP1A/OmbEgsEAAMfVEgE=');
  227.   if FindDTM(HomeTeleport, X, Y, MIX1, MIY1, MIX2, MIY2) then
  228.   begin
  229.     MMouse(X, Y, RandomRange(-5, 5), RandomRange(-5, 5));
  230.     ClickMouse2(1);
  231.     if WaitFunc(@LodestoneScreen, 500, 2500) then
  232.     begin
  233.       case location of
  234.         'lumbridge': MouseBox(320, 233, 334, 245, 1);
  235.         'edgeville': MouseBox(289, 148, 299, 162, 1);
  236.       end;
  237.       Wait(RandomRange(17500, 22500));
  238.       MarkTime(t);
  239.       SetRest;
  240.       while(TimeFromMark(T) < 20000) do
  241.       begin
  242.         Wait(RandomRange(1000, 2000));
  243.         if (GetMMLevels('run', S) >= RandomRange(80, 90)) then
  244.           break;
  245.       end;
  246.       Result := True;
  247.     end;
  248.   end;
  249.   FreeDTM(HomeTeleport);
  250. end;
  251.  
  252. {* ToBeefyBills
  253.  * Walks from the Lumbridge Lodestone to Beefy Bills by using radial walking
  254.    and multiple SPS options.
  255. }
  256. function ToBeefyBills: boolean;
  257. var
  258.   X, Y, Attempts: Integer;
  259.   TPA, QuestToBill: TPointArray;
  260.   MyPos, P, T: TPoint;
  261.  
  262. begin
  263.   SymbolAccuracy := 0.6;
  264.   SPS_Setup(RUNESCAPE_SURFACE, ['11_8', '11_9']);
  265.   QuestToBill := [Point(4701, 3569), Point(4701, 3563), Point(4699, 3555),
  266.                   Point(4697, 3550), Point(4692, 3547), Point(4683, 3545),
  267.                   Point(4675, 3544), Point(4668, 3545), Point(4655, 3544),
  268.                   Point(4647, 3544), Point(4637, 3543), Point(4625, 3541),
  269.                   Point(4615, 3540), Point(4609, 3535), Point(4602, 3530),
  270.                   Point(4598, 3525), Point(4597, 3517), Point(4595, 3511),
  271.                   Point(4596, 3505), Point(4596, 3497), Point(4594, 3488),
  272.                   Point(4595, 3481), Point(4596, 3469), Point(4593, 3460),
  273.                   Point(4592, 3454), Point(4589, 3437), Point(4584, 3433),
  274.                   Point(4578, 3429), Point(4572, 3426), Point(4566, 3423),
  275.                   Point(4559, 3418), Point(4554, 3413), Point(4548, 3409),
  276.                   Point(4544, 3402), Point(4543, 3389), Point(4547, 3385),
  277.                   Point(4551, 3387)];
  278.  
  279.   {* Symbol Radial Walking
  280.    * Using multiple symbols to roughly know our position.
  281.    * While one of these symbols is found we can radial walk using the road
  282.   }
  283.   while FindSymbolsMulti(TPA, ['rest', 'dungeon', 'anvil', 'training dummy', 'furnace']) do
  284.   begin
  285.     Inc(Attempts);
  286.     if (Attempts > 15) then
  287.       break;
  288.     RadialWalkTolerance(5198671, 330, 359, 70, RandomRange(-2, 2), RandomRange(-2, 2), 25)
  289.   end;
  290.  
  291.   {* SPS Walking
  292.    * Checking were we got with the radial walk with symbols
  293.    * If the quest symbol is found we can use our path, else we need to walk
  294.      to the spot where symbol radial walk would've gotten us. We can get there
  295.      by using blindwalk
  296.   }
  297.   if FindSymbol(X, Y, 'quest') then
  298.   begin
  299.     RadialWalkTolerance(5330003, 250, 350, 70, RandomRange(-2, 2), RandomRange(-2, 2), 25);
  300.  
  301.     if SPS_WalkPath(QuestToBill) then
  302.       Result := True
  303.   end else
  304.   begin
  305.     MyPos := SPS_GetMyPos;
  306.     P := Point(RandomRange(4663, 4679), RandomRange(3535, 3551));
  307.     if SPS_BlindWalk(P) then
  308.     begin
  309.       if SPS_WalkPath(QuestToBill) then
  310.         Result := True;
  311.     end else
  312.     begin
  313.       T := Point(RandomRange(4543, 4555), RandomRange(3375, 3383));
  314.       if SPS_BlindWalk(T) then
  315.         Result := True;
  316.     end;
  317.   end;
  318. end;
  319.  
  320. {* BeefyCheck
  321.  * If the shop symbol is found we are at Beefy Bill
  322.  * However, the shop symbol is in Lumbridge aswell so we check if we aren't
  323.    finding some symbols that are in lumbridge
  324.  * Also waits until we are done with walking because the function is called
  325.    after walking there
  326. }
  327. function BeefyCheck: Boolean;
  328. var
  329.   X, Y: Integer;
  330.  
  331. begin
  332.   WaitUntilNotMoving;
  333.  
  334.   if FindSymbol(X, Y, 'shop') then
  335.   begin
  336.     if not FindSymbol(X, Y, 'training dummy') then
  337.       Result := True;
  338.   end;
  339. end;
  340.  
  341. {* TradeBeefyBill
  342.  * Uses FindAccurateObj to locate BeefyBill
  343.  * Beefy Bill's colors are similar to the cow & wagon, but by using multiple
  344.    colors Beefy Bill gets detected properly
  345. }
  346. function TradeBeefyBill: boolean;
  347. var
  348.   i: Integer;
  349.   TPA: TPointArray;
  350.  
  351. begin
  352.   TPA := FindAccurateObj([6188652, 10537684], [13, 18], [0.67, 0.20], [0.07, 1.65], 5, MSX1, MSY1, MSX2, MSY2);
  353.   if Length(TPA) > 0 then
  354.   begin
  355.     for i:=0 to high(TPA) do
  356.     begin
  357.       MMouse(TPA[i].x, TPA[i].y, RandomRange(-3, 3), RandomRange(-3, 3));
  358.       if WaitUptextMulti(['eefy', 'ill'], 500) then
  359.       begin
  360.         ClickMouse2(0);
  361.         if WaitOptionMulti(['rade', 'Trade'], 500) then
  362.         begin
  363.           Result := True;
  364.           break;
  365.         end;
  366.       end;
  367.    end;
  368.   end;
  369. end;
  370.  
  371. {* WaitShop
  372.  * Waits until the shop screen is up
  373.  * The one in the SRL repository does not work properly for Beefy Bill's shop
  374. }
  375. function WaitShop: boolean;
  376. begin
  377.   Result := CountColorTolerance(789516, MSX1, MSY1, MSX2, MSY2, 20) > 500;
  378. end;
  379.  
  380. {* BuyChefsHat
  381.  * Buys a chef's hat in Beefy Bill's store.
  382.  * Uses the WaitShop function to determine when the shop is open
  383. }
  384. function BuyChefsHat: boolean;
  385. var
  386.   HatDTM, X, Y: Integer;
  387.  
  388. begin
  389.   WaitUntilNotMoving;
  390.  
  391.   if WaitFunc(@WaitShop, 500, 2500) then
  392.   begin
  393.     HatDTM := DTMFromString('mWAAAAHicY2FgYOhmYWDoAeImIJ4CxGVMDAwZTBC6DojnTJ0KVMUExyJAkh8JM6JhEAAAhgwGLQ==');
  394.     if FindDTM(HatDTM, X, Y, 16, 110, 484, 276) then
  395.     begin
  396.       MMouse(X, Y, RandomRange(-5, 5), RandomRange(-5, 5));
  397.       ClickMouse2(0);
  398.       if WaitOptionMulti(['1', 'uy 1', 'Buy 1'], 500) then
  399.         Result := True;
  400.     end;
  401.     FreeDtm(HatDTM);
  402.   end;
  403. end;
  404.  
  405. {* CloseShop
  406.  * Closes the shop and waits until the mage tab is visible.
  407.  * When the mage tab is visible we
  408. }
  409. procedure CloseShop;
  410. begin
  411.   MouseBox(498, 17, 503, 24, 1);
  412.   while not(TabExists(tab_Magic)) do
  413.     Wait(RandomRange(100, 200));
  414.   Wait(RandomRange(500, 1000));
  415. end;
  416.  
  417. {* GetChefsHat
  418.  * Uses all of the functions above to get a chef's hat from any position
  419.    in RuneScape
  420.  * Has multiple failsafes to make sure we get the chef's hat as it's crucial
  421.    for the other steps in the script.
  422.  * There are also failsafes in the functions used in here.
  423. }
  424. function GetChefsHat: boolean;
  425. begin
  426.   if LodestoneTo('lumbridge') then
  427.     if ToBeefyBills then
  428.       if BeefyCheck then
  429.         if TradeBeefyBill then
  430.         begin
  431.           if BuyChefsHat then
  432.           begin
  433.             Wait(RandomRange(1500, 3000));
  434.             if not(PinScreen) then
  435.             begin
  436.               CloseShop;
  437.               Result := True;
  438.               Exit;
  439.             end else
  440.             begin
  441.               if InPin(Players[0].Pin) then
  442.               begin
  443.                 if TradeBeefyBill then
  444.                   if BuyChefsHat then
  445.                   begin
  446.                     CloseShop;
  447.                     Result := True;
  448.                     Exit;
  449.                   end;
  450.               end;
  451.             end;
  452.           end;
  453.         end;
  454.  
  455.   Inc(HatAttempt);
  456.   while HatAttempt < 5 do
  457.     GetChefsHat;
  458. end;
  459.  
  460. ////////////////////////////////////////////////////////////////////////////////
  461. ///////////////////////////// FUNCTIONS TO GET WHEAT ///////////////////////////
  462. ////////////////////////////////////////////////////////////////////////////////
  463.  
  464. {* ToEastEdge
  465.  * Walks from the edgeville lodestone to the eastern part of edgeville
  466.  * Relies on symbols and radial road walking
  467. }
  468. function ToEastEdge: boolean;
  469. var
  470.   Attempts, X, Y: Integer;
  471.   TPA: TPointArray;
  472.  
  473. begin
  474.   SymbolAccuracy := 0.3;
  475.  
  476.   while FindSymbolsMulti(TPA, ['water', 'shop', 'bank', 'lodestone', 'furnace']) do
  477.   begin
  478.     Inc(Attempts);
  479.     if (Attempts > 10) then
  480.       break;
  481.     RadialWalkTolerance(5197652, 80, 100, 70, RandomRange(-2, 2), RandomRange(-2, 2), 15)
  482.   end;
  483.  
  484.   if FindSymbol(X, Y, 'furnace') then
  485.     Result := True;
  486. end;
  487.  
  488. {* ToWheat
  489.  * Walks from eastern edgeville to the wheat spot north of the cooking guild
  490.  * Relies purely on SPS
  491. }
  492. function EdgeToWheat: boolean;
  493. var
  494.   PathToWheat: TPointArray;
  495.  
  496. begin
  497.   SPS_Setup(RUNESCAPE_SURFACE, ['10_6', '10_7', '11_7', '11_6']);
  498.   PathToWheat := [Point(4288, 2618), Point(4296, 2615), Point(4303, 2610),
  499.                   Point(4310, 2607), Point(4316, 2604), Point(4324, 2599),
  500.                   Point(4334, 2596), Point(4342, 2591), Point(4348, 2583),
  501.                   Point(4351, 2576), Point(4360, 2576), Point(4371, 2577),
  502.                   Point(4375, 2581), Point(4377, 2589), Point(4378, 2597),
  503.                   Point(4378, 2607), Point(4378, 2615), Point(4378, 2622),
  504.                   Point(4378, 2631), Point(4377, 2639), Point(4377, 2646),
  505.                   Point(4378, 2656), Point(4376, 2666), Point(4377, 2676),
  506.                   Point(4378, 2684), Point(4379, 2692), Point(4379, 2701),
  507.                   Point(4379, 2713), Point(4379, 2728), Point(4380, 2737),
  508.                   Point(4380, 2745), Point(4381, 2755), Point(4381, 2766),
  509.                   Point(4384, 2772), Point(4388, 2774), Point(4389, 2783),
  510.                   Point(4380, 2789), Point(4379, 2797), Point(4378, 2808),
  511.                   Point(4380, 2815), Point(4384, 2821), Point(4390, 2825),
  512.                   Point(4396, 2825), Point(4402, 2823), Point(4405, 2819)];
  513.  
  514.   if SPS_WalkPath(PathToWheat) then
  515.     Result := True;
  516. end;
  517.  
  518. {* GetToWheat
  519.  * Uses all of the cooking guild functions to get to the guild
  520.  * Has multiple failsafes to make sure we get to the guild
  521.  * There are also failsafes in the functions used in here
  522. }
  523. function GetToWheat: boolean;
  524. begin
  525.   if LodestoneTo('edgeville') then
  526.     if ToEastEdge then
  527.       if EdgeToWheat then
  528.         Result := True;
  529. end;
  530.  
  531. {* IsFenceClosed
  532.  * Checks if the fence is closed
  533.  * Uses a custom TPA function and uptext to define the result
  534. }
  535. function IsFenceClosed: boolean;
  536. var
  537.   i: Integer;
  538.   P: TPointArray;
  539.  
  540. begin
  541.   P := FindObjByTPA(5077642, 9, 0.05, 0.06, 5, MSX1+50, MSY1+50, MSX2-50, MSY2-50);
  542.   for i:=0 to high(P) do
  543.   begin
  544.     MMouse(P[i].x, P[i].y, RandomRange(-2, 2), RandomRange(-2, 2));
  545.     if WaitUpTextMulti(['Open', 'pen'], 500) then
  546.     begin
  547.       Result := True;
  548.       break;
  549.     end;
  550.   end;
  551. end;
  552.  
  553. {* PositionField
  554.  * Calculactes the wheat field entrance and walks there
  555. }
  556. procedure PositionField;
  557. var
  558.   P: TPointArray;
  559.  
  560. begin
  561.   P := FindObjByTPA(2988238, 10, 0.28, 2.60, 5, MMX1+25, MMY1+25, MMX2-25, MMY2-25);
  562.   MMouse(P[0].x, P[0].y, RandomRange(-2, 2), RandomRange(-2, 2));
  563.   ClickMouse2(1);
  564.   WaitUntilNotMoving;
  565. end;
  566.  
  567. {* HandleFence
  568.  * Checks if the fence is opened or closed and makes a decision based on this
  569.  * Opens the fence if it's closed
  570. }
  571. function HandleFence: boolean;
  572. begin
  573.   PositionField;
  574.   WaitUntilNotMoving;
  575.   case IsFenceClosed of
  576.     True:  if WaitUpTextMulti(['Open', 'pen'], 500) then
  577.            begin
  578.              case RandomRange(0, 3) of
  579.                0, 1: begin;
  580.                        ClickMouse2(1);
  581.                        Result := True;
  582.                      end;
  583.                2: begin
  584.                     ClickMouse2(0);
  585.                     if WaitOptionMulti(['Open', 'pen'], 500) then
  586.                       Result := True;
  587.                   end;
  588.              end;
  589.            end;
  590.     False: Result := True;
  591.   end;
  592.   WaitUntilNotMoving;
  593. end;
  594.  
  595. {* FullInv
  596.  * Checks if your inventory is full
  597.  * Returns true if it's full, false if it isn't full.
  598. }
  599. function FullInv: Boolean;
  600. begin
  601.   SwitchTab(tab_Inv);
  602.  
  603.   if InvFull then
  604.     Result := True
  605. end;
  606.  
  607. {* PickWheat
  608.  * Picks wheat
  609.  * Using TPA to get the wheat points
  610. }
  611. procedure PickWheat;
  612. var
  613.   i: Integer;
  614.   P: TPointArray;
  615.  
  616. begin
  617.   P := FindObjByTPA(5939611, 12, 0.15, 0.73, 3, MSX1+50, MSY1+50, MSX2-50, MSY2-50);
  618.   SortTPAFrom(P, Point(MSCX, MSCY));
  619.  
  620.   for i:=0 to high(P) do
  621.   begin
  622.     MMouse(P[i].x, P[i].y, RandomRange(-1, 1), RandomRange(-1, 1));
  623.     if WaitUpTextMulti(['heat', 'ick', 'Wheat', 'Pick'], 500) then
  624.     begin
  625.       ClickMouse2(1);
  626.       WaitUntilNotMoving;
  627.       Wait(RandomRange(300, 600));
  628.       break;
  629.     end;
  630.   end;
  631. end;
  632.  
  633. {* EquipHat
  634.  * Equips the chef's hat to free inventory space and to gain access to the
  635.    Cooking guild
  636. }
  637. procedure EquipHat;
  638. var
  639.   HatDTM, X, Y: Integer;
  640.  
  641. begin
  642.   Switchtab(tab_Inv);
  643.   HatDTM := DTMFromString('mWAAAAHicY2FgYOhmYWDoAeImIJ4CxGVMDAwZTBC6DojnTJ0KVMUExyJAkh8JM6JhEAAAhgwGLQ==');
  644.   if FindDTM(HatDTM, X, Y, MIX1, MIY1, MIX2, MIY2) then
  645.     Mouse(X, Y, RandomRange(-5, 5), RandomRange(-5, 5), 1);
  646.   FreeDTM(HatDTM);
  647. end;
  648.  
  649. {* GetWheat
  650.  * Handles everything to get a full inventory of wheat
  651. }
  652. function GetWheat: boolean;
  653. var
  654.   MaxTime: Integer;
  655.  
  656. begin
  657.   MaxTime := GetTimeRunning + 90000;
  658.   if HandleFence then
  659.     while ((GetTimeRunning < MaxTime) and not(FullInv)) do
  660.       while not(FullInv) do
  661.         PickWheat;
  662.  
  663.   if GetTimeRunning < MaxTime then
  664.     Result := True;
  665. end;
  666.  
  667. {* HandleWheat
  668.  * Handles everything to get a 14 wheat from scratch
  669.  * Lodestones to Edgeville, walks to the wheat, handles the fence and picks
  670.    an inventory full of wheat. In the meantime it also equips the chef's hat
  671. }
  672. function HandleWheat: boolean;
  673. begin
  674.   if GetToWheat then
  675.   begin
  676.     EquipHat;
  677.     if GetWheat then
  678.       Result := True;
  679.   end;
  680. end;
  681.  
  682. ////////////////////////////////////////////////////////////////////////////////
  683. /////////////////////// FUNCTIONS FOR THE COOKING GUILD ////////////////////////
  684. ////////////////////////////////////////////////////////////////////////////////
  685.  
  686. {* PositionGuild
  687.  * Calculactes the route from wheat field to cooking guild entrance
  688. }
  689. function PositionGuild: boolean;
  690. var
  691.   TPA: TPointArray;
  692.   P: TPoint;
  693.  
  694. begin
  695.   TPA := FindObjByTPA(2987217, 20, 0.26, 2.60, 5, MMX1+20, MMY1+20, MMX2-20, MMY2-20);
  696.   if Length(TPA) > 0 then
  697.   begin
  698.     SortTPAFrom(TPA, Point(MMCX, MMCY));
  699.     P := Point(TPA[0].x+5, TPA[0].y+75);
  700.     if (P.y > 160) then
  701.       P.y := 160;
  702.     MMouse(P.x, P.y, RandomRange(-3, 3), RandomRange(-3, 3));
  703.     ClickMouse2(1);
  704.     WaitUntilNotMoving;
  705.     Result := True;
  706.   end;
  707. end;
  708.  
  709. {* EnterGuild
  710.  * Clicks on the Cooking Guild door
  711.  * Uses a TPA to find the door, because everything matches it lowers the angle
  712. }
  713. function EnterGuild: boolean;
  714. var
  715.   i: Integer;
  716.   TPA: TPointArray;
  717.  
  718. begin
  719.   SetAngle(SRL_ANGLE_LOW);
  720.   TPA := FindObjByTPA(3760754, 13, 0.04, 0.46, 5, MSX1, MSY1, MSX2, MSY2);
  721.   SortTPAFrom(TPA, Point(MSCX, MSCY));
  722.   for i:=0 to high(TPA) do
  723.   begin
  724.     MMouse(TPA[i].x, TPA[i].y, RandomRange(-5, 5), RandomRange(-5, 5));
  725.     if WaitUptextMulti(['pen', 'oor', 'Open', 'Door'], 500) then
  726.     begin
  727.       ClickMouse2(1);
  728.       Result := True;
  729.       break;
  730.     end;
  731.   end;
  732.   Wait(RandomRange(1000, 2000));
  733.   SetAngle(SRL_ANGLE_HIGH);
  734.   WaitUntilNotMoving;
  735. end;
  736.  
  737. {* ClimbStairs(Direction: String)
  738.  * Climbs the stairs in the chosen direction
  739.  * Combines two TPA's to detect the stairs properly
  740. }
  741. function ClimbStairs(Direction: String): boolean;
  742. var
  743.   i: Integer;
  744.   TPA: TPointArray;
  745.  
  746. begin
  747.   //FindAccurateObj(colors, tols, hues, sats, dist, x1, y1, x2, y2);
  748.   TPA := FindAccurateObj([8164510, 9216424], [7, 12], [0.06, 0.13], [0.62, 0.45], 10, MSX1, MSY1, MSX2, MSY2);
  749.   for i:=0 to high(TPA) do
  750.   begin
  751.     SortTPAFrom(TPA, Point(MSCX, MSCY));
  752.     MMouse(TPA[i].x, TPA[i].y, RandomRange(-3, 3), RandomRange(-3, 3));
  753.     if WaitUptextMulti(['tair', 'case', 'Staircase'], 500) then
  754.     begin
  755.       ClickMouse2(0);
  756.       case Direction of
  757.         'up': if WaitOptionMulti(['up', 'Climb-up'], 1000) then Result := True;
  758.         'down': if WaitOptionMulti(['down', 'Climb-down'], 1000) then Result := True;
  759.       end;
  760.       WaitUntilNotMoving;
  761.       break;
  762.     end;
  763.   end;
  764. end;
  765.  
  766. {* FindSymbolsString
  767.  * Searches the screen for multiple symbols
  768.  * Returns a TStringArray which contains the detected symbols
  769. }
  770. function FindSymbolsString(Names: TStringArray; Accuracy: Extended): TStringArray;
  771. var
  772.   i, X, Y, L: Integer;
  773.  
  774. begin
  775.   SymbolAccuracy := Accuracy;
  776.   for i:=0 to high(Names) do
  777.   if FindSymbol(X, Y, Names[i]) then
  778.   begin
  779.     L := Length(Result);
  780.     SetLength(Result, L+1);
  781.     Result[L] := Names[i];
  782.   end;
  783. end;
  784.  
  785. {* GuildFloor
  786.  * Uses symbols to define the floor the player is at
  787. }
  788. function GuildFloor: Integer;
  789. var
  790.   i, j: Integer;
  791.   SymbolList, DetectedSymbols: TStringArray;
  792.   Define: TBooleanArray;
  793.  
  794. begin
  795.   SymbolList := ['water source', 'bank', 'mill', 'churn'];
  796.   SetLength(Define, Length(SymbolList));
  797.   DetectedSymbols := FindSymbolsString(SymbolList, 0.7);
  798.   for i:=0 to high(DetectedSymbols) do
  799.     for j:=0 to high(SymbolList) do
  800.       if (DetectedSymbols[i] = SymbolList[j]) then
  801.         begin
  802.           if j > 2 then
  803.             Result := 1
  804.           else
  805.             Result := 0;
  806.           exit;
  807.         end;
  808.   Result := 2;
  809. end;
  810.  
  811. {* ToFloor
  812.  * Gets to the floor of choice
  813.  * Uses other custom made functions
  814. }
  815. procedure ToFloor(Floor: Integer);
  816. var
  817.   CurrentFloor, Dif: Integer;
  818.  
  819. begin
  820.   CurrentFloor := GuildFloor;
  821.   writeln('Cur floor: ' + IntToStr(CurrentFloor));
  822.   while not(Floor = CurrentFloor) do
  823.   begin
  824.     Dif := Floor - CurrentFloor;
  825.     writeln('Dif: ' + IntToStr(Dif));
  826.     if (Dif > 0) then
  827.     begin
  828.       ClimbStairs('up');
  829.       Inc(CurrentFloor);
  830.     end else
  831.     begin
  832.       ClimbStairs('down');
  833.       Dec(CurrentFloor);
  834.     end;
  835.   end;
  836. end;
  837.  
  838. {* ToHopper
  839.  * Gets to the hopper on the 2nd floor
  840.  * Uses other custom made functions
  841. }
  842. procedure ToHopper;
  843. var
  844.   CurrentFloor: Integer;
  845.   P: TPoint;
  846.  
  847. begin
  848.   CurrentFloor := GuildFloor;
  849.   if not(CurrentFloor = 2) then
  850.     ToFloor(2);
  851.  
  852.   P := Point(MMCX - 10, MMCY - 20);
  853.   MMouse(P.x, P.y, RandomRange(-2, 2), RandomRange(-2, 2));
  854.   ClickMouse2(1);
  855.   WaitUntilNotMoving;
  856. end;
  857.  
  858. {* FillHopper
  859.  * Fills the hopper
  860.  * Uses other custom made functions
  861. }
  862. procedure FillHopper;
  863. var
  864.   CurrentFloor, i: Integer;
  865.   TPA: TPointArray;
  866.  
  867. begin
  868.   CurrentFloor := GuildFloor;
  869.   if not(CurrentFloor = 2) then
  870.   begin
  871.     ToFloor(2);
  872.     ToHopper;
  873.   end;
  874.  
  875.   TPA := FindObjByTPA(5661540, 14, 0.12, 0.42, 5, MSX1, MSY1, MSX2, MSY2);
  876.   if Length(TPA) > 0 then
  877.   begin
  878.     for i:=0 to high(TPA) do
  879.     begin
  880.       MMouse(TPA[i].x, TPA[i].y, RandomRange(-5, 5), RandomRange(-3, 3));
  881.       if WaitUpTextMulti(['opp', 'per', 'Hopper'], 500) then
  882.       begin
  883.         ClickMouse2(1);
  884.         Wait(RandomRange(1500, 2000));
  885.         break;
  886.       end;
  887.     end;
  888.   end;
  889. end;
  890.  
  891. {* OperateControls
  892.  * Operates the controls
  893.  * Uses other custom made functions
  894. }
  895. procedure OperateControls;
  896. var
  897.   CurrentFloor, i: Integer;
  898.   TPA: TPointArray;
  899.  
  900. begin
  901.   CurrentFloor := GuildFloor;
  902.   if not(CurrentFloor = 2) then
  903.   begin
  904.     ToFloor(2);
  905.     ToHopper;
  906.   end;
  907.  
  908.   TPA := FindObjByTPA(1125686, 4, 0.12, 0.52, 5, MSX1, MSY1, MSX2, MSY2);
  909.   if Length(TPA) > 0 then
  910.   begin
  911.     for i:=0 to high(TPA) do
  912.     begin
  913.       MMouse(TPA[i].x, TPA[i].y, RandomRange(-3, 3), RandomRange(-3, 3));
  914.       if WaitUpTextMulti(['rate', 'control', 'Operate'], 500) then
  915.       begin
  916.         ClickMouse2(1);
  917.         Wait(RandomRange(1500, 2000));
  918.         break;
  919.       end;
  920.     end;
  921.   end;
  922. end;
  923.  
  924. {* GoAndEnterGuild
  925.  * Walks to the cooking guild and enters
  926. }
  927. function GoAndEnterGuild: Boolean;
  928. begin
  929.   if PositionGuild then
  930.     if EnterGuild then
  931.       Result := True;
  932. end;
  933.  
  934. {* MakeFlour
  935.  * Walks to the cooking guild and enters
  936.  * Climbs to the right floor
  937.  * Makes flour from the wheat
  938. }
  939. function MakeFlour: boolean;
  940. var
  941.   Wheat, X, Y, i: Integer;
  942.   Box: TBox;
  943.  
  944. begin
  945.    ToFloor(2);
  946.    ToHopper;
  947.    SwitchTab(tab_Inv);
  948.    Wheat := DTMFromString('mWAAAAHicY2FgYHBiYmBwAWJ7IHYGYkFGBgZpIJYBYh4gntSZxNBcHcFQkOnNsHB6DgM/UA8yZkTDIAAAbbkHSA==');
  949.    while(FindDTM(Wheat, X, Y, MIX1, MIY1, MIX2, MIY2)) do
  950.    begin
  951.       MMouse(X, Y, RandomRange(-5, 5), RandomRange(-5, 5));
  952.      ClickMouse2(1);
  953.      FillHopper;
  954.      OperateControls;
  955.  
  956.      if FindBlackChatMessage('flour bin') then
  957.      begin
  958.        for i:=0 to 27 do
  959.        begin
  960.          Box := IntToBox(InvBox(i).X1, InvBox(i).Y1, InvBox(i).X2, InvBox(i).Y2);
  961.          if FindDTM(Wheat, X, Y, Box.X1, Box.Y1, Box.X2, Box.Y2) then
  962.          begin
  963.            MMouse(X, Y, RandomRange(-5, 5), RandomRange(-5, 5));
  964.            ClickMouse2(0);
  965.            WaitOptionMulti(['rop', 'Drop'], 500);
  966.          end;
  967.        end;
  968.        break;
  969.      end;
  970.      Result := True;
  971.    end;
  972.    FreeDTM(Wheat);
  973. end;
  974.  
  975. {* MiddleFloor
  976.  * Walks to the middle of the floor
  977.  * Is smart and knows what to do for each floor
  978.  * Inverts the black color
  979. }
  980. procedure MiddleFloor;
  981. var
  982.   OurFloor, X, Y: Integer;
  983.   TPA, TPA2, TPA3: TPointArray;
  984.   P: TPoint;
  985.   Box: TBox;
  986.  
  987. begin
  988.   OurFloor := GuildFloor;
  989.   if (OurFloor = 0) then
  990.   begin
  991.     SymbolAccuracy := 0.5;
  992.     if FindSymbol(X, Y, 'bank') then
  993.     begin
  994.       MMouse(X-10, Y+10, RandomRange(-2, 2), RandomRange(-2, 2));
  995.       ClickMouse2(1);
  996.       WaitUntilNotMoving;
  997.     end;
  998.   end else
  999.   begin
  1000.     FindColorsTolerance(TPA, 0, MMX1, MMY1, MMX2, MMY2, 30);
  1001.     Box := IntToBox(MMCX-50, MMCY-50, MMCX+50, MMCY+50);
  1002.     TPA2 := TPAFromBox(Box);
  1003.     TPA3 := ClearTPAFromTPA(TPA2, TPA);
  1004.     P := MiddleTPA(TPA3);
  1005.     MMouse(P.x+3, P.y+3, RandomRange(-3, 3), RandomRange(-3, 3));
  1006.     ClickMouse2(1);
  1007.     WaitUntilNotMoving;
  1008.   end;
  1009. end;
  1010.  
  1011. {* Loot
  1012.  * Loops through all choices and makes a smart decision of what item to loot
  1013.  * Can't find the pie dish accurately using it's own colors, so a smart way of
  1014.    detection it the other way around has been added :)
  1015.  * MATH
  1016. }
  1017. procedure Loot(Name: Integer);
  1018. var
  1019.   TPA, PlayerBox: TPointArray;
  1020.   P: TPoint;
  1021.   Dist: Extended;
  1022.   i, L, T: Integer;
  1023.  
  1024. begin
  1025.   TPA := GetMiniMapDotsIn('item', MMX1, MMY1, MMX2, MMY2);
  1026.   if (Length(TPA)>0) then
  1027.   begin
  1028.     SortTPAFrom(TPA, Point(MMCX, MMCY));
  1029.     P := Point(TPA[0].x, TPA[0].y);
  1030.     Dist := Abs(MMCX-P.x) + Abs(MMCY-P.y);
  1031.  
  1032.     if Dist > 20 then
  1033.     begin
  1034.       MMouse(P.x, P.y, RandomRange(-2, 2), RandomRange(-2, 2));
  1035.       ClickMouse2(1);
  1036.       WaitUntilNotMoving;
  1037.     end;
  1038.  
  1039.     PlayerBox := TPAFromBox(IntToBox(MSCX-20, MSCY-35, MSCX+20, MSCY+15));
  1040.     //SMART_DrawBox(IntToBox(MSCX-20, MSCY-35, MSCX+20, MSCY+15));
  1041.     TPA := FindObjByTPA(Items[Name].Color, Items[Name].Tol, Items[Name].Hue, Items[Name].Sat, 3, MSX1, MSY1, MSX2, MSY2);
  1042.     TPA := ClearTPAFromTPA(TPA, PlayerBox);
  1043.     if Name = 4 then
  1044.     begin
  1045.       if Length(TPA) > 0 then
  1046.         for i:=0 to high(TPA) do
  1047.           TPA[i] := Point(TPA[i].x + 35, TPA[i].y);
  1048.     end;
  1049.  
  1050.     L := Length(TPA);
  1051.     if L > 0 then
  1052.     begin
  1053.       SortTPAFrom(TPA, Point(MSCX, MSCY));
  1054.       writeln('detection');
  1055.       MarkTime(T);
  1056.       for i:=0 to L-1 do
  1057.       begin
  1058.         if TimeFromMark(T) > 2000 then
  1059.           break;
  1060.  
  1061.         Dist := Abs(MSCX-TPA[i].x) + Abs(MSCY-TPA[i].y);
  1062.         //writeln(Dist);
  1063.         if ((Dist > 10) and (Dist < 300)) then
  1064.         begin
  1065.           //writeln('moving mouse');
  1066.           MMouse(TPA[i].x, TPA[i].y, RandomRange(-1, 1), RandomRange(-1, 1));
  1067.           if WaitUptextMulti(Items[Name].Uptext, 500) then
  1068.           begin
  1069.             ClickMouse2(1);
  1070.             Wait(RandomRange(1000, 2000));
  1071.             WaitUntilNotMoving;
  1072.             break;
  1073.           end;
  1074.         end;
  1075.       end;
  1076.     end;
  1077.   end;
  1078. end;
  1079.  
  1080. {* CountInv
  1081.  * Counts the amount of items in the inventory
  1082. }
  1083. function CountInv: Integer;
  1084. var
  1085.   i, count: Integer;
  1086.  
  1087. begin
  1088.   SwitchTab(tab_Inv);
  1089.   for i:=1 to 29 do
  1090.     if ExistsItem(i) then
  1091.     Inc(count);
  1092.   Result := count;
  1093. end;
  1094.  
  1095. {* Loot2ndFloor
  1096.  * Loots stuff from the 2nd floor
  1097. }
  1098. function Loot2ndFloor: boolean;
  1099. var
  1100.   count1, count2: Integer;
  1101.  
  1102. begin
  1103.   count1 := CountInv;
  1104.  
  1105.   count2 := CountInv;
  1106.   if (count2 > count1) then
  1107.     Result := True;
  1108. end;
  1109.  
  1110. {* Loot1stFloor
  1111.  * Loots stuff from the 1st floor
  1112. }
  1113. function Loot1stFloor: boolean;
  1114. var
  1115.   count1, count2: Integer;
  1116.  
  1117. begin
  1118.   count1 := CountInv;
  1119.  
  1120.   count2 := CountInv;
  1121.   if (count2 > count1) then
  1122.     Result := True;
  1123. end;
  1124.  
  1125. {* LootAll
  1126.  * Loots stuff from the 1st & 2nd floor
  1127. }
  1128. procedure LootAll;
  1129. begin
  1130.   DeclareItems;
  1131.   MiddleFloor;
  1132.   while(FullInv = False) do
  1133.   begin
  1134.     ToFloor(1);
  1135.     Loot(DISH);
  1136.     Loot(APPLE);
  1137.     Loot(APPLE);
  1138.  
  1139.     ToFloor(2);
  1140.     Loot(GRAPE);
  1141.     Loot(POT);
  1142.     Loot(APPLE);
  1143.     Loot(JUG);
  1144.   end;
  1145.   writeln(FullInv);
  1146. end;
  1147.  
  1148. {* GetFlourFromBin
  1149.  * Gets flour from the bin :P
  1150. }
  1151. procedure GetFlourFromBin;
  1152. var
  1153.   TPA: TPointArray;
  1154.   i, FloorNr: Integer;
  1155.  
  1156. begin
  1157.   FloorNr := GuildFloor;
  1158.   if not(GuildFloor = 0) then
  1159.     ToFloor(0);
  1160.  
  1161.   TPA := FindObjByTPA(15793147, 5, 1.52, 15.44, 5, MSX1, MSY1, MSX2, MSY2);
  1162.   if Length(TPA)>0 then
  1163.   begin
  1164.     for i:=0 to high(TPA) do
  1165.     begin
  1166.       MMouse(TPA[i].x, TPA[i].y, RandomRange(-5, 5), RandomRange(-5, 5));
  1167.       if WaitUptextMulti(['flour', 'bin', 'our'], 500) then
  1168.       begin
  1169.         ClickMouse2(1);
  1170.         WaitUntilNotMoving;
  1171.         Wait(RandomRange(7500, 10000));
  1172.         break;
  1173.       end;
  1174.     end;
  1175.   end;
  1176. end;
  1177.  
  1178. {* ClickOnDrain
  1179.  * Clicks on the drain
  1180. }
  1181. procedure ClickOnDrain;
  1182. var
  1183.   TPA: TPointArray;
  1184.   i: Integer;
  1185.  
  1186. begin
  1187.   TPA := FindObjByTPA(10000800, 7, 0.35, 0.22 , 5, MSX1, MSY1, MSX2, MSY2);
  1188.   if Length(TPA)>0 then
  1189.   begin
  1190.     for i:=0 to high(TPA) do
  1191.     begin
  1192.       MMouse(TPA[i].x, TPA[i].y, RandomRange(-2, 2), RandomRange(-2, 2));
  1193.       if WaitUptextMulti(['drain', 'and', 'Pump'], 500) then
  1194.       begin
  1195.         ClickMouse2(1);
  1196.         WaitUntilNotMoving;
  1197.         Wait(RandomRange(3000, 5000));
  1198.         break;
  1199.       end;
  1200.     end;
  1201.   end;
  1202. end;
  1203.  
  1204. {* FillJug
  1205.  * Fills the jugs in your inventory
  1206. }
  1207. procedure FillJug;
  1208. var
  1209.   JugDTM, X, Y: Integer;
  1210.  
  1211. begin
  1212.   SwitchTab(tab_Inv);
  1213.   JugDTM := DTMFromString('mWAAAAHicY2FgYPjJxsDwHYjfAjEzOwODCDMDAxMQiwKxJBBnpaUCVTHBMReQRMaMaBgEAEXmBLU=');
  1214.  
  1215.   if FindDTM(JugDTM, X, Y, MIX1, MIY1, MIX2, MIY2) then
  1216.   begin
  1217.     MMouse(X, Y, RandomRange(-5, 5), RandomRange(-5, 5));
  1218.     ClickMouse2(1);
  1219.     ClickOnDrain;
  1220.   end;
  1221.  
  1222.   FreeDTM(JugDTM);
  1223. end;
  1224.  
  1225. {* LoadIngredientDTMs
  1226.  * Loads multiple DTMs
  1227. }
  1228. function LoadIngredientDTMs: TIntegerArray;
  1229. var
  1230.   JugDTM, DishDTM, AppleDTM, GrapeDTM, FlourDTM, DoughDTM: Integer;
  1231.  
  1232. begin
  1233.   JugDTM := DTMFromString('mggAAAHicY2NgYJjPxsAwD4insEHYs4B4LRALMzMwyAGxKBAzATEXEPMDcV5mJlAXEwbmB5LYMCMODAEAXvcF/w==');
  1234.   DishDTM := DTMFromString('mrAAAAHic42BgYDjOxsCwiw1CHwLis0B8FYjPA/E+IH7NxMDwCogfAPEXKH4DxA+B+BEQZ/nrAU1hwon5gSQ+zEgAwwAA4OoPQw==');
  1235.   AppleDTM := DTMFromString('mWAAAAHicY2FgYJjNxsAwGYjnAPFiIH7OBMHvgPgZEMfOEQWqYoJjLiCJjBnRMAgAAOUFB3Q=');
  1236.   GrapeDTM := DTMFromString('mggAAAHicY2NgYDjFxsBwAIhPAPF5KH0WiI2ZGRhMgdgOiC2BWAuI9YGYgYEJB8YOGHFgCAAAsH4GPQ==');
  1237.   FlourDTM := DTMFromString('mrAAAAHic42BgYDjBxsCwG4hPAfFpIL4GxPuB+DIQHwTiE0wQvBOIrwLxSSDeC8QHgPgyEBf5GwFNYcKJ+YEkPsxIAMMAAGYSDkI=');
  1238.   DoughDTM := DTMFromString('mbQAAAHicY2VgYHjHxsDwHIjfQ/E3IJ7FzMAwB4inA/EiIJ4NxM1NhUDVTCiYH0iiY0YsGAwAKmAJtA==');
  1239.   Result := [GrapeDTM, FlourDTM, AppleDTM, JugDTM, DishDTM, DoughDTM];
  1240. end;
  1241.  
  1242. {* CountIngredients
  1243.  * Counts the stuff you have looted
  1244. }
  1245. function CountIngredients: T2DPointArray;
  1246. var
  1247.   X, Y, i, j, L: Integer;
  1248.   Ingredients: TIntegerArray;
  1249.   Box: TBox;
  1250.  
  1251. begin
  1252.   Ingredients := LoadIngredientDTMs;
  1253.   SwitchTab(tab_Inv);
  1254.  
  1255.   SetLength(Result, Length(Ingredients)+1);
  1256.   for i:=0 to high(Ingredients) do
  1257.     for j:=1 to 28 do
  1258.     begin
  1259.       Box := InvBox(j);
  1260.       if FindDTM(Ingredients[i], X, Y, Box.X1, Box.Y1, Box.X2, Box.Y2) then
  1261.       begin
  1262.         L := Length(Result[i]);
  1263.         SetLength(Result[i], L+1);
  1264.         Result[i][L] := Point(X, Y);
  1265.         writeln(IntToStr(i) + ': ' + ToStr(Result[i][L]));
  1266.       end;
  1267.     end;
  1268.  
  1269.   FreeDTMs(Ingredients);
  1270. end;
  1271.  
  1272. {* DropIngredients
  1273.  * Drops the ingredients that we can't use with our inventory
  1274.  * One of the best procedures in this script IMO.
  1275. }
  1276. procedure DropIngredients;
  1277. var
  1278.   Lengths: TIntegerArray;
  1279.   Positions: T2DPointArray;
  1280.   i, NUMBER, Difference: Integer;
  1281.  
  1282. begin
  1283.   Positions := CountIngredients;
  1284.   SetLength(Lengths, Length(Positions)+1);
  1285.   for i:=0 to high(Positions) do
  1286.     Lengths[i] := Length(Positions[i]);
  1287.  
  1288.   // Same amount of apples as dishes
  1289.   if not(Lengths[APPLE] = Lengths[DISH]) then
  1290.   begin
  1291.     Difference := Floor(Abs(Lengths[APPLE]-Lengths[DISH]));
  1292.     writeln('Difference between apple and dishes: ' + IntToStr(Difference));
  1293.     if Lengths[APPLE] > Lengths[DISH] then
  1294.       NUMBER := APPLE
  1295.     else
  1296.       NUMBER := DISH;
  1297.     for i:=0 to Difference-1 do
  1298.     begin
  1299.       MMouse(Positions[NUMBER][i].x, Positions[NUMBER][i].y, RandomRange(-3, 3), RandomRange(-3, 3));
  1300.       if WaitUpTextMulti(['Apple', 'Pie dish'], 250) then
  1301.       begin
  1302.         ClickMouse2(0);
  1303.         WaitOptionMulti(['rop', 'Drop'], 500);
  1304.       end;
  1305.       writeln(IntToStr(i) + ': ' + IntToStr(Lengths[NUMBER]));
  1306.     end;
  1307.   end;
  1308.  
  1309.   // Same amount of jugs as grapes
  1310.   if not(Lengths[JUG] = Lengths[GRAPE]) then
  1311.   begin
  1312.     Difference := Floor(Abs(Lengths[JUG]-Lengths[GRAPE]));
  1313.     writeln('Difference between jug and grape: ' + IntToStr(Difference));
  1314.     if Lengths[JUG] > Lengths[GRAPE] then
  1315.       NUMBER := JUG
  1316.     else
  1317.       NUMBER := GRAPE;
  1318.     for i:=0 to Difference-1 do
  1319.     begin
  1320.       MMouse(Positions[NUMBER][i].x, Positions[NUMBER][i].y, RandomRange(-3, 3), RandomRange(-3, 3));
  1321.       if WaitUpTextMulti(['Jug', 'Grapes'], 250) then
  1322.       begin
  1323.         ClickMouse2(0);
  1324.         WaitOptionMulti(['rop', 'Drop'], 500);
  1325.       end;
  1326.       writeln(IntToStr(i) + ': ' + IntToStr(Lengths[NUMBER]));
  1327.     end;
  1328.   end;
  1329.  
  1330.   Wait(RandomRange(1000, 1500));
  1331. end;
  1332.  
  1333. {* DoughSelect
  1334.  * Checks if we can do something with the dough or other ingredients
  1335. }
  1336. function DoughSelect: boolean;
  1337. begin
  1338.   Result := CountColorTolerance(4206603, 133, 400, 388, 465, 10) > 150;
  1339. end;
  1340.  
  1341. {* PieDough
  1342.  * Makes pie dough by using the pot of flour on the drain
  1343. }
  1344. procedure PieDough;
  1345. var
  1346.   Locs: T2DPointArray;
  1347.   PL, JL, R: Integer;
  1348.  
  1349. begin
  1350.   Locs := CountIngredients;
  1351.   PL := Length(Locs[POT]);
  1352.   JL := Length(Locs[JUG]);
  1353.   if ((PL > 0) and (JL > 0)) then
  1354.   begin
  1355.     // Moving to a random pot
  1356.     R := Random(PL);
  1357.     MMouse(Locs[POT][r].x, Locs[POT][r].y, RandomRange(-3, 3), RandomRange(-3, 3));
  1358.     ClickMouse2(1);
  1359.     // Clicking on the drain
  1360.     ClickOnDrain;
  1361.     // Waiting for the option to make dough
  1362.     if WaitFunc(@DoughSelect, 150, 1500) then
  1363.     begin
  1364.       MouseBox(226, 400, 297, 455, 1);
  1365.       Wait(RandomRange(PL*750, PL*1500));
  1366.     end;
  1367.   end;
  1368. end;
  1369.  
  1370. {* PieMake
  1371.  * Makes a raw apple pie
  1372. }
  1373. function PieMake: boolean;
  1374. var
  1375.   X, Y, ShellDTM: Integer;
  1376.   DTMs: TIntegerArray;
  1377.  
  1378. begin
  1379.   DTMs := LoadIngredientDTMs;
  1380.   ShellDTM := DTMFromString('mlwAAAHicY2dgYChkY2DIA+IkIC4A4logTgXiGiDWYWZgUAJibSA2A2I9IDYGYjUgnlvmCtTNhBVzAUl+HJgRD4YCANIoBls=');
  1381.  
  1382.   // Clicking on dough
  1383.   if FindDTM(DTMs[DOUGH], X, Y, MIX1, MIY1, MIX2, MIY2) then
  1384.   begin
  1385.     MMouse(X, Y, RandomRange(-2, 2), RandomRange(-2, 2));
  1386.     ClickMouse2(1);
  1387.     // Clicking on dish
  1388.     if FindDTM(DTMs[DISH], X, Y, MIX1, MIY1, MIX2, MIY2) then
  1389.     begin
  1390.       MMouse(X, Y, RandomRange(-4, 4), RandomRange(-4, 4));
  1391.       ClickMouse2(1);
  1392.       // Using dough on dish to make pastry shell
  1393.       if WaitFunc(@DoughSelect, 150, 1500) then
  1394.       begin
  1395.         MouseBox(236, 400, 283, 455, 1);
  1396.         Wait(RandomRange(4000, 5000));
  1397.         // Clicking on apple
  1398.         if FindDTM(DTMs[APPLE], X, Y, MIX1, MIY1, MIX2, MIY2) then
  1399.         begin
  1400.           MMouse(X, Y, RandomRange(-4, 4), RandomRange(-4, 4));
  1401.           ClickMouse2(1);
  1402.           // Using apple on pie shell
  1403.           if FindDTM(ShellDTM, X, Y, MIX1, MIY1, MIX2, MIY2) then
  1404.           begin
  1405.             MMouse(X, Y, RandomRange(-4, 4), RandomRange(-4, 4));
  1406.             ClickMouse2(1);
  1407.             // Making unfinished pie's
  1408.             if WaitFunc(@DoughSelect, 150, 1500) then
  1409.             begin
  1410.               MouseBox(236, 400, 283, 455, 1);
  1411.               Wait(RandomRange(4000, 5000));
  1412.               Result := True;
  1413.             end;
  1414.           end;
  1415.         end;
  1416.       end;
  1417.     end;
  1418.   end;
  1419.  
  1420.   FreeDTMs(DTMs);
  1421.   FreeDTM(ShellDTM);
  1422. end;
  1423.  
  1424. {* WineMake
  1425.  * Makes wine
  1426. }
  1427. procedure WineMake;
  1428. var
  1429.   X, Y: Integer;
  1430.   DTMs: TIntegerArray;
  1431.  
  1432. begin
  1433.   FillJug;
  1434.   DTMs := LoadIngredientDTMs;
  1435.  
  1436.   if FindDTM(DTMs[JUG], X, Y, MIX1, MIY1, MIX2, MIY2) then
  1437.   begin
  1438.     MMouse(X, Y, RandomRange(-3, 3), RandomRange(-3, 3));
  1439.     ClickMouse2(1);
  1440.     if FindDTM(DTMs[GRAPE], X, Y, MIX1, MIY1, MIX2, MIY2) then
  1441.     begin
  1442.       MMouse(X, Y, RandomRange(-3, 3), RandomRange(-3, 3));
  1443.       ClickMouse2(1);
  1444.       if WaitFunc(@DoughSelect, 150, 1500) then
  1445.       begin
  1446.         MouseBox(236, 400, 283, 455, 1);
  1447.         Wait(RandomRange(3000, 4000));
  1448.       end;
  1449.     end;
  1450.   end;
  1451.  
  1452.   FreeDTMs(DTMs);
  1453. end;
  1454.  
  1455. {* CookPie
  1456.  * Cooks the pie's we have made, if any.
  1457. }
  1458. procedure CookPie;
  1459. var
  1460.   CurFloor, ApplePieDTM, i, X, Y: Integer;
  1461.   TPA: TPointArray;
  1462.  
  1463. begin
  1464.   CurFloor := GuildFloor;
  1465.   if not(CurFloor = 1) then
  1466.     ToFloor(1);
  1467.  
  1468.   ApplePieDTM := DTMFromString('mbQAAAHicY2VgYDjBhsAHgPgiEB9lYmDYC8SXmCBsEF7X7ANUzQTGaxp9wHx+IA8dM2LBYAAAtjIMvA==');
  1469.   if FindDTM(ApplePieDTM, X, Y, MIX1, MIY1, MIX2, MIY2) then
  1470.   begin
  1471.     MMouse(X, Y, RandomRange(-5, 5), RandomRange(-5, 5));
  1472.     ClickMouse2(1);
  1473.     TPA := FindObjByTPA(1384894, 12, 0.02, 0.47, 8, MSX1, MSY1, MSX2, MSY2);
  1474.     for i:=0 to high(TPA) do
  1475.     begin
  1476.       MMouse(TPA[i].x, TPA[i].y, RandomRange(-3, 3), RandomRange(-3, 3));
  1477.       if WaitUpTextMulti(['ange', 'Range'], 500) then
  1478.       begin
  1479.         ClickMouse2(1);
  1480.         WaitUntilNotMoving;
  1481.         if WaitFunc(@DoughSelect, 150, 1500) then
  1482.         begin
  1483.           MouseBox(236, 400, 283, 455, 1);
  1484.           Wait(RandomRange(5000, 7000));
  1485.         end;
  1486.         break;
  1487.       end;
  1488.     end;
  1489.   end;
  1490.   FreeDTM(ApplePieDTM);
  1491. end;
  1492.  
  1493. {* DropEverything
  1494.  * Drops everything in your inventory to start fresh again!
  1495. }
  1496. procedure DropEverything;
  1497. var
  1498.   i: Integer;
  1499.   Box: TBox;
  1500.   P: TPoint;
  1501.  
  1502. begin
  1503.   for i:=1 to 28 do
  1504.     if ExistsItem(i) then
  1505.     begin
  1506.       Box := InvBox(i);
  1507.       P := Point((Box.X1+Box.X2)/2, (Box.Y1+Box.Y2)/2);
  1508.       MMouse(P.x, P.y, RandomRange(-5, 5), RandomRange(-5, 5));
  1509.       ClickMouse2(0);
  1510.       WaitOptionMulti(['rop', 'Drop'], 500);
  1511.     end;
  1512. end;
  1513.  
  1514. begin
  1515.   // SETTING UP SMART PROPERLY
  1516.   SetupSRL;
  1517.   DeclarePlayers;
  1518.   LoginPlayerToLob;
  1519.   OpenWorldScreen;
  1520.   SelectWorld(10);
  1521.   LoginPlayer;
  1522.   Wait(1000 + Random(3000));
  1523.   ClickNorth(SRL_ANGLE_HIGH);
  1524.  
  1525.   // GETTING A CHEF'S HAT, WHEAT, AND ENTERING THE GUILD
  1526.   GetChefsHat;
  1527.   HandleWheat;
  1528.   GoAndEnterGuild;
  1529.  
  1530.   // INSIDE THE COOKING GUILD! THE INTERESTING PART!
  1531.   MakeFlour;
  1532.   MarkTime(Timer);
  1533.   while(TimeFromMark(Timer) < 1800000) do
  1534.   begin
  1535.     LootAll;
  1536.     GetFlourFromBin;
  1537.     CountIngredients;
  1538.     DropIngredients;
  1539.     PieDough;
  1540.     PieMake;
  1541.     WineMake;
  1542.     CookPie;
  1543.     DropEverything;
  1544.   end;
  1545.   Logout;
  1546. end.
Advertisement
Add Comment
Please, Sign In to add comment