2
2
3
3
import activities .activity .Activity ;
4
4
import activities .banking .DepositAllBanking ;
5
+ import org .osbot .rs07 .api .filter .ActionFilter ;
6
+ import org .osbot .rs07 .api .filter .NameFilter ;
5
7
import org .osbot .rs07 .api .map .Area ;
6
8
import org .osbot .rs07 .api .map .Position ;
7
9
import org .osbot .rs07 .api .model .NPC ;
11
13
12
14
import java .util .Arrays ;
13
15
import java .util .List ;
16
+ import java .util .Random ;
14
17
15
18
public class RomeoAndJuliet extends QuestActivity {
16
19
17
- private static final Area ROMEO = new Area (3205 , 3431 , 3220 , 3415 );
18
- private static final Area JULIET = new Area (new Position (3155 , 3425 , 1 ), new Position (3161 , 3426 , 1 ));
19
- private static final Area LAWRENCE = new Area (3252 , 3486 , 3259 , 3472 );
20
- private static final Area APOTHECARY = new Area (3197 , 3406 , 3192 , 3402 );
21
- private static final Area BERRIES = new Area (3263 , 3365 , 3278 , 3375 );
20
+ private static final Area ROMEO_AREA = new Area (3205 , 3431 , 3220 , 3415 );
21
+ private static final Area JULIET_AREA = new Area (new Position (3155 , 3425 , 1 ), new Position (3161 , 3426 , 1 ));
22
+ private static final Area LAWRENCE_AREA = new Area (3252 , 3486 , 3259 , 3472 );
23
+ private static final Area APOTHECARY_AREA = new Area (3197 , 3406 , 3192 , 3402 );
24
+ private static final Area BERRIES_AREA = new Area (3263 , 3365 , 3278 , 3375 );
22
25
23
26
private static final List <Position > BERRIES_PATH = Arrays .asList (new Position []{new Position (3193 , 3403 , 0 ), new Position (3193 , 3403 , 0 ), new Position (3191 , 3404 , 0 ), new Position (3191 , 3407 , 0 ), new Position (3194 , 3407 , 0 ), new Position (3197 , 3407 , 0 ), new Position (3200 , 3407 , 0 ), new Position (3200 , 3407 , 0 ), new Position (3203 , 3407 , 0 ), new Position (3206 , 3410 , 0 ), new Position (3209 , 3410 , 0 ), new Position (3210 , 3413 , 0 ), new Position (3210 , 3413 , 0 ), new Position (3210 , 3416 , 0 ), new Position (3211 , 3419 , 0 ), new Position (3212 , 3420 , 0 ), new Position (3212 , 3420 , 0 ), new Position (3215 , 3423 , 0 ), new Position (3218 , 3426 , 0 ), new Position (3221 , 3427 , 0 ), new Position (3224 , 3427 , 0 ), new Position (3227 , 3427 , 0 ), new Position (3230 , 3428 , 0 ), new Position (3230 , 3428 , 0 ), new Position (3233 , 3428 , 0 ), new Position (3236 , 3428 , 0 ), new Position (3239 , 3428 , 0 ), new Position (3242 , 3428 , 0 ), new Position (3245 , 3428 , 0 ), new Position (3248 , 3428 , 0 ), new Position (3251 , 3428 , 0 ), new Position (3254 , 3428 , 0 ), new Position (3257 , 3428 , 0 ), new Position (3260 , 3428 , 0 ), new Position (3263 , 3428 , 0 ), new Position (3266 , 3428 , 0 ), new Position (3269 , 3428 , 0 ), new Position (3272 , 3428 , 0 ), new Position (3275 , 3426 , 0 ), new Position (3275 , 3426 , 0 ), new Position (3277 , 3423 , 0 ), new Position (3278 , 3420 , 0 ), new Position (3280 , 3418 , 0 ), new Position (3281 , 3415 , 0 ), new Position (3284 , 3413 , 0 ), new Position (3286 , 3410 , 0 ), new Position (3288 , 3407 , 0 ), new Position (3289 , 3404 , 0 ), new Position (3290 , 3401 , 0 ), new Position (3290 , 3398 , 0 ), new Position (3290 , 3398 , 0 ), new Position (3290 , 3395 , 0 ), new Position (3290 , 3392 , 0 ), new Position (3290 , 3389 , 0 ), new Position (3290 , 3386 , 0 ), new Position (3290 , 3383 , 0 ), new Position (3290 , 3380 , 0 ), new Position (3290 , 3377 , 0 ), new Position (3287 , 3375 , 0 ), new Position (3284 , 3375 , 0 ), new Position (3281 , 3372 , 0 ), new Position (3281 , 3372 , 0 ), new Position (3278 , 3370 , 0 ), new Position (3275 , 3369 , 0 ), new Position (3275 , 3369 , 0 ), new Position (3272 , 3369 , 0 )});
24
27
private static final List <Position > APOTHECARY_PATH = Arrays .asList (new Position []{new Position (3256 , 3371 , 0 ), new Position (3256 , 3371 , 0 ), new Position (3260 , 3371 , 0 ), new Position (3264 , 3371 , 0 ), new Position (3268 , 3371 , 0 ), new Position (3272 , 3374 , 0 ), new Position (3276 , 3375 , 0 ), new Position (3280 , 3375 , 0 ), new Position (3284 , 3375 , 0 ), new Position (3288 , 3375 , 0 ), new Position (3288 , 3375 , 0 ), new Position (3290 , 3379 , 0 ), new Position (3290 , 3383 , 0 ), new Position (3290 , 3387 , 0 ), new Position (3290 , 3391 , 0 ), new Position (3290 , 3395 , 0 ), new Position (3290 , 3399 , 0 ), new Position (3290 , 3403 , 0 ), new Position (3288 , 3407 , 0 ), new Position (3288 , 3407 , 0 ), new Position (3286 , 3411 , 0 ), new Position (3282 , 3414 , 0 ), new Position (3281 , 3418 , 0 ), new Position (3279 , 3421 , 0 ), new Position (3276 , 3424 , 0 ), new Position (3276 , 3424 , 0 ), new Position (3272 , 3426 , 0 ), new Position (3268 , 3426 , 0 ), new Position (3264 , 3426 , 0 ), new Position (3260 , 3427 , 0 ), new Position (3256 , 3428 , 0 ), new Position (3252 , 3428 , 0 ), new Position (3248 , 3428 , 0 ), new Position (3244 , 3428 , 0 ), new Position (3240 , 3428 , 0 ), new Position (3236 , 3428 , 0 ), new Position (3232 , 3428 , 0 ), new Position (3228 , 3428 , 0 ), new Position (3224 , 3428 , 0 ), new Position (3220 , 3428 , 0 ), new Position (3216 , 3424 , 0 ), new Position (3216 , 3424 , 0 ), new Position (3212 , 3423 , 0 ), new Position (3208 , 3421 , 0 ), new Position (3204 , 3420 , 0 ), new Position (3200 , 3418 , 0 ), new Position (3200 , 3418 , 0 ), new Position (3200 , 3414 , 0 ), new Position (3198 , 3410 , 0 ), new Position (3198 , 3410 , 0 ), new Position (3195 , 3409 , 0 ), new Position (3191 , 3407 , 0 ), new Position (3191 , 3403 , 0 ), new Position (3193 , 3403 , 0 )});
25
28
26
- private static final String [] ROMEO_OPTIONS = {
29
+ private static final String [] QUEST_ITEMS = {
30
+ "Cadava potion" ,
31
+ "Cadava berries" ,
32
+ "Message"
33
+ };
34
+
35
+ private final DialogueCompleter romeoDialogueCompleter = new DialogueCompleter (
36
+ "Romeo" ,
37
+ ROMEO_AREA ,
27
38
"Perhaps I could help to find her for you?" ,
28
39
"Yes, ok, I'll let her know." ,
29
40
"Ok, thanks."
30
- } ;
41
+ ) ;
31
42
32
- private static final String [] APOTHECARY_OPTIONS = {
43
+ private final DialogueCompleter apothecaryDialogueCompleter = new DialogueCompleter (
44
+ "Apothecary" ,
45
+ APOTHECARY_AREA ,
33
46
"Talk about something else." ,
34
47
"Talk about Romeo & Juliet." ,
35
48
"Ok, thanks."
36
- } ;
49
+ ) ;
37
50
38
- private static final String [] QUEST_ITEMS = {
39
- "Cadava potion" ,
40
- "Cadava berries" ,
41
- "Message"
42
- };
51
+ private final DialogueCompleter lawrenceDialogueCompleter = new DialogueCompleter (
52
+ "Father Lawrence" ,
53
+ LAWRENCE_AREA
54
+ );
55
+
56
+ private final DialogueCompleter julietDialogueCompleter = new DialogueCompleter (
57
+ "Juliet" ,
58
+ JULIET_AREA
59
+ );
43
60
44
61
private final DepositAllBanking depositAllBanking = new DepositAllBanking (QUEST_ITEMS );
45
62
@@ -50,6 +67,10 @@ public RomeoAndJuliet() {
50
67
@ Override
51
68
public void onStart () {
52
69
depositAllBanking .exchangeContext (getBot ());
70
+ romeoDialogueCompleter .exchangeContext (getBot ());
71
+ apothecaryDialogueCompleter .exchangeContext (getBot ());
72
+ lawrenceDialogueCompleter .exchangeContext (getBot ());
73
+ julietDialogueCompleter .exchangeContext (getBot ());
53
74
}
54
75
55
76
@ Override
@@ -66,19 +87,17 @@ public void runActivity() throws InterruptedException {
66
87
67
88
switch (getProgress ()) {
68
89
case 0 :
69
- talkToRomeo ();
90
+ case 20 :
91
+ romeoDialogueCompleter .run ();
70
92
break ;
71
93
case 10 :
72
- talkToJuliet ();
73
- break ;
74
- case 20 :
75
- talkToRomeo ();
94
+ julietDialogueCompleter .run ();
76
95
break ;
77
96
case 30 :
78
- talkToLawrence ();
97
+ lawrenceDialogueCompleter . run ();
79
98
break ;
80
99
case 40 :
81
- talkToApothecary ();
100
+ apothecaryDialogueCompleter . run ();
82
101
break ;
83
102
case 50 :
84
103
// Make sure we are not in the cut scene
@@ -97,7 +116,7 @@ public void runActivity() throws InterruptedException {
97
116
getDialogues ().clickContinue ();
98
117
}
99
118
} else {
100
- talkToRomeo ();
119
+ romeoDialogueCompleter . run ();
101
120
}
102
121
break ;
103
122
case 100 :
@@ -111,84 +130,39 @@ public void runActivity() throws InterruptedException {
111
130
112
131
private void deliverCadavaPotion () throws InterruptedException {
113
132
if (getInventory ().contains ("Cadava potion" )) {
114
- talkToJuliet ();
133
+ julietDialogueCompleter . run ();
115
134
} else if (getInventory ().contains ("Cadava berries" )) {
116
- talkToApothecary ();
117
- } else {
118
- getItemFromRandomObject (BERRIES , BERRIES_PATH , "Cadava berries" , "Cadava bush" , "Pick-from" );
119
- }
120
- }
121
-
122
- private void talkToApothecary () throws InterruptedException {
123
- NPC ApothecaryNPC = getNpcs ().closest ("Apothecary" );
124
- if (ApothecaryNPC == null ) {
125
- if (getInventory ().contains ("Cadava berries" )) {
135
+ NPC ApothecaryNPC = getNpcs ().closest ("Apothecary" );
136
+ if (ApothecaryNPC == null ) {
126
137
getWalking ().walkPath (APOTHECARY_PATH );
127
138
} else {
128
- getWalking (). webWalk ( APOTHECARY );
139
+ apothecaryDialogueCompleter . run ( );
129
140
}
130
141
} else {
131
- completeDialog ("Apothecary" , APOTHECARY_OPTIONS );
132
- }
133
-
134
- }
135
-
136
- private void talkToLawrence () throws InterruptedException {
137
- NPC LawrenceNPC = getNpcs ().closest ("Father Lawrence" );
138
- if (LawrenceNPC == null ) {
139
- getWalking ().webWalk (LAWRENCE );
140
- } else {
141
- completeDialog ("Father Lawrence" );
142
- }
143
- }
144
-
145
- private void talkToRomeo () throws InterruptedException {
146
- NPC RomeoNPC = getNpcs ().closest ("Romeo" );
147
- if (RomeoNPC == null ) {
148
- getWalking ().webWalk (ROMEO );
149
- } else {
150
- completeDialog ("Romeo" , ROMEO_OPTIONS );
142
+ pickRandomCadavaBerries ();
151
143
}
152
144
}
153
145
154
- private void talkToJuliet () throws InterruptedException {
155
- NPC JulietNPC = getNpcs ().closest ("Juliet" );
156
- if (JulietNPC == null ) {
157
- getWalking ().webWalk (JULIET );
158
- } else {
159
- completeDialog ("Juliet" );
160
- }
161
- }
146
+ private void pickRandomCadavaBerries () throws InterruptedException {
147
+ if (RomeoAndJuliet .BERRIES_AREA .contains (myPlayer ())) {
148
+ List <RS2Object > objects = getObjects ().filter (
149
+ new NameFilter <>("Cadava bush" ),
150
+ new ActionFilter <>("Pick-from" )
151
+ );
162
152
163
- private void getItemFromRandomObject (Area place , List <Position > path , String itemName , String objectName , String interaction ) throws InterruptedException {
164
- if (place .contains (myPlayer ())) {
165
- List <RS2Object > objects = getObjects ().filter (o -> o .getName ().equals (objectName ) && o .hasAction (interaction ));
166
153
if (objects .isEmpty ()) {
167
154
return ;
168
155
}
169
- RS2Object object = objects .get (random (0 , objects .size () - 1 ));
170
- if (object != null && object .interact (interaction )) {
171
- Sleep .sleepUntil (() -> getInventory ().contains (itemName ), 15000 );
172
- }
173
- } else {
174
- getWalking ().walkPath (path );
175
- }
176
156
177
- }
157
+ RS2Object object = objects . get ( new Random (). nextInt ( objects . size ()));
178
158
179
- private void completeDialog ( String npcName , String ... options ) throws InterruptedException {
180
- if (! getDialogues (). inDialogue ()) {
181
- talkTo ( npcName );
159
+ if ( object != null && object . interact ( "Pick-from" )) {
160
+ Sleep . sleepUntil (() -> getInventory (). contains ( "Cadava berries" ), 15000 );
161
+ }
182
162
} else {
183
- getDialogues ().completeDialogue ( options );
163
+ getWalking ().walkPath ( RomeoAndJuliet . BERRIES_PATH );
184
164
}
185
- }
186
165
187
- private void talkTo (String npcName ) {
188
- NPC npc = getNpcs ().closest (npcName );
189
- if (npc != null && npc .interact ("Talk-to" )) {
190
- Sleep .sleepUntil (() -> getDialogues ().inDialogue (), 5000 );
191
- }
192
166
}
193
167
194
168
@ Override
0 commit comments