mixster
2008-10-04 19:52:45
procedure DTMFromInv(var oDTM: Integer; slot, refPts: Integer);
var
Skel: TDTM;
mainPt: TDTMPointDef;
subPts: array of TDTMPointDef;
outPts: TPointArray;
invBoxC: TBox;
i, outRat, rI: Integer;
begin
invBoxC := InvBox(slot);
if not FindColorsTolerance(outPts, 65536, invBoxC.x1 + 2, invBoxC.y1 + 2, invBoxC.x2 - 2, invBoxC.y2 - 2, 1) then
begin
Writeln('Unable to create DTM from inventory slot as no outline colours found');
Exit;
end;
with mainPt do
begin
x := (invBoxC.x1 + invBoxC.x2) div 2;
y := (invBoxC.y1 + invBoxC.y2) div 2;
areasize:= 0;
areashape:= 0;
color:= GetColor(mainPt.x, mainPt.y);
tolerance:= 422;
end;
SetArrayLength(subPts, refPts);
outRat := GetArrayLength(outPts) div refPts;
for i := 0 to refPts - 1 do
begin
rI := Random(Random(Round(outRat)));
with subPts[i] do
begin
x := outPts[round(i * outRat) + rI].x;
y := outPts[round(i * outRat) + rI].y;
areasize:= 0;
areashape:= 0;
color:= 65536;
tolerance:= 1;
end;
end;
Skel.MainPoint := mainPt;
Skel.SubPoints := subPts;
oDTM := AddDTM(Skel);
end;
function CompStrWArr(str: string; strArr: array of string): boolean;
var
i: Integer;
begin
for i := 0 to High(strArr) do
if Result then
Exit;
if str = strArr[i] then
Result := True;
end;
function SmartDrop(var iDtmArr: array of Integer; var sDtmArr: array of string; sItemsArr: array of string; bDropMatched: Boolean): Integer;
var
iX, iY, iItemX, iItemY, iItem, iDtm, iStr, iItemOffset: Integer;
bDir, bDropSet: Boolean;
tbItem: TBox;
begin
bDir := RBool;
for iItemY := 1 to 7 do
begin
for iItemX := 1 to 4 do
begin
bDropSet := False;
if((bDir)and(iItemY mod 2 = 1))or((not(bDir))and(iItemY mod 2 = 0))then
iItemOffset := 5 - iItemX
else
iItemOffset := iItemX;
iItem := ((iItemY - 1) * 4) + iItemOffset;
if(not(ExistsItem(iItem)))then
begin
Continue;
end;
tbItem := InvBox(iItem);
if(High(iDtmArr) >= 0) then
begin
for iDtm := 0 to High(iDtmArr) do
begin
if((CompStrWArr(sDtmArr[iDtm], sItemsArr)) and (FindDtm(iDtmArr[iDtm], iX, iY, tbItem.x1, tbItem.y1, tbItem.x2, tbItem.y2))and(not(bDropSet)))then
begin
bDropSet := True;
end;
end;
end;
if(not(bDropSet))then
begin
MMouseItem(iItem);
Wait(250+Random(Random(1000)));
for iStr := 0 to High(sItemsArr) do
begin
if(IsUpText(sItemsArr[iStr])and(not(bDropSet)))then
begin
bDropSet := True;
SetArrayLength(iDtmArr, High(iDtmArr) + 2);
SetArrayLength(sDtmArr, High(sDtmArr) + 2);
DTMFromInv(iDtmArr[High(iDtmArr)], iItem, 15);
sDtmArr[High(sDtmArr)] := sItemsArr[iStr];
end;
end;
end;
if(not(bDropSet xor bDropMatched))then
begin
GetMousePos(iX, iY);
if(not((iX >= tbItem.x1) and (iX <= tbItem.x2) and (iY >= tbItem.y1) and (iY <= tbItem.y2)))then
DropItem(iItem)
else
begin
Mouse(iX, iY, 1, 1, False);
Wait(150 + Random(75));
if(not(ChooseOption('Drop')))then
Dec(Result)
else
Wait(100 + Random(50));
end;
Inc(Result);
Wait(Random(Random(500)));
end;
end;
end;
end;DTMFromInv: generates a DTM and places in oDTM made from slot slot with refPts number of reference points. May be disgruntled by stacks - haven't tested extensively with stacks - but shouldn't have a problem, if so should be easy enough to fix.
CompStrWArr: small function that SmartDrop uses - returns true is string str is in the string array strArr.
SmartDrop: iDTMArr holds the DTM's it creates - should be empty as function fills it out. sDTMArr holds the item that the same index of iDTMArr holds - should also be blank as function fills it out. sItemsArr should be filled out with the items it should drop or keep (depending on bDropMatched). bDropMatched should be true if you want it to drop items that it matches UpText to and/or DTM or false if you want it to drop all others.
Hoping for feedback - especially as it is my only RuneScape related procedures. Also hoping that one bit may get added in even a small way :)