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

Commit a3bdd43

Browse files
ExplvExplv
authored andcommitted
Bug fixes and updating to use fixed paths
1 parent bfae6e0 commit a3bdd43

File tree

9 files changed

+175
-42
lines changed

9 files changed

+175
-42
lines changed

src/sections/BankSection.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import org.osbot.rs07.api.model.RS2Object;
88
import utils.Sleep;
99

10+
import java.util.Arrays;
11+
import java.util.List;
12+
1013
public final class BankSection extends TutorialSection {
1114

1215
private static final Area BANK_AREA = new Area(
@@ -35,6 +38,13 @@ public final class BankSection extends TutorialSection {
3538
}
3639
);
3740

41+
private static final List<Position> PATH_TO_BANK = Arrays.asList(
42+
new Position(3111, 3123, 0),
43+
new Position(3114, 3119, 0),
44+
new Position(3118, 3116, 0),
45+
new Position(3121, 3118, 0)
46+
);
47+
3848
public BankSection() {
3949
super("Financial Advisor");
4050
}
@@ -49,7 +59,9 @@ public final void onLoop() throws InterruptedException {
4959
switch (getProgress()) {
5060
case 510:
5161
if (!BANK_AREA.contains(myPosition())) {
52-
getWalking().webWalk(BANK_AREA);
62+
if (getWalking().walkPath(PATH_TO_BANK)) {
63+
getDoorHandler().handleNextObstacle(BANK_AREA);
64+
}
5365
} else if (getDialogues().isPendingOption()) {
5466
getDialogues().selectOption("Yes.");
5567
} else if (getObjects().closest("Bank booth").interact("Use")) {

src/sections/CookingSection.java

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

33
import org.osbot.rs07.api.map.Area;
44
import org.osbot.rs07.api.map.Position;
5+
import org.osbot.rs07.api.model.RS2Object;
56
import org.osbot.rs07.api.ui.Tab;
67
import utils.Sleep;
78

9+
import java.util.Arrays;
10+
import java.util.List;
11+
812
public class CookingSection extends TutorialSection {
913

1014
private static final Area COOK_BUILDING = new Area(3073, 3083, 3078, 3086);
15+
private static final List<Position> PATH_TO_COOK_BUILDING = Arrays.asList(
16+
new Position(3087, 3091, 0),
17+
new Position(3083, 3086, 0),
18+
new Position(3080, 3083, 0)
19+
);
1120

1221
public CookingSection() {
1322
super("Master Chef");
@@ -21,7 +30,11 @@ public final void onLoop() throws InterruptedException {
2130
}
2231
switch (getProgress()) {
2332
case 130:
24-
getWalking().webWalk(COOK_BUILDING);
33+
if (getWalking().walkPath(PATH_TO_COOK_BUILDING)) {
34+
if (getDoorHandler().handleNextObstacle(COOK_BUILDING)) {
35+
Sleep.sleepUntil(() -> getProgress() == 140, 5000);
36+
}
37+
}
2538
break;
2639
case 140:
2740
talkToInstructor();
@@ -36,7 +49,9 @@ public final void onLoop() throws InterruptedException {
3649
getTabs().open(Tab.MUSIC);
3750
break;
3851
case 180:
39-
getWalking().webWalk(new Position(3071, 3090, 0));
52+
if (getDoorHandler().handleNextObstacle(new Position(3071, 3090, 0))) {
53+
Sleep.sleepUntil(() -> getProgress() != 180, 5000);
54+
}
4055
break;
4156
}
4257
}

src/sections/MiningSection.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@
1010
import org.osbot.rs07.utility.Condition;
1111
import utils.Sleep;
1212

13+
import java.util.Arrays;
14+
import java.util.List;
1315
import java.util.Optional;
1416

1517
public final class MiningSection extends TutorialSection {
1618

1719
private static final Area SMITH_AREA = new Area(3076, 9497, 3082, 9504);
1820

21+
private static final List<Position> PATH_TO_SMITH_AREA = Arrays.asList(
22+
new Position(3080, 9518, 0),
23+
new Position(3080, 9511, 0),
24+
new Position(3080, 9505, 0)
25+
);
26+
27+
private static final List<Position> PATH_TO_GATE = Arrays.asList(
28+
new Position(3086, 9505, 0),
29+
new Position(3091, 9503, 0)
30+
);
31+
1932
public MiningSection() {
2033
super("Mining Instructor");
2134
}
@@ -26,11 +39,10 @@ public final void onLoop() throws InterruptedException {
2639
selectContinue();
2740
return;
2841
}
42+
2943
switch (getProgress()) {
3044
case 260:
31-
if (!isInstructorVisible()) {
32-
walkToInstructor();
33-
} else {
45+
if (getWalking().walkPath(PATH_TO_SMITH_AREA)) {
3446
talkToInstructor();
3547
}
3648
break;
@@ -63,32 +75,28 @@ public final void onLoop() throws InterruptedException {
6375
}
6476
break;
6577
case 350:
66-
getDaggerWidget().ifPresent(widget -> {
67-
if (widget.interact()) {
78+
Optional<RS2Widget> daggerWidgetOpt = getDaggerWidget();
79+
if (daggerWidgetOpt.isPresent()) {
80+
if (daggerWidgetOpt.get().interact()) {
6881
Sleep.sleepUntil(() -> getInventory().contains("Bronze dagger"), 6000);
6982
}
70-
});
83+
} else {
84+
smith();
85+
}
7186
break;
7287
case 360:
73-
getWalking().webWalk(new Position(3109, 9510, 0));
88+
if (getWalking().walkPath(PATH_TO_GATE)) {
89+
if (getDoorHandler().handleNextObstacle(new Position(3096, 9503, 0))) {
90+
Sleep.sleepUntil(() -> getProgress() != 360, 5000);
91+
}
92+
}
7493
break;
7594
}
7695
}
7796

78-
private void walkToInstructor() {
79-
WebWalkEvent webWalkEvent = new WebWalkEvent(SMITH_AREA);
80-
webWalkEvent.setBreakCondition(new Condition() {
81-
@Override
82-
public boolean evaluate() {
83-
return isInstructorVisible();
84-
}
85-
});
86-
execute(webWalkEvent);
87-
}
88-
8997
private void smith() {
9098
if (!SMITH_AREA.contains(myPosition())) {
91-
getWalking().walk(SMITH_AREA.getRandomPosition());
99+
getWalking().walk(SMITH_AREA);
92100
} else if (!"Bronze bar".equals(getInventory().getSelectedItemName())) {
93101
getInventory().getItem("Bronze bar").interact("Use");
94102
} else if (getObjects().closest("Anvil").interact("Use")) {
@@ -97,7 +105,7 @@ private void smith() {
97105
}
98106

99107
private Optional<RS2Widget> getDaggerWidget() {
100-
RS2Widget daggerTextWidget = getWidgets().getWidgetContainingText("Dagger");
108+
RS2Widget daggerTextWidget = getWidgets().getWidgetContainingText(312, "Dagger");
101109
if (daggerTextWidget != null) {
102110
return Optional.ofNullable(getWidgets().get(daggerTextWidget.getRootId(), daggerTextWidget.getSecondLevelId()));
103111
}

src/sections/PriestSection.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,24 @@
33
import org.osbot.rs07.api.map.Area;
44
import org.osbot.rs07.api.map.Position;
55
import org.osbot.rs07.api.ui.Tab;
6+
import utils.Sleep;
7+
8+
import java.util.Arrays;
9+
import java.util.List;
610

711
public final class PriestSection extends TutorialSection {
812

9-
private static final Area church = new Area(3120, 3103, 3128, 3110);
13+
private static final Area CHURCH_AREA = new Area(3120, 3103, 3128, 3110);
14+
15+
private static final List<Position> PATH_TO_CHURCH = Arrays.asList(
16+
new Position(3131, 3124, 0),
17+
new Position(3134, 3121, 0),
18+
new Position(3134, 3117, 0),
19+
new Position(3132, 3114, 0),
20+
new Position(3130, 3111, 0),
21+
new Position(3130, 3108, 0),
22+
new Position(3129, 3106, 0)
23+
);
1024

1125
public PriestSection() {
1226
super("Brother Brace");
@@ -21,8 +35,10 @@ public final void onLoop() throws InterruptedException {
2135

2236
switch (getProgress()) {
2337
case 550:
24-
if (!church.contains(myPosition())) {
25-
getWalking().webWalk(church);
38+
if (getInstructor() == null) {
39+
getWalking().walkPath(PATH_TO_CHURCH);
40+
} else if (!getMap().canReach(getInstructor())) {
41+
getDoorHandler().handleNextObstacle(CHURCH_AREA);
2642
} else {
2743
talkToInstructor();
2844
}
@@ -43,7 +59,9 @@ public final void onLoop() throws InterruptedException {
4359
talkToInstructor();
4460
break;
4561
case 610:
46-
getWalking().webWalk(new Position(3122, 3101, 0));
62+
if (getDoorHandler().handleNextObstacle(new Position(3122, 3101, 0))) {
63+
Sleep.sleepUntil(() -> getProgress() != 610, 5000);
64+
}
4765
break;
4866
}
4967
}

src/sections/QuestSection.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
package sections;
22

33
import org.osbot.rs07.api.map.Area;
4+
import org.osbot.rs07.api.map.Position;
45
import org.osbot.rs07.api.ui.Tab;
56
import utils.CachedWidget;
67
import utils.Sleep;
78

8-
import java.util.HashMap;
9-
import java.util.Map;
10-
import java.util.Random;
9+
import java.util.*;
1110
import java.util.function.Consumer;
1211

1312
public final class QuestSection extends TutorialSection {
1413

1514
private static final Area QUEST_BUILDING = new Area(3083, 3119, 3089, 3125);
1615

16+
private static final List<Position> PATH_TO_QUEST_BUILDING = Arrays.asList(
17+
new Position(3071, 3090, 0),
18+
new Position(3071, 3094, 0),
19+
new Position(3071, 3099, 0),
20+
new Position(3072, 3103, 0),
21+
new Position(3074, 3108, 0),
22+
new Position(3076, 3111, 0),
23+
new Position(3077, 3115, 0),
24+
new Position(3076, 3118, 0),
25+
new Position(3076, 3122, 0),
26+
new Position(3079, 3125, 0),
27+
new Position(3083, 3127, 0),
28+
new Position(3086, 3126, 0)
29+
);
30+
1731
public QuestSection() {
1832
super("Quest Guide");
1933
}
@@ -41,7 +55,11 @@ public final void onLoop() throws InterruptedException {
4155
getSettings().setRunning(true);
4256
break;
4357
case 210:
44-
getWalking().webWalk(QUEST_BUILDING);
58+
if (getWalking().walkPath(PATH_TO_QUEST_BUILDING)) {
59+
if (getDoorHandler().handleNextObstacle(QUEST_BUILDING)) {
60+
Sleep.sleepUntil(() -> getProgress() != 210, 5000);
61+
}
62+
}
4563
break;
4664
case 220:
4765
talkToInstructor();

src/sections/SurvivalSection.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
package sections;
22

3-
import org.osbot.rs07.api.map.Area;
3+
import org.osbot.rs07.api.filter.NameFilter;
4+
import org.osbot.rs07.api.filter.PositionFilter;
45
import org.osbot.rs07.api.map.Position;
56
import org.osbot.rs07.api.model.Entity;
7+
import org.osbot.rs07.api.model.GroundDecoration;
68
import org.osbot.rs07.api.model.NPC;
79
import org.osbot.rs07.api.model.RS2Object;
810
import org.osbot.rs07.api.ui.Tab;
11+
import org.osbot.rs07.event.WalkingEvent;
912
import utils.Sleep;
1013

14+
import java.util.Arrays;
15+
import java.util.Comparator;
16+
import java.util.List;
17+
import java.util.Optional;
18+
1119
public final class SurvivalSection extends TutorialSection {
1220

21+
private final List<Position> PATH_TO_GATE = Arrays.asList(
22+
new Position(3098, 3092, 0),
23+
new Position(3092, 3091, 0)
24+
);
25+
1326
public SurvivalSection() {
1427
super("Survival Expert");
1528
}
@@ -58,7 +71,14 @@ public final void onLoop() throws InterruptedException {
5871
}
5972
break;
6073
case 120:
61-
getWalking().webWalk(new Area(3073, 3083, 3078, 3086));
74+
RS2Object gate = getObjects().closest("Gate");
75+
if (gate != null) {
76+
if (gate.interact("Open")){
77+
Sleep.sleepUntil(() -> getProgress() == 130, 5000);
78+
}
79+
} else {
80+
getWalking().walkPath(PATH_TO_GATE);
81+
}
6282
break;
6383
}
6484
}
@@ -79,14 +99,40 @@ private void fish() {
7999
}
80100

81101
private void lightFire() {
82-
if (!"Tinderbox".equals(getInventory().getSelectedItemName())) {
102+
if (standingOnFire()) {
103+
getEmptyPosition().ifPresent(position -> {
104+
WalkingEvent walkingEvent = new WalkingEvent(position);
105+
walkingEvent.setMinDistanceThreshold(0);
106+
execute(walkingEvent);
107+
});
108+
} else if (!"Tinderbox".equals(getInventory().getSelectedItemName())) {
83109
getInventory().getItem("Tinderbox").interact("Use");
84110
} else if (getInventory().getItem("Logs").interact()) {
85111
Position playerPos = myPosition();
86112
Sleep.sleepUntil(() -> !myPosition().equals(playerPos), 10_000);
87113
}
88114
}
89115

116+
private boolean standingOnFire() {
117+
return getObjects().singleFilter(getObjects().getAll(), obj -> obj.getPosition().equals(myPosition()) && obj.getName().equals("Fire")) != null;
118+
}
119+
120+
private Optional<Position> getEmptyPosition() {
121+
List<Position> allPositions = myPlayer().getArea(10).getPositions();
122+
123+
// Remove any position with an object (except ground decorations, as they can be walked on)
124+
for(RS2Object object : getObjects().getAll()){
125+
if (object instanceof GroundDecoration) {
126+
continue;
127+
}
128+
allPositions.removeIf(position -> object.getPosition().equals(position));
129+
}
130+
131+
allPositions.removeIf(position -> !getMap().canReach(position));
132+
133+
return allPositions.stream().min(Comparator.comparingInt(p -> myPosition().distance(p)));
134+
}
135+
90136
private void cook() {
91137
if (!"Raw shrimps".equals(getInventory().getSelectedItemName())) {
92138
getInventory().getItem("Raw shrimps").interact("Use");

src/sections/TutorialSection.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package sections;
22

3+
import org.osbot.rs07.api.model.NPC;
34
import org.osbot.rs07.api.ui.RS2Widget;
45
import org.osbot.rs07.script.MethodProvider;
56
import utils.Sleep;
@@ -20,16 +21,16 @@ protected final int getProgress() {
2021
return getConfigs().get(281);
2122
}
2223

23-
protected boolean isInstructorVisible() {
24-
return getNpcs().closest(INSTRUCTOR_NAME) != null;
25-
}
26-
2724
protected final void talkToInstructor() {
28-
if (getNpcs().closest(INSTRUCTOR_NAME).interact("Talk-to")) {
25+
if (getInstructor().interact("Talk-to")) {
2926
Sleep.sleepUntil(this::pendingContinue, 5000);
3027
}
3128
}
3229

30+
protected NPC getInstructor() {
31+
return getNpcs().closest(INSTRUCTOR_NAME);
32+
}
33+
3334
protected boolean pendingContinue() {
3435
RS2Widget continueWidget = getContinueWidget();
3536
return continueWidget!= null && continueWidget.isVisible();

0 commit comments

Comments
 (0)