-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathWorlds.simba
261 lines (220 loc) · 6.75 KB
/
Worlds.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
(*
Worlds
=============
Methods that involve any interfaces to do with world switching
*)
(*
LOGOUT INTERFACE
================
Logout Tab functionality.
*)
{*
R_Logout
~~~~~~~~
Logs the player out of the game.
Example:
R_Logout;
*}
Function R_Logout: Boolean;
var
Widget: RSWidget;
begin
R_OpenGametab(GAMETAB_LOGOUT);
Wait(50, RandomRange(250, 692));
if (RSWidget.IsValid(R_LOGOUT_CONTAINER.Group, R_LOGOUT_CONTAINER.Child)) and (not R_WidgetIsHidden(R_LOGOUT_LOGOUT_BUTTON)) then
begin
Widget := RSWidget.Get(R_LOGOUT_LOGOUT_BUTTON.Group, R_LOGOUT_LOGOUT_BUTTON.Child);
if Widget.ref <> nil then
begin
Mouse.Click(Widget.Bounds, MOUSE_LEFT);
Result := True;
Widget.Free;
end;
end else if (RSWidget.IsValid(R_WORLD_SWITCHER_CONTAINER.Group, R_WORLD_SWITCHER_CONTAINER.Child)) and (not R_WidgetIsHidden(R_WORLD_SWITCHER_LOGOUT_BUTTON)) then
begin
Widget := RSWidget.Get(R_WORLD_SWITCHER_LOGOUT_BUTTON.Group, R_WORLD_SWITCHER_LOGOUT_BUTTON.Child);
if Widget.ref <> nil then
begin
Mouse.Click(Widget.Bounds, MOUSE_LEFT);
Result := True;
Widget.Free;
end;
end;
end;
{*
R_CloseWorldSwitcher
~~~~~~~~~~~~~~~~~~~~
Closes the world switcher and returns to the main logout tab.
Example:
R_CloseWorldSwitcher;
*}
Function R_CloseWorldSwitcher: Boolean;
var
Widget: RSWidget;
begin
R_OpenGametab(GAMETAB_LOGOUT);
Wait(50, RandomRange(250, 692));
if (RSWidget.IsValid(R_WORLD_SWITCHER_CONTAINER.Group, R_WORLD_SWITCHER_CONTAINER.Child)) and (not R_WidgetIsHidden(R_WORLD_SWITCHER_CLOSE)) then
begin
Widget := RSWidget.Get(R_WORLD_SWITCHER_CLOSE.Group, R_WORLD_SWITCHER_CLOSE.Child);
if Widget.ref <> nil then
begin
Mouse.Click(Widget.Bounds, MOUSE_LEFT);
Result := True;
Widget.Free;
end;
end
end;
{*
R_OpenWorldSwitcher
~~~~~~~~~~~~~~~~~~~
Opens the world switcher.
Example:
R_OpenWorldSwitcher;
*}
Function R_OpenWorldSwitcher: Boolean;
var
Widget: RSWidget;
begin
Result := not R_WidgetIsHidden(R_WORLD_SWITCHER_SCROLL_UP);
if Result then
Exit(True);
if R_WidgetIsHidden(R_LOGOUT_CONTAINER) then
begin
R_OpenGametab(GAMETAB_LOGOUT);
Wait(50, RandomRange(250, 692));
end;
if (not R_WaitUntilVisible(R_LOGOUT_CONTAINER, 2500)) or R_WidgetIsHidden(R_LOGOUT_WORLD_SWITCHER_BUTTON) then
Exit(False);
Widget := RSWidget.Get(R_LOGOUT_WORLD_SWITCHER_BUTTON.Group, R_LOGOUT_WORLD_SWITCHER_BUTTON.Child);
if Widget.ref <> nil then
begin
Mouse.Click(Widget.Bounds, MOUSE_LEFT);
Result := R_WaitUntilVisible(R_WORLD_SWITCHER_SCROLL_UP, 2500);
Widget.Free;
end;
end;
{*
R_WorldToBox
~~~~~~~~~~~~
Utility function that converts a given world to mainscreen coordinates.
Example:
R_WorldToBox(500);
*}
Function R_WorldToBox(World: Int32): TBox;
var
WorldWidget: RSWidget;
begin
WorldWidget := RSWidget.Get(R_WORLD_SWITCHER_LIST.Group, R_WORLD_SWITCHER_LIST.Child, World);
Result := WorldWidget.Bounds;
WorldWidget.Free;
end;
{*
R_ScrollToWorld
~~~~~~~~~~~~~~~
Scrolls to the proper world in the world switcher.
Example:
R_ScrollToWorld(500, RSScroll.SCROLLBAR);
*}
Function R_ScrollToWorld(World: Int32; ScrollType: RSScroll = RSScroll.SCROLLWHEEL): Boolean;
var
ScrollBar, ScrollArrow, WorldContainer: RSWidget;
WorldContainerBounds: TBox;
T: Timer;
Direction: Boolean;
P: TPoint;
begin
WorldContainer := RSWidget.Get(R_WORLD_SWITCHER_LIST_INTERFACE_CONTAINER_CHILD.Group, R_WORLD_SWITCHER_LIST_INTERFACE_CONTAINER_CHILD.Child);
if WorldContainer.ref = nil then
Exit(False);
//Adds a buffer to make sure that the world is completely clickable
WorldContainerBounds := [WorldContainer.Bounds.X1, WorldContainer.Bounds.Y1 + 15, WorldContainer.Bounds.X2, WorldContainer.Bounds.Y2 - 15];
WorldContainer.Free;
if WorldContainerBounds.Contains(R_WorldToBox(World)) then
Exit(True);
Direction := WorldContainerBounds.Middle.Y > R_WorldToBox(World).Middle.Y;
//Scroll the interface using the mouse-wheel
if ScrollType = RSScroll.SCROLLWHEEL then
begin
Mouse.Move(WorldContainerBounds);
T.Start;
while not WorldContainerBounds.Contains(R_WorldToBox(World)) do
begin
if T.ElapsedTime > 5000 then
Exit(False);
Mouse.Scroll(3, Direction);
end;
Exit(WorldContainerBounds.Contains(R_WorldToBox(World).Middle));
end;
//Scroll the interface using the scroll-bar
if ScrollType = RSScroll.SCROLLBAR then
begin
ScrollBar := RSWidget.Get(R_WORLD_SWITCHER_SCROLL_BAR.Group, R_WORLD_SWITCHER_SCROLL_BAR.Child, R_WORLD_SWITCHER_SCROLL_BAR.Index);
if ScrollBar.ref = nil then
Exit(False);
Mouse.Move(ScrollBar.Bounds);
Mouse.Hold(MOUSE_LEFT);
ScrollBar.Free;
T.Start;
while not WorldContainerBounds.Contains(R_WorldToBox(World)) do
begin
if T.ElapsedTime > 5000 then
begin
Mouse.Release(MOUSE_LEFT);
Exit(False);
end;
P := Mouse.Position;
if Direction then
Mouse.Move(P.X + RandomRange(-1, 1), P.Y - RandomRange(3, 7))
else
Mouse.Move(P.X + RandomRange(-1, 1), P.Y + RandomRange(3, 7));
end;
Mouse.Release(MOUSE_LEFT);
Exit(WorldContainerBounds.Contains(R_WorldToBox(World).Middle));
end;
//Scroll the interface using the arrows
if ScrollType = RSScroll.SCROLLARROWS then
begin
if Direction then
ScrollArrow := RSWidget.Get(R_WORLD_SWITCHER_SCROLL_UP.Group, R_WORLD_SWITCHER_SCROLL_UP.Child, R_WORLD_SWITCHER_SCROLL_UP.Index)
else
ScrollArrow := RSWidget.Get(R_WORLD_SWITCHER_SCROLL_DOWN.Group, R_WORLD_SWITCHER_SCROLL_DOWN.Child, R_WORLD_SWITCHER_SCROLL_DOWN.Index);
if ScrollArrow.ref = nil then
Exit(False);
Mouse.Move(ScrollArrow.Bounds);
Mouse.Hold(MOUSE_LEFT);
ScrollArrow.Free;
T.Start;
while not WorldContainerBounds.Contains(R_WorldToBox(World)) do
begin
if T.ElapsedTime > 20000 then
begin
Mouse.Release(MOUSE_LEFT);
Exit(False);
end;
end;
Mouse.Release(MOUSE_LEFT);
Exit(WorldContainerBounds.Contains(R_WorldToBox(World).Middle));
end;
end;
{*
R_SelectWorld
~~~~~~~~~~~~~
Clicks on the selected world if it is visible in the list.
Example:
R_SelectWorld(500);
*}
Function R_SelectWorld(World: Int32): Boolean;
var
Widget: RSWidget;
begin
if (not RSWidget.IsValid(R_WORLD_SWITCHER_LIST.Group, R_WORLD_SWITCHER_LIST.Child, World)) or R_WidgetIsHidden(R_WORLD_SWITCHER_LIST) then
Exit(False);
Widget := RSWidget.Get(R_WORLD_SWITCHER_LIST.Group, R_WORLD_SWITCHER_LIST.Child, World);
if (Widget.ref <> nil) and (RSWidget.Get(R_WORLD_SWITCHER_LIST_INTERFACE_CONTAINER_CHILD.Group, R_WORLD_SWITCHER_LIST_INTERFACE_CONTAINER_CHILD.Child).Bounds.Contains(Widget.Bounds)) then
begin
Mouse.Click(Widget.Bounds, MOUSE_LEFT);
Result := True;
Widget.Free;
end;
end;