Skip to content
This repository was archived by the owner on Feb 9, 2022. It is now read-only.

Commit d79cfd5

Browse files
author
Explv
committed
Update quests to use DialogueCompleter class
Fix quest bugs
1 parent 7318658 commit d79cfd5

File tree

7 files changed

+173
-273
lines changed

7 files changed

+173
-273
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.explv.explv_osbot_manager</groupId>
88
<artifactId>explvs_aio</artifactId>
9-
<version>v3.1.7</version>
9+
<version>v3.1.8</version>
1010
<repositories>
1111
<repository>
1212
<id>local-repo</id>

src/main/java/activities/quests/DialogueCompleter.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.osbot.rs07.api.map.Area;
44
import org.osbot.rs07.api.model.NPC;
5+
import org.osbot.rs07.event.WebWalkEvent;
6+
import org.osbot.rs07.utility.Condition;
57
import util.Executable;
68
import util.Sleep;
79

@@ -26,9 +28,17 @@ public DialogueCompleter(final String npcName, final String... dialogueOptions)
2628
public void run() throws InterruptedException {
2729
NPC npc = getNpcs().closest(npcName);
2830

29-
if (npc == null) {
31+
if (npc == null || !npc.isOnScreen() || !getMap().canReach(npc)) {
3032
if (area != null && !area.contains(myPosition())) {
31-
getWalking().webWalk(area);
33+
WebWalkEvent webWalkEvent = new WebWalkEvent(area);
34+
webWalkEvent.setBreakCondition(new Condition() {
35+
@Override
36+
public boolean evaluate() {
37+
NPC npc = getNpcs().closest(npcName);
38+
return npc != null && npc.isOnScreen() && getMap().canReach(npc);
39+
}
40+
});
41+
execute(webWalkEvent);
3242
return;
3343
} else {
3444
log(String.format("Could not find NPC with name '%s'", npcName));

src/main/java/activities/quests/RomeoAndJuliet.java

Lines changed: 57 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import activities.activity.Activity;
44
import activities.banking.DepositAllBanking;
5+
import org.osbot.rs07.api.filter.ActionFilter;
6+
import org.osbot.rs07.api.filter.NameFilter;
57
import org.osbot.rs07.api.map.Area;
68
import org.osbot.rs07.api.map.Position;
79
import org.osbot.rs07.api.model.NPC;
@@ -11,35 +13,50 @@
1113

1214
import java.util.Arrays;
1315
import java.util.List;
16+
import java.util.Random;
1417

1518
public class RomeoAndJuliet extends QuestActivity {
1619

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);
2225

2326
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)});
2427
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)});
2528

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,
2738
"Perhaps I could help to find her for you?",
2839
"Yes, ok, I'll let her know.",
2940
"Ok, thanks."
30-
};
41+
);
3142

32-
private static final String[] APOTHECARY_OPTIONS = {
43+
private final DialogueCompleter apothecaryDialogueCompleter = new DialogueCompleter(
44+
"Apothecary",
45+
APOTHECARY_AREA,
3346
"Talk about something else.",
3447
"Talk about Romeo & Juliet.",
3548
"Ok, thanks."
36-
};
49+
);
3750

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+
);
4360

4461
private final DepositAllBanking depositAllBanking = new DepositAllBanking(QUEST_ITEMS);
4562

@@ -50,6 +67,10 @@ public RomeoAndJuliet() {
5067
@Override
5168
public void onStart() {
5269
depositAllBanking.exchangeContext(getBot());
70+
romeoDialogueCompleter.exchangeContext(getBot());
71+
apothecaryDialogueCompleter.exchangeContext(getBot());
72+
lawrenceDialogueCompleter.exchangeContext(getBot());
73+
julietDialogueCompleter.exchangeContext(getBot());
5374
}
5475

5576
@Override
@@ -66,19 +87,17 @@ public void runActivity() throws InterruptedException {
6687

6788
switch (getProgress()) {
6889
case 0:
69-
talkToRomeo();
90+
case 20:
91+
romeoDialogueCompleter.run();
7092
break;
7193
case 10:
72-
talkToJuliet();
73-
break;
74-
case 20:
75-
talkToRomeo();
94+
julietDialogueCompleter.run();
7695
break;
7796
case 30:
78-
talkToLawrence();
97+
lawrenceDialogueCompleter.run();
7998
break;
8099
case 40:
81-
talkToApothecary();
100+
apothecaryDialogueCompleter.run();
82101
break;
83102
case 50:
84103
// Make sure we are not in the cut scene
@@ -97,7 +116,7 @@ public void runActivity() throws InterruptedException {
97116
getDialogues().clickContinue();
98117
}
99118
} else {
100-
talkToRomeo();
119+
romeoDialogueCompleter.run();
101120
}
102121
break;
103122
case 100:
@@ -111,84 +130,39 @@ public void runActivity() throws InterruptedException {
111130

112131
private void deliverCadavaPotion() throws InterruptedException {
113132
if (getInventory().contains("Cadava potion")) {
114-
talkToJuliet();
133+
julietDialogueCompleter.run();
115134
} 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) {
126137
getWalking().walkPath(APOTHECARY_PATH);
127138
} else {
128-
getWalking().webWalk(APOTHECARY);
139+
apothecaryDialogueCompleter.run();
129140
}
130141
} 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();
151143
}
152144
}
153145

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+
);
162152

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));
166153
if (objects.isEmpty()) {
167154
return;
168155
}
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-
}
176156

177-
}
157+
RS2Object object = objects.get(new Random().nextInt(objects.size()));
178158

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+
}
182162
} else {
183-
getDialogues().completeDialogue(options);
163+
getWalking().walkPath(RomeoAndJuliet.BERRIES_PATH);
184164
}
185-
}
186165

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-
}
192166
}
193167

194168
@Override

0 commit comments

Comments
 (0)