WarPie90

Craft that shit! BOT BOT BOT!

Jun 23rd, 2023 (edited)
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 7.30 KB | None | 0 0
  1. program new;
  2. {$DEFINE SRL_USE_REMOTEINPUT}
  3. {$I SRL/osr.simba}
  4.  
  5. const
  6.   WHAT_TO_MAKE      = ERSCraftItem.RUBY_AMULET;
  7.   GEM_NEEDED_2_MAKE = 'Ruby';
  8.  
  9.   LOGIN_NAME        = 'yourname';
  10.   LOGIN_PASS        = 'yourpass';
  11.   IS_MEMBER         = False;
  12.  
  13. type
  14.   TSimpleCrafter = record
  15.     RSW: TRSWalker;
  16.   end;
  17.  
  18.  
  19. const
  20.   F2P_WORLDS = [301,308,380,434,435,436,437,451];
  21.   P2P_WORLDS = [302,303,304,305,306,307,309,310,311,312,313,314,315,317,318,319,320];
  22.  
  23.  
  24. procedure TMouse.Move(Rect: TRectangle; ForcedMove: Boolean = False); override;
  25. begin
  26.   if (ForcedMove) or (not Rect.Contains(Mouse.Position())) then
  27.     Mouse.Move(srl.rowp(mouse.Position(), Rect));
  28. end;
  29.  
  30.  
  31. function TSimpleCrafter.WorldToMS(PlayerPoint, WorldPoint: TPoint): TRectangle;
  32. var pt: TPoint;
  33. begin
  34.   pt := RSW.WorldToMM(PlayerPoint, WorldPoint, Minimap.GetCompassAngle(False));
  35.   Result := Minimap.PointToMsRect(pt);
  36. end;
  37.  
  38. procedure TSimpleCrafter.DeclarePlayers();
  39. begin
  40.   if IS_MEMBER then
  41.     Login.AddPlayer(LOGIN_NAME, LOGIN_PASS, '', P2P_WORLDS)
  42.   else
  43.     Login.AddPlayer(LOGIN_NAME, LOGIN_PASS, '', F2P_WORLDS);
  44. end;
  45.  
  46. procedure TSimpleCrafter.DoAntiban();
  47. begin
  48.   Antiban.DismissRandom();
  49.   if Antiban.DoAntiban() then
  50.     Login.LoginPlayer(); // if we got logged out, and not logged back in
  51. end;
  52.  
  53.  
  54. function TSimpleCrafter.FindFurnace(): TRectangle;
  55. var
  56.   pipe, bricks, concrete: TPointArray;
  57.   ATPA: T2DPointArray;
  58.   m: TPoint;
  59.   v: Vector3;
  60.   r1,r2: TRectangle;
  61.   t: Double;
  62. begin
  63.   srl.FindColors(pipe,     CTS1(1776416, 0),             MainScreen.Bounds);
  64.   srl.FindColors(concrete, CTS2(8421769, 5, 0.40, 0.19), MainScreen.Bounds);
  65.   srl.FindColors(bricks,   CTS2(3755630, 7, 0.10, 0.17), MainScreen.Bounds);
  66.  
  67.   pipe := pipe.PointsInRangeOf(bricks, 0, 15);
  68.   pipe := pipe.PointsInRangeOf(concrete, 0, 5);
  69.   if Length(pipe) = 0 then Exit;
  70.  
  71.   ATPA := pipe.Cluster(1);
  72.   pipe := ATPA.Biggest();
  73.  
  74.   m := pipe.Mean();
  75.   v := MainScreen.PointToMM(m, 9);
  76.  
  77.   r1 := Minimap.VecToMsRect(Vec3(v.x,v.y,4), 0.5,1);
  78.   r2 := Minimap.VecToMsRect(Vec3(v.x,v.y,0), 0.5,1);
  79.  
  80.   r1 := r1.Expand(-MainScreen.NormalizeDistance(5));
  81.   r2 := r2.Expand(-MainScreen.NormalizeDistance(5));
  82.  
  83.   RSClient.Image.Clear();
  84.   Result := TPointArray([r1.ToTPA+r2.ToTPA]).MinAreaRect();
  85. end;
  86.  
  87. function TSimpleCrafter.OpenEdgevilleBank(BoothCoord: TPoint = [4353,2047]): Boolean;
  88. var
  89.   r: TRectangle;
  90.   booth, grayOfBank, frameOfBank: TPointArray;
  91. begin
  92.   // Generate a searcharea near the approximate location of the bankbooth.
  93.   r := Self.WorldToMS(Self.RSW.GetMyPos(), BoothCoord).Expand(10);
  94.  
  95.   (*
  96.   Filter logic:
  97.     1. Find gray panel of the bank
  98.     2. Find wood frame of bank
  99.     3. With the use of PointInRangeOf we combine the two where they are in range
  100.        of 10 px from eachother. So, where gray is found near brown frame.
  101.     4. We apply some minimal errotion to the resulting points in order to
  102.        reduce pixelation noise.
  103.     5. We cluster it, and select the largest cluster, with the assumption that
  104.        it will be the bank booth itself.
  105.   *)
  106.  
  107.   // 1. and 2.
  108.   srl.FindColors(grayOfBank, CTS2(6251883, 6, 1.07, 0.87), r.Bounds());
  109.   srl.FindColors(frameOfBank, CTS2(1069673, 6, 0.11, 1.29), r.Bounds());
  110.  
  111.   // 3.
  112.   booth := grayOfBank.PointsInRangeOf(frameOfBank, 0, 10);
  113.   booth += frameOfBank.PointsInRangeOf(grayOfBank, 0, 10);
  114.  
  115.   // 4. and 5.
  116.   booth := booth.Erode(1).Cluster(1).Biggest();
  117.  
  118.   // R now contains a rectangle of approximately the same area as the bank
  119.   // it may at times be a little large though, meaning unclickable pixels.
  120.   r := booth.MinAreaRect();
  121.  
  122.   // you can now debug it to see what we found:
  123.   //RSClient.Image.DrawTPA(Bank, $00FF00);
  124.   //RSClient.Image.DrawRect(R, $0000FF);
  125.  
  126.   // because of the note above we will try a few times, each time it will generate
  127.   // a new random point in the rectangle:
  128.   for 1 to 5 do
  129.     if Bank.Open(srl.rowp(Mouse.Position(), r)) then
  130.       Exit(True);
  131. end;
  132.  
  133. function TSimpleCrafter.SmeltThatShit(): Boolean;
  134. var
  135.   t: TCountdown;
  136.   XP: Int32;
  137.   r: TRectangle;
  138.  
  139.   function WaitSmelting(ItemReduced: string): Boolean;
  140.   begin
  141.     WriteLn('Waiting while smelting - using: '+ ItemReduced);
  142.     XP := XPBar.Read();
  143.     t.Init(Random(4000,5000));
  144.     while not t.IsFinished() do
  145.     begin
  146.       if XPBar.Read() > XP then
  147.       begin
  148.         XP := XPBar.Read();
  149.         t.Init(Random(4000,5000));
  150.  
  151.         if (Inventory.CountItem(ItemReduced) = 0) then break;
  152.       end;
  153.     end;
  154.   end;
  155.  
  156. begin
  157.   Self.RSW.WebWalk([4402, 2022], 0, 1.0);
  158.  
  159.   if Inventory.CountItem('Gold ore') > 0 then
  160.   begin
  161.     r := Self.FindFurnace();
  162.     Mouse.Click(r, MOUSE_LEFT);
  163.  
  164.     if not Make.IsOpen(3000) then
  165.       RaiseException('AFASGLSKADGS!! FUCK GOD DAMN IT... SLACKY Y U MAKE BAD BOTS!!!');
  166.  
  167.     Make.Select(4, -1, False);
  168.     WaitSmelting('Gold ore');
  169.   end;
  170.  
  171.   r := Self.FindFurnace();
  172.   Mouse.Click(r, MOUSE_LEFT);
  173.   if CraftScreen.IsOpen(3000) then
  174.   begin
  175.     if not CraftScreen.CraftItem(WHAT_TO_MAKE, -1, False) then
  176.       RaiseException('Crafting failed');
  177.  
  178.  
  179.     WaitSmelting('Gold bar');
  180.   end else
  181.     RaiseException('AAAAAARRRRRRGGGGG!!!! SHIT BOT OMG!!! RAAAAAGEEEEE!!!!!');
  182. end;
  183.  
  184.  
  185.  
  186. function TSimpleCrafter.DoBankingStuff(): Boolean;
  187. begin
  188.   Self.RSW.WebWalk([4352,2040], 0, 1.0);
  189.   for 0 to 3 do
  190.   begin
  191.     if Self.OpenEdgevilleBank() then
  192.       break;
  193.   end;
  194.  
  195.   bank.DepositAll;
  196.   WaitUntil(Inventory.Count() = 0, 50, 5000);
  197.   if not bank.WithdrawItem(['Amulet mould', 1, False], False) then
  198.     RaiseException('Amoulet mould extraction failed -- cool!');
  199.  
  200.   if not bank.WithdrawItem(['Gold bar', 13, False], False) then
  201.     if not bank.WithdrawItem(['Gold ore', 13, False], False) then
  202.       RaiseException('Gold extraction failed -- cool!');
  203.  
  204.   if not bank.WithdrawItem([GEM_NEEDED_2_MAKE, 13, False], False) then
  205.     RaiseException(GEM_NEEDED_2_MAKE+' extraction failed -- cool!');
  206. end;
  207.  
  208.  
  209.  
  210. procedure TSimpleCrafter.SetupAntiban();
  211. begin
  212.   Antiban.Skills := [ERSSkill.CRAFTING];
  213.   Antiban.MaxZoom := 60;
  214.   Antiban.MinZoom := 30;
  215.  
  216.   Antiban.AddTask(ONE_MINUTE*5,  @Antiban.LoseFocus       );
  217.   Antiban.AddTask(ONE_MINUTE*10, @Antiban.HoverSkills     );
  218.   Antiban.AddTask(ONE_MINUTE*10, @Antiban.RandomTab       );
  219.   Antiban.AddTask(ONE_MINUTE*25, @Antiban.RandomRightClick);
  220.   Antiban.AddTask(ONE_MINUTE*40, @Antiban.RandomRotate    );
  221.  
  222.   Antiban.AddBreak(25 * ONE_MINUTE, 01 * ONE_MINUTE, 0.01);
  223.   Antiban.AddBreak(45 * ONE_MINUTE, 05 * ONE_MINUTE, 0.05);
  224.   Antiban.AddBreak(02 * ONE_HOUR,   10 * ONE_MINUTE, 0.15);
  225.   Antiban.AddBreak(04 * ONE_HOUR,   45 * ONE_MINUTE, 0.85);
  226.   Antiban.AddBreak(17 * ONE_HOUR,   08 * ONE_HOUR,   0.99);
  227. end;
  228.  
  229. procedure TSimpleCrafter.Setup();
  230. begin
  231.   Mouse.Speed := Random(14, 16);
  232.   RSW.Setup([RSWalkerRegions.EDGEVILLE]);
  233.  
  234.   self.DeclarePlayers();
  235.   self.SetupAntiban();
  236.   Login.LoginPlayer();
  237. end;
  238.  
  239.  
  240.  
  241. var
  242.   bot: TSimpleCrafter;
  243.   retry: Boolean;
  244. begin
  245.   bot.Setup();
  246.  
  247.   while True do begin
  248.     bot.RSW.AdaptiveWalk := Random() > 0.9;
  249.  
  250.     WriteLn('---- RESTART ----');
  251.  
  252.     bot.DoBankingStuff();
  253.     Bot.DoAntiban();
  254.  
  255.     retry := False;
  256.     repeat
  257.       try
  258.         bot.SmeltThatShit();
  259.       except
  260.         Writeln GetExceptionMessage();
  261.         retry := True;
  262.       end;
  263.       Bot.DoAntiban();
  264.     until(not retry) or (not Chat.LeveledUp());
  265.   end;
  266. end.
Add Comment
Please, Sign In to add comment