Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program BarbFlyFisher_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. Worst case, manually walk to barb. village
- [==============================================================================}
- type
- TFisherStyle = (FishCookBank, FishCookDrop, FishDrop);
- const
- LOGIN_NAME = 'yourname';
- LOGIN_PASS = 'yourpass';
- IS_MEMBER = FALSE; // TRUE or FALSE
- STYLE = FishCookBank; // FishCookBank or FishCookDrop, FishDrop
- type
- TFisher = record
- StatsDebugTick: Int64;
- RSW: TRSWalker;
- Debug: TMufasaBitmap;
- 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();
- begin
- if GetTickCount() - StatsDebugTick > 2000 then
- begin
- ClearDebug();
- ClearDebug();
- WriteLn('+---| STATS |----------------------------------------');
- WriteLn('|- Script Runtime : ', SRL.MsToTime(GetTimeRunning, Time_Short));
- 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
- function TFisher.FindFishingSpot(scanTime: Int32=450): T2DPointArray;
- var
- i: Int32;
- SUM,TPA: TPointArray;
- R: TRectangle;
- t: TCountDown;
- begin
- t.Init(scanTime);
- while not t.IsFinished do
- begin
- srl.FindColors(TPA, CTS2(8875103,16,0.2,0.7), Mainscreen.Bounds);
- SUM += TPA.Edges();
- end;
- SUM.ClearDuplicates();
- SUM := ClearTPAFromTPA(Sum, Sum.Edges());
- Result := SUM.Cluster(5);
- Result.FilterSize(12, __GT__);
- RSClient.Image.Clear();
- for i:=0 to High(Result) do
- RSClient.Image.DrawTPA(Result[i], Random($FFFFFF));
- end;
- // Open a bank
- 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(): Boolean;
- var
- ATPA: T2DPointArray;
- TPA: TPointArray;
- 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.
- while Self.IsFishing() do
- begin
- Self.ProcessWhileWaiting();
- Chat.ClickContinue();
- WaitEx(70,10);
- end;
- Exit(True);
- end else
- begin
- 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(Point(4393, 2292), RSW.GetMyPos) > 8 then
- RSW.WebWalk(Point(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(Mainscreen.Center());
- 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;
- if (Make.IsOpen(2000)) then
- Make.Select(0, MAKE_QUANTITY_ALL, False);
- //Chat.ClickButtonId('How many', 1, 'Cook', 3000);
- if Self.WaitCooking() then
- Break;
- end;
- if(not FoundFire) then
- Minimap.SetCompassAngle([0,90,180,270][Random(4)]+Random(-15,15));
- until False;
- 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(True);
- end;
- // drop all the fish in our inventory, cooked, raw and burnt.
- procedure Drop();
- var
- Ptrn: TIntegerArray;
- i: Int32;
- item: string;
- begin
- WriteLn('Status: Dropping fish!');
- items := ['Salmon', 'Trout', 'Burnt fish', 'Raw trout', 'Raw salmon'];
- for item in items do
- Inventory.FindItem(item, slots);
- //sort by order
- for i:=0 to 27 do
- if slots.Find(i) <> -1 then
- Ptrn += i;
- // same as Inventory.ShiftDrop(ptrn) except we add some errors to the order
- Inventory.ShiftDrop(Inventory.ErrorPattern(ptrn));
- end;
- begin
- if STYLE in [FishCookDrop, FishDrop] then
- Drop()
- 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();
- 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