SRL Archive - Reflection Development

Some Refleftion Banking functions


Heysus

2009-01-24 14:24:57

R_Withdraw
{*******************************************************************************
Function R_Withdraw(Name, Amount: string): boolean;
By: Heysus
Description: Withdraws an item from the bank.
*******************************************************************************}

Function R_Withdraw(Name, Amount: string): boolean;
var
I: integer;
P: TPoint;
BankSlots: TBankSlotArray;
begin
Result := false;
if not R_LoggedIn then
exit;
if not R_BankScreen then
if not R_OpenBank then
exit;

BankSlots := GetBankArray;
for i:=0 to High(BankSlots) do
begin
if Lowercase(BankSlots[i].Name) = Lowercase(Name) then
begin
P := BankIndexToMSPoint(i + 1);
Mouse(P.x + 16, P.y + 16, 4, 4, Amount = '1')
if Amount = '1' then
begin
Result := true;
exit;
end;
Wait(RandomRange(50, 100));
if OptionExists(Amount) then
begin
R_ChooseOption(Amount);
Result := true;
exit;
end else
begin
R_ChooseOption('Withdraw-X');
MarkTime(t);
While TimeFromMark(t) < 4000 do
begin
Wait(100);
if GetInterfaceText(752, 4) = 'Enter amount:' then
break;
end;
Wait(RandomRange(400, 800));
if GetInterfaceText(752, 4) = 'Enter amount:' then
begin
TypeSend(Amount);
Result := true;
exit;
end;
end;
end;
end;
end;






R_Deposit
{*******************************************************************************
Function R_Deposit(ID: integer; Amount: string): boolean;
By: Heysus
Description: Deposits an item into the bank.
*******************************************************************************}

Function R_Deposit(ID: integer; Amount: string): boolean;
var
N: integer;
Slots: TIntegerArray;
begin
Result := false;
if not R_LoggedIn then
exit;
if not R_BankScreen then
if not R_OpenBank then
exit;

if Amount = '0' then
begin
Result := true;
exit;
end;

if not InventoryContains(ID, Slots) then
exit;
if R_CountItemsStacks(ID) = 1 then
Amount := '1';
MouseItem(Slots[0], Amount = '1');
if Amount = '1' then
begin
Result := true;
exit;
end;
Wait(RandomRange(50, 100));
if OptionExists(Amount) then
begin
R_ChooseOption(Amount);
Result := true;
exit;
end else
begin
R_ChooseOption('Deposit-X');
MarkTime(t);
While TimeFromMark(t) < 4000 do
begin
Wait(100);
if GetInterfaceText(752, 4) = 'Enter amount:' then
break;
end;
Wait(RandomRange(400, 800));
if GetInterfaceText(752, 4) = 'Enter amount:' then
begin
TypeSend(Amount);
Result := true;
exit;
end;
end;
end;


This is the same OpenBankReflection but I combined all the tiles into one TPA since there is no real reason to have them seperated. (It finds the nearest one anyway) Also changed it to R_OpenBank cuz most of the other reflection procedures start with "R_".



function R_OpenBankBooth: Boolean;

var
Tiles : TPointArray;
P : TPoint;
iTime, Tries : Integer;

begin
Result := R_BankScreen or PinScreen;
if Result then Exit;

Tiles := [
// Varrock East
Point(3251,3419), Point(3252,3419), Point(3253,3419), Point(3254,3419),
Point(3255,3419), Point(3256,3419),
// Varrock West
Point(3190,3435), Point(3190,3437), Point(3190,3439), Point(3190,3441),
Point(3190,3443), Point(3181,3444), Point(3181,3442), Point(3181,3440),
Point(3181,3438), Point(3181,3436),
// Falador West
Point(2945,3367), Point(2946,3367), Point(2947,3367), Point(2948,3367),
// Falador East
Point(3010,3354), Point(3011,3354), Point(3012,3354), Point(3013,3354),
Point(3014,3354), Point(3015,3354),
// Lumbridge
Point(3208,3221),
// Draynor
Point(3091,3419), Point(3091,3245), Point(3091,3244), Point(3091,3243),
Point(3091,3242),
//Al-Kharid
Point(3268,3168), Point(3268,3167), Point(3268,3166), Point(3268,3165),
Point(3268,3164),
// Seers
Point(2729,3494), Point(2728,3494), Point(2727,3494), Point(2724,3494),
Point(2722,3494),
// Edgeville
Point(3095,3489), Point(3095,3491), Point(3095,3493), Point(3097,3495),
// Catherby
Point(2807, 3442), Point(2809, 3442), Point(2810, 3442), Point(2811, 3442),
// Fishing Guild
Point(2585, 3422), Point(2585, 3421), Point(2585, 3419), Point(2585, 3418)
];

SortTPAFrom(Tiles, GetMyPos);
if (DistanceFrom(Tiles[0]) > 2) or not TileOnMS(Tiles[0], 10) then
begin
if not(TileOnMM(Tiles[0])) then
begin
SRL_Warn('R_OpenBankBooth', 'Could not find Bank Booth.', Warn_AllVersions);
Exit;
end;
WalkToTile(Tiles[0], 0, 0);
Wait(50);
R_Flag;
Wait(RandomRange(100, 200));
end;
if not(TileOnMS(Tiles[0], 10)) then
begin
SetAngle(True);
MakeCompass('n');
Wait(RandomRange(200, 400));
if not(TileOnMS(Tiles[0], 10)) then
begin
SRL_Warn('R_OpenBankBooth', 'Could get MS Point.', Warn_AllVersions);
Exit;
end;
end;
iTime := GetTimeRunning + 45000;
repeat
P := TileToMS(Tiles[0], 10);
MMouse(p.x - 5, p.y - 5, 11, 11);
Wait(RandomRange(200, 300));
if IsUpText('ank') then
begin
GetMousePos(P.x, P.y);
Mouse(P.x, P.y, 0, 0, false);
Wait(RandomRange(80, 110));
P.x := 0;
if R_ChooseActionMulti(['e-q']) then
repeat
R_Flag;
Wait(RandomRange(50, 90));
Inc(Tries);
Result := R_BankScreen or PinScreen;
until Result or (Tries > 40);
end;
until Result or (GetTimeRunning > iTime);
end;





function R_OpenBankBankers: Boolean;

var
NPCs : TNPCArray;
I, H, iTime : Integer;
P : TPoint;

begin
Result := R_BankScreen or PinScreen;
if Result then Exit;

NPCs := SortNPCs(GetNPCsByName('ank'));
H := High(NPCs);
if H = -1 then Exit;

for I := 0 to H do
begin
if not R_LoggedIn then Exit;

if DistanceFrom(NPCs[I].Tile) > 4 then
begin
WalkToTile(NPCs[I].Tile, 2, 0);
R_Flag;
end;

P := TileToMS(NPCs[I].Tile, NPCs[I].Height / 2);
if not PointInBox(P, IntToBox(MSX1, MSY1, MSX2, MSY2)) then
begin
SRL_Warn('R_OpenBankers', 'Could not get the Main screen point.', Warn_AllVersions);
Exit;
end;

MMouse(P.x, P.y, 4, 4);
Wait(RandomRange(80, 110));
if IsUpText('ank') then
begin
GetMousePos(P.x, P.y);
Mouse(P.x, P.y, 0, 0, False);
Wait(RandomRange(100, 150));
R_ChooseActionMulti(['ank']);
R_Flag;
iTime := GetTimeRunning + 4000;
while not (Result) and R_LoggedIn and (GetTimeRunning < iTime) do
begin
Wait(100);
Result := R_BankScreen or PinScreen;
end;
Wait(Random(80));
if Result then Break;
end;
end;
if not Result then
SRL_Warn('OpenBankBankers', 'Could not open the Bank.', Warn_AllVersions);
end;


Function R_OpenBank: Boolean;

var
Functs : array [0..1] of function: Boolean;
I : Integer;

begin
Result := R_BankScreen or PinScreen;
if R_BankScreen or PinScreen then Exit;

case Random(2) of
0: begin
Functs[0] := @R_OpenBankBooth;
Functs[1] := @R_OpenBankBankers;
end;
1: begin
Functs[0] := @R_OpenBankBankers;
Functs[1] := @R_OpenBankBooth;
end;
end;

Result := True;
for I := 0 to 1 do
if Functs[I]() then
Exit;

Result := False;
end;



almost

2009-01-24 14:55:41

I like R_Withdraw and R_Deposit, I think they are needed.
I like how this is done-
if Lowercase(BankSlots[i].Name) = Lowercase(Name) then
begin
P := BankIndexToMSPoint(i);
Mouse(P.x + 16, P.y + 16, 4, 4, Amount = '1')
It checks lowercased and the Mouse part is done in one line instead of a case or if then statement.
But one thing.
What if your item is not on screen?
It could be in another tab or you might have to scroll down on the current tab to see it.
You could add in a repeat that scrolls down until the MS point is actually on screen or you have scrolled all the way.

The tiles are separated for efficiency.
Sorting a TPA with 50 points takes a lot longer than 3.

ian.

2009-01-24 14:57:37

nice ^^ good to see you added

if (DistanceFrom(Tiles[0]) > 2) or not TileOnMS(Tiles[0], 10) then

^^

Heysus

2009-01-24 15:03:32

From: almost


The tiles are separated for efficiency.
Sorting a TPA with 50 points takes a lot longer than 3.


Thats not really a problem. I just timed it and it took <1 ms to sort the TPA. And this way you don't have to enter in which bank to open. :)


What if your item is not on screen?
It could be in another tab or you might have to scroll down on the current tab to see it.
You could add in a repeat that scrolls down until the MS point is actually on screen or you have scrolled all the way.


I'm not really sure how to do that since BankIndexToMSPoint doesn't work if you scroll down. I could mabye have it use the search button though.

almost

2009-01-24 15:29:32

Oh yes I'm thinking of a different procedure :duh:
SortTPAFrom works in less than a ms even with 100 points.

I just tested out the withdraw function, and I'm wondering if you even tested it at all.
There are 2 huge problems.
It withdraws the item to the left of the item you tell it to every time.
Pretty simple though, just do
P := BankIndexToMSPoint(i + 1);
The other one I know you can't help, but it will be a big problem.
If you have tabs at all in your bank it throws everything off.
Even for withdrawing the first item in your bank, while it is on screen.

Heysus

2009-01-24 15:38:24

I actually did test it and I have no idea how it worked. :confused:

The reason it's messed up is because of the bank tabs. The order starts at tab 2 and ends with the items that aren't in tabs. (BankSlot[0] would be the first item in tab 2).

I also just did a DebugTBankSlotArray and the Index for every item was 0 so I don't really know how to make it work. :duh:

Edit: It worked when I tested it because I only had 1 item in a tab.

almost

2009-01-24 16:05:45

K, well change the BankIndexToMSPoint to use i + 1 and everything looks good.
At least as good as it can for right now.

Widget

2009-01-25 19:04:13

There's two ways I can think of to solve the tabs problem.
1) MMouse to the first item using coords and get the UpText, loop through the items until it matches exactly, and set that as the offset.
2) Find a hook or interface ID or something that lets us get the ID of the object of the tab header (the picture that shows the first item in the tab), then loop through the items until the ID matches and set that as the offset.

There are also two fields for X and Y of an interface, but they act up when they aren't showing and I'm not sure if we can figure out how to use them to tell if an item is on the screen or not

Nava2

2009-01-26 11:59:35

We couldn't find a hook for the tabs, this is why it was never included into the SVN.

Nice work, just some testing would be a good idea.

The R_OpenBankBooth is like that becuase it is MUCH easier to do that, readability wise. Its not about speed. Its about clean code.

Also, amount shouldn't be a string. Use an integer, and do a simple IntToStr. There is no reason for it to be a string, and just causes more problems than it solves.

Lastly, your R_OpenBank does not work now.

Just so you know ;)

Heysus

2009-01-26 14:00:53

From: Nava2

Also, amount shouldn't be a string. Use an integer, and do a simple IntToStr. There is no reason for it to be a string, and just causes more problems than it solves.


The reason it's a string is so you can use 'All' or 'All but one'.

From: Nava2

Lastly, your R_OpenBank does not work now. Just so you know ;)

What? It worked perfectly for every bank i've tried it on.

senrath

2009-01-26 14:23:39

From: Heysus
The reason it's a string is so you can use 'All' or 'All but one'.


Then I'd recommend using Variant instead of String. It can take integers, extendeds, and strings. And it might take others as well, but I'm not sure.

Nava2

2009-01-26 21:37:37

From: Heysus
The reason it's a string is so you can use 'All' or 'All but one'.


What? It worked perfectly for every bank i've tried it on.


What the next kid said.

From: senrath
Then I'd recommend using Variant instead of String. It can take integers, extendeds, and strings. And it might take others as well, but I'm not sure.


xD

Also, i figured it didn't since the Function calling looks wrong.