This repository was archived by the owner on Aug 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTiles.java
More file actions
85 lines (69 loc) · 2.31 KB
/
Tiles.java
File metadata and controls
85 lines (69 loc) · 2.31 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
package mAPI;
import java.util.Comparator;
import org.powerbot.game.api.methods.Calculations;
import org.powerbot.game.api.methods.Walking;
import org.powerbot.game.api.methods.interactive.Players;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.util.Time;
import org.powerbot.game.api.util.Timer;
import org.powerbot.game.api.wrappers.Tile;
public class Tiles {
public static double distanceTo(Tile t) {
return Calculations.distance(t, Players.getLocal().getPosition());
}
public static Tile getNearestTile(Tile[] arr) {
Tile tile = new Tile(0, 0, 0);
Tile from = Players.getLocal().getPosition();
double distance = 9999999, temp;
int index = 0;
for(int i=0;i<arr.length;i++) {
tile = arr[i];
temp = Calculations.distance(from, tile);
if(temp<distance) {
distance = temp;
index = i;
}
}
return arr[index];
}
public static Tile MidPoint(Tile a, Tile b) {
return new Tile(a.getX()+b.getX()/2, a.getY()+b.getY()/2, a.getPlane());
}
public static Tile randomizeTile(Tile a, int off) {
return new Tile(Random.nextInt(a.getX() - off, a.getX() + off),
Random.nextInt(a.getY() - off, a.getY() + off), a.getPlane());
}
public static Tile[] reversePath(Tile[] arr) {
for (int left=0, right=arr.length-1; left<right; left++, right--) {
Tile temp = arr[left]; arr[left] = arr[right]; arr[right] = temp;
}
return arr;
}
public static final Comparator<Tile> TILE_DIST = new Comparator<Tile>() {
@Override
public int compare(Tile a, Tile b) {
return distanceTo(a) < distanceTo(b) ? 1 :
distanceTo(a) > distanceTo(b) ? -1 : 0;
}
};
public static boolean tileOnMM(Tile a) {
return (distanceTo(a) < 18);
}
public static boolean tileOnMS(Tile a) {
return distanceTo(a) < 3;
}
public static boolean tilesEqual(Tile a, Tile b) {
return (a.getX() == b.getX()) && (a.getY() == b.getY()) && (a.getPlane() == b.getPlane());
}
public static boolean walkTileMM(Tile a, int r_off) {
a = randomizeTile(a, r_off);
if (Walking.walk(a));
Timer timeout = new Timer(30000);
while (distanceTo(a) > (r_off+1)) {
Time.sleep(500 + Random.nextInt(0, 100));
if ((timeout.getRemaining() == 0) || (Walking.getDestination() == null))
break;
}
return distanceTo(a) <= (r_off+1);
}
}