WarPie90

Untitled

May 27th, 2023 (edited)
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 15.66 KB | None | 0 0
  1. program BarbFlyFisher_Extended_V001;
  2. {$DEFINE SRL_USE_REMOTEINPUT}
  3. {$I SRL/osr.simba}
  4.  
  5. {$H-}
  6. {==============================================================================]
  7. | Barbarian FlyFisher ™
  8. |
  9. | Steps to use:
  10. |   1. For longer runs you need to declare user details bellow
  11. |   2. Start the script wherever, just have fishing rod and feathers in your inv
  12. |
  13. | Any issues starting it: Re-target RS, and try again, may help if you log
  14. | in manually before doing that.
  15. |
  16. | Banking might not work very well.
  17. [==============================================================================}
  18. type
  19.   TFisherStyle = (FishCookBank, FishCookDrop, FishDrop);
  20.  
  21. const
  22.   LOGIN_NAME = 'yourname';
  23.   LOGIN_PASS = 'yourpass';
  24.   IS_MEMBER  = FALSE;        // TRUE or FALSE
  25.   STYLE      = FishCookDrop; // FishCookBank or FishCookDrop, FishDrop
  26.  
  27. type
  28.   TFisher = record
  29.     StatsDebugTick: Int64;
  30.     FishingXP: Int32;
  31.     StartupXP: Int32;
  32.     RSW: TRSWalker;
  33.   end;
  34.  
  35. var
  36.   Bot: TFisher;
  37.  
  38. const
  39.   F2P_WORLDS = [301,308,380,434,435,436,437,451];
  40.   P2P_WORLDS = [302,303,304,305,306,307,309,310,311,312,313,314,315,317,318,319,320];
  41.  
  42.  
  43.  
  44.  
  45. procedure TMouse.Move(Rect: TRectangle; ForcedMove: Boolean = False); override;
  46. begin
  47.   if (ForcedMove) or (not Rect.Contains(Mouse.Position())) then
  48.     Mouse.Move(srl.rowp(mouse.Position(), Rect));
  49. end;
  50.  
  51.  
  52. // -----------------------------------------------------------------------------
  53. // -----------------------------------------------------------------------------
  54. // FISHER
  55.  
  56.  
  57. function TFisher.WorldToMS(PlayerPoint, WorldPoint: TPoint): TRectangle;
  58. var pt: TPoint;
  59. begin
  60.   pt := RSW.WorldToMM(PlayerPoint, WorldPoint, Minimap.GetCompassAngle(False));
  61.   Result := Minimap.PointToMsRect(pt);
  62. end;
  63.  
  64. procedure TFisher.DeclarePlayers();
  65. begin
  66.   if IS_MEMBER then
  67.     Login.AddPlayer(LOGIN_NAME, LOGIN_PASS, '', P2P_WORLDS)
  68.   else
  69.     Login.AddPlayer(LOGIN_NAME, LOGIN_PASS, '', F2P_WORLDS);
  70. end;
  71.  
  72. procedure TFisher.DoAntiban();
  73. begin
  74.   Antiban.DismissRandom();
  75.   if Antiban.DoAntiban() then
  76.     Login.LoginPlayer(); // if we got logged out, and not logged back in
  77. end;
  78.  
  79. procedure TFisher.PostAction(AntiBan:Boolean=True);
  80. begin
  81.   WaitEx(450,70);
  82.   if AntiBan then Self.DoAntiban();
  83. end;
  84.  
  85.  
  86. procedure TFisher.ProcessWhileWaiting();
  87. var
  88.   xpNow, xpGained, fishingXP, cookingXP: Int32;
  89.   xpHour, fishingXPHour, cookingXPHour: Double;
  90. begin
  91.   if GetTickCount() - StatsDebugTick > 2000 then
  92.   begin
  93.     // total XP
  94.     xpNow    := XPBar.Read();
  95.     xpGained := xpNow - Self.StartupXP;
  96.     xpHour   := xpGained / GetTimeRunning() * 1000 * 60 * 60;
  97.  
  98.     // Fishing XP
  99.     fishingXPHour := Self.FishingXP / GetTimeRunning() * 1000 * 60 * 60;
  100.  
  101.     // Cooking XP {is the difference in gained XP}
  102.     cookingXP     := xpGained - Self.FishingXP;
  103.     cookingXPHour := cookingXP / GetTimeRunning() * 1000 * 60 * 60;
  104.  
  105.     ClearDebug();
  106.     WriteLn('+---| STATS |----------------------------------------');
  107.     WriteLn('|- Script Runtime:   ', SRL.MsToTime(GetTimeRunning, Time_Short));
  108.     WriteLn('|- Fishing Exp/hour: ', FloatToStr(Round(fishingXPHour,1)));
  109.     WriteLn('|- Cooking Exp/hour: ', FloatToStr(Round(cookingXPHour,1)));
  110.     WriteLn('|- Total Exp/hour:   ', FloatToStr(Round(xpHour,1)));
  111.     WriteLn('|- Total Exp Gain:   ', xpGained);
  112.     WriteLn('+----------------------------------------------------');
  113.     Self.StatsDebugTick := GetTickCount();
  114.   end;
  115.   Self.DoAntiban();
  116. end;
  117.  
  118.  
  119. // Find fishingspots by finding the edges of the water, over and over again
  120. // Then do some fancy stuff to remove land->water borders.
  121. // what's left is an accurate TPA of the fishingspot
  122. //
  123. // However any movement near water will affect this, like lowering a lobsterpot
  124. // so we expand on it with using actual pixels that match flickering colors
  125. //
  126. // MaxIslands: Further more I think a fishingspot should be dense, not be
  127. // cluttered by many small unconnected pixels. So when character is moving it
  128. // wont detect much at all. This is to avoid having to mouse over a ton.
  129. function TFisher.FindFishingSpot(scanTime: Int32=450; MaxIslands: Int32 = 10): T2DPointArray;
  130. var
  131.   i: Int32;
  132.   SUM,TPA,pix: TPointArray;
  133.   tmp: T2DPointArray;
  134.   R: TRectangle;
  135.   t: TCountDown;
  136.   c: TCircle;
  137. begin
  138.   t.Init(scanTime);
  139.   while not t.IsFinished do
  140.   begin
  141.     srl.FindColors(TPA, CTS2(8875103, 16,0.20,0.70), Mainscreen.Bounds);
  142.     srl.FindColors(pix, CTS2(14397886,20,0.92,1.60), Mainscreen.Bounds);
  143.     TPA := TPA.PointsInRangeOf(pix, 0, 4);
  144.     SUM += TPA.Edges();
  145.   end;
  146.  
  147.   SUM.ClearDuplicates();
  148.   SUM := ClearTPAFromTPA(Sum, Sum.Edges());
  149.   tmp := SUM.Cluster(5);
  150.   tmp.FilterSize(12, __GT__);
  151.  
  152.   // MaxIslands ->
  153.   for i:=0 to High(tmp) do
  154.     if (Length(tmp[i].Cluster(1)) <= MaxIslands) and (tmp[i].MinAreaRect().MaxRadius() < 50) then
  155.       Result += tmp[i];
  156.  
  157.   // debug
  158.   RSClient.Image.Clear();
  159.   for i:=0 to High(Result) do
  160.   begin
  161.     RSClient.Image.DrawTPA(Result[i], Random($FFFFFF));
  162.     c := Result[i].MinAreaCircle();
  163.     RSClient.Image.DrawCircle(c.Mean(), c.Radius, Random($FFFFFF));
  164.   end;
  165. end;
  166.  
  167.  
  168. // Open the bank in Edgeville using the first booth
  169. function TFisher.OpenEdgevilleBank(): Boolean;
  170. var
  171.   r: TRectangle;
  172.   booth, grayOfBank, frameOfBank: TPointArray;
  173. begin
  174.   // Generate a searcharea near the approximate location of the bankbooth.
  175.   r := Self.WorldToMS(Self.RSW.GetMyPos(), [4348,2062]).Expand(10);
  176.  
  177.   (*
  178.   Filter logic:
  179.     1. Find gray panel of the bank
  180.     2. Find wood frame of bank
  181.     3. With the use of PointInRangeOf we combine the two where they are in range
  182.        of 10 px from eachother. So, where gray is found near brown frame.
  183.     4. We apply some minimal errotion to the resulting points in order to
  184.        reduce pixelation noise.
  185.     5. We cluster it, and select the largest cluster, with the assumption that
  186.        it will be the bank booth itself.
  187.   *)
  188.  
  189.   // 1. and 2.
  190.   srl.FindColors(grayOfBank, CTS2(6251883, 6, 1.07, 0.87), r.Bounds());
  191.   srl.FindColors(frameOfBank, CTS2(1069673, 6, 0.11, 1.29), r.Bounds());
  192.  
  193.   // 3.
  194.   booth := grayOfBank.PointsInRangeOf(frameOfBank, 0, 10);
  195.   booth += frameOfBank.PointsInRangeOf(grayOfBank, 0, 10);
  196.  
  197.   // 4. and 5.
  198.   booth := booth.Erode(1).Cluster(1).Biggest();
  199.  
  200.   // R now contains a rectangle of approximately the same area as the bank
  201.   // it may at times be a little large though, meaning unclickable pixels.
  202.   r := booth.MinAreaRect();
  203.  
  204.   // you can now debug it to see what we found:
  205.   //RSClient.Image.DrawTPA(Bank, $00FF00);
  206.   //RSClient.Image.DrawRect(R, $0000FF);
  207.  
  208.   // because of the note above we will try a few times, each time it will generate
  209.   // a new random point in the rectangle:
  210.   for 1 to 5 do
  211.     if Bank.Open(srl.rowp(Mouse.Position(), r)) then
  212.       Exit(True);
  213. end;
  214.  
  215.  
  216. // Basically we find the fishingrod by checking the two tiles infront of
  217. // our character. It can fail if your character covers most of the rod
  218. function TFisher.IsFishing(): Boolean;
  219. var
  220.   rect1,rect2: TRectangle;
  221.   TPA1,TPA2: TPointArray;
  222. begin
  223.   Rect1 := Minimap.StaticToMsRect(Minimap.Center()+[4,0],1);
  224.   Rect2 := Minimap.StaticToMsRect(Minimap.Center()+[7,0],1);
  225.  
  226.   RSClient.Image.DrawRect(Rect1, $FFFFFF);
  227.   RSClient.Image.DrawRect(Rect2, $FFFFFF);
  228.  
  229.   if srl.FindColors(TPA1, CTS2(6694,10), Rect1.Bounds) > 12 then
  230.     Result := srl.FindColors(TPA2, CTS2(6694,10), Rect2.Bounds) > 5;
  231. end;
  232.  
  233.  
  234. // Finds fishing spots, click one, and waits while we are fishing
  235. //
  236. function TFisher.Fish(MaxTimeCatch: Int32 = 10000{milliseconds}): Boolean;
  237. var
  238.   ATPA: T2DPointArray;
  239.   TPA: TPointArray;
  240.   timer: TCountDown;
  241.   z1,z2: Int32;
  242. begin
  243.   if (not Inventory.ContainsItem('Fly fishing rod')) or
  244.      (not Inventory.ContainsItem('Feather')) then
  245.     TerminateScript('No feathers or fly fishing rod');
  246.  
  247.   ATPA := Self.FindFishingSpot();
  248.   ATPA.SortByMiddle(MainScreen.Center());
  249.   for TPA in ATPA do
  250.   begin
  251.     mouse.Move(TPA.Bounds);
  252.     if not MainScreen.IsUpText(['Fishing spot']) then
  253.       Continue;
  254.  
  255.     mouse.Click(MOUSE_LEFT);
  256.     if MainScreen.DidRedClick() then
  257.     begin
  258.       Wait(700,1000);
  259.       Minimap.WaitPlayerMoving();
  260.       Wait(1400,1700);
  261.  
  262.       Self.FindFishingSpot(); //update drawing.
  263.  
  264.       // wait while we are catching fish.
  265.       // isFishing checks if our fishingrod is visible
  266.       // in case of false positive, we check for increment of XP.
  267.       timer.Init(MaxTimeCatch);
  268.       z1 := XPBar.Read();
  269.       while Self.IsFishing() and (not timer.IsFinished()) do
  270.       begin
  271.         Self.ProcessWhileWaiting();
  272.         Chat.ClickContinue();
  273.         WaitEx(70,10);
  274.  
  275.         z2 := XPBar.Read();
  276.         if z1 <> z2 then
  277.         begin
  278.           timer.Init(MaxTimeCatch);
  279.           Self.FishingXP += z2 - z1;
  280.           z1 := z2;
  281.         end;
  282.       end;
  283.  
  284.       // no need to check the other groups in the ATPA, it's outdated as we have
  285.       // been fishing, so exit successfully
  286.       Exit(True);
  287.     end else
  288.     begin
  289.       // Well, we clicked, but no red click, so we missed somehow.
  290.       // Probably in motion.
  291.       Wait(700,1200);
  292.       Minimap.WaitPlayerMoving();
  293.       Wait(700,1200);
  294.       Exit(False);
  295.     end;
  296.   end;
  297. end;
  298.  
  299.  
  300. // Waits while we are cooking.
  301. // Cooking is determined by checking if the number of raw fish in our inventory
  302. // is reducing. It must reduce by at least 1 within 5.5 seconds.
  303. function TFisher.WaitCooking(): Boolean;
  304. var
  305.   c, currCount: Int32;
  306.   t: TCountDown;
  307. begin
  308.   c := Inventory.CountItem('Raw trout') + Inventory.CountItem('Raw salmon');
  309.  
  310.   t.Init(5500);
  311.   repeat
  312.     if Chat.LeveledUp() then
  313.       Break;
  314.  
  315.     currCount := Inventory.CountItem('Raw trout') + Inventory.CountItem('Raw salmon');
  316.     if currCount <> c then
  317.     begin
  318.       c := currCount;
  319.       t.Restart(50);
  320.     end;
  321.     Self.ProcessWhileWaiting();
  322.     Wait(70);
  323.   until t.IsFinished() or (c = 0);
  324.   Result := True;
  325. end;
  326.  
  327.  
  328. // Do the cooking!
  329. // 1. Walks to a point near the eternal fire.
  330. // 2. Searches for the fire and uses a fish on the fire
  331. //    If it fails to find the fire it rotates the screen and tries again.
  332. // 3. Cooks it, and waits til we dont cook any more, or till we level up.
  333. // Repeats #2->#3 until there are no more fish in our inventory.
  334. function TFisher.Cook(): Boolean;
  335. var
  336.   idx: Int32;
  337.   arr: TIntegerArray;
  338.   rect: TRectangle;
  339.   objects: T2DPointArray;
  340.   fire: TPointArray;
  341.   foundFire: Boolean;
  342. begin
  343.   Inventory.Open();
  344.   if (not Inventory.ContainsItem('Raw trout')) and (not Inventory.ContainsItem('Raw salmon')) then
  345.     Exit;
  346.  
  347.   if Distance([4393, 2292], RSW.GetMyPos()) > 4*2 then
  348.     RSW.WebWalk([4393, 2292], 2);
  349.  
  350.   repeat
  351.     arr := [];
  352.     Inventory.FindItems(['Raw trout', 'Raw salmon'], arr);
  353.     if(arr = []) then
  354.       Break;
  355.  
  356.     FoundFire := False;
  357.  
  358.     srl.FindColors(Fire, CTS2(12348,15), MainScreen.Bounds());
  359.     objects := Fire.Cluster(5);
  360.     objects.FilterSize(16, __GT__);
  361.     objects.SortByMiddle(Self.WorldToMS(RSW.GetMyPos(), [4393, 2292]).Mean());
  362.  
  363.     Inventory.ClickSlot(arr[0]);
  364.     for fire in objects do
  365.     begin
  366.       rect := fire.MinAreaRect();
  367.       mouse.Move(rect);
  368.  
  369.       Wait(60,100); //wait for game to refresh
  370.       if MainScreen.IsUpText('Fire') then
  371.         mouse.Click(mouse_Left)
  372.       else if MainScreen.IsUpText('options') then
  373.       begin
  374.         if not ChooseOption.Select('Fire') then
  375.         begin
  376.           Wait(60,200);
  377.           Continue;
  378.         end
  379.       end else
  380.         continue;
  381.  
  382.       foundFire := True;
  383.  
  384.       // whenever we try to cook a single fish Make wont open.
  385.       if (Make.IsOpen(2000)) then
  386.         Make.Select(0, MAKE_QUANTITY_ALL, False);
  387.  
  388.       if Self.WaitCooking() then
  389.         Break;
  390.     end;
  391.  
  392.     if(not FoundFire) then
  393.       Minimap.SetCompassAngle([0,90,180,270][Random(4)]+Random(-15,15));
  394.   until False;
  395. end;
  396.  
  397.  
  398. procedure TFisher.DropInventory();
  399. var
  400.   items: TStringArray;
  401.   item: string;
  402.   ptrn, slots: TIntegerArray;
  403.   slices: TIntegerArray;
  404.   sequences: T2DIntArray;
  405.   i,hi: Int32;
  406. begin
  407.   ptrn := Inventory.ErrorPattern(DROP_PATTERN_REGULAR, 10);
  408.  
  409.   hi := 0;
  410.   while hi <> Length(ptrn) do
  411.   begin
  412.     slices += srl.TruncatedGauss(Length(ptrn), hi, 6);
  413.     hi := slices[High(slices)];
  414.   end;
  415.   sequences += Copy(ptrn, 0, slices[0]);
  416.   for i:=1 to High(slices) do
  417.     sequences += Copy(ptrn, slices[i-1], 28-slices[i-1]);
  418.  
  419.  
  420.   for i:=0 to High(sequences) do
  421.   begin
  422.     ptrn := sequences[i];
  423.  
  424.     // check if we have an antiban ready and lined up
  425.     Self.DoAntiban();
  426.  
  427.     // shift-drop the rest of our ores
  428.     Inventory.ShiftDrop(['Salmon', 'Trout', 'Burnt fish', 'Raw trout', 'Raw salmon'], ptrn);
  429.  
  430.     if (Random() < 0.8) and (i = High(sequences))  then
  431.       break;
  432.  
  433.     Sleep(srl.TruncatedGauss(0, 6000, 6));
  434.   end;
  435. end;
  436.  
  437. // Clear the inventory by dropping, or banking fish.
  438. //
  439. procedure TFisher.DoInventory();
  440. var
  441.   items: TStringArray;
  442.   slots: TIntegerArray;
  443.   item: string;
  444.   t: TCountDown;
  445.  
  446.   // Deposits all the fish in our inventory, cooked, raw and burnt.
  447.   procedure Deposit();
  448.   begin
  449.     WriteLn('Status: Depositing fish! @ ', WorldWeb.LOCATION_EDGEVILLE_BANK);
  450.     RSW.WebWalk(WorldWeb.LOCATION_EDGEVILLE_BANK, 3);
  451.     Self.OpenEdgevilleBank();
  452.     if not Bank.IsOpen() then
  453.       TerminateScript('No bank');
  454.  
  455.     items := ['Salmon', 'Trout', 'Burnt fish', 'Raw trout', 'Raw salmon'];
  456.     for item in items do
  457.     begin
  458.       slots := [];
  459.       Inventory.FindItem(item, slots);
  460.       if Length(slots) > 0 then
  461.       begin
  462.         Bank.DepositItem([item, BANK_DEPOSIT_ALL], True);
  463.         t.Init(2000);
  464.         while (not t.IsFinished()) and Inventory.IsSlotUsed(slots[0]) do
  465.           Wait(70,160);
  466.       end;
  467.     end;
  468.  
  469.     Bank.Close(Random() > 0.1);
  470.   end;
  471. begin
  472.   if STYLE in [FishCookDrop, FishDrop] then
  473.     Self.DropInventory()
  474.   else
  475.     Deposit();
  476. end;
  477.  
  478. // Runs the bot
  479. //
  480. procedure TFisher.Run();
  481. begin
  482.   MainScreen.SetHighestPitch();
  483.  
  484.   while RSClient.IsLoggedIn() do
  485.   begin
  486.     if Inventory.IsFull() then
  487.     begin
  488.       if STYLE <> FishDrop then
  489.       begin
  490.         self.Cook();
  491.         self.PostAction();
  492.       end;
  493.       self.DoInventory();
  494.       self.PostAction();
  495.     end;
  496.  
  497.     if not self.Fish() then
  498.     begin
  499.       if RSW.GetMyPos.DistanceTo([4407, 2286]) > 20 then
  500.         RSW.WebWalk([4407, 2286],3)
  501.       else
  502.         RSW.WebWalk([4382, 2321],3);
  503.       Wait(700,1200);
  504.     end;
  505.  
  506.     RsClient.Image.Clear();
  507.     Self.ProcessWhileWaiting();
  508.   end;
  509. end;
  510.  
  511. procedure TFisher.SetupAntiban();
  512. begin
  513.   Antiban.Skills := [ERSSkill.FISHING, ERSSkill.COOKING];
  514.   Antiban.MaxZoom := 60;
  515.   Antiban.MinZoom := 30;
  516.  
  517.   Antiban.AddTask(ONE_MINUTE*5,  @Antiban.LoseFocus       );
  518.   //Antiban.AddTask(ONE_MINUTE*8,  @Antiban.HoverPlayers    );
  519.   Antiban.AddTask(ONE_MINUTE*10, @Antiban.HoverSkills     );
  520.   Antiban.AddTask(ONE_MINUTE*10, @Antiban.RandomTab       );
  521.   Antiban.AddTask(ONE_MINUTE*25, @Antiban.RandomRightClick);
  522.   Antiban.AddTask(ONE_MINUTE*40, @Antiban.RandomRotate    );
  523.  
  524.   Antiban.AddBreak(25 * ONE_MINUTE, 01 * ONE_MINUTE, 0.01);
  525.   Antiban.AddBreak(45 * ONE_MINUTE, 05 * ONE_MINUTE, 0.05);
  526.   Antiban.AddBreak(02 * ONE_HOUR,   10 * ONE_MINUTE, 0.15);
  527.   Antiban.AddBreak(04 * ONE_HOUR,   45 * ONE_MINUTE, 0.85);
  528.   Antiban.AddBreak(17 * ONE_HOUR,   07 * ONE_HOUR,   0.99);
  529. end;
  530.  
  531. procedure TFisher.Init();
  532. begin
  533.   WorldWeb.Load();
  534.   RSW.Setup('world', [RSWalkerRegions.WORLD]);
  535.   RSW.WebGraph := WorldWeb;
  536.   RSW.AdaptiveWalk := True;
  537.   RSW_ADAPTIVE_SCREEN_TOGGLE_DISTANCES := [45,140];
  538.  
  539.   self.DeclarePlayers();
  540.   self.SetupAntiban();
  541.  
  542.   Login.LoginPlayer();
  543.  
  544.   Self.StartupXP := XPBar.Read();
  545. end;
  546.  
  547. procedure TFisher.Free();
  548. begin
  549.   RSW.Free();
  550. end;
  551.  
  552.  
  553. begin
  554.   bot.Init();
  555.   AddOnTerminate(@bot.Free);
  556.   bot.Run();
  557. end.
Add Comment
Please, Sign In to add comment