Tniffoc
2009-04-01 21:03:56
This script would be kept SRL Members only because of Leeching and Jagex control. Obviously, as seen by my FFA releases, I don't usually like to keep things high up, but this one has it's advantages. I've used an RSBot Karamja fisher before and made profit like no other. This is a great opportunity for SRL.
I will set up some sourceforge/svn if the interest is large enough.
Project IRC: #srl:karaproject
Thanks for looking!
~Tniffoc
Developers:
- Mormonman
- noidea
- Blumblebee
- Dr D Dervish
Helpers:
- Iron Man
- kingarabian
This is the current version of the script. Not completed yet. Duh.
{*******************************************************************************
CURRENT CREDITS
Wizzup? - DebugTPA
Tniffoc - GetTolerance, HueSatTolCol, SaFindObjectTPA, SaFindObjectColorArray
noidea - FindFish
*******************************************************************************}
program Kara;
{.include SRL/SRL.scar}
type
THSLColor = record
h: Extended;
s: Extended;
l: Extended;
end;
TRGBColor = record
r: Integer;
g: Integer;
b: Integer;
end;
TXYZColor = record
x: Extended;
y: Extended;
z: Extended;
end;
function GetTolerance(arr: array of Integer; theCTS: Integer): Integer;
var
cts,i: Integer;
begin
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(theCTS);
for i:=0 to High(arr)-1 do
begin
Result := 0;
while(not SimilarColors(arr[i],arr[i+1],Result)) do
begin
Inc(Result);
end;
end;
ColorToleranceSpeed(cts);
Inc(Result);
end;
procedure HueSatTolCol(var hue,sat: Extended; var tol,col: Integer; arr: array of Integer; cts: Integer);
var
i,ii,r,g,b: Integer;
hslarr: array of THSLColor;
rgbarr: array of TRGBColor;
xyzarr: array of TXYZColor;
rgbminmax: array[0..1] of TRGBColor;
minmax: array[0..1] of THSLColor;
xyzminmax: array[0..1] of TXYZColor;
h,s,l,x,y,z: Extended;
hmod,smod: Extended;
bestCol: THSLColor;
begin
SetLength(hslarr,Length(arr));
for i:=0 to High(arr) do
begin
ColorToHSL(arr[i],hslarr[i].h,hslarr[i].s,hslarr[i].l);
end;
// hslarr now contains the contents of arr in HSL form.
minmax[0].h := 255;
minmax[0].s := 255;
minmax[0].l := 255;
// MinMax[0] = MIN MinMax[1] = MAX
ii := High(hslarr);
for i:=0 to ii do
begin
minmax[0].h := MinE(minmax[0].h,hslarr[i].h);
minmax[0].s := MinE(minmax[0].s,hslarr[i].s);
minmax[0].l := MinE(minmax[0].l,hslarr[i].l);
minmax[1].h := MaxE(minmax[1].h,hslarr[i].h);
minmax[1].s := MaxE(minmax[1].s,hslarr[i].s);
minmax[1].l := MaxE(minmax[1].l,hslarr[i].l);
end;
h := minmax[1].h - minmax[0].h;
s := minmax[1].s - minmax[0].s;
l := minmax[1].l - minmax[0].l;
hmod := (h/l);
smod := (s/l);
if(hmod < 0.1)then
hmod := 0.1;
if(smod < 0.1) then
smod := 0.1;
hue := hmod;
sat := smod;
if(cts < 2)then
begin
ii := High(arr);
SetLength(rgbarr, ii+1);
for i:=0 to ii do
begin
ColorToRGB(arr[i],rgbarr[i].r,rgbarr[i].g,rgbarr[i].b);
end;
ii := High(rgbarr);
rgbminmax[0].r := 255;
rgbminmax[0].g := 255;
rgbminmax[0].b := 255;
for i:=0 to ii do
begin
rgbminmax[0].r := Min(rgbminmax[0].r, rgbarr[i].r);
rgbminmax[0].g := Min(rgbminmax[0].g, rgbarr[i].g);
rgbminmax[0].b := Min(rgbminmax[0].b, rgbarr[i].b);
rgbminmax[1].r := Max(rgbminmax[1].r, rgbarr[i].r);
rgbminmax[1].g := Max(rgbminmax[1].g, rgbarr[i].g);
rgbminmax[1].b := Max(rgbminmax[1].b, rgbarr[i].b);
end;
r := rgbminmax[1].r - rgbminmax[0].r;
g := rgbminmax[1].g - rgbminmax[0].g;
b := rgbminmax[1].b - rgbminmax[0].b;
col := RGBToColor(r,g,b);
tol := GetTolerance(arr,cts);
end;
if(cts = 2) then
begin
bestCol.h := (minmax[0].h + minmax[1].h) div 2;
bestCol.s := (minmax[0].s + minmax[1].s) div 2;
bestCol.l := (minmax[0].l + minmax[1].l) div 2;
col := HSLToColor(bestCol.h,bestCol.s,bestCol.l);
tol := Round(l + 0.1);
end;
if(cts = 3) then
begin
SetLength(xyzarr,Length(arr));
for i:=0 to High(xyzarr) do
begin
ColorToXYZ(arr[i],xyzarr[i].x,xyzarr[i].y,xyzarr[i].z);
end;
xyzminmax[0].x := 255;
xyzminmax[0].y := 255;
xyzminmax[0].z := 255;
for i:=0 to High(xyzarr) do
begin
xyzminmax[0].x := MinE(xyzminmax[0].x,xyzarr[i].x);
xyzminmax[0].y := MinE(xyzminmax[0].y,xyzarr[i].y);
xyzminmax[0].z := MinE(xyzminmax[0].z,xyzarr[i].z);
xyzminmax[1].x := MaxE(xyzminmax[1].x,xyzarr[i].x);
xyzminmax[1].y := MaxE(xyzminmax[1].y,xyzarr[i].y);
xyzminmax[1].z := MaxE(xyzminmax[1].z,xyzarr[i].z);
end;
x := xyzminmax[1].x - xyzminmax[0].x;
y := xyzminmax[1].y - xyzminmax[0].y;
z := xyzminmax[1].z - xyzminmax[0].z;
col := XYZToColor(x,y,z);
tol := GetTolerance(arr,cts);
end;
end;
Function DebugTPA(Points: TPointArray; BmpName: String): Boolean;
Var
Width, Height, ClientBMP, I, L: Integer;
xs, ys, xe, ye: Integer;
Begin
Try
Begin
xe := xs xor xs;
ye := ys xor ys;
xs := 1 shl 20;
ys := 1 shl 20;
For I := 0 To High(Points) Do
Begin
xs := Min(xs, Points[i].X);
ys := Min(ys, Points[i].Y);
xe := Max(xe, Points[i].X);
ye := Max(ye, Points[i].Y);
End;
Width := xe - xs;
Height := ye - ys;
DisplayDebugImgWindow(0, 0);
DisplayDebugImgWindow(Width, Height);
ClientBMP := BitmapFromString(Width, Height, '');
CopyClientToBitmap(ClientBMP, xs, ys, xe, ye);
For I := 0 To High(Points) Do
FastSetPixel(ClientBMP, Points[i].X - xs, Points[i].Y - ys, 255);
If BmpName <> '' Then
SaveBitmap(ClientBMP, ScriptPath + BmpName + '.bmp');
SafeDrawBitmap(ClientBMP, GetDebugCanvas, 0, 0);
DisplayDebugImgWindow(Width, Height);
FreeBitmap(ClientBMP);
End
Except
FreeBitmap(ClientBMP);
End;
Result := True;
End;
{*******************************************************************************
function SaFindObjectTPA(color: Integer; upTexts: TStringArray; huemod, satmod: Extended; colorSpeed, tolerance, splitX, splitY: Integer): TPoint;
By: Tniffoc
Description: Returns the x,y coordinates of the object defined by the arguments
on the main screen.
Valid Arguments:
color - The color the the object
upTexts - All the possible up texts for the object being found
huemod - The hue modifier (only applicable if you are using colorSpeed 2)
satmod - The sat modifier (only applicable if you are using colorSpeed 2)
colorSpeed - The speed to be used. If you don't know what this is, look it up.
tolerance - The tolerance to be used when finding the object.
splitX: The size of the object across the x axis.
splitY: the size of the object across the y axis.
*******************************************************************************}
function SaFindObjectTPA(color: Integer; upTexts: TStringArray; huemod, satmod: Extended; colorSpeed, tolerance, splitX, splitY: Integer): TPoint;
var
cts,i,sax,say,count: Integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(colorSpeed);
if(colorSpeed = 2) then
SetColorSpeed2Modifiers(huemod,satmod);
FindColorsSpiralTolerance(MSCX,MSCY,TPA,color,MSX1,MSY1,MSX2,MSY2,tolerance);
//DebugTPA(TPA,'');
i := Length(TPA);
if((i > splitX) and (i > splitY)) then
begin
ATPA := SplitTPAEx(TPA,splitX,splitY);
for i:=0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i],sax,say);
MMouse(sax,say,2,2);
wait(500 + random(500));
wait(200 + random(500));
for count:=0 to High(upTexts) do
begin
if(IsUpText(upTexts[count])) then
begin
GetMousePos(sax,say);
Result := Point(sax,say);
ColorToleranceSpeed(cts);
Exit;
end;
end;
end;
end else
begin
for i:=0 to High(TPA) do
begin
MMouse(TPA[i].x,TPA[i].y,2,2);
wait(500 + random(500));
wait(200 + random(500));
if(IsUpText(upTexts[count])) then
begin
GetMousePos(sax,say);
Result := Point(sax,say);
ColorToleranceSpeed(cts);
Exit;
end;
end;
end;
Result := Point(0,0);
end;
{*******************************************************************************
function SaFindObjectColorArray(arr: array of Integer; upTexts: TStringArray; colorSpeed,splitX,splitY: Integer): TPoint;
By: Tniffoc
Description: Finds the object defined by the parameters.
Valid Arguments:
arr - An array of colors from the object.
upTexts - An array of strings possible for the UpTexts of the object ex. 'illow' for willow.
colorSpeed - The speed to be used. If you don't know, look up ColorSpeedTolerance.
splitX - The size of the object across the X axis.
splitY - The size of the object across the Y axis.
*******************************************************************************}
function SaFindObjectColorArray(arr: array of Integer; upTexts: TStringArray; colorSpeed,splitX,splitY: Integer): TPoint;
var
color,tolerance: Integer;
hm,sm: Extended;
begin
HueSatTolCol(hm,sm,tolerance,color,arr,colorSpeed);
Result := SaFindObjectTPA(color,upTexts,hm,sm,colorSpeed,tolerance,splitX,splitY);
end;
Function FindFish(var Spot: TPoint; x1, y1, x2, y2: Integer) : Boolean;
Var
CTS, I: Integer;
Spott: TPointArray;
ATPA: Array of TPointArray;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.10, 0.24);
FindColorsSpiralTolerance(MSCX, MSCY, Spott, 11972264 , x1, y1, x2, y2, 13);
//DebugTPA(Spott, 'lll');
If Length(Spott) < 1 then
begin
Writeln('Error, couldn''t find fishing spot!');
Result := False;
exit;
end;
ColorToleranceSpeed(CTS);
ATPA := TPAToATPAEx(Spott, 6, 6);
For I := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], Spot.x, Spot.y);
If not (distance(Spot.x, Spot.y, MSCX, MSCY) > 200)then
begin
Result := True;
Break;
end;
end;
end;
{*******************************************************************************
function SaFindObjectTPA(color: Integer; upTexts: TStringArray; huemod, satmod: Extended; colorSpeed, tolerance, splitX, splitY: Integer): TPoint;
By: Tniffoc
Description: Returns the x,y coordinates of the object defined by the arguments
on the main screen.
Valid Arguments:
color - The color the the object
upTexts - All the possible up texts for the object being found
huemod - The hue modifier (only applicable if you are using colorSpeed 2)
satmod - The sat modifier (only applicable if you are using colorSpeed 2)
colorSpeed - The speed to be used. If you don't know what this is, look it up.
tolerance - The tolerance to be used when finding the object.
splitX: The size of the object across the x axis.
splitY: the size of the object across the y axis.
*******************************************************************************}
function SaFindObjectTPAEx(color: Integer; upTexts: TStringArray; huemod, satmod: Extended; colorSpeed, tolerance, splitX, splitY: Integer; sortPoint: TPoint): TPoint;
var
cts,i,sax,say,count: Integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(colorSpeed);
if(colorSpeed = 2) then
SetColorSpeed2Modifiers(huemod,satmod);
FindColorsSpiralTolerance(MSCX,MSCY,TPA,color,MSX1,MSY1,MSX2,MSY2,tolerance);
SortTPAFrom(TPA,sortPoint);
DebugTPA(TPA,'');
i := Length(TPA);
if((i > splitX) and (i > splitY)) then
begin
ATPA := SplitTPAEx(TPA,splitX,splitY);
for i:=0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i],sax,say);
MMouse(sax,say,2,2);
wait(500 + random(500));
wait(200 + random(500));
for count:=0 to High(upTexts) do
begin
if(IsUpText(upTexts[count])) then
begin
GetMousePos(sax,say);
Result := Point(sax,say);
ColorToleranceSpeed(cts);
Exit;
end;
end;
end;
end else
begin
for i:=0 to High(TPA) do
begin
MMouse(TPA[i].x,TPA[i].y,2,2);
wait(500 + random(500));
wait(200 + random(500));
if(IsUpText(upTexts[count])) then
begin
GetMousePos(sax,say);
Result := Point(sax,say);
ColorToleranceSpeed(cts);
Exit;
end;
end;
end;
Result := Point(0,0);
end;
{*******************************************************************************
function SaFindObjectColorArray(arr: array of Integer; upTexts: TStringArray; colorSpeed,splitX,splitY: Integer): TPoint;
By: Tniffoc
Description: Finds the object defined by the parameters.
Valid Arguments:
arr - An array of colors from the object.
upTexts - An array of strings possible for the UpTexts of the object ex. 'illow' for willow.
colorSpeed - The speed to be used. If you don't know, look up ColorSpeedTolerance.
splitX - The size of the object across the X axis.
splitY - The size of the object across the Y axis.
*******************************************************************************}
function SaFindObjectColorArrayEx(arr: array of Integer; upTexts: TStringArray; colorSpeed,splitX,splitY: Integer; sortPoint: TPoint): TPoint;
var
color,tolerance: Integer;
hm,sm: Extended;
begin
HueSatTolCol(hm,sm,tolerance,color,arr,colorSpeed);
Result := SaFindObjectTPAEx(color,upTexts,hm,sm,colorSpeed,tolerance,splitX,splitY,sortPoint);
end;
function FindSailor(var Spot: TPoint): Boolean;
var
colors: array of Integer;
p: TPoint;
i: Integer;
begin
colors := [7884600,7490357,8870207,8475964];
p := Point(0,0);
while((i < 6) and (p.x = 0) and (p.y = 0)) do
begin
p := SaFindObjectColorArray(colors,['eaman','orris','resnor'],2,5,5);
if((p.x = 0) and (p.y = 0)) then
Result := false
else
begin
Result := true;
Spot := p;
end;
Inc(i);
end;
end;
function FindGankPlank(var Spot: TPoint; b: Boolean): Boolean;
var
p: TPoint;
begin
if b then
MakeCompass('S')
else
MakeCompass('E');
SetAngle(false);
p := SaFindObjectColorArrayEx([2243147,2506835,3166569,3562358],['plank'],3,5,5,Point(MSCX,MSCY+40));
if((p.x = 0) and (p.y = 0)) then
Result := false
else
Result := true;
Spot := p;
end;
procedure SeamanToKaraDock;
var
p: TPoint;
i: Integer;
begin
if(FindSailor(p)) then
begin
Mouse(p.x,p.y,0,0,true);
wait(1000 + random(500));
i := 0;
while(i < 10) do
begin
if(ClickContinue(false,false)) then
break
else
begin
FindSailor(p);
Mouse(p.x,p.y,0,0,true);
wait(1000 + random(500));
end;
Inc(i);
end;
if(i > 10) then
begin
Players[CurrentPlayer].Active := false;
Exit;
end;
FFlag(0);
wait(250 + random(250));
ClickContinue(true,true);
ClickContinue(true,true);
MouseBox(226, 398, 292, 406, 1);
wait(500 + random(200));
ClickContinue(true,true);
i := MSCX xor MSCX;
while(i < 10) do
begin
if(ClickContinue(false,false)) then
break;
wait(1000 + random(500));
Inc(i);
end;
if(i > 10) then
begin
Players[CurrentPlayer].Active := false;
Exit;
end;
if(FindGankPlank(p,true))then
begin
Mouse(p.x,p.y,0,0,true);
end;
end;
end;
var
p: TPoint;
begin
ActivateClient;
SetupSRL;
SeamanToKaraDock;
Writeln(IntToStr(p.x) + ',' + IntToStr(p.y));
end.