WarPie90

Stationary Variable Powerminer

Jan 16th, 2023 (edited)
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 27.13 KB | None | 0 0
  1. program CanItMine;
  2. {$DEFINE SRL_USE_REMOTEINPUT}
  3. {$I SRL/osr.simba}
  4.  
  5. const
  6.   USERNAME = '';
  7.   PASSWORD = '';
  8.  
  9. const
  10.   // Everything else is kept, meaning you have to manually bank at times
  11.   WHAT_TO_DROP: TRSItemArray = ['Iron ore','Tin ore'];
  12.  
  13.   // Extreme and Hyper focus can drop a minimum of? This Should not be more
  14.   // than 3 for 3 rocks spawns, and more than 6 for 2 rock spawns. Has to do
  15.   // with efficient timings.
  16.   MIN_ORE_DROP_COUNT = 3; //4 might be good fit for 2 rock spawn.
  17.  
  18.   // How often is extreme mode allowed to turn towards the next ore, in percent
  19.   // This mainly effects 2-rock spawns like 2xIron, 3xIron would almost always
  20.   // have ores present, so not much turning there if any.
  21.   EXTREME_TURN_PERCENTAGE = 75;
  22.  
  23.  
  24.  
  25. type
  26.   TClickHistory = record
  27.     History: TRectArray;
  28.   end;
  29.  
  30.   TMiner = record
  31.     RSW: TRSWalker;
  32.     OreLocations: TPointArray;
  33.     Sequence: TIntegerArray;
  34.     OreColor: array of TCTS2Color;
  35.  
  36.     SweivelTimer: Double;
  37.     UnfocucsedTimer: Double;
  38.     HyperFocusTimer: Double;
  39.     ExtremeFocusTimer: Double;
  40.  
  41.     CanDebug: TCountDown;
  42.  
  43.     ClickOrder: TClickHistory;
  44.     StartupXP: Int32;
  45.     OreCounter: Int32;
  46.   end;
  47.  
  48. const
  49.   F2P_WORLDS = [301,308,380,434,435,436,437,451];
  50.   P2P_WORLDS = [302,303,304,305,306,307,309,310,311,312,313,314,315,317,318,319,320];
  51.  
  52. var
  53.   Bot: TMiner;
  54.  
  55. procedure TClickHistory.Push(x: TRectangle);
  56.   function IsDuplicateOfCurrent(): Boolean;
  57.   var i: Int32;
  58.   begin
  59.     if Self.History[High(Self.History)].Mean().DistanceTo(x.Mean()) < 16 then
  60.       Exit(True);
  61.   end;
  62.  
  63.   procedure ShiftForward();
  64.   var i: Int32;
  65.   begin
  66.     for i:=High(Self.History) downto 0 do
  67.       Self.History[srl.Modulo(i+1, Length(Self.History))] := Self.History[i];
  68.   end;
  69.  
  70. begin
  71.   // ensure this is not dupicate of the ore that was previously clicked
  72.   // if it is then we shift the array to bring forth the next ore in previous sequence.
  73.   // Note: This should not happen unless we are competing for rocks
  74.   // Also might prevent some unexpected glitches.
  75.   if IsDuplicateOfCurrent() then
  76.   begin
  77.     ShiftForward();
  78.     Exit;
  79.   end;
  80.  
  81.   // otherwise, push it in to the first slot. Bringing forth the last clicked rock
  82.   // to the end, which is also the next rock to click.
  83.   // This way we can access it with .Next()
  84.   Insert(x, Self.History, 0);
  85.   SetLength(Self.History, Length(Bot.OreLocations));
  86. end;
  87.  
  88. function TClickHistory.Next(): TRectangle;
  89. begin
  90.   // only if we have a full set of history should we predict
  91.   if Length(Self.History) >= Length(Bot.OreLocations)  then
  92.   begin
  93.     Result := Self.History[High(Self.History)];
  94.     SetLength(Self.History, Length(Self.History)-1);
  95.   end;
  96. end;
  97.  
  98. function TClickHistory.Top(): TRectangle;
  99. begin
  100.   Result := Self.History[High(Self.History)];
  101. end;
  102.  
  103. procedure TMouse.Move(Rect: TRectangle; ForcedMove: Boolean = False); override;
  104. begin
  105.   if (ForcedMove) or (not Rect.Contains(Mouse.Position())) then
  106.     Mouse.Move(srl.rowp(mouse.Position(), Rect));
  107. end;
  108.  
  109. procedure TSRL.MouseOffClient(direction: Byte);
  110. var
  111.   W,H: Int32;
  112.   pt: TPoint;
  113. begin
  114.   GetClientDimensions(W, H);
  115.   pt := Mouse.Position();
  116.   if (pt.X < 0) or (pt.X > W) or (pt.Y < 0) or (pt.Y > H) then
  117.     Exit();
  118.   if (direction >= 4) then
  119.     direction := Random(0,3);
  120.   case direction of
  121.     0: Mouse.Move(Box(-300, -300, W, 0)); // top
  122.     1: Mouse.Move(Box(0, H, W, H+300));   // bottom
  123.     2: Mouse.Move(Box(-300, 0, 0, H));    // left
  124.     3: Mouse.Move(Box(W, 0, W+300, H));   // right
  125.   end;
  126. end;
  127.  
  128. procedure TAntiban.RandomPOVTask;
  129. begin
  130.   case Random(7) of
  131.     0:   Self.AdjustZoom;
  132.     else Self.RandomRotate;
  133.   end;
  134. end;
  135.  
  136. function TAntiban.HoverPlayerFunc(): Boolean;
  137. var
  138.   i: Int32;
  139.   dots: TPointArray;
  140.   R: TRectangle;
  141. begin
  142.   for i:=0 to Random(0,2) do
  143.   begin
  144.     dots := Minimap.GetDots(ERSMinimapDot.PLAYER);
  145.     if Length(dots) > 0 then
  146.     begin
  147.       R := Minimap.PointToMsRect(dots[Random(Length(dots))]);
  148.       Mouse.Move(R);
  149.       if not MainScreen.IsUpText('level') then
  150.       begin
  151.         if Random() < 0.5 then
  152.           Antiban.Swivel()
  153.         else
  154.           Mouse.Move(R, True);
  155.  
  156.         Result := Random() > 0.5;
  157.         Sleep(srl.TruncatedGauss(500,3100));
  158.       end;
  159.  
  160.       if (Random() > 0.7) and MainScreen.IsUpText('level') then
  161.       begin
  162.         ChooseOption.Open();
  163.         Sleep(srl.TruncatedGauss(0,6000));
  164.         break;
  165.       end;
  166.     end;
  167.   end;
  168. end;
  169.  
  170. procedure TAntiban.HoverPlayer();
  171. begin
  172.   Self.HoverPlayerFunc();
  173. end;
  174.  
  175. procedure TAntiban.LoseFocus(); override;
  176. begin
  177.   if Random() < 0.5 then
  178.     srl.MouseOffClient(srl.SkewedRand(3,0,3));
  179.   Antiban.LoseFocus(srl.SkewedRand(1000,500,30000));
  180. end;
  181.  
  182. procedure TIntegerArray.Shuffle();
  183. var i: Int32;
  184. begin
  185.   for i:=0 to High(self) do
  186.     Swap(Self[i], Self[Random(0, High(Self))]);
  187. end;
  188.  
  189. procedure TPointArray.Shuffle();
  190. var i: Int32;
  191. begin
  192.   for i:=0 to High(self) do
  193.     Swap(Self[i], Self[Random(0, High(Self))]);
  194. end;
  195.  
  196.  
  197. { ============================================================================ }
  198. { ============================================================================ }
  199. { ============================================================================ }
  200. procedure TMiner.DeclarePlayers();
  201. begin
  202.   Login.AddPlayer(USERNAME, PASSWORD, '', F2P_WORLDS);
  203. end;
  204.  
  205. function TMiner.WorldToMS(PlayerPoint, WorldPoint: TPoint): TRectangle;
  206. var pt: TPoint;
  207. begin
  208.   pt := RSW.WorldToMM(PlayerPoint, WorldPoint, Minimap.GetCompassAngle(False));
  209.   Result := Minimap.PointToMsRect(pt);
  210. end;
  211.  
  212. function TMiner.GetOres(): TRectArray;
  213. var
  214.   i: Int32;
  215.   me: TPoint;
  216. begin
  217.   me := RSW.GetMyPos();
  218.   for i:=0 to High(Self.OreLocations) do
  219.     Result += Self.WorldToMS(me, Self.OreLocations[i]);
  220. end;
  221.  
  222. procedure TMiner.OrganizeInv();
  223. var
  224.   move,empty,slots: TIntegerArray;
  225.   i,j,k: Int32;
  226.   a,b: TBox;
  227. begin
  228.   Inventory.FindItems(WHAT_TO_DROP, slots);
  229.  
  230.   for i:=0 to 27 do
  231.   begin
  232.     if Inventory.IsSlotUsed(i) and (slots.Find(i)=-1) then
  233.       move += i;
  234.     if not Inventory.IsSlotUsed(i) then
  235.       empty += i;
  236.   end;
  237.  
  238.   if Length(empty) = 0 then
  239.     Exit;
  240.  
  241.   for i in move do
  242.   begin
  243.     j := empty[high(empty)];
  244.     if j <= i then break;
  245.  
  246.     a := Inventory.GetSlotBox(i);
  247.     b := Inventory.GetSlotBox(j);
  248.     Mouse.Move(a);
  249.     Mouse.Hold(mouse_left);
  250.     WaitEx(100,15);
  251.     Mouse.Move(b);
  252.     WaitEx(100,15);
  253.     Mouse.Release(mouse_left);
  254.     WaitEx(100,15);
  255.  
  256.     empty.Pop();
  257.     empty.Append(i);
  258.     empty.Sort();
  259.   end;
  260. end;
  261.  
  262.  
  263. function TMiner.IsOreAliveFast(R: TRectangle): Boolean;
  264. var
  265.   TPA: TPointArray;
  266.   B: TBox;
  267.   color: TCTS2Color;
  268. begin
  269.   B := R.Bounds();
  270.   B.LimitTo(MainScreen.Bounds);
  271.   for color in Self.OreColor do
  272.     if srl.FindColors(TPA, color, B) > 200 then
  273.       Exit(True);
  274. end;
  275.  
  276. function TMiner.IsOreAlive(R: TRectangle; out Fitted: TRectangle): Boolean;
  277. var
  278.   TPA: TPointArray;
  279.   B: TBox;
  280.   color: TCTS2Color;
  281. begin
  282.   B := R.Bounds();
  283.   B.LimitTo(MainScreen.Bounds);
  284.  
  285.   for color in Self.OreColor do
  286.     if srl.FindColors(TPA, color, B) then begin
  287.       TPA := R.Filter(TPA).Cluster(MainScreen.NormalizeDistance(9)).Biggest();
  288.       Fitted := TPA.MinAreaRect();
  289.       if Length(TPA) > MainScreen.NormalizeDistance(200) then
  290.         Exit(True);
  291.     end;
  292. end;
  293.  
  294.  
  295. procedure TMiner.TryApplySwivel();
  296. begin
  297.   if (Self.SweivelTimer < GetTimeRunning()) then begin
  298.     Antiban.Swivel();
  299.     Self.SweivelTimer := GetTimeRunning() + srl.SkewedRand(30000, 0, 90000, 3);
  300.   end;
  301. end;
  302.  
  303.  
  304. procedure TMiner.TrackExperience();
  305. var
  306.   xpNow, xpGained: Int32;
  307.   xp_hour: Double;
  308. begin
  309.   if not Self.CanDebug.IsFinished() then
  310.     Exit;
  311.  
  312.   //ClearDebug();
  313.  
  314.   xpNow    := XPBar.Read();
  315.   xpGained := xpNow - Self.StartupXP;
  316.   xp_hour  := xpGained / GetTimeRunning() * 1000 * 60 * 60;
  317.  
  318.   WriteLn('--| CanItMine |----------------------------------------');
  319.   if Self.IsHyperFocused()        then WriteLn('CanItMine is set to Hyper focused')
  320.   else if Self.IsExtremeFocused() then WriteLn('CanItMine is set to Extremely focused')
  321.   else if Self.IsUnfocused()      then WriteLn('CanItMine is set to Unfocused')
  322.   else                                 WriteLn('CanItMine is set to Regular');
  323.  
  324.   WriteLn('* Exp/hour:  ', FloatToStr(Round(xp_hour,1)));
  325.   WriteLn('* Exp total: ', xpGained);
  326.   WriteLn('---------------------------------------------------------');
  327.  
  328.   Self.CanDebug.Restart(100);
  329. end;
  330.  
  331.  
  332. procedure TMiner.UnfocusedInit();
  333. begin
  334.   Self.UnfocucsedTimer := GetTimeRunning() + srl.SkewedRand(50000, 0, ONE_MINUTE*3, 3);
  335. end;
  336.  
  337.  
  338. function TMiner.IsUnfocused(): Boolean;
  339. begin
  340.   Result := (GetTimeRunning() < Self.UnfocucsedTimer);
  341. end;
  342.  
  343. procedure TMiner.HyperFocusInit();
  344. begin
  345.   Self.HyperFocusTimer := GetTimeRunning() + srl.SkewedRand(ONE_MINUTE*2.5, 0, ONE_MINUTE*5, 3);
  346. end;
  347.  
  348. procedure TMiner.ExtremeFocusInit();
  349. begin
  350.   Self.ExtremeFocusTimer := GetTimeRunning() + srl.SkewedRand(ONE_MINUTE*2.5, 0, ONE_MINUTE*5, 3);
  351. end;
  352.  
  353. procedure TMiner.LongExtremeFocusInit();
  354. begin
  355.   Self.ExtremeFocusTimer := GetTimeRunning() + srl.SkewedRand(ONE_MINUTE*4, 0, ONE_MINUTE*7, 3);
  356. end;
  357.  
  358. function TMiner.IsHyperFocused(): Boolean;
  359. begin
  360.   Result := (GetTimeRunning() < Self.HyperFocusTimer);
  361. end;
  362.  
  363. function TMiner.IsExtremeFocused(): Boolean;
  364. begin
  365.   Result := (GetTimeRunning() < Self.ExtremeFocusTimer);
  366. end;
  367.  
  368.  
  369. function TMiner.BurstOfUnfocused(): Boolean;
  370. var
  371.   i,hi: Int32;
  372.   ForceMouseOff: Boolean;
  373. begin
  374.   i := 0;
  375.   WriteLn('[Antiban] Unfocused events!');
  376.   Result := True;
  377.   hi := srl.TruncatedGauss(5,0);
  378.   while Result and (i < hi) do
  379.   begin
  380.     Result := False;
  381.  
  382.     if (Random() < 0.33) then
  383.     begin
  384.       WriteLn('[Antiban] Unfocused event: Swivel');
  385.       Antiban.SwivelNear(mouse.Position, 0.4, Random(3), Random(25,50), Random() > 0.5, Random(1,4));
  386.     end;
  387.  
  388.     if (Random() < 0.35) or ForceMouseOff then
  389.     begin
  390.       WriteLn('[Antiban] Unfocused event: MouseOff/LoseFocus!');
  391.       srl.MouseOffClient(srl.SkewedRand(3,0,3));
  392.       Antiban.LoseFocus(srl.SkewedRand(1000,500,30000));
  393.       Result := True;
  394.       ForceMouseOff := False;
  395.     end;
  396.  
  397.     if (Random() < 0.10) then
  398.     begin
  399.       WriteLn('[Antiban] Unfocused event: Check skill');
  400.       Antiban.HoverSkill(ERSSkill.MINING, Trunc(srl.SkewedRand(300,100,3000)), Random() > 0.33);
  401.       srl.MouseOffClient(Random(4));
  402.       Antiban.LoseFocus(Random(1000,20000));
  403.       Result := True;
  404.     end;
  405.  
  406.     if (Random() < 0.05) then
  407.     begin
  408.       WriteLn('[Antiban] Unfocused event: Random right');
  409.       Antiban.RandomRightClick();
  410.       Result := True;
  411.     end;
  412.  
  413.     if (Random() < 0.15) then
  414.     begin
  415.       WriteLn('[Antiban] Unfocused event: Examine player');
  416.       ForceMouseOff := not Antiban.HoverPlayerFunc();
  417.       Result := True;
  418.     end;
  419.  
  420.     Inc(i);
  421.   end;
  422. end;
  423.  
  424. procedure TMiner.TryTurn(R: TRectangle);
  425. begin
  426.   if (R.Mean.DistanceTo(Mouse.Position) < 30) and (not Self.IsOreAliveFast(R)) then
  427.   begin
  428.     Mouse.Move(R);
  429.     Sleep(Random(60,90));
  430.     if MainScreen.IsUpText(['Mine', 'Rocks']) then
  431.       Mouse.Click(R, MOUSE_LEFT, Random() < 0.05);
  432.   end;
  433. end;
  434.  
  435.  
  436. procedure TMiner.DoAntiban(CheckBreaks: Boolean = True; CheckSleeps: Boolean = True);
  437. begin
  438.   Antiban.DoAntiban(CheckBreaks, CheckSleeps);
  439.   if not RSClient.IsLoggedIn() then
  440.     login.LoginPlayer();
  441. end;
  442.  
  443.  
  444. (*
  445.   Mines a series of rocks, and it tries to do it as fast as possible.
  446.  
  447.   There are no added delays like reaction time, other than the search for our
  448.   positon which delays like 20-40 ms, and the PC. Not that good, but just meant
  449.   to be freaking fast.
  450. *)
  451. function TMiner.MineExtremeFocus(): Boolean;
  452. var
  453.   ore, fittedOre, next, junk: TRectangle;
  454.   missing, xp_prior, count: Int32;
  455.   FastMouse: TMouse;
  456.   dropRenderingTimer: TCountDown;
  457.   ForceDrop: Boolean;
  458.  
  459.   function NextOre(pop: Boolean=True): TRectangle;
  460.   var me: TPoint;
  461.   begin
  462.     me := RSW.GetMyPos();
  463.     Result := Self.WorldToMS(me, Self.OreLocations[Self.OreCounter]);
  464.  
  465.     if pop then
  466.     begin
  467.       Inc(Self.OreCounter);
  468.       if Self.OreCounter = Length(Self.OreLocations) then Self.OreCounter := 0;
  469.     end;
  470.   end;
  471. begin
  472.   FastMouse := Mouse;
  473.   FastMouse.Speed := Random(18,23);
  474.   dropRenderingTimer.Init(700);
  475.  
  476.   next := NextOre(); //initalize next rock data
  477.   while Self.IsExtremeFocused() do
  478.   begin
  479.     Ore := NextOre();
  480.  
  481.     if ForceDrop or ((not Self.IsOreAlive(Ore, fittedOre))) then
  482.     begin
  483.       missing += 1;
  484.       if ForceDrop or (dropRenderingTimer.IsFinished() and (missing >= Length(Self.OreLocations)) or ((Inventory.Count() > 6) and (Random() < 0.15))) then
  485.       begin
  486.         Self.IntenseDrop(next.Mean());
  487.         dropRenderingTimer.Restart(70);
  488.         missing := 0;
  489.         count := 0;
  490.         ForceDrop := False;
  491.       end;
  492.       continue;
  493.     end;
  494.  
  495.     count += 1;
  496.  
  497.     // we just click this rock, so add it + cache where we are:
  498.     ClickOrder.Push(fittedOre);
  499.     next := ClickOrder.Next();
  500.  
  501.     RSClient.Image.Clear();
  502.     RSClient.Image.DrawRect(fittedOre, $00FF00);
  503.  
  504.     FastMouse.Move(fittedOre, Random() < 0.05);
  505.     Sleep(Random(60,90));
  506.     if not MainScreen.IsUpText('Mine Rocks') then
  507.       continue;
  508.  
  509.     xp_prior := XPBar.Read();
  510.     FastMouse.Click(fittedOre, MOUSE_LEFT, Random() < 0.15);
  511.     if not MainScreen.DidRedClick() then
  512.       continue;
  513.  
  514.     if {(count < Length(Self.OreLocations)) or }(count < MIN_ORE_DROP_COUNT) then
  515.       FastMouse.Move(next)
  516.     else
  517.     begin
  518.       FastMouse.Move(Inventory.GetSlotBox(0)); //prepare for dropping
  519.       ForceDrop := True;
  520.     end;
  521.  
  522.     WaitUntil((XPBar.Read() <> xp_prior) or (not Self.IsOreAlive(Ore,junk)) or (Chat.LeveledUp()) or Chat.FindOption('is too full to hold', [CHAT_COLOR_BLACK]), 20, Random(8000,10000));
  523.     RSClient.Image.DrawRect(fittedOre, $FF);
  524.  
  525.     if Random(100) < EXTREME_TURN_PERCENTAGE then
  526.       Self.TryTurn(next);
  527.  
  528.     Self.TrackExperience();
  529.   end;
  530. end;
  531.  
  532.  
  533. (*
  534.   Mines a single ore.
  535.  
  536.   Computers are differnt than people, they tend to repeat the same task in the
  537.   exact same amount of time, so I've added a variance to this, ReactionTime.
  538.   Humans, notably gamers, have a focused reactiontime of 150-250 ms.
  539.   This kicks in when we have predicted the next ore to be mined correctly.
  540. *)
  541. function TMiner.MineOnce(out Rect,NextRect: TRectangle): Boolean;
  542. var
  543.   arr: TRectArray;
  544.   R,_: TRectangle;
  545.   circle: TCircle;
  546.   i: Int32;
  547.   HumanResponseTimer, ReactionTime: Double;
  548. begin
  549.   RSClient.Image.Clear();
  550.   HumanResponseTimer := GetTimeRunning();
  551.  
  552.   case Self.IsHyperFocused() of
  553.     True:  ReactionTime := srl.SkewedRand(140, 100, 400);
  554.     False: ReactionTime := srl.SkewedRand(180, 150, 900);
  555.   end;
  556.  
  557.   if Self.IsUnfocused() then
  558.     ReactionTime *= 1.5;
  559.  
  560.   // a 7% chance that our rection time just becomes crap no matter focus
  561.   if(Random() < 0.07) then
  562.     ReactionTime += Random(2000);
  563.  
  564.   // It actually ended up trading one guy, idk how
  565.   if ChooseOption.IsOpen then
  566.     ChooseOption.Close();
  567.  
  568.   arr := Self.GetOres();
  569.   for i:=0 to High(arr) do begin
  570.     if not Self.IsOreAlive(arr[i], R) then
  571.       continue;
  572.  
  573.     // move the mouse
  574.     RSClient.Image.DrawRect(R, $00FF00);
  575.     Mouse.Move(R, Random() < 0.1);
  576.  
  577.     Sleep(Random(10,40));
  578.     if not WaitUntil(MainScreen.IsUpText(['Mine','Rocks']), Random(20,50), Random(200,300)) then
  579.       break;
  580.  
  581.     // a humans reactiontime offset
  582.     WaitUntil(GetTimeRunning() > HumanResponseTimer+ReactionTime, Random(5,15), 2000);
  583.  
  584.     // click it!
  585.     Mouse.Click(R, MOUSE_LEFT, Random() < 0.15);
  586.     Result := MainScreen.DidRedClick();
  587.     if not Result then
  588.       WriteLn('This might be bad');
  589.  
  590.     // random extra clicks
  591.     for 1 to SRL.TruncatedGauss(-2, 3) do
  592.     begin
  593.       circle.x := Mouse.Position().X;
  594.       circle.y := Mouse.Position().Y;
  595.       circle.radius := 5;
  596.       Mouse.Click(circle, MOUSE_LEFT, True);
  597.       Sleep(Random(0,150));
  598.     end;
  599.  
  600.     if not Result then
  601.       continue;
  602.  
  603.     //output current rectangle
  604.     Rect := R;
  605.  
  606.     // burst of unfocused
  607.     if Self.IsUnfocused() and Self.BurstOfUnfocused() then
  608.       Exit(True);
  609.  
  610.     // fill with current, than fetch the next one
  611.     ClickOrder.Push(R);
  612.     nextRect := ClickOrder.Next();
  613.  
  614.     // move mouse to the next ore
  615.     if (Random() > 0.1) or (Self.IsHyperFocused() and (Random() > 0.05)) then
  616.     begin
  617.       Wait(0,700, wdLeft);
  618.       if nextRect.Mean.InBox(MainScreen.Bounds) then
  619.         Mouse.Move(nextRect, Random() < 0.1);
  620.     end;
  621.     break;
  622.   end;
  623.  
  624.   if (not Result) then
  625.     Self.TryApplySwivel();
  626. end;
  627.  
  628. (*
  629.   Mines one inventory of ores
  630. *)
  631. function TMiner.Mine(): Boolean;
  632. var
  633.   next,r,_: TRectangle;
  634.   baseCount,clicks,success,xp_prior: Int32;
  635.   breakrnd: Double;
  636. begin
  637.   Result := False;
  638.   (* the loops criteria like this:
  639.     1. If inventory is open then we check if its full, and if so break
  640.     2. If chat-message too full inventory then be break
  641.     3. If we are in unfocused mode we may click the ore even tho inventory is full a few times
  642.     4. We might miss that it's full on a rare occation as well
  643.   *)
  644.   while True do
  645.   begin
  646.     xp_prior := XPBar.Read();
  647.     if Self.MineOnce(r,next) then
  648.     begin
  649.       if Inventory.IsOpen() then Inc(clicks);
  650.       if Inventory.IsOpen() then baseCount := Inventory.Count();
  651.       Sleep(Random(50,150));
  652.       WaitUntil(not Minimap.IsPlayerMoving(), 30, Random(2000,3000));
  653.  
  654.       WaitUntil((XPBar.Read() <> xp_prior) or (not Self.IsOreAlive(r,_)) or (Chat.LeveledUp()) or Chat.FindOption('is too full to hold', [CHAT_COLOR_BLACK]), 20, Random(8000,12000));
  655.       RSClient.Image.DrawRect(R, $FF);
  656.  
  657.       if Inventory.IsOpen() and (Inventory.Count() > baseCount) then Inc(success);
  658.  
  659.       // turn towards next ore (?)
  660.       if (Random() < 0.1) or Self.IsHyperFocused() then
  661.         Self.TryTurn(next);
  662.  
  663.       // check if we have an antiban ready and lined up
  664.       Self.DoAntiban();
  665.  
  666.       // High competition for the ore? Let's trigger hyper focus!
  667.       if (clicks > Random(3,5)) and (success / clicks < 0.67) then
  668.       begin
  669.         Self.LongExtremeFocusInit();
  670.         WriteLn('[Warning: high competition]: Burst of extreme focus = Enabled!');
  671.         WriteLn('                             Lasts for: ', (Self.HyperFocusTimer-GetTimeRunning()) / 1000, 'sec');
  672.         Exit;
  673.       end;
  674.  
  675.       // a 5% chance of just waiting a little extra between ores.
  676.       if (Random() < 0.05) and (not Self.IsHyperFocused()) then
  677.         Sleep(srl.SkewedRand(70,0,4000));
  678.  
  679.       // There's a random 1.5% chance we trigger a burst of halfassed unfocused working
  680.       if (not Self.IsUnfocused()) and (Random() < 0.015) then
  681.       begin
  682.         Self.UnfocusedInit();
  683.         WriteLn('[Antiban] Burst of unfocused = Enabled!');
  684.         WriteLn('          Lasts for: ', (Self.UnfocucsedTimer-GetTimeRunning()) / 1000, 'sec');
  685.       end;
  686.  
  687.       // There's a random 0.5% chance we trigger hyper focus
  688.       if (not Self.IsHyperFocused()) and (Random() < 0.005) then
  689.       begin
  690.         Self.HyperFocusInit();
  691.         WriteLn('[Antiban] [RND]: Burst of hyper focus = Enabled!');
  692.         WriteLn('          Lasts for: ', (Self.HyperFocusTimer-GetTimeRunning()) / 1000, 'sec');
  693.       end;
  694.  
  695.       // There's a random 1.5% chance we trigger extreme focus
  696.       if (not Self.IsExtremeFocused()) and (Random() < 0.015) then
  697.       begin
  698.         Self.ExtremeFocusInit();
  699.         WriteLn('[Antiban] [RND]: Burst of extreme focus = Enabled!');
  700.         WriteLn('          Lasts for: ', (Self.ExtremeFocusTimer-GetTimeRunning()) / 1000, 'sec');
  701.         break;
  702.       end;
  703.  
  704.       // if inventory isn't open then add a chance for actually opening it again
  705.       // assuming we are not in an unfocused burst
  706.       if (Random(14) = 0) and (not Inventory.IsOpen()) and (not Self.IsUnfocused()) then
  707.         Inventory.Open();
  708.  
  709.       // trigger intense drop every 3th success
  710.       if Self.IsHyperFocused() and (success mod 3 = 0) then
  711.         Self.IntenseDrop(next.Mean());
  712.     end;
  713.  
  714.     // working out loop conditions:
  715.     breakrnd := 0.1;
  716.     if Self.IsUnfocused() then breakrnd := 0.5;
  717.  
  718.     if (Inventory.IsOpen() and Inventory.IsFull()) and (Random() > breakrnd) then
  719.       break;
  720.  
  721.     if RSW.GetMyPos().DistanceTo(Self.OreLocations[0]) > 10 then
  722.       break;
  723.  
  724.     if not RSClient.IsLoggedIn() then
  725.       break;
  726.  
  727.     if (Chat.FindOption('is too full to hold', [CHAT_COLOR_BLACK])) and (Random() > breakrnd) then
  728.       break;
  729.  
  730.     // track XP
  731.     Self.TrackExperience();
  732.   end;
  733.  
  734.   if (Random() < 0.16) and (Chat.FindOption('is too full to hold')) then
  735.     Chat.ClickContinue(Random() > 0.1);
  736. end;
  737.  
  738.  
  739. procedure TMiner.IntenseDrop(ReturnTo: TPoint);
  740. var
  741.   slots,order: TIntegerArray;
  742.   i: Int32;
  743.   n: Int32 = 3;
  744. begin
  745.   // first check if we should reorganize inventory
  746.   Self.OrganizeInv();
  747.  
  748.   // now we can do the dropping
  749.   if Random(5) = 0 then
  750.     n := Random(2,6);
  751.  
  752.   // in case we have a lot more time to drop, so increase rates!
  753.   if Length(Self.OreLocations) < 3 then
  754.   begin
  755.     n := 6;
  756.     if Random(5) = 0 then
  757.       n := Random(4,12);
  758.   end;
  759.  
  760.   if Inventory.FindItems(WHAT_TO_DROP, Slots) then
  761.     for i := 0 to High(DROP_PATTERN_REGULAR) do
  762.       if Slots.Find(DROP_PATTERN_REGULAR[I]) > -1 then
  763.         order += DROP_PATTERN_REGULAR[I];
  764.  
  765.   if (Length(Slots) >= MIN_ORE_DROP_COUNT) then
  766.   begin
  767.     SetLength(order, Min(Length(order), n));
  768.     Inventory.ShiftDrop(Inventory.ErrorPattern(order,3));
  769.     Mouse.Move(ReturnTo,25);
  770.   end;
  771. end;
  772.  
  773.  
  774. procedure TMiner.DropInventory();
  775. var
  776.   ptrn: TIntegerArray;
  777.   slices: TIntegerArray;
  778.   sequences: T2DIntArray;
  779.   i,hi: Int32;
  780. begin
  781.   ptrn := Inventory.ErrorPattern(DROP_PATTERN_REGULAR, 10);
  782.  
  783.   hi := 0;
  784.   while hi <> Length(ptrn) do
  785.   begin
  786.     if Self.IsUnfocused() then
  787.       slices += Random(hi, Length(ptrn))
  788.     else
  789.       slices += srl.TruncatedGauss(Length(ptrn), hi, 6);
  790.     hi := slices[High(slices)];
  791.   end;
  792.   sequences += Copy(ptrn, 0, slices[0]);
  793.   for i:=1 to High(slices) do
  794.     sequences += Copy(ptrn, slices[i-1], 28-slices[i-1]);
  795.  
  796.  
  797.   for i:=0 to High(sequences) do
  798.   begin
  799.     ptrn := sequences[i];
  800.  
  801.     // check if we have an antiban ready and lined up
  802.     Self.DoAntiban();
  803.  
  804.     // shift-drop the rest of our ores
  805.     Inventory.ShiftDrop(WHAT_TO_DROP, ptrn);
  806.     if Self.IsUnfocused() then Self.BurstOfUnfocused();
  807.  
  808.     if (Self.IsHyperFocused()) and (i = High(sequences))  then
  809.       break;
  810.  
  811.     Sleep(srl.TruncatedGauss(0, 6000, 6));
  812.  
  813.     // if we are unfocused shit might happen.
  814.     if Self.IsUnfocused() then
  815.     begin
  816.       Self.BurstOfUnfocused();
  817.       if (Random() < 0.1) then break;
  818.     end;
  819.   end;
  820.  
  821.   //selection := Inventory.GetSelectedSlot();
  822.   //if selection <> -1 then Inventory.ClickSlot(i);
  823. end;
  824.  
  825.  
  826. procedure TMiner.DebugOres();
  827. var
  828.   arr: TRectArray;
  829.   rect,_: TRectangle;
  830. begin
  831.   arr := Self.GetOres();
  832.   for rect in arr do
  833.   begin
  834.     if Self.IsOreAlive(rect,_) then
  835.       RSClient.Image.DrawRect(rect, $00FF00)
  836.     else
  837.       RSClient.Image.DrawRect(rect, $FF);
  838.   end;
  839. end;
  840.  
  841.  
  842. procedure TMiner.SetupOres(out Locations: T2DPointArray; out Colors: array of array of TCTS2Color);
  843. begin
  844.   locations := [];
  845.   colors    := [];
  846.  
  847.   {EastVarrockMine - iron ore}
  848.   locations += [[4950+159, 2976-429],[4954+159, 2972-429]];
  849.   colors    += [CTS2(2240329, 11, 0.12, 0.60)];
  850.  
  851.   {EastArdougneMine - iron ore}
  852.   locations += [[2574+159, 3131-429],[2578+159, 3135-429],[2582+159, 3131-429]];
  853.   colors    += [CTS2(2240329, 11, 0.12, 0.60)];
  854.  
  855.   {LumbridgeTutor - tin ore}
  856.   locations += [[4700+159, 3864-429],[4697+159, 3860-429],[4701+159, 3856-429]];
  857.   colors    += [CTS2(8421769, 10, 0.29, 0.17)];
  858.  
  859.   {AkaridMine - iron ore}
  860.   locations += [[5148, 2782],[5144, 2778],[5148,2774]];
  861.   colors    += [CTS2(2240329, 11, 0.12, 0.60)];
  862.  
  863.   {WildyMine - iron ore}
  864.   locations += [[4229+159, 2172-429],[4226+159, 2167-429]];
  865.   colors    += [CTS2(2240329, 11, 0.12, 0.60)];
  866.  
  867.   {F2P Mining Guild - 2 rock - iron ore}
  868.   locations += [[5987, 6526],[5983, 6530]];
  869.   colors    += [CTS2(2240329, 11, 0.12, 0.60)];
  870. end;
  871.  
  872.  
  873. procedure TMiner.Setup();
  874. var
  875.   i: Int32;
  876.   me: TPoint;
  877.   reg: TBox;
  878.   locations: T2DPointArray;
  879.   colors: array of array of TCTS2Color;
  880.   R: TRectangle;
  881. begin
  882.   RSClient.Image.Clear();
  883.   Mouse.Speed := Random(14,16);
  884.  
  885.   // ===========================================================================
  886.   // detect ore location automatically based on our current pos:
  887.   RSW.Setup('world');
  888.  
  889.   Self.SetupOres(locations, colors);
  890.  
  891.   me := RSW.GetMyPos();
  892.   WriteLn('Found your location as: ', me);
  893.   for i:=0 to High(locations) do
  894.     if Distance(locations[i][0], me) < 4*4 then //4 tiles away at most
  895.     begin
  896.       Self.OreLocations := locations[i];
  897.       break;
  898.     end;
  899.  
  900.   if Self.OreLocations = [] then
  901.     TerminateScript('Not near any ores');
  902.  
  903.   RSW.Free(); // release world RSW.
  904.  
  905.   Self.OreColor := colors[i]; // `i` was defined in the loop above.
  906.  
  907.  
  908.   // ===========================================================================
  909.   // load powerminer by region:
  910.   reg := [Self.OreLocations[0].x-150,Self.OreLocations[0].y-150,Self.OreLocations[0].x+150,Self.OreLocations[0].y+150];
  911.   Self.RSW.Setup('world', TBoxArray([reg]));
  912.  
  913.  
  914.   // ===========================================================================
  915.   // Debug test
  916.   Self.DebugOres();
  917.  
  918.  
  919.   // ===========================================================================
  920.   // Setup standard shit
  921.   Self.SweivelTimer := GetTimeRunning() + srl.SkewedRand(2000, 0, 10000, 3);
  922.   Self.DeclarePlayers();
  923.  
  924.   Antiban.Skills := [ERSSkill.MINING];
  925.   Antiban.MaxZoom := 60;
  926.   Antiban.MinZoom := 30;
  927.  
  928.   Antiban.AddTask(5  * ONE_MINUTE, @Antiban.HoverPlayer);
  929.   Antiban.AddTask(6  * ONE_MINUTE, @Antiban.RandomPOVTask);
  930. //Antiban.AddTask(8  * ONE_MINUTE, @Antiban.RandomRightClick);
  931.   Antiban.AddTask(8  * ONE_MINUTE, @Antiban.Swivel);
  932.   Antiban.AddTask(9  * ONE_MINUTE, @Antiban.HoverSkills);
  933.   Antiban.AddTask(10 * ONE_MINUTE, @Antiban.LoseFocus);
  934.   Antiban.AddTask(12 * ONE_MINUTE, @Antiban.RandomTab);
  935.  
  936.   Antiban.AddBreak(30  * ONE_MINUTE, 1  * ONE_MINUTE, 0.33, 0.01);
  937.   Antiban.AddBreak(60  * ONE_MINUTE, 2  * ONE_MINUTE, 0.33, 0.02);
  938.   Antiban.AddBreak(80  * ONE_MINUTE, 5  * ONE_MINUTE, 0.33, 0.15);
  939.   Antiban.AddBreak(100 * ONE_MINUTE, 10 * ONE_MINUTE, 0.33, 0.75);
  940.   Antiban.AddBreak(150 * ONE_MINUTE, 30 * ONE_MINUTE, 0.33, 0.85);
  941.   //Antiban.AddSleep('00:00', 8, 1, 1.0);
  942.  
  943.   RSW.ScreenWalk := True;
  944.  
  945.   Self.StartupXP := XPBar.Read();
  946.  
  947.   me := Self.RSW.GetMyPos();
  948.   for i:=0 to High(Self.OreLocations) do
  949.     Self.ClickOrder.History += self.WorldToMS(me, Self.OreLocations[i]);
  950.  
  951.   Self.CanDebug.Init(2000);
  952. end;
  953.  
  954. var rsw_time: Double;
  955. begin
  956.   srl.Setup();
  957.   Bot.Setup();
  958.  
  959.   rsw_time := PerformanceTimer();
  960.   Bot.RSW.GetMyPos();
  961.   WriteLn(PerformanceTimer() - rsw_time, 'ms to look up position!');
  962.  
  963.   while RSClient.IsLoggedIn() do
  964.   begin
  965.     if Bot.RSW.GetMyPos().DistanceTo(Bot.OreLocations[0]) < 10 then
  966.     begin
  967.       if Bot.IsExtremeFocused() then
  968.         Bot.MineExtremeFocus()
  969.       else
  970.         Bot.Mine();
  971.     end
  972.     else
  973.       TerminateScript('There are no ores near by');
  974.  
  975.     if Inventory.IsFull() then
  976.       Bot.DropInventory();
  977.  
  978.     if not RSClient.IsLoggedIn() then
  979.       login.LoginPlayer();
  980.   end;
  981. end.
Tags: pascal Simba
Add Comment
Please, Sign In to add comment