Advertisement
phl0w

iTGraahkRC

Apr 22nd, 2012
1,791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.91 KB | None | 0 0
  1. import java.awt.AlphaComposite;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Rectangle;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9.  
  10. import org.powerbot.concurrent.Task;
  11. import org.powerbot.concurrent.strategy.Strategy;
  12. import org.powerbot.game.api.ActiveScript;
  13. import org.powerbot.game.api.Manifest;
  14. import org.powerbot.game.api.methods.Calculations;
  15. import org.powerbot.game.api.methods.Settings;
  16. import org.powerbot.game.api.methods.Tabs;
  17. import org.powerbot.game.api.methods.Walking;
  18. import org.powerbot.game.api.methods.Widgets;
  19. import org.powerbot.game.api.methods.input.Mouse;
  20. import org.powerbot.game.api.methods.interactive.Players;
  21. import org.powerbot.game.api.methods.node.Menu;
  22. import org.powerbot.game.api.methods.node.SceneEntities;
  23. import org.powerbot.game.api.methods.tab.Inventory;
  24. import org.powerbot.game.api.methods.tab.Skills;
  25. import org.powerbot.game.api.util.Filter;
  26. import org.powerbot.game.api.util.Random;
  27. import org.powerbot.game.api.util.Time;
  28. import org.powerbot.game.api.wrappers.Area;
  29. import org.powerbot.game.api.wrappers.Tile;
  30. import org.powerbot.game.api.wrappers.node.Item;
  31. import org.powerbot.game.api.wrappers.node.SceneObject;
  32. import org.powerbot.game.api.wrappers.widget.Widget;
  33. import org.powerbot.game.api.wrappers.widget.WidgetChild;
  34. import org.powerbot.game.bot.event.MessageEvent;
  35. import org.powerbot.game.bot.event.listener.MessageListener;
  36. import org.powerbot.game.bot.event.listener.PaintListener;
  37.  
  38. @Manifest(authors = { "Flow_HRS" }, name = "iTGraahkRC", description = "Crafts nature runes with graahk. Renews familiar and ring of duelling. Start at castle wars.", version = 0.2)
  39. public class iTGraahkRC extends ActiveScript implements MessageListener,
  40.         PaintListener {
  41.  
  42.     private boolean needNewRing;
  43.     private long lastDebug, startTime;
  44.     private boolean[] hasClicked = new boolean[4];
  45.     private int startXp, startLevel, crafted;
  46.     private String status = "nothing";
  47.     private final int PURE_ESSENCE = 7936, POUCH_SMALL = 5509,
  48.             POUCH_MEDIUM = 5510, POUCH_LARGE = 5512, POUCH_GIANT = 5514,
  49.             GRAAHK_POUCH = 12810;
  50.     private long lastWalk;
  51.     private boolean guiInitialized = true;
  52.     private HashMap<Integer, Boolean> pouches = new HashMap<Integer, Boolean>(); // PouchID,
  53.                                                                                     // filled
  54.  
  55.     private final int[][] POUCH_DATA = { { POUCH_SMALL, 3, 2 },
  56.             { POUCH_MEDIUM, 6, 8 }, { POUCH_LARGE, 9, 32 },
  57.             { POUCH_GIANT, 12, 128 } };
  58.     private final Area AREA_BANK = new Area(new Tile(2436, 33100, 0), new Tile(
  59.             2452, 3074, 0)), AREA_ALTAR = new Area(new Tile(2390, 4830, 0),
  60.             new Tile(2410, 4850, 0));
  61.     private Tile[] pathToAltar = new Tile[] { new Tile(2792, 3007, 0),
  62.             new Tile(2805, 3007, 0), new Tile(2810, 3008, 0),
  63.             new Tile(2815, 3008, 0), new Tile(2820, 3010, 0),
  64.             new Tile(2825, 3011, 0), new Tile(2829, 3014, 0),
  65.             new Tile(2833, 3018, 0), new Tile(2837, 3021, 0),
  66.             new Tile(2840, 3025, 0), new Tile(2843, 3029, 0),
  67.             new Tile(2848, 3030, 0), new Tile(2853, 3029, 0),
  68.             new Tile(2857, 3026, 0), new Tile(2860, 3022, 0),
  69.             new Tile(2864, 3021, 0) };
  70.  
  71.     private void updatePouches() {
  72.         for (int i = 0; i < POUCH_DATA.length; i++) {
  73.             if (Inventory.getCount(POUCH_DATA[i][0]) > 0) {
  74.                 pouches.put(POUCH_DATA[i][0], false);
  75.                 log.info("Pd:" + POUCH_DATA[i][0] + ".");
  76.             }
  77.         }
  78.     }
  79.  
  80.     @Override
  81.     protected void setup() {
  82.         provide(new Debug());
  83.         updatePouches();
  84.         provide(new WearRing());
  85.         provide(new EnterRuins());
  86.         provide(new Summon());
  87.         provide(new Interaction());
  88.         provide(new BankMisc());
  89.         provide(new Banking());
  90.         provide(new WalkingGeneral());
  91.         provide(new WalkAltar());
  92.         provide(new CraftRunes());
  93.         provide(new TeleportToBank());
  94.         startTime = System.currentTimeMillis();
  95.         startXp = Skills.getExperience(Skills.RUNECRAFTING);
  96.         startLevel = Skills.getLevel(Skills.RUNECRAFTING);
  97.     }
  98.  
  99.     private SceneObject getChest() {
  100.         return SceneEntities.getNearest(new Filter<SceneObject>() {
  101.             public boolean accept(SceneObject loc) {
  102.                 return loc != null && loc.getId() == 4483;
  103.             }
  104.         });
  105.     }
  106.  
  107.     private SceneObject getRuins() {
  108.         return SceneEntities.getNearest(new Filter<SceneObject>() {
  109.             public boolean accept(SceneObject loc) {
  110.                 return loc != null && loc.getId() == 2460;
  111.             }
  112.         });
  113.     }
  114.  
  115.     private SceneObject getAltar() {
  116.         return SceneEntities.getNearest(new Filter<SceneObject>() {
  117.             public boolean accept(SceneObject loc) {
  118.                 return loc != null && loc.getId() == 2486;
  119.             }
  120.         });
  121.     }
  122.  
  123.     @Override
  124.     public void messageReceived(MessageEvent arg0) {
  125.         String msg = arg0.getMessage();
  126.         if (msg.contains("crumbles to dust")) {
  127.             needNewRing = true;
  128.         }
  129.     }
  130.  
  131.     private AlphaComposite makeComposite(float alpha) {
  132.         int type = AlphaComposite.SRC_OVER;
  133.         return (AlphaComposite.getInstance(type, alpha));
  134.     }
  135.  
  136.     @Override
  137.     public void onRepaint(Graphics g) {
  138.         if (guiInitialized) {
  139.             Graphics2D g2d = (Graphics2D) g;
  140.  
  141.             Font title = new Font("Monotype Corsiva", Font.PLAIN, 25);
  142.             Font author = new Font("Monotype Corsiva", Font.PLAIN, 16);
  143.             Font info = new Font("Book Antiqua", Font.PLAIN, 15);
  144.  
  145.             Rectangle bg = new Rectangle(10, 23, 250, 155);
  146.             Rectangle border = new Rectangle(8, 21, 254, 159);
  147.             g2d.setColor(Color.RED);
  148.             g2d.setComposite(makeComposite(0.5f));
  149.             g2d.fill(bg);
  150.             g2d.setColor(Color.BLACK);
  151.             g2d.fill(border);
  152.             g2d.setComposite(makeComposite(1.0f));
  153.  
  154.             g2d.setColor(Color.WHITE);
  155.  
  156.             g2d.fill(new Rectangle(Mouse.getX() + 1, Mouse.getY() - 4, 2, 15));
  157.             g2d.fill(new Rectangle(Mouse.getX() - 6, Mouse.getY() + 2, 16, 2));
  158.  
  159.             int expGained = Skills.getExperiences()[Skills.RUNECRAFTING]
  160.                     - startXp;
  161.             int expHour = (int) ((expGained) * 3600000D / (System
  162.                     .currentTimeMillis() - startTime));
  163.             int cutHour = (int) ((crafted) * 3600000D / (System
  164.                     .currentTimeMillis() - startTime));
  165.             g2d.setFont(title);
  166.             g2d.drawString("iTGraahkRC", 20, 50);
  167.             g2d.setFont(author);
  168.             g2d.drawString("By: Flow_HRS", 20, 65);
  169.  
  170.             g2d.setFont(info);
  171.             g2d.drawString("Runecrafting level: "
  172.                     + Skills.getLevels()[Skills.RUNECRAFTING] + "/"
  173.                     + startLevel + ".", 20, 85);
  174.             g2d.drawString(
  175.                     "Runecrafting experience gained: " + expGained + ".", 20,
  176.                     100);
  177.             g2d.drawString("Runecrafting experience/hour: " + expHour + ".",
  178.                     20, 115);
  179.             g2d.drawString("Crafted " + crafted + " runes.", 20, 130);
  180.             g2d.drawString("Crafting " + cutHour + " runes per hour.", 20, 145);
  181.             g2d.drawString("Status: " + status + ".", 20, 160);
  182.             g2d.drawString(
  183.                     "Time running: "
  184.                             + formatTime(System.currentTimeMillis() - startTime)
  185.                             + ".", 20, 175);
  186.         }
  187.     }
  188.  
  189.     public String formatTime(final long milliseconds) {
  190.         final long t_seconds = milliseconds / 1000;
  191.         final long t_minutes = t_seconds / 60;
  192.         final long t_hours = t_minutes / 60;
  193.         final long seconds = t_seconds % 60;
  194.         final long minutes = t_minutes % 60;
  195.         final long hours = t_hours % 500;
  196.         return hours + ":" + minutes + ":" + seconds;
  197.     }
  198.  
  199.     private class Debug extends Strategy implements Task {
  200.  
  201.         @Override
  202.         public boolean validate() {
  203.             return (System.currentTimeMillis() - lastDebug) > 5000;
  204.         }
  205.  
  206.         @Override
  207.         public void run() {
  208.             lastDebug = System.currentTimeMillis();
  209.             log.info("Familiar id: " + Widgets.get(662, 1).getModelId());
  210.             log.info("Familiar: "
  211.                     + (Widgets.get(747, 0).getTextureId() == 1802));
  212.             log.info("Time left: " + Widgets.get(662, 43).getText());
  213.             log.info("Player in bank: "
  214.                     + AREA_BANK.contains(Players.getLocal().getLocation()));
  215.         }
  216.     }
  217.  
  218.     private class Summon extends Strategy implements Task {
  219.  
  220.         @Override
  221.         public boolean validate() {
  222.             return guiInitialized && Inventory.getCount(GRAAHK_POUCH) > 0
  223.                     && Settings.get(448) == -1
  224.                     && !Widgets.get(762, 1).validate();
  225.         }
  226.  
  227.         @Override
  228.         public void run() {
  229.             status = "summoning";
  230.             for (Item i : Inventory.getItems()) {
  231.                 if (i.getId() == GRAAHK_POUCH) {
  232.                     i.getWidgetChild().interact("Summon");
  233.                     break;
  234.                 }
  235.             }
  236.             Time.sleep(Random.nextInt(800, 1600));
  237.         }
  238.     }
  239.  
  240.     private class Interaction extends Strategy implements Task {
  241.  
  242.         @Override
  243.         public boolean validate() {
  244.             return guiInitialized
  245.                     && Widgets.get(662, 1).getModelId() == 7363
  246.                     // && !Widgets.get(1188, 11).validate()
  247.                     && AREA_BANK.contains(Players.getLocal().getLocation())
  248.                     && !Widgets.get(762, 1).validate()
  249.                     && Inventory.getCount(PURE_ESSENCE) > 0
  250.                     && Players.getLocal().getAnimation() == -1;
  251.         }
  252.  
  253.         @Override
  254.         public void run() {
  255.             status = "interacting";
  256.             Widgets.get(747, 5).click(true);
  257.             Time.sleep(Random.nextInt(1200, 1800));
  258.             if (Widgets.get(1188, 13).validate()) {
  259.                 Widgets.get(1188, 13).click(true);
  260.             }
  261.             Time.sleep(Random.nextInt(600, 1200));
  262.         }
  263.     }
  264.  
  265.     private class BankMisc extends Strategy implements Task {
  266.  
  267.         @Override
  268.         public boolean validate() {
  269.             return guiInitialized
  270.                     && AREA_BANK.contains(Players.getLocal().getLocation())
  271.                     && !Players.getLocal().isMoving()
  272.                     && !Widgets.get(762, 1).validate()
  273.                     && Inventory.getCount(PURE_ESSENCE) == 0
  274.                     && getChest() != null;
  275.         }
  276.  
  277.         @Override
  278.         public void run() {
  279.             status = "walking to bank";
  280.             if (Calculations.distance(Players.getLocal().getLocation(),
  281.                     getChest().getLocation()) >= 4) {
  282.                 Walking.walk(new Tile(2444, 3083, 0));
  283.                 Time.sleep(Random.nextInt(800, 1000));
  284.                 while (Players.getLocal().isMoving()) {
  285.                     Time.sleep(100);
  286.                 }
  287.             } else {
  288.                 if (getChest().validate()) {
  289.                     getChest().click(true);
  290.                     status = "opening bank";
  291.                     while (!Widgets.get(762, 1).validate()) {
  292.                         Time.sleep(100);
  293.                     }
  294.                 }
  295.                 Time.sleep(Random.nextInt(1000, 1200));
  296.             }
  297.         }
  298.     }
  299.  
  300.     public class Banking extends Strategy implements Task {
  301.  
  302.         public boolean withdraw(int item, String withdraw) {
  303.             Widget bank = Widgets.get(762);
  304.             WidgetChild items = bank.getChild(95);
  305.             int baseX = items.getAbsoluteX(), baseY = items.getAbsoluteY();
  306.             for (WidgetChild child : items.getChildren()) {
  307.                 if (child.getChildId() == item) {
  308.                     Mouse.click(
  309.                             child.getRelativeX() + baseX
  310.                                     + (child.getWidth() / 2),
  311.                             child.getRelativeY() + baseY
  312.                                     + (child.getHeight() / 2), false);
  313.                     return Menu.select(withdraw);
  314.                 }
  315.             }
  316.             return false;
  317.         }
  318.  
  319.         private boolean deposit(int item, String action) {
  320.             for (Item i : Inventory.getItems()) {
  321.                 if (i.getId() == item) {
  322.                     return i.getWidgetChild().interact(action);
  323.                 }
  324.             }
  325.             return false;
  326.         }
  327.  
  328.         private final boolean NEED_WITHDRAW_GRAAHK() {
  329.             return Settings.get(448) == -1
  330.                     || Widgets.get(662, 1).getModelId() == -1;
  331.         }
  332.  
  333.         public void fillPouches() {
  334.             for (int pouch : pouches.keySet()) {
  335.                 if (Inventory.getCount(PURE_ESSENCE) > 0) {
  336.                     if (Inventory.getCount(pouch) > 0) {
  337.                         Item i = Inventory.getItem(pouch);
  338.                         while (!i.getWidgetChild().interact("Fill")) {
  339.                             Time.sleep(Random.nextInt(80, 120));
  340.                         }
  341.                         pouches.put(pouch, true);
  342.                     } else {
  343.                         pouches.remove(pouch);
  344.                     }
  345.                 }
  346.             }
  347.         }
  348.  
  349.         public void fillPouch(int pouchID, int minEssence, int boolNumber) {
  350.             if (Inventory.getCount(pouchID) != 0 && !hasClicked[boolNumber]) {
  351.                 if (Inventory.getCount(PURE_ESSENCE) >= minEssence) {
  352.                     for (Item i : Inventory.getItems()) {
  353.                         if (i.getId() == pouchID) {
  354.                             i.getWidgetChild().interact("Fill");
  355.                             hasClicked[boolNumber] = true;
  356.                         }
  357.                     }
  358.                 } else {
  359.                     withdraw(PURE_ESSENCE, "Withdraw-All");
  360.                     Time.sleep(Random.nextInt(800, 1200));
  361.                     fillPouch(pouchID, minEssence, boolNumber);
  362.                 }
  363.             } else {
  364.                 return;
  365.             }
  366.         }
  367.  
  368.         @Override
  369.         public boolean validate() {
  370.             return guiInitialized && Widgets.get(762, 1).validate();
  371.         }
  372.  
  373.         @Override
  374.         public void run() {
  375.             status = "banking";
  376.             // log.info("dogf");
  377.             if (needNewRing) {
  378.                 if (Inventory.getCount(2552) == 0) {
  379.                     withdraw(2552, "Withdraw-1");
  380.                     Time.sleep(Random.nextInt(300, 500));
  381.                 } else {
  382.                     log.info("New ring needed but didn't withdraw?");
  383.                 }
  384.                 needNewRing = false;
  385.             }
  386.             if (NEED_WITHDRAW_GRAAHK()) {
  387.                 withdraw(GRAAHK_POUCH, "Withdraw-1");
  388.             }
  389.             deposit(561, "Deposit-All");
  390.             Time.sleep(Random.nextInt(1000, 2000));
  391.             withdraw(PURE_ESSENCE, "Withdraw-All");
  392.             Time.sleep(Random.nextInt(1000, 2000));
  393.             status = "filling pouches";
  394.             fillPouches();
  395.             withdraw(PURE_ESSENCE, "Withdraw-All");
  396.             Time.sleep(Random.nextInt(400, 700));
  397.             Widgets.get(762, 45).click(true);
  398.         }
  399.     }
  400.  
  401.     private class WearRing extends Strategy implements Task {
  402.  
  403.         @Override
  404.         public boolean validate() {
  405.             return guiInitialized && Tabs.getCurrent() == Tabs.INVENTORY
  406.                     && Inventory.getCount(2552) > 0;
  407.         }
  408.  
  409.         @Override
  410.         public void run() {
  411.             for (Item i : Inventory.getItems()) {
  412.                 if (i.getId() == 2552) {
  413.                     i.getWidgetChild().interact("Wear");
  414.                     break;
  415.                 }
  416.             }
  417.             Time.sleep(Random.nextInt(800, 1200));
  418.         }
  419.     }
  420.  
  421.     private class WalkingGeneral extends Strategy implements Task {
  422.  
  423.         @Override
  424.         public boolean validate() {
  425.             return guiInitialized
  426.                     && !AREA_BANK.contains(Players.getLocal().getLocation())
  427.                     && !AREA_ALTAR.contains(Players.getLocal().getLocation())
  428.                     && System.currentTimeMillis() - lastWalk > 600;
  429.         }
  430.  
  431.         @Override
  432.         public void run() {
  433.             status = "walking to ruins";
  434.             walkPath(pathToAltar);
  435.             // altar.traverse();
  436.         }
  437.     }
  438.  
  439.     private class EnterRuins extends Strategy implements Task {
  440.  
  441.         @Override
  442.         public boolean validate() {
  443.             if (getRuins() != null) {
  444.                 return guiInitialized
  445.                         && !AREA_BANK
  446.                                 .contains(Players.getLocal().getLocation())
  447.                         && !AREA_BANK
  448.                                 .contains(Players.getLocal().getLocation())
  449.                         && Calculations.distance(Players.getLocal()
  450.                                 .getLocation(), getRuins().getLocation()) < 6;
  451.             } else {
  452.                 return false;
  453.             }
  454.         }
  455.  
  456.         @Override
  457.         public void run() {
  458.             status = "entering ruins";
  459.             getRuins().interact("Enter");
  460.             Time.sleep(Random.nextInt(1200, 2400));
  461.         }
  462.     }
  463.  
  464.     private class WalkAltar extends Strategy implements Task {
  465.  
  466.         @Override
  467.         public boolean validate() {
  468.             return guiInitialized
  469.                     && getAltar() != null
  470.                     && AREA_ALTAR.contains(Players.getLocal().getLocation())
  471.                     && Calculations.distance(getAltar().getLocation(), Players
  472.                             .getLocal().getLocation()) >= 4
  473.                     && !Players.getLocal().isMoving();
  474.         }
  475.  
  476.         @Override
  477.         public void run() {
  478.             status = "walking to altar";
  479.             Walking.walk(new Tile(2400, 4839, 0));
  480.             Time.sleep(Random.nextInt(800, 1600));
  481.         }
  482.     }
  483.  
  484.     private class CraftRunes extends Strategy implements Task {
  485.  
  486.         private void emptyPouches() {
  487.             for (int i : pouches.keySet()) {
  488.                 if (pouches.get(i)) {
  489.                     Item pouch = Inventory.getItem(i);
  490.                     while (!pouch.getWidgetChild().interact("Empty")) {
  491.                         Time.sleep(Random.nextInt(80, 120));
  492.                     }
  493.                     pouches.put(i, false);
  494.                 }
  495.             }
  496.             getAltar().interact("Craft-rune");
  497.         }
  498.  
  499.         @Override
  500.         public boolean validate() {
  501.             return guiInitialized
  502.                     && AREA_ALTAR.contains(Players.getLocal().getLocation())
  503.                     && getAltar() != null
  504.                     && Calculations.distance(getAltar().getLocation(), Players
  505.                             .getLocal().getLocation()) < 4
  506.                     && !Players.getLocal().isMoving()
  507.                     && Inventory.getCount(PURE_ESSENCE) > 0
  508.                     && Players.getLocal().getAnimation() == -1;
  509.         }
  510.  
  511.         @Override
  512.         public void run() {
  513.             status = "crafting runes";
  514.             if (Tabs.getCurrent() != Tabs.INVENTORY) {
  515.                 Tabs.INVENTORY.open();
  516.             }
  517.             getAltar().interact("Craft-rune");
  518.             Time.sleep(Random.nextInt(1800, 2200));
  519.             emptyPouches();
  520.         }
  521.     }
  522.  
  523.     private class TeleportToBank extends Strategy implements Task {
  524.  
  525.         private boolean doneAllPouches() {
  526.             int falses = 0;
  527.             for (Map.Entry<Integer, Boolean> p : pouches.entrySet()) {
  528.                 if (!p.getValue()) {
  529.                     falses++;
  530.                 }
  531.             }
  532.             return falses == pouches.size();
  533.         }
  534.  
  535.         @Override
  536.         public boolean validate() {
  537.             return guiInitialized
  538.                     && AREA_ALTAR.contains(Players.getLocal().getLocation())
  539.                     && doneAllPouches()
  540.                     && Inventory.getCount(PURE_ESSENCE) == 0;
  541.         }
  542.  
  543.         @Override
  544.         public void run() {
  545.             status = "teleporting";
  546.             Tabs.EQUIPMENT.open();
  547.             Time.sleep(Random.nextInt(800, 1200));
  548.             if (Widgets.get(387, 33).getChildId() != -1) {
  549.                 Widgets.get(387, 33).interact("Castle Wars");
  550.             } else {
  551.                 stop();
  552.                 log.info("Script fucked up dogf");
  553.             }
  554.             Time.sleep(Random.nextInt(3000, 4000));
  555.             Tabs.INVENTORY.open();
  556.             crafted += getCount();
  557.         }
  558.  
  559.         private int getCount() {
  560.             for (Item i : Inventory.getItems()) {
  561.                 if (i.getId() == 561) {
  562.                     return i.getStackSize();
  563.                 }
  564.             }
  565.             return 0;
  566.         }
  567.     }
  568.  
  569.     public void walkPath(final Tile... path) {
  570.         if (Walking.getEnergy() > Random.nextInt(30, 50)) {
  571.             Walking.setRun(true);
  572.         }
  573.         for (int i = path.length - 1; i >= 0; i--) {
  574.             if (Calculations.distanceTo(path[i]) >= 15) {
  575.                 continue;
  576.             }
  577.             if (Walking.walk(path[i])) {
  578.                 break;
  579.             }
  580.         }
  581.     }
  582.  
  583.     public static int energyToTurnOn = 20;
  584.  
  585. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement