I made some deposit box stuff for a script I'm making. Basically a modified version of olly's functions in bankscreen.simba
Simba Code:
(*
DepositBox
==========
The depositbox file holds functions and procedures that are used in the
Runescape deposit box screen.
The source for this file can be found `here <https://github.com/SRL/SRL-6/blob/master/lib/interfaces/depositbox.simba>`_.
*)
{$include_once interfaces.simba}
{$f-}
{*
const Internal
~~~~~~~~~~~~~~
Internal deposit box constants.
*}
const
_BOX_SLOTS_OFFSET: TPoint = [41, 60];
(*
const Deposit Buttons
~~~~~~~~~~~~~~~~~~~~~
Integer constants that represent the order of the quick deposit buttons.
*)
const
QUICK_DEPOSITBOX_INVENTORY = 0;
QUICK_DEPOSITBOX_EQUIPMENT = 1;
QUICK_DEPOSITBOX_BOB = 2;
QUICK_DEPOSITBOX_MONEY_POUCH = 3;
(*
type TRSDepositBox
~~~~~~~~~~~~~~~~~~
A type that stores the deposit box interface properties.
*)
type
TRSDepositBox = type TRSInterface;
(*
var depositBox
~~~~~~~~~~~~~~
Variable that stores functions and properties of the Runescape deposit box interface.
Example:
.. code-block:: pascal
if (depositBox.isOpen() then
writeln('Deposit Box is open!');
*)
var
depositBox: TRSDepositBox;
{*
TRSDepositBox.__init
~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
procedure TRSDepositBox.__init();
Initializes the TRSDepositBox.
.. note::
- by Olly
- Last Updated: 15 January 2014 by The Mayor
Example:
.. code-block:: pascal
depositBox.__init();
*}
{$IFNDEF CODEINSIGHT}
procedure TRSDepositBox.__init();
begin
with (self) do
begin
name := 'RS Deposit Box Screen';
ID := ID_INTERFACE_DEPOSITBOX;
parentID := -1;
static := true;
setBounds([108, 46, 481, 327]);
end;
end;
{$ENDIF}
(*
TRSDepositBox.isOpen
~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSDepositBox.isOpen(waitTime: integer = 0): boolean;
Returns true if the deposit box is open, includes a optional parameter
'waitTime' (default 0) which will search for the deposit box screen until
'waitTime' is reached.
.. note::
- by Olly
- Last Updated: 15 January 2014 by The Mayor
Example:
.. code-block:: pascal
if (depositBox.isOpen()) then
writeln('It''s open!');
*)
function TRSDepositBox.isOpen(waitTime: integer = 0): boolean;
const
TEXT_COLOR = 379903;
BACKGROUND_COLOR = 2366479;
BACKGROUND_TOLERANCE = 19;
var
t, CTS: integer;
begin
t := (getSystemTime() + waitTime);
repeat
if (getColor(self.x1 +62, self.y1 +19) = TEXT_COLOR) then
if (countColorTolerance(BACKGROUND_COLOR, self.getBounds(), BACKGROUND_TOLERANCE) > 20000) then
begin
result := true;
break;
end;
until (getSystemTime() >= t);
setColorToleranceSpeed(cts);
end;
(*
TRSDepositBox.close
~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSDepositBox.close(): boolean;
Closes the deposit box screen, will return if succesful or not.
.. note::
- by Olly
- Last Updated: 15 January 2014 by The Mayor
Example:
.. code-block:: pascal
if (depositBox.close()) then
writeln('Closed the deposit box');
*)
function TRSDepositBox.close(): boolean;
var
timeOut: integer;
begin
result := false;
timeOut := (getSystemTime() + randomRange(5000, 6000));
if (not self.isOpen()) then
exit(true);
mouseBox(intToBox(self.x1+346, self.y1+14, self.x1+359, self.y1+27), MOUSE_LEFT);
wait(50 + random(50));
while (timeOut > getSystemTime()) do
begin
if (not self.isOpen()) then
begin
result := true;
break;
end;
wait(50 + random(50));
end;
print('depositBox.close(): result = '+boolToStr(result), TDebug.SUB);
end;
(*
TRSDepositBox.getSlotBoxes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSDepositBox.getSlotBoxes(): TBoxArray;
Returns a TBoxArray of all of the deposit box slot boxes.
.. note::
- by Olly
- Last Updated: 15 January 2014 by The Mayor
Example:
.. code-block:: pascal
boxArr := depositBox.getSlotBoxes();
*)
function TRSDepositBox.getSlotBoxes(): TBoxArray;
begin
if (not self.isOpen()) then
begin
print('depositBox.getSlotBoxes(): Unable to return deposit box slots since the deposit box isn''t open', TDebug.ERROR);
exit();
end;
result := grid(7, 4, 35, 31, 48, 50, point(self.x1 + _BOX_SLOTS_OFFSET.x, self.y1 + _BOX_SLOTS_OFFSET.y));
end;
(*
TRSDepositBox.getSlotBox
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSDepositBox.getSlotBox(slot: integer): TBox;
Returns the TBox of the desired deposit box slot. Slots
start at the top left at 1 and count across the columns.
.. note::
- by Olly
- Last Updated: 15 January 2014 by The Mayor
Example:
.. code-block:: pascal
mouseBox(depositBox.getSlotBox(1), MOUSE_MOVE);
*)
function TRSDepositBox.getSlotBox(slot: integer): TBox;
begin
if (not inRange(slot, 1, 28)) then
begin
print('depositBox.getSlotBox(): Slot '+toStr(slot)+' is invalid', TDebug.WARNING);
exit(intToBox(-1, -1, -1, -1));
end;
if (not self.isOpen()) then
begin
print('DepositBox.getSlotBox(): Unable to return TBox since the deposit box isn''t open', TDebug.ERROR);
exit();
end;
// - 1 because the grid (array) starts at 0.
result := gridBox(slot -1, 4, 7, 35, 31, 48, 50, point(self.x + _BOX_SLOTS_OFFSET.x, self.y + _BOX_SLOTS_OFFSET.y));
end;
(*
TRSDepositBox.count
~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSDepositBox.count(): integer;
Returns the number of items in the deposit box screen.
.. note::
- by Olly
- Last Updated: 15 January 2014 by The Mayor
Example:
.. code-block:: pascal
var
c: integer;
begin
c := depositBox.count();
*)
function TRSDepositBox.count(): integer;
var
b: TBoxArray := depositBox.getSlotBoxes();
i: integer;
begin
if (not self.isOpen()) then
begin
print('depositBox.count(): Unable to check count since the deposit box isn''t open', TDebug.ERROR);
exit(-1);
end;
for i := 0 to high(b) do
if (isItemIn(b[i])) then
inc(result);
print('depositBox.count(): result = '+intToStr(result), TDebug.SUB);
end;
(*
TRSDepositBox.isEmpty
~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSDepositBox.isEmpty: boolean;
Returns true if the deposit box screen is empty.
.. note::
- by Olly
- Last Updated: 15 January 2014 by The Mayor
Example:
.. code-block:: pascal
if (depositBox.isEmpty) then
writeln('our inventory is empty!');
*)
function TRSDepositBox.isEmpty: boolean;
begin
if (not self.isOpen()) then
begin
print('depositBox.isEmpty: Unable to check is deposit box is empty since the deposit box isn''t open', TDebug.ERROR);
exit(false);
end;
result := (not (self.getBounds().colorExists(ITEM_OUTLINE_BLACK)));
print('depositBox.isEmpty: result = '+boolToStr(result), TDebug.SUB);
end;
(*
TRSDepositBox.quickDeposit
~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: pascal
function TRSDepositBox.quickDeposit(depositType: integer): boolean;
Will click the quick deposit button 'depositType', vaild deposit types are:
* QUICK_DEPOSITBOX_INVENTORY
* QUICK_DEPOSITBOX_EQIUPMENT
* QUICK_DEPOSITBOX_BOB
* QUICK_DEPOSITBOX_MONEY_POUCH
.. note::
- by Olly
- Last Updated: 15 January 2014 by The Mayor
Example:
.. code-block:: pascal
depositBox.quickDeposit(QUICK_DEPOSITBOX_INVENTORY);
*)
function TRSDepositBox.quickDeposit(depositType: integer): boolean;
const
DEPOSIT_BUTTON_OFFSET: TPoint = [229, 255];
var
b: TBox;
begin
result := true;
if (not self.isOpen()) then
begin
print('depositBox.quickDeposit(): Unable to quick-deposit since deposit box isn''t open', TDebug.ERROR);
exit(false);
end;
b := gridBox(depositType, 4, 1, 34, 23, 37, 0,
point(self.x + DEPOSIT_BUTTON_OFFSET.x,
self.y + DEPOSIT_BUTTON_OFFSET.y));
mouseBox(b, MOUSE_LEFT);
wait(200 + random(300));
print('depositBox.quickDeposit(): Clicked quick deposit id ' + intToStr(depositType), TDebug.SUB);
end;
begin
depositBox.__init();
end;