-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathChat.simba
288 lines (256 loc) · 6.15 KB
/
Chat.simba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
{$include_once Internal/Reflection.simba}
{$include_once Constants.simba}
{$include_once Mouse.simba}
{$include_once Timing.simba}
type
TRSChatMessage = record
Name: String;
Message: String;
LineNumber: Int32;
end;
{*
R_ChatMessages
~~~~~~~~~~~~~~~~~~~~~~
Returns an array of TRSChatMessage containing all in-game
chat messages in your chat box.
Example:
Messages := R_ChatMessages();
for I:=0 to High(Messages) do
...
*}
Function R_ChatMessages(Limit: UInt32 = 0): Array of TRSChatMessage;
var
I, J, Count: Int32;
ChatWidget: RSWidget;
Children: Array of RSWidget;
Name: String;
Message: String;
begin
ChatWidget := RSWidget.Get(R_CHATBOX_MESSAGES_CHATLINES_TEXT.Group, R_CHATBOX_MESSAGES_CHATLINES_TEXT.Child);
if ChatWidget.ref = nil then
Exit;
J := 0;
Count := 0;
Children := ChatWidget.Children;
For I := 0 to High(Children) do
begin
if Limit > 0 then
begin
if Count = Limit then
break;
Inc(Count);
end;
Name := Children[I].Text.SanitizeRS;
Message := Children[I + 1].Text.SanitizeRS;
if (Name = '') and (Message = '') then
begin
I += 1;
Continue;
end;
if (Name <> '') and (Message = '') then
Swap(Name, Message);
Result += [Name, Message, J];
I += 1;
J += 1;
end;
ChatWidget.Free;
end;
{*
R_ChatDialog
~~~~~~~~~~~~~~~~~~~~~~
Returns true if the Chat Dialog is open.
Example:
if R_ChatDialog then
...
*}
Function R_ChatDialog: Boolean;
var
Dialog: RSWidget;
begin
Dialog := RSWidget.Get(R_CHATBOX_DIALOG.Group, R_CHATBOX_DIALOG.Child);
if Dialog.ref <> nil then
begin
Dialog.Free;
Exit(True);
end;
Dialog := RSWidget.Get(R_CHATBOX_PLAYER_DIALOG.Group, R_CHATBOX_PLAYER_DIALOG.Child);
if Dialog.ref <> nil then
begin
Dialog.Free;
Exit(True);
end;
end;
{*
R_ChatDialogText
~~~~~~~~~~~~~~~~~~~~~~
Returns the chat dialog text.
Example:
writeln(R_ChatDialogText);
...
*}
Function R_ChatDialogText: String;
var
Dialog: RSWidget;
begin
Dialog := RSWidget.Get(R_INTERFACE_CHAT_DIALOG_TEXT.Group, R_INTERFACE_CHAT_DIALOG_TEXT.Child);
if Dialog.ref <> nil then
begin
Result := Dialog.Text;
Dialog.Free;
Exit;
end;
Dialog := RSWidget.Get(R_CHATBOX_NPC_TEXT.Group, R_CHATBOX_NPC_TEXT.Child);
if Dialog.ref <> nil then
begin
Result := Dialog.Text;
Dialog.Free;
Exit;
end;
Dialog := RSWidget.Get(R_CHATBOX_PLAYER_TEXT.Group, R_CHATBOX_PLAYER_TEXT.Child);
if Dialog.ref <> nil then
begin
Result := Dialog.Text;
Dialog.Free;
Exit;
end;
end;
{*
R_ChatInput
~~~~~~~~~~~~~~~~~~~~~~
Returns true if the chat input option is open (Chat screen with '*').
Example:
if R_ChatInput then
...
*}
Function R_ChatInput: Boolean;
var
Input: RSWidget;
begin
Input := RSWidget.Get(R_CHATBOX_MESSAGES_CHATINPUT.Group, R_CHATBOX_MESSAGES_CHATINPUT.Child);
if Input.ref <> nil then
begin
Mouse.Click(Input.Bounds, MOUSE_LEFT);
Input.Free;
Exit(True);
end;
end;
{*
R_ChatChooseOptionIsOpen
~~~~~~~~~~~~~~~~~~~~~~
Returns true if chat option is open.
Example:
if R_ChatChooseOptionIsOpen then
Keyboard.Send("2");
...
*}
Function R_ChatChooseOptionIsOpen: Boolean;
var
Widget: RSWidget;
begin
Widget := RSWidget.Get(R_CHATBOX_NPC_DIALOG_OPTION.Group, R_CHATBOX_NPC_DIALOG_OPTION.Child);
Result := Widget.ref <> nil;
if Result then
begin
Widget.Free;
end;
end;
{*
R_ChatChooseOption
~~~~~~~~~~~~~~~~~~~~~~
Returns true if selected specified chat option.
Example:
if R_ChatChooseOption(['Yes']) then
...
*}
Function R_ChatChooseOption(options: Array of String; caseSensitive: Boolean = True; useMouse: Boolean = True): Boolean;
var
I, J: Int32;
Dialog: RSWidget;
Items: Array of RSWidget;
Title: String;
begin
Dialog := RSWidget.Get(R_CHATBOX_NPC_DIALOG_OPTION.Group, R_CHATBOX_NPC_DIALOG_OPTION.Child);
if Dialog.ref = nil then
Exit(False);
Items := Dialog.Children;
Dialog.Free;
For I := 1 to High(Items) do
begin
Title := Items[I].Text;
if Title <> '' then
begin
For J := 0 to High(Options) do
begin
if (caseSensitive and (Pos(Options[J], Title) > 0)) or (not caseSensitive and (Pos(Lowercase(Options[J]), Lowercase(Title)) > 0)) then
begin
if useMouse then
begin
Mouse.Click(Items[I].Bounds, MOUSE_LEFT);
end else
begin
Keyboard.Send(ToStr(I));
end;
RSTypeArray(Items).Free;
Exit(True);
end;
end;
end;
end;
end;
{*
R_ClickToContinueIsOpen
~~~~~~~~~~~~~~~~~~~~~~
Returns true if 'Click to continue' is open.
Example:
if R_ClickToContinueIsOpen then
...
*}
Function R_ClickToContinueIsOpen(): Boolean;
begin
Result := (RSWidget.Get(R_CHATBOX_NPC_CLICK_TO_CONTINUE.Group, R_CHATBOX_NPC_CLICK_TO_CONTINUE.Child).ref <> nil)
or (RSWidget.Get(R_CHATBOX_PLAYER_CLICK_TO_CONTINUE.Group, R_CHATBOX_PLAYER_CLICK_TO_CONTINUE.Child).ref <> nil)
or (RSWidget.Get(R_INTERFACE_LEVEL_UP_CONTINUE.Group, R_INTERFACE_LEVEL_UP_CONTINUE.Child).ref <> nil)
or (RSWidget.Get(R_INTERFACE_CHAT_DIALOG_CONTINUE.Group, R_INTERFACE_CHAT_DIALOG_CONTINUE.Child).ref <> nil);
end;
{*
R_ClickToContinue
~~~~~~~~~~~~~~~~~~~~~~
Returns true if clicked 'Click to continue'.
Example:
if R_ClickToContinue then
...
*}
Function R_ClickToContinue(useMouse: Boolean = True): Boolean;
var
FoundWidget: RSWidget;
EachWidget : RWidget;
WidgetsToCheck : array of RWidget;
begin
WidgetsToCheck := [
R_CHATBOX_NPC_CLICK_TO_CONTINUE,
R_CHATBOX_PLAYER_CLICK_TO_CONTINUE,
R_INTERFACE_LEVEL_UP_CONTINUE,
R_INTERFACE_CHAT_DIALOG_CONTINUE,
R_INTERFACE_NEW_ACTIONS_CONTINUE
];
for EachWidget in WidgetsToCheck do
begin
FoundWidget := RSWidget.Get(EachWidget.Group, EachWidget.Child);
if FoundWidget.ref <> nil then
begin
if Result then
begin
Wait(216, Random(300, 626));
end;
if useMouse then
begin
Mouse.Click(FoundWidget.Bounds, MOUSE_LEFT);
end else
begin
Keyboard.PressKey(VK_SPACE);
end;
FoundWidget.Free;
Result := True;
end;
end;
end;