-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMLM2.java
More file actions
232 lines (198 loc) · 9.13 KB
/
Copy pathMLM2.java
File metadata and controls
232 lines (198 loc) · 9.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import org.rspeer.runetek.adapter.component.Item;
import org.rspeer.runetek.adapter.scene.Player;
import org.rspeer.runetek.adapter.scene.SceneObject;
import org.rspeer.runetek.api.commons.Time;
import org.rspeer.runetek.api.commons.math.Random;
import org.rspeer.runetek.api.component.Bank;
import org.rspeer.runetek.api.component.DepositBox;
import org.rspeer.runetek.api.component.tab.Inventory;
import org.rspeer.runetek.api.movement.Movement;
import org.rspeer.runetek.api.movement.position.Area;
import org.rspeer.runetek.api.movement.position.Position;
import org.rspeer.runetek.api.scene.Players;
import org.rspeer.runetek.api.scene.SceneObjects;
import org.rspeer.script.Script;
import org.rspeer.script.ScriptMeta;
import org.rspeer.ui.Log;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.io.File;
@ScriptMeta(developer = "Sri", name = "Motherlode2", desc = "Mining")
public class MLM2 extends Script {
private String state = "start";
// private String state = "depositToBank";
private Area firstFloorLadder = Area.rectangular(new Position(3756, 5671), new Position(3753, 5673));
private Area secondFloorLadder = Area.rectangular(new Position(3753, 5677), new Position(3757, 5674));
private Area bankArea = Area.rectangular(new Position(3760, 5669), new Position(3758, 5665));
private Area oreVeinArea = Area.rectangular(new Position(3748, 5676), new Position(3762, 5684));
private Position secondFloorPosition = new Position(3755, 5675);
private Position firstFloorPosition = new Position(3755, 5672);
private Position rockfallOne = new Position(3757, 5677);
private Position rockfallTwo = new Position(3748, 5684);
private int lowDelta = 80;
private int highDelta = 170;
private int depositCount = 0;
public int getRand(int low, int high) {
int highRand = org.rspeer.runetek.api.commons.math.Random.high(low, high);
int lowRand = org.rspeer.runetek.api.commons.math.Random.low(low, high);
int rand;
if (org.rspeer.runetek.api.commons.math.Random.nextInt(0, 100) < 50) {
rand = lowRand;
}
else {
rand = highRand;
}
return rand;
}
public void randomWait(int low, int high) {
low = low + lowDelta;
high = high + highDelta;
int sleepTime = getRand(low, high);
Time.sleep(sleepTime);
}
public void sound() {
try
{
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(new File("C:\\Notification.wav")));
clip.start();
}
catch (Exception exc)
{
exc.printStackTrace(System.out);
}
}
@Override
public int loop() {
//Mine rockfall if we are within 1 block of it
if (!Players.getLocal().isAnimating()) {
SceneObject rockfall = SceneObjects.getNearest("Rockfall");
if (rockfall != null && rockfall.getPosition().distance(Players.getLocal().getPosition()) == 1) {
rockfall.interact("Mine");
Time.sleepUntil(() -> !Players.getLocal().isAnimating(), getRand(5000, 10000));
Time.sleep(getRand(500, 1100));
}
}
if (state.equals("start")) {
//Walk to ladder if not moving
if (!Players.getLocal().isMoving() && Players.getLocal().getTarget() == null) {
Movement.walkTo(Random.nextElement(firstFloorLadder.getTiles()));
randomWait(400, 600);
}
//If ladder is within 5, 7 tiles, click it
SceneObject ladder = SceneObjects.getNearest("Ladder");
int dist = Random.nextInt(5, 7);
if (ladder != null && ladder.getPosition().distance(Players.getLocal().getPosition()) < dist) {
ladder.interact("Climb");
Time.sleepUntil(() -> secondFloorPosition.distance(Players.getLocal().getPosition()) == 0, getRand(7000, 15000));
randomWait(450, 850);
}
//If on second floor, change state
if (secondFloorPosition.distance(Players.getLocal().getPosition()) == 0) {
state = "mining";
}
}
if (state.equals("mining")) {
Item gem = Inventory.getFirst(g -> g.getName().equals("Uncut sapphire") || g.getName().equals("Uncut emerald") || g.getName().equals("Uncut ruby") || g.getName().equals("Uncut diamond"));
if (gem != null) {
gem.interact("Drop");
randomWait(800, 1400);
}
//Mine ore vein
// SceneObject oreVein = SceneObjects.getNearest("Ore vein");
SceneObject oreVein = SceneObjects.getNearest(ov -> ov.getName().equals("Ore vein") && oreVeinArea.contains(ov.getPosition()));
// SceneObject oreVein = SceneObjects.getNearest(ov -> ov.getName() == "Ore vein" && ov.getPosition().distance(rockfallOne) != 2 && ov.getPosition().distance(rockfallTwo) != 2);
if (oreVein != null) {
if (!Players.getLocal().isAnimating()) {
oreVein.interact("Mine");
Log.fine("Mining");
}
Time.sleepUntil(() -> !Players.getLocal().isAnimating() && Players.getLocal().getTarget() == null, getRand(29000, 35000));
randomWait(700, 1400);
}
if (Inventory.isFull()) {
state = "climbDown";
}
}
if (state.equals("climbDown")) {
//If user is not moving, walk to second floor ladder
if (!Players.getLocal().isMoving() && Players.getLocal().getTarget() == null) {
Movement.walkTo(Random.nextElement(secondFloorLadder.getTiles()));
randomWait(500, 800);
}
//If ladder is within 3, 6 tiles, click it
SceneObject ladder = SceneObjects.getNearest("Ladder");
int dist = Random.nextInt(3, 6);
if (ladder != null && ladder.getPosition().distance(Players.getLocal().getPosition()) < dist) {
ladder.interact("Climb");
Time.sleepUntil(() -> firstFloorPosition.distance(Players.getLocal().getPosition()) == 0, getRand(7000, 15000));
randomWait(450, 850);
}
//If on first floor coordinate
if (firstFloorPosition.distance(Players.getLocal().getPosition()) == 0) {
state = "depositHopper";
}
}
if (state.equals("depositHopper")) {
//Hopper - Deposit
SceneObject hopper = SceneObjects.getNearest("Hopper");
if (hopper != null && Inventory.isFull()) {
hopper.interact("Deposit");
Time.sleepUntil(() -> Inventory.isEmpty(), getRand(10000, 15000));
randomWait(700, 1800);
if (Inventory.isEmpty()) {
depositCount++;
if (depositCount == 3) {
state = "depositToBank";
}
else {
state = "start";
}
}
}
}
if (state.equals("depositToBank")) {
Log.fine("Deposit");
SceneObject sack = SceneObjects.getNearest("Sack");
//Check within this function
if (sack != null && Inventory.isEmpty()) {
sack.interact("Search");
Log.info("Before search sleep");
Time.sleepUntil(() -> !Inventory.isEmpty(), getRand(8000, 13000));
Log.info("After search sleep");
randomWait(2000, 3000);
Log.info("Before move");
if (!Inventory.isEmpty() && !Players.getLocal().isMoving()) {
Movement.walkTo(Random.nextElement(bankArea.getTiles()));
randomWait(300, 700);
}
Log.info("After move");
}
//If depositBox is within 3, 6 tiles, click it
SceneObject bankChest = SceneObjects.getNearest(26707);
int dist = Random.nextInt(5, 8);
if (!Inventory.isEmpty() && bankChest != null && bankChest.getPosition().distance(Players.getLocal().getPosition()) <= dist) {
Log.fine("In dp if");
// Bank.open();
bankChest.interact("Use");
Time.sleepUntil(() -> Bank.isOpen(), getRand(7000, 15000));
randomWait(550, 950);
Bank.depositInventory();
Time.sleepUntil(() -> Inventory.isEmpty(), getRand(5000, 10000));
randomWait(400, 900);
Bank.close();
Log.fine("Before close sleep");
Time.sleepUntil(() -> !Bank.isOpen(), getRand(6000, 12000));
Log.fine("After close sleep");
randomWait(550, 950);
depositCount--;
}
//If deposited all, go to start
if (depositCount == 0 && Inventory.isEmpty() && !Bank.isOpen()) {
Log.fine("State switch");
state = "start";
}
}
return 0;
}
}