-
Notifications
You must be signed in to change notification settings - Fork 0
/
RSUtil.java
113 lines (101 loc) · 4.01 KB
/
RSUtil.java
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
package scripts;
import java.awt.Image;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import org.tribot.api.General;
import org.tribot.api2007.Inventory;
import org.tribot.api2007.Objects;
import org.tribot.api2007.Skills;
import org.tribot.api2007.types.RSItem;
import org.tribot.api2007.types.RSObject;
public class RSUtil {
/**
* Gets the per hour value for the specified value.
* @param value The value to evaluate.
* @param startTime The time in ms when the script started.
* @return The per hour value.
*/
public static long getPerHour(final int value, final long startTime) {
return (long)(value * 3600000D / (System.currentTimeMillis() - startTime));
}
/**
* Gets the xp gained for the specified skill based on the start xp.
* @param skill The skill to get the xp gained.
* @param startXp The starting xp of the skill.
* @return The xp gained.
*/
public static String getXpGainedAnHour(final Skills.SKILLS skill, final int startXp, final long startTime) {
final int xp = skill.getXP() - startXp;
return "" + xp + " (" + getPerHour(xp, startTime) + ")";
}
/**
* Gets the players current hit points.
* @return the players current hit points.
*/
public static int getPlayerHPPercent() {
return (int) (100.0 * ((double)Skills.SKILLS.HITPOINTS.getCurrentLevel() / (double)Skills.SKILLS.HITPOINTS.getActualLevel()));
}
/**
* Gets the the Image from the specified url.
* @param url The url to get the Image from.
* @return The Image retrieved; null if no Image was found.
*/
public static Image getImageFromUrl(final String url) {
try {
return ImageIO.read(new URL(url));
} catch (IOException e) {
General.println("Failed to retreive image from: " + url);
return null;
}
}
/**
* Gets the nearest RSObject with the specified name.
* @param name The name of the RSObject to search for.
* @param dist The distance away from the player.
* @return the nearest RSObject with the specified name; null of no objects were found.
*/
public static RSObject getObject(final String name, final int dist) {
final RSObject[] objs = Objects.findNearest(dist, name);
return objs.length > 0 ? objs[0] : null;
}
/**
* Gets the nearest RSObject with the specified id.
* @param id The id of the RSObject to search for.
* @param dist The distance away from the player.
* @return the nearest RSObject with the specified id; null of no objects were found.
*/
public static RSObject getObject(final int id, final int dist) {
final RSObject[] objs = Objects.findNearest(dist, id);
return objs.length > 0 ? objs[0] : null;
}
/**
* Gets the first item in the Inventory that matches the specified id.
* @param id The id of the item to search for.
* @return the first item in the Inventory that matches the specified id;
* null of no items were found.
*/
public static RSItem getItem(final int id) {
final RSItem[] inv = Inventory.find(id);
return (inv != null && inv.length > 0) ? inv[0] : null;
}
/**
* Gets the first item in the Inventory that matches the specified name.
* @param name The name of the item to search for.
* @return the first item in the Inventory that matches the specified name;
* null of no items were found.
*/
public static RSItem getItem(final String name) {
final RSItem[] inv = Inventory.find(name);
return (inv != null && inv.length > 0) ? inv[0] : null;
}
/**
* Checks to see if the inventory contains the specified item.
* @param id The id of the item.
* @return true if the inventory contains the item; false otherwise.
*/
public static boolean hasItem(final int id) {
final RSItem[] inv = Inventory.find(id);
return inv != null && inv.length > 0;
}
}