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

Commit 3b448c7

Browse files
ExplvExplv
authored andcommitted
- Reliability improvements to rune essence mining
1 parent cf7cba5 commit 3b448c7

File tree

2 files changed

+48
-36
lines changed

2 files changed

+48
-36
lines changed

AIO/src/org/aio/activities/skills/mining/RuneEssMiningActivity.java

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
import org.aio.util.ResourceMode;
55
import org.aio.util.Sleep;
66
import org.osbot.rs07.api.map.Area;
7-
import org.osbot.rs07.api.map.Position;
87
import org.osbot.rs07.api.model.Entity;
8+
import org.osbot.rs07.api.model.RS2Object;
9+
import org.osbot.rs07.event.WalkingEvent;
910

10-
import java.util.Arrays;
1111
import java.util.Comparator;
1212
import java.util.Optional;
1313
import java.util.stream.Stream;
1414

1515
public class RuneEssMiningActivity extends MiningActivity {
1616

17-
private final Area auburyHouse = new Area(
17+
private static final Area AUBURY_HOUSE = new Area(
1818
new int[][]{
1919
{ 3250, 3403 },
2020
{ 3250, 3401 },
@@ -28,39 +28,26 @@ public class RuneEssMiningActivity extends MiningActivity {
2828
}
2929
);
3030

31-
private final int[][] gridPortalCoordinates = {
32-
{ 37, 29 },
33-
{ 33, 76 },
34-
{ 72, 77 },
35-
{ 74, 33 }
36-
};
37-
3831
public RuneEssMiningActivity(final ResourceMode resourceMode) {
3932
super(null, Rock.RUNE_ESSENCE, resourceMode);
4033
}
4134

4235
@Override
4336
public void onStart() throws InterruptedException {
4437
super.onStart();
45-
4638
miningNode = new MiningNode();
4739
miningNode.exchangeContext(getBot());
4840
}
4941

5042
@Override
5143
public void runActivity() throws InterruptedException {
52-
if ((shouldBank() || pickaxeBanking.toolUpgradeAvailable()) && getObjects().closest("Rune Essence") != null) {
44+
if ((shouldBank() || pickaxeBanking.toolUpgradeAvailable()) && inEssenceMine()) {
5345
leaveEssenceMine();
5446
} else {
5547
super.runActivity();
5648
}
5749
}
5850

59-
@Override
60-
public boolean canExit() {
61-
return getObjects().closest("Rune Essence") == null;
62-
}
63-
6451
@Override
6552
protected boolean inventoryContainsNonMiningItem() {
6653
return getInventory().contains(item -> {
@@ -73,43 +60,68 @@ protected boolean inventoryContainsNonMiningItem() {
7360
});
7461
}
7562

63+
private boolean inEssenceMine() {
64+
return getClosestRuneEssence() != null;
65+
}
66+
67+
private RS2Object getClosestRuneEssence() {
68+
return getObjects().closest("Rune Essence");
69+
}
70+
7671
private void leaveEssenceMine() {
77-
Optional<Entity> portal = Stream.concat(getObjects().getAll().stream(), getNpcs().getAll().stream())
78-
.filter(entity -> entity.getName().contains("Portal"))
79-
.min(Comparator.comparingInt(p -> myPosition().distance(p.getPosition())));
80-
if (portal.isPresent()) {
81-
if (portal.get().interact("Use", "Exit")) {
82-
Sleep.sleepUntil(() -> auburyHouse.contains(myPosition()), 10_000);
83-
}
84-
} else {
85-
Position[] portalPositions = new Position[4];
86-
for (int i = 0; i < gridPortalCoordinates.length; i++) {
87-
portalPositions[i] = new Position(getMap().getBaseX() + gridPortalCoordinates[i][0], getMap().getBaseY() + gridPortalCoordinates[i][1], myPlayer().getZ());
88-
}
89-
Position closestPosition = Arrays.stream(portalPositions).min(Comparator.comparingInt(p -> myPosition().distance(p))).get();
90-
getWalking().walk(closestPosition);
72+
Optional<Entity> portal = getClosestPortal();
73+
74+
if (!portal.isPresent()) {
75+
getWalking().walk(getClosestRuneEssence());
76+
} else if (myPosition().distance(portal.get().getPosition()) > 3) {
77+
WalkingEvent walkingEvent = new WalkingEvent(portal.get());
78+
walkingEvent.setMinDistanceThreshold(2);
79+
execute(walkingEvent);
80+
} else if (portal.get().interact("Use", "Exit")) {
81+
Sleep.sleepUntil(() -> AUBURY_HOUSE.contains(myPosition()), 10_000);
9182
}
9283
}
9384

85+
private Optional<Entity> getClosestPortal() {
86+
// For some reason portals can be both Objects and NPCs
87+
return Stream.concat(
88+
getObjects().getAll().stream(),
89+
getNpcs().getAll().stream()
90+
)
91+
.filter(entity -> entity.getName().contains("Portal"))
92+
.min(Comparator.comparingInt(p -> myPosition().distance(p.getPosition())));
93+
}
94+
9495
private class MiningNode extends Executable {
96+
9597
@Override
9698
public void run() throws InterruptedException {
9799
if (myPlayer().isAnimating()) {
98100
return;
99-
} else if (getObjects().closest("Rune Essence") != null) {
100-
if (getObjects().closest("Rune Essence").interact("Mine")) {
101+
}
102+
103+
if (inEssenceMine()) {
104+
RS2Object essence = getClosestRuneEssence();
105+
if (myPosition().distance(essence) > 5) {
106+
getWalking().walk(essence);
107+
} else if (essence.interact("Mine")) {
101108
Sleep.sleepUntil(() -> myPlayer().isAnimating(), 10_000);
102109
}
103-
} else if (auburyHouse.contains(myPosition())) {
110+
} else if (AUBURY_HOUSE.contains(myPosition())) {
104111
if (getNpcs().closest("Aubury").interact("Teleport")) {
105112
Sleep.sleepUntil(() -> getNpcs().closest("Aubury") == null, 10_000);
106113
}
107114
} else {
108-
getWalking().webWalk(auburyHouse);
115+
getWalking().webWalk(AUBURY_HOUSE);
109116
}
110117
}
111118
}
112119

120+
@Override
121+
public boolean canExit() {
122+
return !inEssenceMine();
123+
}
124+
113125
@Override
114126
public RuneEssMiningActivity copy() {
115127
return new RuneEssMiningActivity(resourceMode);

AIO/src/org/aio/script/AIO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
@ScriptManifest(author = "Explv", name = "Explv's AIO " + AIO.VERSION, info = "AIO", version = 0, logo = "http://i.imgur.com/58Zz0fb.png")
3232
public class AIO extends Script {
3333

34-
static final String VERSION = "v2.1.3";
34+
static final String VERSION = "v2.1.4";
3535

3636
private Gui gui;
3737
private Paint paint;

0 commit comments

Comments
 (0)