Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program BarbFlyFisher_Extended_V001;
- {$DEFINE SRL_USE_REMOTEINPUT}
- {$I SRL/osr.simba}
- {$H-}
- {==============================================================================]
- | Barbarian FlyFisher ™
- |
- | Steps to use:
- | 1. For longer runs you need to declare user details bellow
- | 2. Start the script wherever, just have fishing rod and feathers in your inv
- |
- | Any issues starting it: Re-target RS, and try again, may help if you log
- | in manually before doing that.
- |
- | Banking might not work very well.
- [==============================================================================}
- type
- TFisherStyle = (FishCookBank, FishCookDrop, FishDrop);
- const
- LOGIN_NAME = 'yourname';
- LOGIN_PASS = 'yourpass';
- IS_MEMBER = FALSE; // TRUE or FALSE
- STYLE = FishCookDrop; // FishCookBank or FishCookDrop, FishDrop
- type
- TFisher = record
- StatsDebugTick: Int64;
- FishingXP: Int32;
- StartupXP: Int32;
- RSW: TRSWalker;
- end;
- var
- Bot: TFisher;
- const
- F2P_WORLDS = [301,308,380,434,435,436,437,451];
- P2P_WORLDS = [302,303,304,305,306,307,309,310,311,312,313,314,315,317,318,319,320];
- procedure TMouse.Move(Rect: TRectangle; ForcedMove: Boolean = False); override;
- begin
- if (ForcedMove) or (not Rect.Contains(Mouse.Position())) then
- Mouse.Move(srl.rowp(mouse.Position(), Rect));
- end;
- // -----------------------------------------------------------------------------
- // -----------------------------------------------------------------------------
- // FISHER
- function TFisher.WorldToMS(PlayerPoint, WorldPoint: TPoint): TRectangle;
- var pt: TPoint;
- begin
- pt := RSW.WorldToMM(PlayerPoint, WorldPoint, Minimap.GetCompassAngle(False));
- Result := Minimap.PointToMsRect(pt);
- end;
- procedure TFisher.DeclarePlayers();
- begin
- if IS_MEMBER then
- Login.AddPlayer(LOGIN_NAME, LOGIN_PASS, '', P2P_WORLDS)
- else
- Login.AddPlayer(LOGIN_NAME, LOGIN_PASS, '', F2P_WORLDS);
- end;
- procedure TFisher.DoAntiban();
- begin
- Antiban.DismissRandom();
- if Antiban.DoAntiban() then
- Login.LoginPlayer(); // if we got logged out, and not logged back in
- end;
- procedure TFisher.PostAction(AntiBan:Boolean=True);
- begin
- WaitEx(450,70);
- if AntiBan then Self.DoAntiban();
- end;
- procedure TFisher.ProcessWhileWaiting();
- var
- xpNow, xpGained, fishingXP, cookingXP: Int32;
- xpHour, fishingXPHour, cookingXPHour: Double;
- begin
- if GetTickCount() - StatsDebugTick > 2000 then
- begin
- // total XP
- xpNow := XPBar.Read();
- xpGained := xpNow - Self.StartupXP;
- xpHour := xpGained / GetTimeRunning() * 1000 * 60 * 60;
- // Fishing XP
- fishingXPHour := Self.FishingXP / GetTimeRunning() * 1000 * 60 * 60;
- // Cooking XP {is the difference in gained XP}
- cookingXP := xpGained - Self.FishingXP;
- cookingXPHour := cookingXP / GetTimeRunning() * 1000 * 60 * 60;
- ClearDebug();
- WriteLn('+---| STATS |----------------------------------------');
- WriteLn('|- Script Runtime: ', SRL.MsToTime(GetTimeRunning, Time_Short));
- WriteLn('|- Fishing Exp/hour: ', FloatToStr(Round(fishingXPHour,1)));
- WriteLn('|- Cooking Exp/hour: ', FloatToStr(Round(cookingXPHour,1)));
- WriteLn('|- Total Exp/hour: ', FloatToStr(Round(xpHour,1)));
- WriteLn('|- Total Exp Gain: ', xpGained);
- WriteLn('+----------------------------------------------------');
- Self.StatsDebugTick := GetTickCount();
- end;
- Self.DoAntiban();
- end;
- // Find fishingspots by finding the edges of the water, over and over again
- // Then do some fancy stuff to remove land->water borders.
- // what's left is an accurate TPA of the fishingspot
- //
- // However any movement near water will affect this, like lowering a lobsterpot
- // so we expand on it with using actual pixels that match flickering colors
- //
- // MaxIslands: Further more I think a fishingspot should be dense, not be
- // cluttered by many small unconnected pixels. So when character is moving it
- // wont detect much at all. This is to avoid having to mouse over a ton.
- function TFisher.FindFishingSpot(scanTime: Int32=450; MaxIslands: Int32 = 10): T2DPointArray;
- var
- i: Int32;
- SUM,TPA,pix: TPointArray;
- tmp: T2DPointArray;
- R: TRectangle;
- t: TCountDown;
- c: TCircle;
- begin
- t.Init(scanTime);
- while not t.IsFinished do
- begin
- srl.FindColors(TPA, CTS2(8875103, 16,0.20,0.70), Mainscreen.Bounds);
- srl.FindColors(pix, CTS2(14397886,20,0.92,1.60), Mainscreen.Bounds);
- TPA := TPA.PointsInRangeOf(pix, 0, 4);
- SUM += TPA.Edges();
- end;
- SUM.ClearDuplicates();
- SUM := ClearTPAFromTPA(Sum, Sum.Edges());
- tmp := SUM.Cluster(5);
- tmp.FilterSize(12, __GT__);
- // MaxIslands ->
- for i:=0 to High(tmp) do
- if (Length(tmp[i].Cluster(1)) <= MaxIslands) and (tmp[i].MinAreaRect().MaxRadius() < 50) then
- Result += tmp[i];
- // debug
- RSClient.Image.Clear();
- for i:=0 to High(Result) do
- begin
- RSClient.Image.DrawTPA(Result[i], Random($FFFFFF));
- c := Result[i].MinAreaCircle();
- RSClient.Image.DrawCircle(c.Mean(), c.Radius, Random($FFFFFF));
- end;
- end;
- // Open the bank in Edgeville using the first booth
- function TFisher.OpenEdgevilleBank(): Boolean;
- var
- r: TRectangle;
- booth, grayOfBank, frameOfBank: TPointArray;
- begin
- // Generate a searcharea near the approximate location of the bankbooth.
- r := Self.WorldToMS(Self.RSW.GetMyPos(), [4348,2062]).Expand(10);
- (*
- Filter logic:
- 1. Find gray panel of the bank
- 2. Find wood frame of bank
- 3. With the use of PointInRangeOf we combine the two where they are in range
- of 10 px from eachother. So, where gray is found near brown frame.
- 4. We apply some minimal errotion to the resulting points in order to
- reduce pixelation noise.
- 5. We cluster it, and select the largest cluster, with the assumption that
- it will be the bank booth itself.
- *)
- // 1. and 2.
- srl.FindColors(grayOfBank, CTS2(6251883, 6, 1.07, 0.87), r.Bounds());
- srl.FindColors(frameOfBank, CTS2(1069673, 6, 0.11, 1.29), r.Bounds());
- // 3.
- booth := grayOfBank.PointsInRangeOf(frameOfBank, 0, 10);
- booth += frameOfBank.PointsInRangeOf(grayOfBank, 0, 10);
- // 4. and 5.
- booth := booth.Erode(1).Cluster(1).Biggest();
- // R now contains a rectangle of approximately the same area as the bank
- // it may at times be a little large though, meaning unclickable pixels.
- r := booth.MinAreaRect();
- // you can now debug it to see what we found:
- //RSClient.Image.DrawTPA(Bank, $00FF00);
- //RSClient.Image.DrawRect(R, $0000FF);
- // because of the note above we will try a few times, each time it will generate
- // a new random point in the rectangle:
- for 1 to 5 do
- if Bank.Open(srl.rowp(Mouse.Position(), r)) then
- Exit(True);
- end;
- // Basically we find the fishingrod by checking the two tiles infront of
- // our character. It can fail if your character covers most of the rod
- function TFisher.IsFishing(): Boolean;
- var
- rect1,rect2: TRectangle;
- TPA1,TPA2: TPointArray;
- begin
- Rect1 := Minimap.StaticToMsRect(Minimap.Center()+[4,0],1);
- Rect2 := Minimap.StaticToMsRect(Minimap.Center()+[7,0],1);
- RSClient.Image.DrawRect(Rect1, $FFFFFF);
- RSClient.Image.DrawRect(Rect2, $FFFFFF);
- if srl.FindColors(TPA1, CTS2(6694,10), Rect1.Bounds) > 12 then
- Result := srl.FindColors(TPA2, CTS2(6694,10), Rect2.Bounds) > 5;
- end;
- // Finds fishing spots, click one, and waits while we are fishing
- //
- function TFisher.Fish(MaxTimeCatch: Int32 = 10000{milliseconds}): Boolean;
- var
- ATPA: T2DPointArray;
- TPA: TPointArray;
- timer: TCountDown;
- z1,z2: Int32;
- begin
- if (not Inventory.ContainsItem('Fly fishing rod')) or
- (not Inventory.ContainsItem('Feather')) then
- TerminateScript('No feathers or fly fishing rod');
- ATPA := Self.FindFishingSpot();
- ATPA.SortByMiddle(MainScreen.Center());
- for TPA in ATPA do
- begin
- mouse.Move(TPA.Bounds);
- if not MainScreen.IsUpText(['Fishing spot']) then
- Continue;
- mouse.Click(MOUSE_LEFT);
- if MainScreen.DidRedClick() then
- begin
- Wait(700,1000);
- Minimap.WaitPlayerMoving();
- Wait(1400,1700);
- Self.FindFishingSpot(); //update drawing.
- // wait while we are catching fish.
- // isFishing checks if our fishingrod is visible
- // in case of false positive, we check for increment of XP.
- timer.Init(MaxTimeCatch);
- z1 := XPBar.Read();
- while Self.IsFishing() and (not timer.IsFinished()) do
- begin
- Self.ProcessWhileWaiting();
- Chat.ClickContinue();
- WaitEx(70,10);
- z2 := XPBar.Read();
- if z1 <> z2 then
- begin
- timer.Init(MaxTimeCatch);
- Self.FishingXP += z2 - z1;
- z1 := z2;
- end;
- end;
- // no need to check the other groups in the ATPA, it's outdated as we have
- // been fishing, so exit successfully
- Exit(True);
- end else
- begin
- // Well, we clicked, but no red click, so we missed somehow.
- // Probably in motion.
- Wait(700,1200);
- Minimap.WaitPlayerMoving();
- Wait(700,1200);
- Exit(False);
- end;
- end;
- end;
- // Waits while we are cooking.
- // Cooking is determined by checking if the number of raw fish in our inventory
- // is reducing. It must reduce by at least 1 within 5.5 seconds.
- function TFisher.WaitCooking(): Boolean;
- var
- c, currCount: Int32;
- t: TCountDown;
- begin
- c := Inventory.CountItem('Raw trout') + Inventory.CountItem('Raw salmon');
- t.Init(5500);
- repeat
- if Chat.LeveledUp() then
- Break;
- currCount := Inventory.CountItem('Raw trout') + Inventory.CountItem('Raw salmon');
- if currCount <> c then
- begin
- c := currCount;
- t.Restart(50);
- end;
- Self.ProcessWhileWaiting();
- Wait(70);
- until t.IsFinished() or (c = 0);
- Result := True;
- end;
- // Do the cooking!
- // 1. Walks to a point near the eternal fire.
- // 2. Searches for the fire and uses a fish on the fire
- // If it fails to find the fire it rotates the screen and tries again.
- // 3. Cooks it, and waits til we dont cook any more, or till we level up.
- // Repeats #2->#3 until there are no more fish in our inventory.
- function TFisher.Cook(): Boolean;
- var
- idx: Int32;
- arr: TIntegerArray;
- rect: TRectangle;
- objects: T2DPointArray;
- fire: TPointArray;
- foundFire: Boolean;
- begin
- Inventory.Open();
- if (not Inventory.ContainsItem('Raw trout')) and (not Inventory.ContainsItem('Raw salmon')) then
- Exit;
- if Distance([4393, 2292], RSW.GetMyPos()) > 4*2 then
- RSW.WebWalk([4393, 2292], 2);
- repeat
- arr := [];
- Inventory.FindItems(['Raw trout', 'Raw salmon'], arr);
- if(arr = []) then
- Break;
- FoundFire := False;
- srl.FindColors(Fire, CTS2(12348,15), MainScreen.Bounds());
- objects := Fire.Cluster(5);
- objects.FilterSize(16, __GT__);
- objects.SortByMiddle(Self.WorldToMS(RSW.GetMyPos(), [4393, 2292]).Mean());
- Inventory.ClickSlot(arr[0]);
- for fire in objects do
- begin
- rect := fire.MinAreaRect();
- mouse.Move(rect);
- Wait(60,100); //wait for game to refresh
- if MainScreen.IsUpText('Fire') then
- mouse.Click(mouse_Left)
- else if MainScreen.IsUpText('options') then
- begin
- if not ChooseOption.Select('Fire') then
- begin
- Wait(60,200);
- Continue;
- end
- end else
- continue;
- foundFire := True;
- // whenever we try to cook a single fish Make wont open.
- if (Make.IsOpen(2000)) then
- Make.Select(0, MAKE_QUANTITY_ALL, False);
- if Self.WaitCooking() then
- Break;
- end;
- if(not FoundFire) then
- Minimap.SetCompassAngle([0,90,180,270][Random(4)]+Random(-15,15));
- until False;
- end;
- procedure TFisher.DropInventory();
- var
- items: TStringArray;
- item: string;
- ptrn, slots: TIntegerArray;
- slices: TIntegerArray;
- sequences: T2DIntArray;
- i,hi: Int32;
- begin
- ptrn := Inventory.ErrorPattern(DROP_PATTERN_REGULAR, 10);
- hi := 0;
- while hi <> Length(ptrn) do
- begin
- slices += srl.TruncatedGauss(Length(ptrn), hi, 6);
- hi := slices[High(slices)];
- end;
- sequences += Copy(ptrn, 0, slices[0]);
- for i:=1 to High(slices) do
- sequences += Copy(ptrn, slices[i-1], 28-slices[i-1]);
- for i:=0 to High(sequences) do
- begin
- ptrn := sequences[i];
- // check if we have an antiban ready and lined up
- Self.DoAntiban();
- // shift-drop the rest of our ores
- Inventory.ShiftDrop(['Salmon', 'Trout', 'Burnt fish', 'Raw trout', 'Raw salmon'], ptrn);
- if (Random() < 0.8) and (i = High(sequences)) then
- break;
- Sleep(srl.TruncatedGauss(0, 6000, 6));
- end;
- end;
- // Clear the inventory by dropping, or banking fish.
- //
- procedure TFisher.DoInventory();
- var
- items: TStringArray;
- slots: TIntegerArray;
- item: string;
- t: TCountDown;
- // Deposits all the fish in our inventory, cooked, raw and burnt.
- procedure Deposit();
- begin
- WriteLn('Status: Depositing fish! @ ', WorldWeb.LOCATION_EDGEVILLE_BANK);
- RSW.WebWalk(WorldWeb.LOCATION_EDGEVILLE_BANK, 3);
- Self.OpenEdgevilleBank();
- if not Bank.IsOpen() then
- TerminateScript('No bank');
- items := ['Salmon', 'Trout', 'Burnt fish', 'Raw trout', 'Raw salmon'];
- for item in items do
- begin
- slots := [];
- Inventory.FindItem(item, slots);
- if Length(slots) > 0 then
- begin
- Bank.DepositItem([item, BANK_DEPOSIT_ALL], True);
- t.Init(2000);
- while (not t.IsFinished()) and Inventory.IsSlotUsed(slots[0]) do
- Wait(70,160);
- end;
- end;
- Bank.Close(Random() > 0.1);
- end;
- begin
- if STYLE in [FishCookDrop, FishDrop] then
- Self.DropInventory()
- else
- Deposit();
- end;
- // Runs the bot
- //
- procedure TFisher.Run();
- begin
- MainScreen.SetHighestPitch();
- while RSClient.IsLoggedIn() do
- begin
- if Inventory.IsFull() then
- begin
- if STYLE <> FishDrop then
- begin
- self.Cook();
- self.PostAction();
- end;
- self.DoInventory();
- self.PostAction();
- end;
- if not self.Fish() then
- begin
- if RSW.GetMyPos.DistanceTo([4407, 2286]) > 20 then
- RSW.WebWalk([4407, 2286],3)
- else
- RSW.WebWalk([4382, 2321],3);
- Wait(700,1200);
- end;
- RsClient.Image.Clear();
- Self.ProcessWhileWaiting();
- end;
- end;
- procedure TFisher.SetupAntiban();
- begin
- Antiban.Skills := [ERSSkill.FISHING, ERSSkill.COOKING];
- Antiban.MaxZoom := 60;
- Antiban.MinZoom := 30;
- Antiban.AddTask(ONE_MINUTE*5, @Antiban.LoseFocus );
- //Antiban.AddTask(ONE_MINUTE*8, @Antiban.HoverPlayers );
- Antiban.AddTask(ONE_MINUTE*10, @Antiban.HoverSkills );
- Antiban.AddTask(ONE_MINUTE*10, @Antiban.RandomTab );
- Antiban.AddTask(ONE_MINUTE*25, @Antiban.RandomRightClick);
- Antiban.AddTask(ONE_MINUTE*40, @Antiban.RandomRotate );
- Antiban.AddBreak(25 * ONE_MINUTE, 01 * ONE_MINUTE, 0.01);
- Antiban.AddBreak(45 * ONE_MINUTE, 05 * ONE_MINUTE, 0.05);
- Antiban.AddBreak(02 * ONE_HOUR, 10 * ONE_MINUTE, 0.15);
- Antiban.AddBreak(04 * ONE_HOUR, 45 * ONE_MINUTE, 0.85);
- Antiban.AddBreak(17 * ONE_HOUR, 07 * ONE_HOUR, 0.99);
- end;
- procedure TFisher.Init();
- begin
- WorldWeb.Load();
- RSW.Setup('world', [RSWalkerRegions.WORLD]);
- RSW.WebGraph := WorldWeb;
- RSW.AdaptiveWalk := True;
- RSW_ADAPTIVE_SCREEN_TOGGLE_DISTANCES := [45,140];
- self.DeclarePlayers();
- self.SetupAntiban();
- Login.LoginPlayer();
- Self.StartupXP := XPBar.Read();
- end;
- procedure TFisher.Free();
- begin
- RSW.Free();
- end;
- begin
- bot.Init();
- AddOnTerminate(@bot.Free);
- bot.Run();
- end.
Add Comment
Please, Sign In to add comment