@@ -10,13 +10,10 @@ Methods to interact with the bank pin interface.
1010type
1111 TRSBankPin = record
1212 Bounds: TBox;
13- Buttons: TRSButtonArray ;
13+ Buttons: TBoxArray ;
1414 end;
1515
1616procedure TRSBankPin.SetupInterface();
17- var
18- boxes: TBoxArray;
19- i: Integer;
2017begin
2118 with InterfaceArea do
2219 begin
@@ -26,21 +23,211 @@ begin
2623 Self.Bounds.Y2 := Min(Floor(Center.Y+(Height-3)/2), Center.Y+157);
2724 end;
2825
29- boxes := TBoxArray.Create(Self.Bounds.TopLeft.Offset(25,88), 3, 3, 55, 55, [39, 17]);
30- boxes.Insert(boxes[2].Offset([84, 0]), 3);
26+ Self.Buttons := TBoxArray.Create(Self.Bounds.TopLeft.Offset(21,84), 3, 3, 63, 63, [31, 9]);
27+ Self.Buttons.Insert(Self.Buttons[2].Offset([84, 0]), 3);
28+ end;
29+
30+ (*
31+ ## BankPin.IsOpen
32+ ```pascal
33+ function TRSBankPin.IsOpen(): Boolean;
34+ ```
35+ Returns true if the bank pin is open.
36+
37+ Example:
38+ ```pascal
39+ WriteLn BankPin.IsOpen();
40+ ```
41+ *)
42+ function TRSBankPin.IsOpen(): Boolean;
43+ begin
44+ Result := Target.HasColor($060D56, 10, 3400, Self.Buttons[0]);
45+ end;
46+
47+ (*
48+ ## BankPin.WaitOpen
49+ ```pascal
50+ function TRSBankPin.WaitOpen(time: Integer = 600; interval: Integer = -1): Boolean;
51+ ```
52+ Returns true if the bank pin opens within `time` milliseconds..
53+
54+ Example:
55+ ```pascal
56+ WriteLn BankPin.WaitOpen();
57+ ```
58+ *)
59+ function TRSBankPin.WaitOpen(time: Integer = 600; interval: Integer = -1): Boolean;
60+ begin
61+ if interval < 0 then interval := RandomMode(100, 50, 1500);
62+ Result := SleepUntil(Self.IsOpen(), interval, time);
63+ end;
64+
65+
66+ (*
67+ ## BankPin.IsLoading
68+ ```pascal
69+ function TRSBankPin.IsLoading(): Boolean;
70+ ```
71+ Returns true if the bank pin is loading.
72+ The bank pin is loading when the interface is open but the pin numbers are not
73+ available yet.
74+
75+ Example:
76+ ```pascal
77+ WriteLn BankPin.IsLoading();
78+ ```
79+ *)
80+ function TRSBankPin.IsLoading(): Boolean;
81+ begin
82+ Result := not Target.HasColor($007FFF, 0, 1, Self.Buttons[0]);
83+ end;
3184
32- SetLength(Self.Buttons, 10);
33- for i := 0 to High(boxes) do
85+ (*
86+ ## BankPin.WaitLoading
87+ ```pascal
88+ function TRSBankPin.WaitLoading(time: Integer = 600; interval: Integer = -1): Boolean;
89+ ```
90+ Returns true if the bank pin finishes loading within `time` milliseconds..
91+ For more information on bank pin loading read {ref}`BankPin.IsLoading`.
92+
93+ Example:
94+ ```pascal
95+ WriteLn BankPin.WaitLoading();
96+ ```
97+ *)
98+ function TRSBankPin.WaitLoading(time: Integer = 600; interval: Integer = -1): Boolean;
99+ begin
100+ if interval < 0 then interval := RandomMode(100, 50, 1500);
101+ Result := SleepUntil(not Self.IsLoading(), interval, time);
102+ end;
103+
104+
105+ (*
106+ ## BankPin.ClickDigit
107+ ```pascal
108+ function TRSBankPin.ClickDigit(digit: Char): Boolean; override;
109+ ```
110+ Clicks a bank pin digit.
111+
112+ Example:
113+ ```pascal
114+ WriteLn BankPin.ClickDigit('5');
115+ ```
116+ *)
117+ function TRSBankPin.ClickDigit(digit: Char): Boolean;
118+ var
119+ i: Integer;
120+ hovering: Boolean;
121+ begin
122+ for i := 0 to High(Self.Buttons) do
34123 begin
35- Self.Buttons[i].Bounds := boxes[i];
36- Self.Buttons[i].EnabledColors := [];
124+ if Self.Buttons[i].Contains(Mouse.Position()) then
125+ begin
126+ hovering := True;
127+ Continue;
128+ end;
129+
130+ if OCR.Locate(Self.Buttons[i], digit, [$007FFF], 0, RSFonts.BOLD) > 0.95 then
131+ begin
132+ Mouse.Click(Self.Buttons[i], EMouseButton.LEFT);
133+ Exit(True);
134+ end;
135+ end;
136+
137+ if hovering then
138+ begin
139+ Mouse.Click(EMouseButton.LEFT);
140+ Exit(True);
37141 end;
38142end;
39143
40- function TRSBankPin.IsOpen(): Boolean;
41- begin //TODO:
42- Result := Target.HasColor($060D56, 10, 30000, Self.Bounds);
144+
145+ (*
146+ ## BankPin.GetDigitIndex
147+ ```pascal
148+ function TRSBankPin.GetDigitIndex(): Integer;
149+ ```
150+ Returns the index of the next digit to enter.
151+
152+ Example:
153+ ```pascal
154+ WriteLn BankPin.GetDigitIndex();
155+ ```
156+ *)
157+ function TRSBankPin.GetDigitIndex(): Integer;
158+ const
159+ DIGITS: TStringArray = ['FIRST', 'SECOND', 'THIRD', 'FOURTH'];
160+ var
161+ i: Integer;
162+ begin
163+ for i := 0 to High(DIGITS) do
164+ if OCR.Locate(Self.Bounds, DIGITS[i], [$FFFFFF], 0, RSFonts.BOLD) > 0.95 then
165+ Exit(i+1);
43166end;
44167
168+ (*
169+ ## BankPin.Enter
170+ ```pascal
171+ function TRSBankPin.Enter(pin: String): Boolean;
172+ ```
173+ Handles entering the bank pin. Will do 4 attempts before terminating with a fatal error.
174+
175+ Example:
176+ ```pascal
177+ BankPin.Enter('0000');
178+ ```
179+ *)
180+ function TRSBankPin.Enter(pin: String; attempts: Integer = 3): Boolean;
181+
182+ function _IsUnlocked(): Boolean;
183+ begin
184+ if Self.IsOpen() then
185+ Exit;
186+ Result := not Chat.GetChat().ContainsAny(['try again', 'forgotten your PIN', 'PIN incorrectly several']);
187+ end;
188+
45189var
190+ i, idx: Integer;
191+ digit: Char;
192+ chatCache: String;
193+ begin
194+ if attempts <= 0 then Exit;
195+
196+ for i := 0 to 3 do
197+ begin
198+ idx := Self.GetDigitIndex();
199+ if idx = 0 then Break;
200+
201+ digit := pin[idx];
202+ if not Self.ClickDigit(digit) then Break;
203+ Biometrics.Sleep(200, 1500, ERandomDir.LEFT);
204+ SleepUntil((idx <> Self.GetDigitIndex()) and not Self.IsLoading(), 100, 5000);
205+ end;
206+
207+ chatCache := Chat.GetChat();
208+ if 'try again' in chatCache then
209+ begin
210+ Chat.ContinueChat();
211+ Exit(Self.Enter(pin, Dec(attempts)));
212+ end;
213+
214+ if 'forgotten your PIN' in chatCache then
215+ begin
216+ SleepUntil(not ('forgotten your PIN' in Chat.GetChat()), 300, 20000);
217+ Exit(Self.Enter(pin, Dec(attempts)));
218+ end;
219+
220+ if 'PIN incorrectly several' in chatCache then
221+ raise GetDebugLn('BankPin', 'Failed to enter the bank pin several times. Check that the pin is correct.');
222+
223+ Result := SleepUntil(_IsUnlocked(), 300, 3000) or Self.Enter(pin, Dec(attempts));
224+ end;
225+
226+
227+ var
228+ (*
229+ (BankPin variable)=
230+ ## var BankPin
231+ Global {ref}`TRSBankPin` variable.
232+ *)
46233 BankPin: TRSBankPin;
0 commit comments