WarPie90

Barbarian village flyfisher

May 24th, 2023 (edited)
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 12.80 KB | None | 0 0
  1. program BarbFlyFisher_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. Worst case, manually walk to barb. village
  15. [==============================================================================}
  16. type
  17.   TFisherStyle = (FishCookBank, FishCookDrop, FishDrop);
  18.  
  19. const
  20.   LOGIN_NAME = 'yourname';
  21.   LOGIN_PASS = 'yourpass';
  22.   IS_MEMBER  = FALSE;        // TRUE or FALSE
  23.   STYLE      = FishCookBank; // FishCookBank or FishCookDrop, FishDrop
  24.  
  25. type
  26.   TFisher = record
  27.     StatsDebugTick: Int64;
  28.     RSW: TRSWalker;
  29.     Debug: TMufasaBitmap;
  30.   end;
  31.  
  32. var
  33.   Bot: TFisher;
  34.  
  35. const
  36.   F2P_WORLDS = [301,308,380,434,435,436,437,451];
  37.   P2P_WORLDS = [302,303,304,305,306,307,309,310,311,312,313,314,315,317,318,319,320];
  38.  
  39.  
  40.  
  41.  
  42. procedure TMouse.Move(Rect: TRectangle; ForcedMove: Boolean = False); override;
  43. begin
  44.   if (ForcedMove) or (not Rect.Contains(Mouse.Position())) then
  45.     Mouse.Move(srl.rowp(mouse.Position(), Rect));
  46. end;
  47.  
  48.  
  49. // -----------------------------------------------------------------------------
  50. // -----------------------------------------------------------------------------
  51. // FISHER
  52.  
  53.  
  54. function TFisher.WorldToMS(PlayerPoint, WorldPoint: TPoint): TRectangle;
  55. var pt: TPoint;
  56. begin
  57.   pt := RSW.WorldToMM(PlayerPoint, WorldPoint, Minimap.GetCompassAngle(False));
  58.   Result := Minimap.PointToMsRect(pt);
  59. end;
  60.  
  61. procedure TFisher.DeclarePlayers();
  62. begin
  63.   if IS_MEMBER then
  64.     Login.AddPlayer(LOGIN_NAME, LOGIN_PASS, '', P2P_WORLDS)
  65.   else
  66.     Login.AddPlayer(LOGIN_NAME, LOGIN_PASS, '', F2P_WORLDS);
  67. end;
  68.  
  69. procedure TFisher.DoAntiban();
  70. begin
  71.   Antiban.DismissRandom();
  72.   if Antiban.DoAntiban() then
  73.     Login.LoginPlayer(); // if we got logged out, and not logged back in
  74. end;
  75.  
  76. procedure TFisher.PostAction(AntiBan:Boolean=True);
  77. begin
  78.   WaitEx(450,70);
  79.   if AntiBan then Self.DoAntiban();
  80. end;
  81.  
  82.  
  83. procedure TFisher.ProcessWhileWaiting();
  84. begin
  85.   if GetTickCount() - StatsDebugTick > 2000 then
  86.   begin
  87.     ClearDebug();
  88.     ClearDebug();
  89.     WriteLn('+---| STATS |----------------------------------------');
  90.     WriteLn('|- Script Runtime    : ', SRL.MsToTime(GetTimeRunning, Time_Short));
  91.     WriteLn('+----------------------------------------------------');
  92.     Self.StatsDebugTick := GetTickCount();
  93.   end;
  94.   Self.DoAntiban();
  95. end;
  96.  
  97.  
  98. // Find fishingspots by finding the edges of the water, over and over again
  99. // Then do some fancy stuff to remove land->water borders.
  100. // what's left is an accurate TPA of the fishingspot
  101. function TFisher.FindFishingSpot(scanTime: Int32=450): T2DPointArray;
  102. var
  103.   i: Int32;
  104.   SUM,TPA: TPointArray;
  105.   R: TRectangle;
  106.   t: TCountDown;
  107. begin
  108.   t.Init(scanTime);
  109.   while not t.IsFinished do
  110.   begin
  111.     srl.FindColors(TPA, CTS2(8875103,16,0.2,0.7), Mainscreen.Bounds);
  112.     SUM += TPA.Edges();
  113.   end;
  114.  
  115.   SUM.ClearDuplicates();
  116.   SUM := ClearTPAFromTPA(Sum, Sum.Edges());
  117.   Result := SUM.Cluster(5);
  118.   Result.FilterSize(12, __GT__);
  119.  
  120.   RSClient.Image.Clear();
  121.   for i:=0 to High(Result) do
  122.     RSClient.Image.DrawTPA(Result[i], Random($FFFFFF));
  123. end;
  124.  
  125. // Open a bank
  126. function TFisher.OpenEdgevilleBank(): Boolean;
  127. var
  128.   R: TRectangle;
  129.   Booth, GrayOfBank, FrameOfBank: TPointArray;
  130. begin
  131.   // generate a searcharea near the approximate location of the bankbooth.
  132.   r := Self.WorldToMS(Self.RSW.GetMyPos(), [4348,2062]).Expand(10);
  133.  
  134.   (*
  135.   Filter logic:
  136.     1. Find gray panel of the bank
  137.     2. Find wood frame of bank
  138.     3. With the use of PointInRangeOf we combine the two where they are in range
  139.        of 10 px from eachother. So, where gray is found near brown frame.
  140.     4. We apply some minimal errotion to the resulting points in order to
  141.        reduce pixelation noise.
  142.     5. We cluster it, and select the largest cluster, with the assumption that
  143.        it will be the bank booth itself.
  144.   *)
  145.  
  146.   // 1. and 2.
  147.   srl.FindColors(GrayOfBank, CTS2(6251883, 6, 1.07, 0.87), r.Bounds());
  148.   srl.FindColors(FrameOfBank, CTS2(1069673, 6, 0.11, 1.29), r.Bounds());
  149.  
  150.   // 3.
  151.   Booth := GrayOfBank.PointsInRangeOf(FrameOfBank, 0, 10);
  152.   Booth += FrameOfBank.PointsInRangeOf(GrayOfBank, 0, 10);
  153.  
  154.   // 4. and 5.
  155.   Booth := Booth.Erode(1).Cluster(1).Biggest();
  156.  
  157.   // R now contains a rectangle of approximately the same area as the bank
  158.   // it may at times be a little large though, meaning unclickable pixels.
  159.   R := Booth.MinAreaRect();
  160.  
  161.   // you can now debug it to see what we found:
  162.   //RSClient.Image.DrawTPA(Bank, $00FF00);
  163.   //RSClient.Image.DrawRect(R, $0000FF);
  164.  
  165.   // because of the note above we will try a few times, each time it will generate
  166.   // a new random point in the rectangle:
  167.   for 1 to 5 do
  168.     if Bank.Open(srl.rowp(Mouse.Position(), R)) then
  169.       Exit(True);
  170. end;
  171.  
  172.  
  173. // Basically we find the fishingrod by checking the two tiles infront of
  174. // our character. It can fail if your character covers most of the rod
  175. function TFisher.IsFishing(): Boolean;
  176. var
  177.   rect1,rect2: TRectangle;
  178.   TPA1,TPA2: TPointArray;
  179. begin
  180.   Rect1 := Minimap.StaticToMsRect(Minimap.Center()+[4,0],1);
  181.   Rect2 := Minimap.StaticToMsRect(Minimap.Center()+[7,0],1);
  182.  
  183.   RSClient.Image.DrawRect(Rect1, $FFFFFF);
  184.   RSClient.Image.DrawRect(Rect2, $FFFFFF);
  185.  
  186.   if srl.FindColors(TPA1, CTS2(6694,10), Rect1.Bounds) > 12 then
  187.     Result := srl.FindColors(TPA2, CTS2(6694,10), Rect2.Bounds) > 5;
  188. end;
  189.  
  190. // Finds fishing spots, click one, and waits while we are fishing
  191. //
  192. function TFisher.Fish(): Boolean;
  193. var
  194.   ATPA: T2DPointArray;
  195.   TPA: TPointArray;
  196. begin
  197.   if (not Inventory.ContainsItem('Fly fishing rod')) or
  198.      (not Inventory.ContainsItem('Feather')) then
  199.     TerminateScript('No feathers or fly fishing rod');
  200.  
  201.   ATPA := Self.FindFishingSpot();
  202.   ATPA.SortByMiddle(MainScreen.Center());
  203.   for TPA in ATPA do
  204.   begin
  205.     mouse.Move(TPA.Bounds);
  206.     if not MainScreen.IsUpText(['Fishing spot']) then
  207.       Continue;
  208.  
  209.     mouse.Click(MOUSE_LEFT);
  210.     if MainScreen.DidRedClick() then
  211.     begin
  212.       Wait(700,1000);
  213.       Minimap.WaitPlayerMoving();
  214.       Wait(1400,1700);
  215.  
  216.       Self.FindFishingSpot(); //update drawing.
  217.       while Self.IsFishing() do
  218.       begin
  219.         Self.ProcessWhileWaiting();
  220.         Chat.ClickContinue();
  221.         WaitEx(70,10);
  222.       end;
  223.       Exit(True);
  224.     end else
  225.     begin
  226.       Wait(700,1200);
  227.       Minimap.WaitPlayerMoving();
  228.       Wait(700,1200);
  229.       Exit(False);
  230.     end;
  231.   end;
  232. end;
  233.  
  234. // Waits while we are cooking.
  235. // Cooking is determined by checking if the number of raw fish in our inventory
  236. // is reducing. It must reduce by at least 1 within 5.5 seconds.
  237. function TFisher.WaitCooking(): Boolean;
  238. var
  239.   c, currCount: Int32;
  240.   t: TCountDown;
  241. begin
  242.   c := Inventory.CountItem('Raw trout') + Inventory.CountItem('Raw salmon');
  243.  
  244.   t.Init(5500);
  245.   repeat
  246.     if Chat.LeveledUp() then
  247.       Break;
  248.  
  249.     currCount := Inventory.CountItem('Raw trout') + Inventory.CountItem('Raw salmon');
  250.     if currCount <> c then
  251.     begin
  252.       c := currCount;
  253.       t.Restart(50);
  254.     end;
  255.     Self.ProcessWhileWaiting();
  256.     Wait(70);
  257.   until t.IsFinished() or (c = 0);
  258.   Result := True;
  259. end;
  260.  
  261. // Do the cooking!
  262. // 1. Walks to a point near the eternal fire.
  263. // 2. Searches for the fire and uses a fish on the fire
  264. //    If it fails to find the fire it rotates the screen and tries again.
  265. // 3. Cooks it, and waits til we dont cook any more, or till we level up.
  266. // Repeats #2->#3 until there are no more fish in our inventory.
  267. function TFisher.Cook(): Boolean;
  268. var
  269.   idx: Int32;
  270.   arr: TIntegerArray;
  271.   rect: TRectangle;
  272.   objects: T2DPointArray;
  273.   fire: TPointArray;
  274.   foundFire: Boolean;
  275. begin
  276.   Inventory.Open();
  277.   if (not Inventory.ContainsItem('Raw trout')) and (not Inventory.ContainsItem('Raw salmon')) then
  278.     Exit;
  279.  
  280.   if Distance(Point(4393, 2292), RSW.GetMyPos) > 8 then
  281.     RSW.WebWalk(Point(4393, 2292), 2);
  282.  
  283.   repeat
  284.     arr := [];
  285.     Inventory.FindItems(['Raw trout', 'Raw salmon'], arr);
  286.     if(arr = []) then
  287.       Break;
  288.  
  289.     FoundFire := False;
  290.  
  291.     srl.FindColors(Fire, CTS2(12348,15), MainScreen.Bounds());
  292.     objects := Fire.Cluster(5);
  293.     objects.FilterSize(16, __GT__);
  294.     objects.SortByMiddle(Mainscreen.Center());
  295.  
  296.     Inventory.ClickSlot(arr[0]);
  297.     for fire in objects do
  298.     begin
  299.       rect := fire.MinAreaRect();
  300.       mouse.Move(rect);
  301.  
  302.       Wait(60,100); //wait for game to refresh
  303.       if MainScreen.IsUpText('Fire') then
  304.         mouse.Click(mouse_Left)
  305.       else if MainScreen.IsUpText('options') then
  306.       begin
  307.         if not ChooseOption.Select('Fire') then
  308.         begin
  309.           Wait(60,200);
  310.           Continue;
  311.         end
  312.       end else
  313.         continue;
  314.  
  315.       foundFire := True;
  316.  
  317.       if (Make.IsOpen(2000)) then
  318.         Make.Select(0, MAKE_QUANTITY_ALL, False);
  319.  
  320.       //Chat.ClickButtonId('How many', 1, 'Cook', 3000);
  321.       if Self.WaitCooking() then
  322.         Break;
  323.     end;
  324.  
  325.     if(not FoundFire) then
  326.       Minimap.SetCompassAngle([0,90,180,270][Random(4)]+Random(-15,15));
  327.   until False;
  328. end;
  329.  
  330.  
  331. // Clear the inventory by dropping, or banking fish.
  332. //
  333. procedure TFisher.DoInventory();
  334. var
  335.   items: TStringArray;
  336.   slots: TIntegerArray;
  337.   item: string;
  338.   t: TCountDown;
  339.  
  340.   // Deposits all the fish in our inventory, cooked, raw and burnt.
  341.   procedure Deposit();
  342.   begin
  343.     WriteLn('Status: Depositing fish! @ ', WorldWeb.LOCATION_EDGEVILLE_BANK);
  344.     RSW.WebWalk(WorldWeb.LOCATION_EDGEVILLE_BANK, 3);
  345.     Self.OpenEdgevilleBank();
  346.     if not Bank.IsOpen() then
  347.       TerminateScript('No bank');
  348.  
  349.     items := ['Salmon', 'Trout', 'Burnt fish', 'Raw trout', 'Raw salmon'];
  350.     for item in items do
  351.     begin
  352.       slots := [];
  353.       Inventory.FindItem(item, slots);
  354.       if Length(slots) > 0 then
  355.       begin
  356.         Bank.DepositItem([item, BANK_DEPOSIT_ALL], True);
  357.         t.Init(2000);
  358.         while (not t.IsFinished()) and Inventory.IsSlotUsed(slots[0]) do
  359.           Wait(70,160);
  360.       end;
  361.     end;
  362.  
  363.     Bank.Close(True);
  364.   end;
  365.  
  366.   // drop all the fish in our inventory, cooked, raw and burnt.
  367.   procedure Drop();
  368.   var
  369.     Ptrn: TIntegerArray;
  370.     i: Int32;
  371.     item: string;
  372.   begin
  373.     WriteLn('Status: Dropping fish!');
  374.     items := ['Salmon', 'Trout', 'Burnt fish', 'Raw trout', 'Raw salmon'];
  375.     for item in items do
  376.       Inventory.FindItem(item, slots);
  377.  
  378.     //sort by order
  379.     for i:=0 to 27 do
  380.       if slots.Find(i) <> -1 then
  381.         Ptrn += i;
  382.  
  383.     // same as Inventory.ShiftDrop(ptrn) except we add some errors to the order
  384.     Inventory.ShiftDrop(Inventory.ErrorPattern(ptrn));
  385.   end;
  386. begin
  387.   if STYLE in [FishCookDrop, FishDrop] then
  388.     Drop()
  389.   else
  390.     Deposit();
  391. end;
  392.  
  393. // Runs the bot
  394. //
  395. procedure TFisher.Run();
  396. begin
  397.   MainScreen.SetHighestPitch();
  398.  
  399.   while RSClient.IsLoggedIn() do
  400.   begin
  401.     if Inventory.IsFull() then
  402.     begin
  403.       if STYLE <> FishDrop then
  404.       begin
  405.         self.Cook();
  406.         self.PostAction();
  407.       end;
  408.       self.DoInventory();
  409.       self.PostAction();
  410.     end;
  411.  
  412.     if not self.Fish() then
  413.     begin
  414.       if RSW.GetMyPos.DistanceTo([4407, 2286]) > 20 then
  415.         RSW.WebWalk([4407, 2286],3)
  416.       else
  417.         RSW.WebWalk([4382, 2321],3);
  418.       Wait(700,1200);
  419.     end;
  420.  
  421.     RsClient.Image.Clear();
  422.     Self.ProcessWhileWaiting();
  423.   end;
  424. end;
  425.  
  426. procedure TFisher.SetupAntiban();
  427. begin
  428.   Antiban.Skills := [ERSSkill.FISHING, ERSSkill.COOKING];
  429.   Antiban.MaxZoom := 60;
  430.   Antiban.MinZoom := 30;
  431.  
  432.   Antiban.AddTask(ONE_MINUTE*5,  @Antiban.LoseFocus       );
  433.   //Antiban.AddTask(ONE_MINUTE*8,  @Antiban.HoverPlayers    );
  434.   Antiban.AddTask(ONE_MINUTE*10, @Antiban.HoverSkills     );
  435.   Antiban.AddTask(ONE_MINUTE*10, @Antiban.RandomTab       );
  436.   Antiban.AddTask(ONE_MINUTE*25, @Antiban.RandomRightClick);
  437.   Antiban.AddTask(ONE_MINUTE*40, @Antiban.RandomRotate    );
  438.  
  439.   Antiban.AddBreak(25 * ONE_MINUTE, 01 * ONE_MINUTE, 0.01);
  440.   Antiban.AddBreak(45 * ONE_MINUTE, 05 * ONE_MINUTE, 0.05);
  441.   Antiban.AddBreak(02 * ONE_HOUR,   10 * ONE_MINUTE, 0.15);
  442.   Antiban.AddBreak(04 * ONE_HOUR,   45 * ONE_MINUTE, 0.85);
  443.   Antiban.AddBreak(17 * ONE_HOUR,   07 * ONE_HOUR,   0.99);
  444. end;
  445.  
  446. procedure TFisher.Init();
  447. begin
  448.   WorldWeb.Load();
  449.   RSW.Setup('world', [RSWalkerRegions.WORLD],);
  450.   RSW.WebGraph := WorldWeb;
  451.   RSW.AdaptiveWalk := True;
  452.   RSW_ADAPTIVE_SCREEN_TOGGLE_DISTANCES := [45,140];
  453.  
  454.   self.DeclarePlayers();
  455.   self.SetupAntiban();
  456.  
  457.   Login.LoginPlayer();
  458. end;
  459.  
  460. procedure TFisher.Free();
  461. begin
  462.   RSW.Free();
  463. end;
  464.  
  465.  
  466. begin
  467.   bot.Init();
  468.   AddOnTerminate(@bot.Free);
  469.   bot.Run();
  470. end.
Add Comment
Please, Sign In to add comment