1
1
package activities .tutorial_island ;
2
2
3
+ import org .osbot .rs07 .api .Configs ;
3
4
import org .osbot .rs07 .api .ui .RS2Widget ;
4
5
import org .osbot .rs07 .api .ui .Tab ;
5
6
import org .osbot .rs07 .event .Event ;
13
14
14
15
import java .util .Arrays ;
15
16
import java .util .Collections ;
17
+ import java .util .Optional ;
16
18
import java .util .Random ;
17
19
import java .util .stream .Collectors ;
18
20
19
21
public final class RuneScapeGuideSection extends TutorialSection {
22
+ private enum UsernameCheckStatus {
23
+ NOT_AVAILABLE (0 ),
24
+ CHECKING (1 ),
25
+ AVAILABLE (2 );
20
26
27
+ int bitNum ;
21
28
22
- private final CachedWidget nameAcceptedWidget = new CachedWidget (w -> w .getMessage ().contains ("Great!" ));
29
+ UsernameCheckStatus (int bitNum ) {
30
+ this .bitNum = bitNum ;
31
+ }
32
+
33
+ static UsernameCheckStatus getUsernameCheckStatus (Configs configs ) {
34
+ int configVal = configs .get (1042 );
23
35
24
- private final CachedWidget nameLookupWidget = new CachedWidget (w -> w .getMessage ().contains ("Look up name" ));
25
- private final CachedWidget nameInputWidget = new CachedWidget (w -> w .getMessage ().contains ("What name would you like to check" ));
26
- private final CachedWidget nameSetWidget = new CachedWidget ("Set name" );
27
- private final CachedWidget nameScreenDetectionWidget = new CachedWidget ("Choose display name" );
36
+ for (UsernameCheckStatus checkStatus : values ()) {
37
+ if ((configVal & (1 << checkStatus .bitNum )) != 0 ) {
38
+ return checkStatus ;
39
+ }
40
+ }
28
41
42
+ return null ;
43
+ }
44
+ }
45
+
46
+ private final CachedWidget nameAcceptedWidget = new CachedWidget (w -> w .getMessage ().contains ("Great!" ));
47
+ private final CachedWidget lookupNameWidget = new CachedWidget (w -> w .getMessage ().contains ("Look up name" ));
48
+ private final CachedWidget inputNameWidget = new CachedWidget (w -> w .getMessage ().contains ("Please pick a unique display name" ));
49
+ private final CachedWidget setNameWidget = new CachedWidget ("Set name" );
50
+ private final CachedWidget chooseDisplayNameWidget = new CachedWidget ("Choose display name" );
51
+ private final CachedWidget suggestionsWidget = new CachedWidget ("one of our suggestions" );
29
52
private final CachedWidget creationScreenWidget = new CachedWidget ("Head" );
30
53
private final CachedWidget experienceWidget = new CachedWidget ("What's your experience with Old School Runescape?" );
54
+
31
55
private boolean isAudioDisabled ;
32
56
33
57
public RuneScapeGuideSection () {
@@ -45,13 +69,13 @@ public final void onLoop() throws InterruptedException {
45
69
case 0 :
46
70
case 1 :
47
71
case 2 :
48
- if (nameScreenDetectionWidget . get (getWidgets ()). isPresent ( )) {
72
+ if (chooseDisplayNameWidget . isVisible (getWidgets ())) {
49
73
setDisplayName ();
50
- } else if (isCreationScreenVisible ( )) {
74
+ } else if (creationScreenWidget . isVisible ( getWidgets () )) {
51
75
createRandomCharacter ();
52
- } else if (experienceWidget .get (getWidgets ()). isPresent ( )) {
76
+ } else if (experienceWidget .isVisible (getWidgets ())) {
53
77
if (getDialogues ().selectOption (random (1 , 3 ))) {
54
- Sleep .sleepUntil (() -> !experienceWidget .get (getWidgets ()). map ( widget -> ! widget . isVisible ()). orElse ( true ), 2000 , 600 );
78
+ Sleep .sleepUntil (() -> !experienceWidget .isVisible (getWidgets ()), 2000 , 600 );
55
79
}
56
80
} else {
57
81
talkToInstructor ();
@@ -79,24 +103,40 @@ public final void onLoop() throws InterruptedException {
79
103
}
80
104
}
81
105
82
- private void setDisplayName () {
83
- if (nameAcceptedWidget .get (getWidgets ()).isPresent ()) {
84
- nameSetWidget .get (getWidgets ()).ifPresent (rs2Widget -> {
85
- if (rs2Widget .interact ()) {
86
- Sleep .sleepUntil (() -> !nameScreenDetectionWidget .get (getWidgets ()).isPresent (), 8000 , 600 );
106
+ private void setDisplayName () throws InterruptedException {
107
+ UsernameCheckStatus checkStatus = UsernameCheckStatus .getUsernameCheckStatus (getConfigs ());
108
+
109
+ if (checkStatus == null ) {
110
+ log ("Couldn't determine username check status" );
111
+ getBot ().getScriptExecutor ().stop ();
112
+ return ;
113
+ }
114
+
115
+ switch (checkStatus ) {
116
+ case NOT_AVAILABLE :
117
+ if (suggestionsWidget .isVisible (getWidgets ())) {
118
+ Optional <RS2Widget > suggestionWidget = suggestionsWidget .getRelative (getWidgets (), 0 , random (2 , 5 ), 0 );
119
+ if (suggestionWidget .isPresent () && suggestionWidget .get ().interact ("Set name" )) {
120
+ Sleep .sleepUntil (() -> nameAcceptedWidget .get (getWidgets ()).isPresent (), 5000 );
121
+ }
122
+ } else if (inputNameWidget .isVisible (getWidgets ()) && getKeyboard ().typeString (generateRandomString (5 ), true )) {
123
+ Sleep .sleepUntil (() -> UsernameCheckStatus .getUsernameCheckStatus (getConfigs ()) == UsernameCheckStatus .CHECKING , 2000 , 100 );
124
+ } else if (lookupNameWidget .interact (getWidgets ())) {
125
+ Sleep .sleepUntil (() -> !inputNameWidget .isVisible (getWidgets ()), 8000 , 600 );
126
+ }
127
+ break ;
128
+ case CHECKING :
129
+ Sleep .sleepUntil (() -> UsernameCheckStatus .getUsernameCheckStatus (getConfigs ()) != UsernameCheckStatus .CHECKING , 2000 , 100 );
130
+ break ;
131
+ case AVAILABLE :
132
+ if (setNameWidget .interact (getWidgets ())) {
133
+ Sleep .sleepUntil (
134
+ () -> !chooseDisplayNameWidget .isVisible (getWidgets ()),
135
+ 8000 ,
136
+ 600
137
+ );
87
138
}
88
- });
89
- } else if (nameInputWidget .get (getWidgets ()).isPresent ()
90
- && nameInputWidget .get (getWidgets ()).get ().isVisible ()
91
- && getKeyboard ().typeString (generateRandomString (5 ), true )) {
92
-
93
- final int configValue = getConfigs ().get (1042 );
94
-
95
- Sleep .sleepUntil (() -> getConfigs ().get (1042 ) != configValue , 8000 , 600 );
96
- Sleep .sleepUntil (() -> getConfigs ().get (1042 ) == configValue || nameAcceptedWidget .get (getWidgets ()).isPresent (), 8000 , 600 );
97
- } else if (nameLookupWidget .get (getWidgets ()).isPresent ()
98
- && nameLookupWidget .get (getWidgets ()).get ().interact ()) {
99
- Sleep .sleepUntil (() -> nameInputWidget .get (getWidgets ()).isPresent () && nameInputWidget .get (getWidgets ()).get ().isVisible (), 8000 , 600 );
139
+ break ;
100
140
}
101
141
}
102
142
@@ -109,10 +149,6 @@ private String generateRandomString(int maxLength) {
109
149
.collect (Collectors .joining ());
110
150
}
111
151
112
- private boolean isCreationScreenVisible () {
113
- return creationScreenWidget .get (getWidgets ()).filter (RS2Widget ::isVisible ).isPresent ();
114
- }
115
-
116
152
private void createRandomCharacter () throws InterruptedException {
117
153
if (new Random ().nextInt (2 ) == 1 ) {
118
154
getWidgets ().getWidgetContainingText ("Female" ).interact ();
@@ -131,7 +167,7 @@ private void createRandomCharacter() throws InterruptedException {
131
167
}
132
168
133
169
if (getWidgets ().getWidgetContainingText ("Accept" ).interact ()) {
134
- Sleep .sleepUntil (() -> !isCreationScreenVisible ( ), 3000 , 600 );
170
+ Sleep .sleepUntil (() -> !creationScreenWidget . isVisible ( getWidgets () ), 3000 , 600 );
135
171
}
136
172
}
137
173
0 commit comments