Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileWriter;
- import java.util.HashMap;
- import java.util.Map;
- import org.rsbot.Configuration;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.wrappers.RSComponent;
- import org.rsbot.script.wrappers.RSInterface;
- @ScriptManifest(authors = { "Equinox" }, name = "EquinoxMagicUpdater")
- public class EquinoxMagicUpdater extends Script {
- int cpIDX = 0;
- String file = "";
- int miss = 0;
- @Override
- public int loop() {
- RSInterface intr = interfaces.get(193);
- RSComponent[] comps = intr.getComponents();
- RSComponent scroll = intr.getComponent(0);
- if (cpIDX < 0 || cpIDX >= comps.length) {
- log.severe("Missed: " + miss);
- if (!new File(Configuration.Paths.getScriptCacheDirectory())
- .exists())
- new File(Configuration.Paths.getScriptCacheDirectory())
- .mkdirs();
- write(file, new File(Configuration.Paths.getScriptCacheDirectory()
- + "/normal_spells"));
- return -1;
- }
- RSComponent comp = comps[cpIDX];
- cpIDX++;
- RSComponent n7 = intr.getComponent(54);
- String lvlStr = "-1";
- String name = "null";
- Map<Rune, Integer> counts = new HashMap<Rune, Integer>();
- for (byte b = 0; b < 5 && (name.equals("null") || lvlStr.equals("-1")); b++) {
- interfaces.scrollTo(comp, scroll);
- mouse.hop(comp.getCenter());
- sleep(1000);
- n7 = intr.getComponent(54);
- if (n7 != null && n7.isValid()) {
- RSComponent[] children = n7.getComponents();
- for (int i = 0; i < children.length - 1; i++) {
- RSComponent cRune = children[i];
- if (cRune != null
- && cRune.getText() != null
- && cRune.getText().trim().toLowerCase()
- .startsWith("level ")) {
- String[] data = cRune.getText().split(":", 2);
- if (data.length == 2) {
- lvlStr = data[0].trim().toLowerCase()
- .replace("Level", "");
- name = data[1].trim().toUpperCase()
- .replace("-", "_").replace(" ", "_");
- }
- }
- if (cRune != null && cRune.getComponentID() >= 0) {
- Rune r = Rune.getRune(cRune.getComponentID());
- if (r != null) {
- RSComponent cRuneCount = children[i + 1];
- if (cRuneCount != null
- && cRuneCount.getText() != null) {
- String[] st = cRuneCount.getText().trim()
- .split("/");
- if (st.length >= 2) {
- String next = st[1];
- try {
- Integer it = Integer.valueOf(next);
- counts.put(r, it);
- } catch (Exception e) {
- log.severe(e.toString());
- }
- }
- }
- }
- }
- }
- }
- }
- if (!name.equals("null") && !lvlStr.equals("-1")) {
- String constD = fetchConst(comp.getTextureID(), name, lvlStr,
- counts);
- file += constD + ",\n";
- log.info(constD);
- } else {
- miss++;
- log.severe("Missed: " + cpIDX);
- }
- return 100;
- }
- String[] combatKeys = new String[] { "rush", "strike", "bolt", "blast",
- "wave", "surge", "burst", "barrage", "blitz" };
- public boolean isCombat(String name) {
- for (String s : combatKeys) {
- if (name.toLowerCase().contains(s.toLowerCase()))
- return true;
- }
- return false;
- }
- public String getCombatType(String name) {
- if (isCombat(name))
- return "Combat";
- if (name.toLowerCase().contains("tele"))
- return "Teleport";
- return "Misc";
- }
- public String fetchConst(int tex, String name, String lvl,
- Map<Rune, Integer> runes) {
- String runeMap = "";
- for (Rune r : runes.keySet()) {
- runeMap += ",Rune." + r.name();
- }
- runeMap = "new Rune[]{"
- + (runeMap.length() > 0 ? runeMap.substring(1) : "") + "}";
- String countMap = "";
- for (Integer r : runes.values()) {
- countMap += "," + r;
- }
- countMap = "new int[]{"
- + (countMap.length() > 0 ? countMap.substring(1) : "") + "}";
- return name + "(" + tex + "," + "Type." + getCombatType(name) + ","
- + runeMap + "," + countMap + "," + stripNonNum(lvl)
- + (isCombat(name) ? ",true" : "") + ")";
- }
- private static char[] nums = { '.', '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9' };
- public String stripNonNum(String s) {
- String dest = "";
- for (char character : s.toCharArray()) {
- for (char c : nums) {
- if (character == c) {
- dest += Character.toString(character);
- }
- }
- }
- return dest;
- }
- public void write(String s, File f) {
- try {
- if (!f.exists())
- f.createNewFile();
- BufferedWriter write = new BufferedWriter(new FileWriter(f));
- write.write(s);
- write.close();
- } catch (Exception e) {
- log.severe(e.toString());
- }
- }
- enum Rune {
- AIR(556),
- FIRE(554),
- EARTH(557),
- WATER(555),
- MIND(558),
- CHAOS(562),
- DEATH(560),
- BLOOD(565),
- ARMADYL(21773),
- BODY(559),
- COSMIC(564),
- ASTRAL(9075),
- NATURE(561),
- LAW(563),
- SOUL(566);
- private final int[] ids;
- private Rune(int... ids) {
- this.ids = ids;
- }
- public int[] getIDs() {
- return ids;
- }
- public static Rune getRune(int id) {
- for (Rune r : values())
- for (int i : r.getIDs())
- if (i == id)
- return r;
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment