Simba Code:
(*
Actionbar
=========
The actionbar file holds functions and procedures that are used in the runescape Action Bar.
The source for this file can be found `here <https://github.com/SRL/SRL-6/blob/master/lib/interfaces/actionbar.simba>`_.
*)
{$f-}
(*
Consts, Types, Vars
~~~~~~~~~~~~~~~~~~~
The following constants, types and variables are used throughout the actionBar methods.
*)
{*
**const internal**
Internal constants used throughout the actionBar methods
*}
const
ACTION_BAR_SLOT_LOW = 1;
ACTION_BAR_SLOT_HIGH = 14;
_AB_BAR_HP_OFFSET = 46;
_AB_BAR_ADRENALINE_OFFSET = 185;
_AB_BAR_PRAYER_OFFSET = 324;
_AB_BAR_SUMMONING_OFFSET = 463;
(*
**const Action Bar Stat Bars**
Constants that represent the stat bars on the action bar
* AB_BAR_HP
* AB_BAR_ADRENALINE
* AB_BAR_PRAYER
* AB_BAR_SUMMONING
*)
const
AB_BAR_HP = 1;
AB_BAR_ADRENALINE = 2;
AB_BAR_PRAYER = 3;
AB_BAR_SUMMONING = 4;
(*
**type TRSActionBar**
.. code-block:: pascal
type
TRSActioinBar = type TRSInterface;
A type that stores the action bar interface properties.
*)
type
TRSActionBar = record(TRSInterface)
{$IFNDEF CODEINSIGHT}
__slots: TBoxArray;
{$ENDIF}
setSlots: boolean;
end;
(*
**var actionBar**
.. code-block:: pascal
var
actionBar: TRSActionBar;
A variable through which scripters can access the TRSActionBar type methods.
*)
var
actionBar: TRSActionBar;
(*
TRSActionBar methods
~~~~~~~~~~~~~~~~~~~~
The following methods should be called through the **actionBar** variable.
Example:
.. code-block:: pascal
if actionBar.isEmpty() then
writeln('There is nothing in any of the slots');
*)
{*
__init
------
.. code-block:: pascal
procedure TRSActionBar.__init();
Initializes the TRSActionBar.
.. note::
- by euphemism
- Last Updated: 18 April 2013 by euphemism
Example:
.. code-block:: pascal
actionBar.__init();
*}
{$IFNDEF CODEINSIGHT}
procedure TRSActionBar.__init();
begin
with (self) do
begin
name := 'RS Action Bar';
ID := ID_INTERFACE_ACTION_BAR;
parentID := ID_INTERFACE_MAINSCREEN;
static := false;
setSlots := false;
end;
end;
{$ENDIF}
{*
__find
------
.. code-block:: pascal
function TRSActionBar.__find(out height: integer): boolean;
Returns true if the action bar is found and its bounds are set. This is designed to
work with standard EOC and the EOC-legacy ActionBar. The height is also passed to
**height** for determining if the ActionBar is minimised.
.. note::
- by The Mayor
- Last Updated: 1 August 2015 by The Mayor
Example:
.. code-block:: pascal
var
h: Integer;
begin
if (not actionbar.__find(h)) then
writeln('Failed to find the actionbar');
end;
*}
{$IFNDEF CODEINSIGHT}
function TRSActionBar.__find(out height: integer): boolean;
label
LegacyBar;
const
BUTTON_COL = [462872, 6];
BORDER_COL = 3945514;
var
i, j: Integer;
p: TPoint;
TPA: TPointArray;
ATPA: T2DPointArray;
borderColor: TColorData := [4997944, 10, [2, [0.10, 0.29, 0.00]]];
begin
if findColorsTolerance(TPA, BUTTON_COL[0], getClientBounds(), BUTTON_COL[1]) then
begin
ATPA := TPA.cluster(1);
ATPA.filterBetween(1, 10);
if (length(ATPA) < 1) then
begin
print('TRSActionBar.__find(): Didn''t find button border colors');
goto LegacyBar;
end;
for i := 0 to high(ATPA) do
if (ATPA[i].getBounds().getWidth() = 13) and (ATPA[i].getBounds().getHeight() = 13) then
begin
p := ATPA[i].getBounds().getMiddle();
for j := (p.y + 70) downto p.y do
if getColor(p.x, j) = BORDER_COL then
begin
height := abs((p.Y - 9) - j);
self.setBounds([0, (p.Y - 9), gameTabs.tabArea.x1-1, (p.Y - 9) + height]);
result := true;
if (not self.setSlots) then
begin
__slots := grid(14, 1, 29, 29, 36, 0, point(self.x1 + 67, self.y1 + 53));
self.setSlots := true;
end;
print('TRSActionBar.__find(): EOC bar height = ' + toStr(height));
exit(true);
end;
end;
end;
LegacyBar:
if borderColor.gatherIn(TPA, getClientBounds()) then
begin
ATPA := TPA.cluster(2);
ATPA.filterBetween(1, 250);
if (length(ATPA) < 1) then
begin
print('TRSActionBar.__find(): Didn''t find enough border colors');
exit();
end;
ATPA.sortBySize(True);
for i := 0 to high(ATPA) do
if inRange(ATPA[i].getBounds().getWidth(), 576, 577) then
begin
height := ATPA[i].getBounds().getHeight();
self.setBounds(ATPA[i].getBounds());
print('TRSActionBar.__find(): Legacy bar height = ' + toStr(height));
exit(true);
end;
end;
end;
{$ENDIF}
{*
__find (overload)
-----------------
.. code-block:: pascal
function TRSActionBar.__find(): boolean; overload;
Overloaded method without the height parameter.
.. note::
- by Olly
- Last Updated: 24 November 2013 by Olly
Example:
.. code-block:: pascal
if (not actionbar.__find()) then
writeln('Failed to find the actionbar');
*}
{$IFNDEF CODEINSIGHT}
function TRSActionBar.__find(): boolean; overload;
var
foo: integer;
begin
result := self.__find(foo);
end;
{$ENDIF}
{*
__isSlotValid
-------------
.. code-block:: pascal
function TRSActionBar.__isSlotValid(slot: integer): boolean;
Returns true if the **slot** is a valid slot number.
.. note::
- by euphemism
- Last Updated: 15 September 2013 by euphemism
Example:
.. code-block:: pascal
if actionBar.__isSlotValid(5) then
actionBar.clickSlot(5);
*}
{$IFNDEF CODEINSIGHT}
function TRSActionBar.__isSlotValid(slot: integer): boolean;
begin
if inRange(slot, ACTION_BAR_SLOT_LOW, ACTION_BAR_SLOT_HIGH) then
exit(true);
print('Action Bar slot ' + toStr(slot) + ' is not in the range of 1 - ' + toStr(length(self.__slots)) + '.', TDebug.ERROR);
end;
{$ENDIF}
{*
__clickButton
-------------
.. code-block:: pascal
function TRSActionBar.__clickButton(): boolean;
Clicks the minimize/maximise button.
.. note::
- by Olly
- Last Updated: 12 December 2013 by Olly
Example:
.. code-block:: pascal
if actionBar.__clickButton() then
writeln('clicked!');
*}
{$IFNDEF CODEINSIGHT}
function TRSActionBar.__clickButton(): boolean;
var
b: TBox;
begin
b := [self.x2-15, self.y1+3, self.x2-3, self.y1+15];
result := pointInBox(middleBox(b), self.getBounds());
if (result) then
mouseBox(b, MOUSE_LEFT);
end;
{$ENDIF}
(*
minimize
--------
.. code-block:: pascal
function TRSActionBar.minimize(): boolean;
Returns true if it minimizes the action bar.
.. note::
- by Olly
- Last Updated: 12 December 2013 by Olly
Example:
.. code-block:: pascal
actionBar.minimize();
*)
function TRSActionBar.minimize(): boolean;
var
hei: integer;
begin
result := false;
if (not self.__find(hei)) then
print('Cannot close the actionbar, since we can''t find it!', TDebug.ERROR);
result := true;
if (hei > 40) then
result := self.__clickButton()
else
print('TRSActionBar.minimize(): Actionbar is already minimized');
print('TRSActionBar.minimize(): result = ' + boolToStr(result));
end;
(*
maximize
--------
.. code-block:: pascal
function TRSActionBar.minimize(): boolean;
Returns true if it maximizes the action bar.
.. note::
- by Olly
- Last Updated: 12 December 2013 by Olly
Example:
.. code-block:: pascal
actionBar.maximize();
*)
function TRSActionBar.maximize(): boolean;
var
hei: integer;
begin
result := false;
if (not self.__find(hei)) then
print('Cannot close the actionbar, since we can''t find it!', TDebug.ERROR);
result := true;
if (hei < 40) then
result := self.__clickButton()
else
print('TRSActionBar.maximize(): Actionbar is already open');
print('TRSActionBar.maximize(): result = ' + boolToStr(result));
end;
{*
open
----
Depreciated - use actionBar.maximize();
*}
function TRSActionBar.open(): boolean;
begin
result := self.maximize();
end;
(*
getCurrentBar
-------------
.. code-block:: pascal
function TRSActionBar.getCurrentBar(): Integer;
Returns the number of the Action Bar setup currently displayed. Members can
have up to five different Action Bar setups.
.. note::
- by euphemism
- Last Updated: 18 April 2013 by euphemism
Example:
.. code-block:: pascal
if (actionBar.getCurrentBar() = 1) then
writeln('The first Action Bar setup is currently displayed.');
*)
function TRSActionBar.getCurrentBar(): Integer;
begin
result := strToIntDef(getTextAtEx(intToBox(self.getBounds().x1 + 25,
self.getBounds().y1 + 49, self.getBounds().x1 + 35, self.getBounds().y1 + 59),
0, 0, 0, 3111603, 0, 'UpChars'), -1); //Color is of the number showing which bar is active.
print('TRSActionBar.getCurrentBar() returned ' + toStr(result), TDebug.LOG);
end;
(*
switchToBar
-----------
.. code-block:: pascal
function TRSActionBar.switchToBar(barNumber: integer; useBindKey: boolean = false): boolean;
Switches to the **barNumber** action bar setup. If **useBindKey** is set to true
*(default = false)* it will use the keyboard, else it will use the mouse.
.. note::
- by euphemism
- Last Updated: 18 April 2013 by euphemism
Example:
.. code-block:: pascal
if actionBar.switchToBar(3) then
writeln('Switched to bar number 3');
*)
function TRSActionBar.switchToBar(barNumber: integer; useBindKey: boolean = false): boolean;
var
currentBar, r, i, diff: integer;
timeMarker: TTimeMarker;
keys: tIntegerArray;
begin
result := false;
if (not inRange(barNumber, 1, 5)) then
begin
print('TRSActionBar.switchToBar: barNumber must be within 1-5.', TDebug.ERROR);
exit;
end;
currentBar:= self.getCurrentBar();
if (barNumber = currentBar) then
exit(true);
if (useBindKey) then
begin
keys:= [VK_LSHIFT, VK_0 + barNumber];
for i := 0 to 1 do
begin
keyDown(keys[i]);
wait(randomRange(10, 200 - i * 100));
end;
r:= random(2);
keyUp(keys[r]);
wait(random(60));
keyUp(keys[abs(r - 1)]);
end else
begin
diff := abs(currentBar - barNumber);
if (inRange(diff, 2, 3)) then
begin
intToBox(self.getBounds().x1 + 25, self.getBounds().y1 + 49,
self.getBounds().x1 + 35, self.getBounds().y1 + 59).mouse(MOUSE_RIGHT);
chooseOption.select([intToStr(barNumber)], 618);
end else
begin
if ((currentBar < barNumber) xor (diff > 2)) then
intToBox(self.getBounds().x1 + 39, self.getBounds().y1 + 50,
self.getBounds().x1 + 43, self.getBounds().y1 + 57).mouse(MOUSE_LEFT)
else
intToBox(self.getBounds().x1 + 16, self.getBounds().y1 + 50,
self.getBounds().x1 + 20, self.getBounds().y1 + 57).mouse(MOUSE_LEFT);
end;
end;
timeMarker.start();
while (timeMarker.getTime() < randomRange(3000, 4000)) do
begin
result := (barNumber = self.getCurrentBar());
if (result) then
exit;
end;
end;
(*
isSlotEmpty
-----------
.. code-block:: pascal
function TRSActionBar.isSlotEmpty(slot: integer): boolean;
Returns true if the Action Bar slot **slot** is empty.
.. note::
- by euphemism
- Last Updated: 5th July 2014 by The Mayor
Example:
.. code-block:: pascal
if actionBar.isSlotEmpty(1) then
writeln('The first Action Bar slot is empty.');
*)
function TRSActionBar.isSlotEmpty(slot: integer): boolean;
begin
if (not (self.__isSlotValid(slot))) then
exit();
result := (getColor(self.__slots[slot - 1].getMiddle().x, self.__slots[slot - 1].getMiddle().y) = 2761233);
end;
(*
isEmpty
-------
.. code-block:: pascal
function TRSActionBar.isEmpty(): boolean;
Returns true if every slot in the Action Bar is empty.
.. note::
- by euphemism
- Last Updated: 18 April 2013 by euphemism
Example:
.. code-block:: pascal
if actionBar.isEmpty() then
writeln('Every slot in the Action Bar is empty!');
*)
function TRSActionBar.isEmpty(): boolean;
var
i: integer;
begin
for i := ACTION_BAR_SLOT_LOW to ACTION_BAR_SLOT_HIGH do
if (not self.isSlotEmpty(i)) then
exit(false);
result := true;
end;
(*
getSlotBox
----------
.. code-block:: pascal
function TRSActionBar.getSlotBox(slot: integer): TBox;
Returns a TBox of the Action Bar slot, **slot**
.. note::
- by Olly
- Last Updated: 18 September 2013 by Olly
Example:
.. code-block:: pascal
var
b: TBox;
begin
b := actionBar.getSlotBox(1);
end;
*)
function TRSActionBar.getSlotBox(slot: integer): TBox;
begin
if (not self.__isSlotValid(slot)) then
exit(intToBox(-1, -1, -1, -1));
result := self.__slots[slot - 1];
end;
(*
pointToSlot
-----------
.. code-block:: pascal
function TRSActionBar.pointToSlot(pnt: TPoint): integer;
Returns the Action Bar slot which the TPoint **pnt** fall within. If it doesn't fall
within any slot, it returns -1.
.. note::
- by Olly
- Last Updated: 20 November 2013 by Olly
Example:
.. code-block:: pascal
var
x, y, myDTM: Integer;
begin
myDTM := DTMFromString('heapsofstuff');
if findDTM(myDTM, x, y, actionBar.getBounds()) then
writeLn(Found DTM in slot ' + toStr(actionBar.pointToSlot([x, y]));
end;
*)
function TRSActionBar.pointToSlot(pnt: TPoint): integer;
var
i: byte;
begin
result := -1;
for i := ACTION_BAR_SLOT_LOW to ACTION_BAR_SLOT_HIGH do
if pointInBox(pnt, self.getSlotBox(i)) then
exit(i);
end;
(*
clickSlot
---------
.. code-block:: pascal
function TRSActionBar.clickSlot(slot: integer; clickType: integer = MOUSE_LEFT): boolean;
Clicks the Action Bar slot **slot** using **click type** *(default = MOUSE_LEFT)*
.. note::
- by euphemism
- Last Updated: 18 April 2013 by euphemism
Example:
.. code-block:: pascal
if (actionBar.clickSlot(1)) then
writeln('There was something in slot 1 and we clicked it!');
*)
function TRSActionBar.clickSlot(slot: integer; clickType: integer = MOUSE_LEFT): boolean;
begin
if (not self.__isSlotValid(slot)) or self.isSlotEmpty(slot) then
exit(false);
mouseBox(self.__slots[slot - 1], clickType);
result := true;
end;
(*
isSlotActive
------------
.. code-block:: pascal
function TRSActionBar.isSlotActive(slot: integer): boolean;
Returns true if the Action Bar slot **slot** is activated (i.e., it has been
clicked/has the white border).
.. note::
- by Ashaman88
- Last Updated: 21 January 2014 by Ashaman88
Example:
.. code-block:: pascal
if (actionBar.isSlotActive(1)) then
writeln('The first Action Bar slot is activated.');
*)
function TRSActionBar.isSlotActive(slot: integer): boolean;
begin
if (not self.__isSlotValid(slot)) then
exit(false);
result := (getColor(self.__slots[slot - 1].x1-1, self.__slots[slot - 1].y2-1) = 13158600); //Color is of the white box present outside of an active slot.
end;
(*
isLocked
--------
.. code-block:: pascal
function TRSActionBar.isLocked(): boolean;
Returns true if the Action Bar is locked.
.. note::
- by euphemism
- Last Updated: 5 July 2014 by The Mayor
Example:
.. code-block:: pascal
if actionBar.isLocked() then
writeln('The Action Bar is locked.');
*)
function TRSActionBar.isLocked(): boolean;
const
GAP_COLOR = 1775120; // Point between the shackle and the body.
begin // I.e. the gap when it's unlocked
result := (not (getColor(self.x2 - 9, self.y2 - 13) = GAP_COLOR));
end;
{*
__toggleLock
------------
.. code-block:: pascal
function TRSActionBar.__toggleLock(lock: boolean): boolean;
Returns true if it locks or unlocks the Action Bar. Scripters should use either
actionBar.lock() or actionBar.unlock() instead.
.. note::
- by euphemism
- Last Updated: 5 July 2014 by The Mayor
Example:
.. code-block:: pascal
if actionBar.__toggleLock(true) then
writeln('Successfully locked the Action Bar.');
*}
{$IFNDEF CODEINSIGHT}
function TRSActionBar.__toggleLock(lock: boolean): boolean;
var
timeMarker: TTimeMarker;
begin
if (((lock) and (not self.isLocked())) or ((not lock) and (self.isLocked()))) then //Lape currently does weird things with xor
begin
intToBox(actionBar.x2 - 15, actionBar.y2 - 17,
actionBar.x2 - 7, actionBar.y2 - 5).mouse(MOUSE_LEFT);
timeMarker.start();
repeat
wait(randomRange(10, 30));
result := (lock = self.isLocked());
until (result or (timeMarker.getTime() > randomRange(1900, 2300)));
end else
result := true;
end;
{$ENDIF}
(*
lock
----
.. code-block:: pascal
function TRSActionBar.lock(): boolean;
Returns true if the Action Bar is locked, or it successfully locks it.
.. note::
- by euphemism
- Last Updated: 18 April 2013 by euphemism
Example:
.. code-block:: pascal
if actionBar.lock() then
writeln('Action Bar is now, or already was, locked.');
*)
function TRSActionBar.lock(): boolean;
begin
result := self.__toggleLock(true);
end;
(*
unlock
------
.. code-block:: pascal
function TRSActionBar.unlock(): boolean;
Returns true if the Action Bar is unlocked, or it successfully unlocks it.
.. note::
- by euphemism
- Last Updated: 18 April 2013 by euphemism
Example:
.. code-block:: pascal
if actionBar.unlock() then
writeln('Action Bar is now, or alreay was, unlocked.');
*)
function TRSActionBar.unlock(): boolean;
begin
result := self.__toggleLock(false);
end;
(*
clearSlot
---------
.. code-block:: pascal
function TRSActionBar.clearSlot(slot: integer): boolean;
Returns true if it clears the specified Action Bar slot.
.. note::
- by euphemism
- Last Updated: 5 July 2014 by The Mayor
Example:
.. code-block:: pascal
if actionBar.clearSlot(1) then
writeln('Successfully cleared slot 1 of the Action Bar.');
*)
function TRSActionBar.clearSlot(slot: integer): boolean;
var
slotBox: TBox;
begin
if (not (self.__isSlotValid(slot))) then
exit(false);
if self.isSlotEmpty(slot) then
exit(true);
self.unlock();
wait(random(300, 500));
self.clickSlot(slot, MOUSE_MOVE);
wait(random(200));
dragMouse(point(50 + random(450), 220 + random(140)));
wait(random(750, 1250));
result := self.isSlotEmpty(slot);
end;
(*
clear
-----
.. code-block:: pascal
function TRSActionBar.clear(): boolean;
Returns true if it successfully clears every slot on the Action Bar.
.. note::
- by euphemism
- Last Updated: 5 July 2014 by The Mayor
Example:
.. code-block:: pascal
if actionBar.clear() then
writeln('Successfully cleared the Action Bar.');
*)
function TRSActionBar.clear(): boolean;
var
t: LongWord;
begin
if self.isEmpty() then
exit(true);
t := getSystemTime() + randomRange(3000, 5500);
repeat
mouseBox(intToBox(self.x2 - 15, self.y2 - 36, self.x2 - 7, self.y2 - 26), MOUSE_RIGHT);
chooseOption.select(['Clear', 'lear']);
if conversationBox.isOpen(randomRange(2500, 3500)) then
begin
conversationBox.selectOption(1);
wait(randomRange(1000, 1500));
end;
if self.isEmpty() then
exit(true);
until (getSystemTime() > t);
end;
{*
__getAbilityCooldown
--------------------
.. code-block:: pascal
function TRSActionBar.__getAbilityCooldown(boxToCheck: TBox; inActionBar: boolean = false): integer;
Returns integer representation (0 - 100) of the cooldown of the ability.
.. note::
- by euphemism
- Last Updated: 15 September 2013 by euphemism
Example:
.. code-block:: pascal
result := self.__getAbilityCooldown(self.__slots[slot - 1], true);
*}
{$IFNDEF CODEINSIGHT}
function TRSActionBar.__getAbilityCooldown(boxToCheck: TBox; inActionBar: boolean = false): integer;
var
colorFix, clientBitmap, i, len, sumTotal, tempBitmap: integer;
valid: boolean;
midPoint: TPoint;
boxEdge, line, tpa: TPointArray;
edgeSegments: T2DPointArray;
begin
result := - 1;
try
clientBitmap := bitmapFromClient(boxToCheck.x1, boxToCheck.y1, boxToCheck.x2, boxToCheck.y2);
setBitmapName(clientBitmap, 'Cooldown Bitmap');
if (inActionBar) then
begin
tpa := tpaFromBox(intToBox(boxToCheck.x1 + 2, boxToCheck.y1 + 18, boxToCheck.x1 + 8, boxToCheck.y1 + 25));
tpa.offset(point( - boxToCheck.x1, - boxToCheck.y1));
for i := 0 to high(tpa) do
fastSetPixel(clientBitmap, tpa[i].x, tpa[i].y, 0);
end;
tempBitmap := brightnessBitmap(clientBitmap, 100);
freeBitmap(clientBitmap);
clientBitmap := posterizeBitmap(tempBitmap, 60);
freeBitmap(tempBitmap);
tempBitmap := contrastBitmap(clientBitmap, 30);
freeBitmap(clientBitmap);
clientBitmap := desaturate(tempBitmap);
freeBitmap(tempBitmap);
boxToCheck.offset(point(- boxToCheck.x1, - boxToCheck.y1));
if ((boxToCheck.x2 mod 2) = 0) then
boxEdge := tpaFromLine(boxToCheck.x2 div 2 - 1, 0, 0, 0)
else
boxEdge := tpaFromLine(boxToCheck.x2 div 2, 0, 0, 0);
appendTPA(boxEdge, tpaFromLine(0, 1, 0, boxToCheck.y2));
appendTPA(boxEdge, tpaFromLine(1, boxToCheck.y2, boxToCheck.x2, boxToCheck.y2));
appendTPA(boxEdge, tpaFromLine(boxToCheck.x2, boxToCheck.y2 - 1, boxToCheck.x2, 0));
appendTPA(boxEdge, tpaFromLine(boxToCheck.x2 - 1, 0, boxEdge[0].x + 1, 0));
len := length(boxEdge);
for i := 0 to (len - 1) do
begin
if (inActionBar) then
begin
if (inRange(i, 0, len div 2)) then
midPoint := point(14, 15)
else
midPoint := point(15, 14);
end else
begin
if (inRange(i, 0, len div 2)) then
midPoint := point(13, 14)
else
midPoint := point(14, 13);
end;
tpaFromLineWrap(midPoint.x, midPoint.y, boxEdge[i].x, boxEdge[i].y, line);
line.sortFromPoint(midPoint);
line.invert();
if (i = 0) then
setlength(line, 6)
else
setlength(line, length(line) - 3);
sumTotal := 0;
sumTotal := sumIntegerArray(fastGetPixels(clientBitmap, line));
if (sumTotal <> 0) then
begin
result := ceil((round(fixD(degrees(arcTan2(boxEdge[i].x - midPoint.x, - (boxEdge[i].y - midPoint.y))))) / 360.0) * 100) + 1;
if (result = 99) then
begin
colorFix := getColor(boxToCheck.x1 + 14, boxToCheck.y1 + 2);
if ((colorFix = 6706) or (colorFix = 1710617)) then
begin
print('TRSActionBar.__getAbilityCooldown() used the colorFix check.', TDebug.LOG);
result := 100;
end;
end;
break;
end else
if (i = (len - 1)) then
result := 0;
end;
finally
freeBitmap(clientBitmap);
end;
end;
{$ENDIF}
(*
getAbilityCooldown
------------------
.. code-block:: pascal
function TRSActionBar.getAbilityCooldown(slot: integer): integer;
Returns integer representation (0 - 100) of the cooldown of the ability
in the Action Bar slot **slot**
.. note::
- by euphemism
- Last Updated: 18 April 2013 by euphemism
Example:
.. code-block:: pascal
if actionBar.getAbilityCooldown(1) = 100 then
writeln('The ability in slot 1 has cooled down 100% and is ready to use.');
*)
function TRSActionBar.getAbilityCooldown(slot: integer): integer;
begin
if (not self.__isSlotValid(slot)) or self.isSlotEmpty(slot) then
exit(-1);
result := self.__getAbilityCooldown(self.__slots[slot - 1], true);
print('TRSActionBar.getAbilityCooldown() checked slot ' + toStr(slot) + 'and got ' + toStr(result), TDebug.LOG);
end;
{*
__getPercent
------------
.. code-block:: pascal
function TRSActionBar.__getPercent(bar: integer): byte;
Returns the percentage of the Action Bar stat bar **bar**
.. note::
- by Turpinator
- Last Updated: 12 December 2013 by Turpinator
Example:
.. code-block:: pascal
actionBar.__getPercent(AB_BAR_HP);
*}
{$IFNDEF CODEINSIGHT}
function TRSActionBar.__getPercent(bar: integer): byte;
const
BACKGROUND_COLOR = 2894115;
var
xx, yy: integer;
begin
xx := (self.x1 + bar);
yy := (self.y1 + 23);
for result := 100 downto 1 do
if (getColor(xx + result, yy) <> BACKGROUND_COLOR) then
break();
end;
{$ENDIF}
(*
getHPPercent
------------
.. code-block:: pascal
function TRSActionBar.getHPPercent(): integer;
Returns the players hitpoints percentage.
.. note::
- by Turpinator
- Last Updated: 12 December 2013 by Turpinator
Example:
.. code-block:: pascal
writeln(actionBar.getHPPercent());
*)
function TRSActionBar.getHPPercent(): integer;
begin
result := self.__getPercent(_AB_BAR_HP_OFFSET);
end;
(*
getAdrenalinePercent
--------------------
.. code-block:: pascal
function TRSActionBar.getAdrenalinePercent(): integer;
Returns the players adrenaline percentage.
.. note::
- by Turpinator
- Last Updated: 12 December 2013 by Turpinator
Example:
.. code-block:: pascal
writeln(actionBar.getAdrenalinePercent());
*)
function TRSActionBar.getAdrenalinePercent(): integer;
begin
result := self.__getPercent(_AB_BAR_ADRENALINE_OFFSET);
end;
(*
getPrayerPercent
----------------
.. code-block:: pascal
function TRSActionBar.getPrayerPercent(): integer;
Returns the players prayer percentage.
.. note::
- by Turpinator
- Last Updated: 12 December 2013 by Turpinator
Example:
.. code-block:: pascal
writeln(actionBar.getPrayerPercent());
*)
function TRSActionBar.getPrayerPercent(): integer;
begin
result := self.__getPercent(_AB_BAR_PRAYER_OFFSET);
end;
(*
getSummoningPercent
-------------------
.. code-block:: pascal
function TRSActionBar.getSummoningPercent(): integer;
Returns the players summoning percent
.. note::
- by Turpinator
- Last Updated: 12 December 2013 by Turpinator
Example:
.. code-block:: pascal
writeln(actionBar.getSummoningPercent());
*)
function TRSActionBar.getSummoningPercent(): integer;
begin
result := self.__getPercent(_AB_BAR_SUMMONING_OFFSET);
end;
{*
__iconBoxes()
-------------
.. code-block:: pascal
function TRSActionBar.__iconBoxes(): TBoxArray;
Returns the TBoxArray of the Action Bar icons.
.. note::
- by Thomas
Example:
.. code-block:: pascal
smartImage.drawBoxes(actionBar.__iconBoxes(), false, clRed);
*}
{$IFNDEF CODEINSIGHT}
function TRSActionBar.__iconBoxes(): TBoxArray;
begin
result := grid(4, 1, 29, 29, 139, 0, [self.getbounds().x1 + 27, self.getbounds().y1 + 18]);
end;
{$ENDIF}
(*
mouseIcon
---------
.. code-block:: pascal
procedure TRSActionBar.mouseIcon(icon, button: integer = MOUSE_LEFT);
Returns true if it clicks the Action Bar stat icon **icon** using the mouse
button **button** *(default = MOUSE_LEFT);
.. note::
- by Ashaman88
- Last Updated: 22 August 2015 by Thomas
Example:
.. code-block:: pascal
actionBar.mouseIcon(AB_BAR_SUMMONING);
*)
procedure TRSActionBar.mouseIcon(icon, button: integer = MOUSE_LEFT);
begin
if not inRange(icon, 1, 4) then
exit();
mouseCircle(self.__iconBoxes()[icon - 1].getMiddle(), 9, button);
end;
(*
isIconEnabled
-------------
.. code-block:: pascal
function TRSActionBar.isIconEnabled(icon: integer): boolean;
Returns true if the selected icon (icon) is enabled.
.. note::
- by Thomas
Example:
.. code-block:: pascal
isIconEnabled(AB_BAR_PRAYER);
*)
function TRSActionBar.isIconEnabled(icon: integer): boolean;
var
color: T2DIntegerArray;
begin
if (not inRange(icon, 1, 3)) then
exit();
// AB_BAR_HP AB_BAR_ADRENALINE AB_BAR_PRAYER
color := [[4884648, 95, 75], [3442349, 85, 130], [11751792, 70, 140]]; // [col, tol, count]
result := countColorTolerance(color[icon - 1][0], self.__iconBoxes()[icon - 1], color[icon - 1][1]) > color[icon - 1][2];
print('TRSActionBar.isIconEnabled(): result = ' + boolToStr(result), TDebug.SUB);
end;
{*
__setIcon
---------
.. code-block:: pascal
function TRSActionBar.__setIcon(icon: integer; enabled: boolean = true): boolean;
Returns true if it successfully enables or disables the icon depending on
the **enabled** parameter *(default = true)*
.. note::
- by Thomas
Example:
.. code-block:: pascal
actionBar.__setIcon(AB_BAR_PRAYER);
actionBar.__setIcon(AB_BAR_PRAYER, false); // To disable it
*}
{$IFNDEF CODEINSIGHT}
function TRSActionBar.__setIcon(icon: integer; enabled: boolean = true): boolean;
var
timeOut: TCountDown;
begin
timeOut.setTime(randomRange(3500, 5000));
repeat
result := (self.isIconEnabled(icon) = enabled);
if (not result) then
begin
self.mouseIcon(icon, MOUSE_LEFT);
wait(1000 + random(1000));
end;
until result or timeOut.isFinished();
print('TRSActionBar.__setIcon(): result = ' + boolToStr(result), TDebug.SUB);
end;
{$ENDIF}
(*
setRetaliate
------------
.. code-block:: pascal
function TRSActionBar.setRetaliate(enabled: boolean = true): boolean;
Returns true if it successfully enables or disables autoretaliate depending on
the **enabled** parameter *(default = true)*
.. note::
- by Ashaman88
- Last Updated: 22 August 2015 by Thomas
Example:
.. code-block:: pascal
actionBar.setRetaliate();
actionBar.setRetaliate(false); // To disable it
*)
function TRSActionBar.setRetaliate(enabled: boolean = true): boolean;
begin
result := self.__setIcon(AB_BAR_ADRENALINE, enabled);
end;
(*
setQuickPrayer
--------------
.. code-block:: pascal
function TRSActionBar.setQuickPrayer(enabled: boolean = true): boolean;
Returns true if it successfully enables or disables QuickPrayer depending on
the **enabled** parameter *(default = true)*
.. note::
- by The Mayor
- Last Updated: 22 August 2015 by Thomas
Example:
.. code-block:: pascal
actionBar.setQuickPrayer();
actionBar.setQuickPrayer(false); // To disable it
*)
function TRSActionBar.setQuickPrayer(enabled: boolean = true): boolean;
begin
result := self.__setIcon(AB_BAR_PRAYER, enabled);
end;
(*
setHealing
----------
.. code-block:: pascal
function TRSActionBar.setHealing(enabled: boolean = true): boolean;
Returns true if it successfully enables or disables Healing depending on
the **enabled** parameter *(default = true)*
.. note::
- by Thomas
Example:
.. code-block:: pascal
actionBar.setHealing();
actionBar.setHealing(false); // To disable it
*)
function TRSActionBar.setHealing(enabled: boolean = true): boolean;
begin
result := self.__setIcon(AB_BAR_HP, enabled);
end;
begin
actionBar.__init();
end;
{$f+}