@@ -9,16 +9,29 @@ Methods to interact with the bank interface
99{$ENDIF}
1010
1111type
12- ERSBankButtons = (WORN, MENU);
12+ (*
13+ ## Bank Enums
14+ ```pascal
15+ ERSBankButtons = enum(WORN, MENU);
16+ ERSBankArrangement = enum(SWAP, INSERT);
17+ ERSWithdrawMode = enum(ITEM, NOTE);
18+ ERSBankQuantity = enum(ONE, FIVE, TEN, CUSTOM, ALL);
19+ ERSBankDynamicButtons = enum(PLACEHOLDERS, SEARCH, DEPOSIT_INVENTORY, DEPOSIT_WORN);
20+ ERSBankInteraction = enum(WITHDRAW, DEPOSIT);
21+ ```
22+ Bank enums used to interact with the bank interface.
23+ *)
24+ ERSBankButtons = enum(WORN, MENU);
1325 ERSBankArrangement = enum(SWAP, INSERT);
14- ERSBankWithdraw = enum(ITEM, NOTE);
26+ ERSWithdrawMode = enum(ITEM, NOTE);
1527 ERSBankQuantity = enum(ONE, FIVE, TEN, CUSTOM, ALL);
1628 ERSBankDynamicButtons = enum(PLACEHOLDERS, SEARCH, DEPOSIT_INVENTORY, DEPOSIT_WORN);
29+ ERSBankInteraction = enum(WITHDRAW, DEPOSIT);
1730
1831 TRSItemBankPosition = record
1932 Tab: Integer;
2033 Scroll: Integer;
21- Box : TBox;
34+ Slot : TBox;
2235 end;
2336
2437 TRSBankItem = record
2942
3043 TRSBankItemArray = array of TRSBankItem;
3144
45+ (*
46+ (TRSBank)=
47+ ## type TRSBank
48+ Record responsible to handle the bank interface.
49+ *)
3250 TRSBank = record
3351 Bounds: TBox;
3452 Slots: TRSSlotInterface;
4563
4664 Buttons: array [ERSBankButtons] of TRSButton;
4765 ArrangementButtons: array [ERSBankArrangement] of TRSButton;
48- WithdrawButtons : array [ERSBankWithdraw ] of TRSButton;
66+ WithdrawModeButtons : array [ERSWithdrawMode ] of TRSButton;
4967 QuantityButtons: array [ERSBankQuantity] of TRSButton;
5068 DynamicButtons: array [ERSBankDynamicButtons] of TRSButton;
5169 ButtonsOffset: Integer;
5573 Items: TStringMap<TRSItemBankPosition>;
5674 end;
5775
76+ {%codetools off}
5877 _IsOpenHelperBox: TBox;
59- const QUANTITY_ALL: Integer = -1;
60- const QUANTITY_ALL_BUT_ONE: Integer = -2;
78+ {%codetools on}
79+ const QUANTITY_ALL: Integer = 0;
80+ const QUANTITY_ALL_BUT_ONE: Integer = -1;
6181 end;
6282
6383(*
@@ -162,8 +182,8 @@ begin
162182 Self.Buttons[i].EnabledColors := [[$0F1043, 0], [$23269F, 0.227]];
163183 Self.ArrangementButtons[i].Index := i;
164184 Self.ArrangementButtons[i].EnabledColors := [[$0F1043, 0], [$23269F, 0.227]];
165- Self.WithdrawButtons [i].Index := i;
166- Self.WithdrawButtons [i].EnabledColors := [[$0F1043, 0], [$23269F, 0.227]];
185+ Self.WithdrawModeButtons [i].Index := i;
186+ Self.WithdrawModeButtons [i].EnabledColors := [[$0F1043, 0], [$23269F, 0.227]];
167187 end;
168188
169189 for i := 0 to 4 do
@@ -186,8 +206,8 @@ begin
186206 Self.ArrangementButtons[ERSBankArrangement.SWAP].Bounds := TBox.Create(X1+5, Y2-26, X1+54, Y2-5);
187207 Self.ArrangementButtons[ERSBankArrangement.INSERT].Bounds := TBox.Create(X1+55, Y2-26, X1+104, Y2-5);
188208
189- Self.WithdrawButtons[ERSBankWithdraw .ITEM].Bounds := TBox.Create(X1+105, Y2-26, X1+154, Y2-5);
190- Self.WithdrawButtons[ERSBankWithdraw .NOTE].Bounds := TBox.Create(X1+155, Y2-26, X1+204, Y2-5);
209+ Self.WithdrawModeButtons[ERSWithdrawMode .ITEM].Bounds := TBox.Create(X1+105, Y2-26, X1+154, Y2-5);
210+ Self.WithdrawModeButtons[ERSWithdrawMode .NOTE].Bounds := TBox.Create(X1+155, Y2-26, X1+204, Y2-5);
191211
192212 for i := 0 to 4 do
193213 Self.QuantityButtons[i].Bounds := TBox.Create(X1+205 + 25 * i, Y2-26, X1+229 + 25 * i, Y2-5);
@@ -209,7 +229,7 @@ begin
209229 begin
210230 Self.Buttons[i].Bounds := Self.Buttons[i].Bounds.Offset([offset, 0]);
211231 Self.ArrangementButtons[i].Bounds := Self.ArrangementButtons[i].Bounds.Offset([offset, 0]);
212- Self.WithdrawButtons [i].Bounds := Self.WithdrawButtons [i].Bounds.Offset([offset, 0]);
232+ Self.WithdrawModeButtons [i].Bounds := Self.WithdrawModeButtons [i].Bounds.Offset([offset, 0]);
213233 end;
214234
215235 for i := 0 to 4 do
@@ -365,16 +385,46 @@ end;
365385
366386
367387
388+ (*
389+ ## Bank.SetArrangement
390+ ```pascal
391+ function TRSBank.SetArrangement(arrangement: ERSBankArrangement): Boolean;
392+ ```
393+ Attempts to set the bank arrangement to `arrangement`, returns true if we succeed.
394+
395+ Example:
396+ ```pascal
397+ WriteLn Bank.SetArrangement(ERSBankArrangement.INSERT);
398+ ```
399+ *)
368400function TRSBank.SetArrangement(arrangement: ERSBankArrangement): Boolean;
369401begin
370402 if Self.ArrangementButtons[arrangement].Enabled() then Exit(True);
371403 Result := Self.ArrangementButtons[arrangement].Enable();
372404end;
373405
374- function TRSBank.SetWithdraw(withdraw: ERSBankWithdraw): Boolean;
406+ (*
407+ ## Bank.SetWithdrawMode
408+ ```pascal
409+ function TRSBank.SetWithdrawMode(noted: Boolean): Boolean;
410+ ```
411+ Attempts to set the bank withdraw mode to noted if `noted` is true or
412+ to item if it's false, returns true if we succeed.
413+
414+ Example:
415+ ```pascal
416+ WriteLn Bank.SetWithdrawMode(True);
417+ ```
418+ *)
419+ function TRSBank.SetWithdrawMode(noted: Boolean): Boolean;
420+ var
421+ btn: ERSWithdrawMode;
375422begin
376- if Self.WithdrawButtons[withdraw].Enabled() then Exit(True);
377- Result := Self.WithdrawButtons[withdraw].Enable();
423+ if noted then btn := ERSWithdrawMode.NOTE
424+ else btn := ERSWithdrawMode.ITEM;
425+
426+ if Self.WithdrawModeButtons[btn].Enabled() then Exit(True);
427+ Result := Self.WithdrawModeButtons[btn].Enable();
378428end;
379429
380430
@@ -394,14 +444,26 @@ WriteLn Bank.Integer2Quantity(7);
394444function TRSBank.Integer2Quantity(const quantity: Integer): ERSBankQuantity;
395445begin
396446 case quantity of
397- 1: Result := ERSBankQuantity.ONE;
398- 5: Result := ERSBankQuantity.FIVE;
399- 10: Result := ERSBankQuantity.TEN;
400- Self.QUANTITY_ALL: Result := ERSBankQuantity.ALL;
401- else Result := ERSBankQuantity.CUSTOM;
447+ 1: Result := ERSBankQuantity.ONE;
448+ 5: Result := ERSBankQuantity.FIVE;
449+ 10: Result := ERSBankQuantity.TEN;
450+ 0, -1: Result := ERSBankQuantity.ALL;
451+ else Result := ERSBankQuantity.CUSTOM;
402452 end;
403453end;
404454
455+ (*
456+ ## Bank.SetQuantity
457+ ```pascal
458+ function TRSBank.SetQuantity(quantity: ERSBankQuantity): Boolean;
459+ ```
460+ Attempts to set the bank quantity to `quantity`, returns true if we succeed.
461+
462+ Example:
463+ ```pascal
464+ WriteLn Bank.SetQuantity(ERSBankQuantity.FIVE);
465+ ```
466+ *)
405467function TRSBank.SetQuantity(quantity: ERSBankQuantity): Boolean;
406468begin
407469 if Self.QuantityButtons[quantity].Enabled() then Exit(True);
@@ -581,6 +643,7 @@ if Bank.Search('logs') then
581643 ShowOnClient(bounds);
582644```
583645*)
646+ {%codetools off}
584647function TRSBank._FindTabText(const tpa: TPointArray; out bounds: TBox): Boolean;
585648var
586649 atpa: T2DPointArray;
@@ -598,7 +661,7 @@ begin
598661 bounds.Y2 += 3;
599662 Result := True;
600663end;
601-
664+ {%codetools on}
602665
603666(*
604667## Bank.FindItemTab
@@ -620,17 +683,6 @@ function TRSBank.FindItemTab(const item: TRSItem): Integer;
620683var
621684 bounds: TBox;
622685begin
623- (* TODO: Remove
624- if Self.Items.Contains(item) then
625- begin
626- if not Self.DynamicButtons[ERSBankDynamicButtons.SEARCH].Enabled() then
627- Exit(Self.GetCurrentTab());
628-
629- if Self.WaitSearchOpen(600) then
630- if not Self.CloseSearch() then Exit(-1); //unknown state, reset search
631- end;
632- *)
633-
634686 if not Self.Search(item.SimplifyName()) then Exit(-1);
635687 if not Self.Items.Find(item, bounds) then Exit(-1);
636688
664716 next: Integer;
665717 down: Boolean;
666718begin
667- (* TODO: Remove
668- if Self.Items.Contains(item) then
669- begin
670- if not Self.DynamicButtons[ERSBankDynamicButtons.SEARCH].Enabled() then
671- Exit(Self.Scroll.GetLevel());
672-
673- if Self.WaitSearchOpen(600) then
674- if not Self.CloseSearch() then Exit(-1); //unknown state, reset search
675- end;
676- *)
677-
678719 if not Self.Scroll.CanScroll() then Exit(-1);
679720
680721 Result := Self.Scroll.GetLevel();
@@ -705,6 +746,113 @@ begin
705746 Result := -1;
706747end;
707748
749+ (*
750+ ## Bank._InteractionHelper
751+ ```pascal
752+ function TRSBank._InteractionHelper(mode: ERSBankInteraction; slot: TBox; amount: Integer; useQuantityButton: Boolean): Boolean;
753+ ```
754+ Internal helper method to handle both withdrawing and depositing.
755+
756+ Example:
757+ ```pascal
758+ if Bank.Items.Find('Abyssal whip', slot) the
759+ Bank._InteractionHelper(ERSBankInteraction.WITHDRAW, slot, 1, True);
760+ ```
761+ *)
762+ {%codetools off}
763+ function TRSBank._InteractionHelper(mode: ERSBankInteraction; slot: TBox; amount: Integer; useQuantityButton: Boolean): Boolean;
764+ var
765+ quantity: ERSBankQuantity;
766+ amountStr, modeStr: String;
767+ begin
768+ amountStr := ToString(amount);
769+ quantity := Self.Integer2Quantity(amount);
770+ if mode = ERSBankInteraction.DEPOSIT then modeStr := 'Deposit-'
771+ else modeStr := 'Withdraw-';
772+
773+ if useQuantityButton then
774+ begin
775+ if not Self.SetQuantity(quantity) then Exit;
776+
777+ Mouse.Move(slot);
778+ if quantity <> ERSBankQuantity.CUSTOM then
779+ begin
780+ Target.MouseClick(EMouseButton.LEFT);
781+ Exit(True);
782+ end;
783+
784+ if MainScreen.IsUpText(modeStr + amountStr) then
785+ begin
786+ Target.MouseClick(EMouseButton.LEFT);
787+ Exit(True);
788+ end;
789+
790+ if not ChooseOption.Select(modeStr + 'X') then Exit;
791+ Exit(Chat.AnswerQuery('Enter amount', amountStr, RandomLeft(1400, 2400)));
792+ end;
793+
794+ Mouse.Move(slot);
795+
796+ if (quantity = ERSBankQuantity.ALL) then
797+ Exit(ChooseOption.Select(modeStr + 'All'));
798+
799+ Result := ChooseOption.Select(modeStr + amountStr + ' ', True, False) or
800+ (ChooseOption.Select(modeStr + 'X') and Chat.AnswerQuery('Enter amount', amountStr, RandomLeft(1400, 2400)));
801+ end;
802+ {%codetools on}
803+
804+ (*
805+ ## Bank.Find
806+ ```pascal
807+ function TRSBank.Find(item: TRSItem; out data: TRSItemBankPosition; attempts: Int32 = 3): Boolean;
808+ ```
809+ Attempts to find `item` in the back by whatever means necessary.
810+ This will search and scroll the bank until the item is found.
811+ By default attempts up to 3 times.
812+
813+ Item position data is returned via `data`.
814+ *)
815+ function TRSBank.Find(item: TRSItem; out data: TRSItemBankPosition; attempts: Int32 = 3): Boolean;
816+ begin
817+ if attempts = 0 then Exit(False);
818+
819+ if Self.Items.Find(item, data.Slot) then
820+ begin
821+ if not Self.DynamicButtons[ERSBankDynamicButtons.SEARCH].Enabled() then
822+ begin
823+ data.Tab := Self.GetCurrentTab();
824+ data.Scroll := Self.Scroll.GetLevel();
825+ Self.Cache.Items.Value[item] := data;
826+ Exit(True);
827+ end;
828+
829+ if Self.WaitSearchOpen(600) then
830+ if not Self.CloseSearch() then Exit(Self.FindItem(item, data, Dec(attempts))); //unknown state, reset search
831+ end;
832+
833+ data.Tab := Self.FindItemTab(item);
834+ if data.Tab = -1 then
835+ Exit(Self.FindItem(item, data, Dec(attempts)));
836+ Self.OpenTab(data.Tab);
837+
838+ if Self.Items.Find(item, data.Slot) then
839+ begin
840+ data.Scroll := Self.Scroll.GetLevel();
841+ Self.Cache.Items.Value[item] := data;
842+ Exit(True);
843+ end;
844+
845+ data.Scroll := Self.FindItemScroll(item);
846+ if data.Scroll = -1 then
847+ Exit(Self.FindItem(item, data, Dec(attempts)));
848+
849+ if not Self.Items.Find(item, data.Slot) then
850+ Exit(Self.FindItem(item, data, Dec(attempts)));
851+
852+ Result := True;
853+ Self.Cache.Items.Value[item] := data;
854+ end;
855+
708856
709857
710858procedure TRSBank.Draw(img: TImage);
@@ -717,7 +865,7 @@ begin
717865 begin
718866 Self.Buttons[i].Draw(img);
719867 Self.ArrangementButtons[i].Draw(img);
720- Self.WithdrawButtons [i].Draw(img);
868+ Self.WithdrawModeButtons [i].Draw(img);
721869 end;
722870
723871 for i := 0 to 4 do
0 commit comments