4
4
import org .aio .util .ResourceMode ;
5
5
import org .aio .util .Sleep ;
6
6
import org .osbot .rs07 .api .map .Area ;
7
- import org .osbot .rs07 .api .map .Position ;
8
7
import org .osbot .rs07 .api .model .Entity ;
8
+ import org .osbot .rs07 .api .model .RS2Object ;
9
+ import org .osbot .rs07 .event .WalkingEvent ;
9
10
10
- import java .util .Arrays ;
11
11
import java .util .Comparator ;
12
12
import java .util .Optional ;
13
13
import java .util .stream .Stream ;
14
14
15
15
public class RuneEssMiningActivity extends MiningActivity {
16
16
17
- private final Area auburyHouse = new Area (
17
+ private static final Area AUBURY_HOUSE = new Area (
18
18
new int [][]{
19
19
{ 3250 , 3403 },
20
20
{ 3250 , 3401 },
@@ -28,39 +28,26 @@ public class RuneEssMiningActivity extends MiningActivity {
28
28
}
29
29
);
30
30
31
- private final int [][] gridPortalCoordinates = {
32
- { 37 , 29 },
33
- { 33 , 76 },
34
- { 72 , 77 },
35
- { 74 , 33 }
36
- };
37
-
38
31
public RuneEssMiningActivity (final ResourceMode resourceMode ) {
39
32
super (null , Rock .RUNE_ESSENCE , resourceMode );
40
33
}
41
34
42
35
@ Override
43
36
public void onStart () throws InterruptedException {
44
37
super .onStart ();
45
-
46
38
miningNode = new MiningNode ();
47
39
miningNode .exchangeContext (getBot ());
48
40
}
49
41
50
42
@ Override
51
43
public void runActivity () throws InterruptedException {
52
- if ((shouldBank () || pickaxeBanking .toolUpgradeAvailable ()) && getObjects (). closest ( "Rune Essence" ) != null ) {
44
+ if ((shouldBank () || pickaxeBanking .toolUpgradeAvailable ()) && inEssenceMine () ) {
53
45
leaveEssenceMine ();
54
46
} else {
55
47
super .runActivity ();
56
48
}
57
49
}
58
50
59
- @ Override
60
- public boolean canExit () {
61
- return getObjects ().closest ("Rune Essence" ) == null ;
62
- }
63
-
64
51
@ Override
65
52
protected boolean inventoryContainsNonMiningItem () {
66
53
return getInventory ().contains (item -> {
@@ -73,43 +60,68 @@ protected boolean inventoryContainsNonMiningItem() {
73
60
});
74
61
}
75
62
63
+ private boolean inEssenceMine () {
64
+ return getClosestRuneEssence () != null ;
65
+ }
66
+
67
+ private RS2Object getClosestRuneEssence () {
68
+ return getObjects ().closest ("Rune Essence" );
69
+ }
70
+
76
71
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 );
91
82
}
92
83
}
93
84
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
+
94
95
private class MiningNode extends Executable {
96
+
95
97
@ Override
96
98
public void run () throws InterruptedException {
97
99
if (myPlayer ().isAnimating ()) {
98
100
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" )) {
101
108
Sleep .sleepUntil (() -> myPlayer ().isAnimating (), 10_000 );
102
109
}
103
- } else if (auburyHouse .contains (myPosition ())) {
110
+ } else if (AUBURY_HOUSE .contains (myPosition ())) {
104
111
if (getNpcs ().closest ("Aubury" ).interact ("Teleport" )) {
105
112
Sleep .sleepUntil (() -> getNpcs ().closest ("Aubury" ) == null , 10_000 );
106
113
}
107
114
} else {
108
- getWalking ().webWalk (auburyHouse );
115
+ getWalking ().webWalk (AUBURY_HOUSE );
109
116
}
110
117
}
111
118
}
112
119
120
+ @ Override
121
+ public boolean canExit () {
122
+ return !inEssenceMine ();
123
+ }
124
+
113
125
@ Override
114
126
public RuneEssMiningActivity copy () {
115
127
return new RuneEssMiningActivity (resourceMode );
0 commit comments