Equinox

Untitled

Oct 3rd, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.09 KB | None | 0 0
  1. import java.io.BufferedWriter;
  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6.  
  7. import org.rsbot.Configuration;
  8. import org.rsbot.script.Script;
  9. import org.rsbot.script.ScriptManifest;
  10. import org.rsbot.script.wrappers.RSComponent;
  11. import org.rsbot.script.wrappers.RSInterface;
  12.  
  13. @ScriptManifest(authors = { "Equinox" }, name = "EquinoxMagicUpdater")
  14. public class EquinoxMagicUpdater extends Script {
  15.     int cpIDX = 0;
  16.     String file = "";
  17.     int miss = 0;
  18.  
  19.     @Override
  20.     public int loop() {
  21.     RSInterface intr = interfaces.get(193);
  22.     RSComponent[] comps = intr.getComponents();
  23.     RSComponent scroll = intr.getComponent(0);
  24.     if (cpIDX < 0 || cpIDX >= comps.length) {
  25.         log.severe("Missed: " + miss);
  26.         if (!new File(Configuration.Paths.getScriptCacheDirectory())
  27.             .exists())
  28.         new File(Configuration.Paths.getScriptCacheDirectory())
  29.             .mkdirs();
  30.         write(file, new File(Configuration.Paths.getScriptCacheDirectory()
  31.             + "/normal_spells"));
  32.         return -1;
  33.     }
  34.     RSComponent comp = comps[cpIDX];
  35.     cpIDX++;
  36.     RSComponent n7 = intr.getComponent(54);
  37.     String lvlStr = "-1";
  38.     String name = "null";
  39.     Map<Rune, Integer> counts = new HashMap<Rune, Integer>();
  40.     for (byte b = 0; b < 5 && (name.equals("null") || lvlStr.equals("-1")); b++) {
  41.         interfaces.scrollTo(comp, scroll);
  42.         mouse.hop(comp.getCenter());
  43.         sleep(1000);
  44.         n7 = intr.getComponent(54);
  45.         if (n7 != null && n7.isValid()) {
  46.         RSComponent[] children = n7.getComponents();
  47.         for (int i = 0; i < children.length - 1; i++) {
  48.             RSComponent cRune = children[i];
  49.             if (cRune != null
  50.                 && cRune.getText() != null
  51.                 && cRune.getText().trim().toLowerCase()
  52.                     .startsWith("level ")) {
  53.             String[] data = cRune.getText().split(":", 2);
  54.             if (data.length == 2) {
  55.                 lvlStr = data[0].trim().toLowerCase()
  56.                     .replace("Level", "");
  57.                 name = data[1].trim().toUpperCase()
  58.                     .replace("-", "_").replace(" ", "_");
  59.             }
  60.             }
  61.             if (cRune != null && cRune.getComponentID() >= 0) {
  62.             Rune r = Rune.getRune(cRune.getComponentID());
  63.             if (r != null) {
  64.                 RSComponent cRuneCount = children[i + 1];
  65.                 if (cRuneCount != null
  66.                     && cRuneCount.getText() != null) {
  67.                 String[] st = cRuneCount.getText().trim()
  68.                     .split("/");
  69.                 if (st.length >= 2) {
  70.                     String next = st[1];
  71.                     try {
  72.                     Integer it = Integer.valueOf(next);
  73.                     counts.put(r, it);
  74.                     } catch (Exception e) {
  75.                     log.severe(e.toString());
  76.                     }
  77.                 }
  78.                 }
  79.             }
  80.             }
  81.         }
  82.         }
  83.     }
  84.     if (!name.equals("null") && !lvlStr.equals("-1")) {
  85.         String constD = fetchConst(comp.getTextureID(), name, lvlStr,
  86.             counts);
  87.         file += constD + ",\n";
  88.         log.info(constD);
  89.     } else {
  90.         miss++;
  91.         log.severe("Missed: " + cpIDX);
  92.     }
  93.     return 100;
  94.     }
  95.  
  96.     String[] combatKeys = new String[] { "rush", "strike", "bolt", "blast",
  97.         "wave", "surge", "burst", "barrage", "blitz" };
  98.  
  99.     public boolean isCombat(String name) {
  100.     for (String s : combatKeys) {
  101.         if (name.toLowerCase().contains(s.toLowerCase()))
  102.         return true;
  103.     }
  104.     return false;
  105.     }
  106.  
  107.     public String getCombatType(String name) {
  108.     if (isCombat(name))
  109.         return "Combat";
  110.     if (name.toLowerCase().contains("tele"))
  111.         return "Teleport";
  112.     return "Misc";
  113.     }
  114.  
  115.     public String fetchConst(int tex, String name, String lvl,
  116.         Map<Rune, Integer> runes) {
  117.     String runeMap = "";
  118.     for (Rune r : runes.keySet()) {
  119.         runeMap += ",Rune." + r.name();
  120.     }
  121.     runeMap = "new Rune[]{"
  122.         + (runeMap.length() > 0 ? runeMap.substring(1) : "") + "}";
  123.     String countMap = "";
  124.     for (Integer r : runes.values()) {
  125.         countMap += "," + r;
  126.     }
  127.     countMap = "new int[]{"
  128.         + (countMap.length() > 0 ? countMap.substring(1) : "") + "}";
  129.     return name + "(" + tex + "," + "Type." + getCombatType(name) + ","
  130.         + runeMap + "," + countMap + "," + stripNonNum(lvl)
  131.         + (isCombat(name) ? ",true" : "") + ")";
  132.     }
  133.  
  134.     private static char[] nums = { '.', '0', '1', '2', '3', '4', '5', '6', '7',
  135.         '8', '9' };
  136.  
  137.     public String stripNonNum(String s) {
  138.     String dest = "";
  139.     for (char character : s.toCharArray()) {
  140.         for (char c : nums) {
  141.         if (character == c) {
  142.             dest += Character.toString(character);
  143.         }
  144.         }
  145.     }
  146.     return dest;
  147.     }
  148.  
  149.     public void write(String s, File f) {
  150.     try {
  151.         if (!f.exists())
  152.         f.createNewFile();
  153.         BufferedWriter write = new BufferedWriter(new FileWriter(f));
  154.         write.write(s);
  155.         write.close();
  156.     } catch (Exception e) {
  157.         log.severe(e.toString());
  158.     }
  159.     }
  160.  
  161.     enum Rune {
  162.     AIR(556),
  163.     FIRE(554),
  164.     EARTH(557),
  165.     WATER(555),
  166.     MIND(558),
  167.     CHAOS(562),
  168.     DEATH(560),
  169.     BLOOD(565),
  170.     ARMADYL(21773),
  171.     BODY(559),
  172.     COSMIC(564),
  173.     ASTRAL(9075),
  174.     NATURE(561),
  175.     LAW(563),
  176.     SOUL(566);
  177.     private final int[] ids;
  178.  
  179.     private Rune(int... ids) {
  180.         this.ids = ids;
  181.     }
  182.  
  183.     public int[] getIDs() {
  184.         return ids;
  185.     }
  186.  
  187.     public static Rune getRune(int id) {
  188.         for (Rune r : values())
  189.         for (int i : r.getIDs())
  190.             if (i == id)
  191.             return r;
  192.         return null;
  193.     }
  194.     }
  195. }
  196.  
Advertisement
Add Comment
Please, Sign In to add comment