Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.AlphaComposite;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Rectangle;
- import java.util.HashMap;
- import java.util.Map;
- import org.powerbot.concurrent.Task;
- import org.powerbot.concurrent.strategy.Strategy;
- import org.powerbot.game.api.ActiveScript;
- import org.powerbot.game.api.Manifest;
- import org.powerbot.game.api.methods.Calculations;
- import org.powerbot.game.api.methods.Settings;
- import org.powerbot.game.api.methods.Tabs;
- import org.powerbot.game.api.methods.Walking;
- import org.powerbot.game.api.methods.Widgets;
- import org.powerbot.game.api.methods.input.Mouse;
- import org.powerbot.game.api.methods.interactive.Players;
- import org.powerbot.game.api.methods.node.Menu;
- import org.powerbot.game.api.methods.node.SceneEntities;
- import org.powerbot.game.api.methods.tab.Inventory;
- import org.powerbot.game.api.methods.tab.Skills;
- import org.powerbot.game.api.util.Filter;
- import org.powerbot.game.api.util.Random;
- import org.powerbot.game.api.util.Time;
- import org.powerbot.game.api.wrappers.Area;
- import org.powerbot.game.api.wrappers.Tile;
- import org.powerbot.game.api.wrappers.node.Item;
- import org.powerbot.game.api.wrappers.node.SceneObject;
- import org.powerbot.game.api.wrappers.widget.Widget;
- import org.powerbot.game.api.wrappers.widget.WidgetChild;
- import org.powerbot.game.bot.event.MessageEvent;
- import org.powerbot.game.bot.event.listener.MessageListener;
- import org.powerbot.game.bot.event.listener.PaintListener;
- @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)
- public class iTGraahkRC extends ActiveScript implements MessageListener,
- PaintListener {
- private boolean needNewRing;
- private long lastDebug, startTime;
- private boolean[] hasClicked = new boolean[4];
- private int startXp, startLevel, crafted;
- private String status = "nothing";
- private final int PURE_ESSENCE = 7936, POUCH_SMALL = 5509,
- POUCH_MEDIUM = 5510, POUCH_LARGE = 5512, POUCH_GIANT = 5514,
- GRAAHK_POUCH = 12810;
- private long lastWalk;
- private boolean guiInitialized = true;
- private HashMap<Integer, Boolean> pouches = new HashMap<Integer, Boolean>(); // PouchID,
- // filled
- private final int[][] POUCH_DATA = { { POUCH_SMALL, 3, 2 },
- { POUCH_MEDIUM, 6, 8 }, { POUCH_LARGE, 9, 32 },
- { POUCH_GIANT, 12, 128 } };
- private final Area AREA_BANK = new Area(new Tile(2436, 33100, 0), new Tile(
- 2452, 3074, 0)), AREA_ALTAR = new Area(new Tile(2390, 4830, 0),
- new Tile(2410, 4850, 0));
- private Tile[] pathToAltar = new Tile[] { new Tile(2792, 3007, 0),
- new Tile(2805, 3007, 0), new Tile(2810, 3008, 0),
- new Tile(2815, 3008, 0), new Tile(2820, 3010, 0),
- new Tile(2825, 3011, 0), new Tile(2829, 3014, 0),
- new Tile(2833, 3018, 0), new Tile(2837, 3021, 0),
- new Tile(2840, 3025, 0), new Tile(2843, 3029, 0),
- new Tile(2848, 3030, 0), new Tile(2853, 3029, 0),
- new Tile(2857, 3026, 0), new Tile(2860, 3022, 0),
- new Tile(2864, 3021, 0) };
- private void updatePouches() {
- for (int i = 0; i < POUCH_DATA.length; i++) {
- if (Inventory.getCount(POUCH_DATA[i][0]) > 0) {
- pouches.put(POUCH_DATA[i][0], false);
- log.info("Pd:" + POUCH_DATA[i][0] + ".");
- }
- }
- }
- @Override
- protected void setup() {
- provide(new Debug());
- updatePouches();
- provide(new WearRing());
- provide(new EnterRuins());
- provide(new Summon());
- provide(new Interaction());
- provide(new BankMisc());
- provide(new Banking());
- provide(new WalkingGeneral());
- provide(new WalkAltar());
- provide(new CraftRunes());
- provide(new TeleportToBank());
- startTime = System.currentTimeMillis();
- startXp = Skills.getExperience(Skills.RUNECRAFTING);
- startLevel = Skills.getLevel(Skills.RUNECRAFTING);
- }
- private SceneObject getChest() {
- return SceneEntities.getNearest(new Filter<SceneObject>() {
- public boolean accept(SceneObject loc) {
- return loc != null && loc.getId() == 4483;
- }
- });
- }
- private SceneObject getRuins() {
- return SceneEntities.getNearest(new Filter<SceneObject>() {
- public boolean accept(SceneObject loc) {
- return loc != null && loc.getId() == 2460;
- }
- });
- }
- private SceneObject getAltar() {
- return SceneEntities.getNearest(new Filter<SceneObject>() {
- public boolean accept(SceneObject loc) {
- return loc != null && loc.getId() == 2486;
- }
- });
- }
- @Override
- public void messageReceived(MessageEvent arg0) {
- String msg = arg0.getMessage();
- if (msg.contains("crumbles to dust")) {
- needNewRing = true;
- }
- }
- private AlphaComposite makeComposite(float alpha) {
- int type = AlphaComposite.SRC_OVER;
- return (AlphaComposite.getInstance(type, alpha));
- }
- @Override
- public void onRepaint(Graphics g) {
- if (guiInitialized) {
- Graphics2D g2d = (Graphics2D) g;
- Font title = new Font("Monotype Corsiva", Font.PLAIN, 25);
- Font author = new Font("Monotype Corsiva", Font.PLAIN, 16);
- Font info = new Font("Book Antiqua", Font.PLAIN, 15);
- Rectangle bg = new Rectangle(10, 23, 250, 155);
- Rectangle border = new Rectangle(8, 21, 254, 159);
- g2d.setColor(Color.RED);
- g2d.setComposite(makeComposite(0.5f));
- g2d.fill(bg);
- g2d.setColor(Color.BLACK);
- g2d.fill(border);
- g2d.setComposite(makeComposite(1.0f));
- g2d.setColor(Color.WHITE);
- g2d.fill(new Rectangle(Mouse.getX() + 1, Mouse.getY() - 4, 2, 15));
- g2d.fill(new Rectangle(Mouse.getX() - 6, Mouse.getY() + 2, 16, 2));
- int expGained = Skills.getExperiences()[Skills.RUNECRAFTING]
- - startXp;
- int expHour = (int) ((expGained) * 3600000D / (System
- .currentTimeMillis() - startTime));
- int cutHour = (int) ((crafted) * 3600000D / (System
- .currentTimeMillis() - startTime));
- g2d.setFont(title);
- g2d.drawString("iTGraahkRC", 20, 50);
- g2d.setFont(author);
- g2d.drawString("By: Flow_HRS", 20, 65);
- g2d.setFont(info);
- g2d.drawString("Runecrafting level: "
- + Skills.getLevels()[Skills.RUNECRAFTING] + "/"
- + startLevel + ".", 20, 85);
- g2d.drawString(
- "Runecrafting experience gained: " + expGained + ".", 20,
- 100);
- g2d.drawString("Runecrafting experience/hour: " + expHour + ".",
- 20, 115);
- g2d.drawString("Crafted " + crafted + " runes.", 20, 130);
- g2d.drawString("Crafting " + cutHour + " runes per hour.", 20, 145);
- g2d.drawString("Status: " + status + ".", 20, 160);
- g2d.drawString(
- "Time running: "
- + formatTime(System.currentTimeMillis() - startTime)
- + ".", 20, 175);
- }
- }
- public String formatTime(final long milliseconds) {
- final long t_seconds = milliseconds / 1000;
- final long t_minutes = t_seconds / 60;
- final long t_hours = t_minutes / 60;
- final long seconds = t_seconds % 60;
- final long minutes = t_minutes % 60;
- final long hours = t_hours % 500;
- return hours + ":" + minutes + ":" + seconds;
- }
- private class Debug extends Strategy implements Task {
- @Override
- public boolean validate() {
- return (System.currentTimeMillis() - lastDebug) > 5000;
- }
- @Override
- public void run() {
- lastDebug = System.currentTimeMillis();
- log.info("Familiar id: " + Widgets.get(662, 1).getModelId());
- log.info("Familiar: "
- + (Widgets.get(747, 0).getTextureId() == 1802));
- log.info("Time left: " + Widgets.get(662, 43).getText());
- log.info("Player in bank: "
- + AREA_BANK.contains(Players.getLocal().getLocation()));
- }
- }
- private class Summon extends Strategy implements Task {
- @Override
- public boolean validate() {
- return guiInitialized && Inventory.getCount(GRAAHK_POUCH) > 0
- && Settings.get(448) == -1
- && !Widgets.get(762, 1).validate();
- }
- @Override
- public void run() {
- status = "summoning";
- for (Item i : Inventory.getItems()) {
- if (i.getId() == GRAAHK_POUCH) {
- i.getWidgetChild().interact("Summon");
- break;
- }
- }
- Time.sleep(Random.nextInt(800, 1600));
- }
- }
- private class Interaction extends Strategy implements Task {
- @Override
- public boolean validate() {
- return guiInitialized
- && Widgets.get(662, 1).getModelId() == 7363
- // && !Widgets.get(1188, 11).validate()
- && AREA_BANK.contains(Players.getLocal().getLocation())
- && !Widgets.get(762, 1).validate()
- && Inventory.getCount(PURE_ESSENCE) > 0
- && Players.getLocal().getAnimation() == -1;
- }
- @Override
- public void run() {
- status = "interacting";
- Widgets.get(747, 5).click(true);
- Time.sleep(Random.nextInt(1200, 1800));
- if (Widgets.get(1188, 13).validate()) {
- Widgets.get(1188, 13).click(true);
- }
- Time.sleep(Random.nextInt(600, 1200));
- }
- }
- private class BankMisc extends Strategy implements Task {
- @Override
- public boolean validate() {
- return guiInitialized
- && AREA_BANK.contains(Players.getLocal().getLocation())
- && !Players.getLocal().isMoving()
- && !Widgets.get(762, 1).validate()
- && Inventory.getCount(PURE_ESSENCE) == 0
- && getChest() != null;
- }
- @Override
- public void run() {
- status = "walking to bank";
- if (Calculations.distance(Players.getLocal().getLocation(),
- getChest().getLocation()) >= 4) {
- Walking.walk(new Tile(2444, 3083, 0));
- Time.sleep(Random.nextInt(800, 1000));
- while (Players.getLocal().isMoving()) {
- Time.sleep(100);
- }
- } else {
- if (getChest().validate()) {
- getChest().click(true);
- status = "opening bank";
- while (!Widgets.get(762, 1).validate()) {
- Time.sleep(100);
- }
- }
- Time.sleep(Random.nextInt(1000, 1200));
- }
- }
- }
- public class Banking extends Strategy implements Task {
- public boolean withdraw(int item, String withdraw) {
- Widget bank = Widgets.get(762);
- WidgetChild items = bank.getChild(95);
- int baseX = items.getAbsoluteX(), baseY = items.getAbsoluteY();
- for (WidgetChild child : items.getChildren()) {
- if (child.getChildId() == item) {
- Mouse.click(
- child.getRelativeX() + baseX
- + (child.getWidth() / 2),
- child.getRelativeY() + baseY
- + (child.getHeight() / 2), false);
- return Menu.select(withdraw);
- }
- }
- return false;
- }
- private boolean deposit(int item, String action) {
- for (Item i : Inventory.getItems()) {
- if (i.getId() == item) {
- return i.getWidgetChild().interact(action);
- }
- }
- return false;
- }
- private final boolean NEED_WITHDRAW_GRAAHK() {
- return Settings.get(448) == -1
- || Widgets.get(662, 1).getModelId() == -1;
- }
- public void fillPouches() {
- for (int pouch : pouches.keySet()) {
- if (Inventory.getCount(PURE_ESSENCE) > 0) {
- if (Inventory.getCount(pouch) > 0) {
- Item i = Inventory.getItem(pouch);
- while (!i.getWidgetChild().interact("Fill")) {
- Time.sleep(Random.nextInt(80, 120));
- }
- pouches.put(pouch, true);
- } else {
- pouches.remove(pouch);
- }
- }
- }
- }
- public void fillPouch(int pouchID, int minEssence, int boolNumber) {
- if (Inventory.getCount(pouchID) != 0 && !hasClicked[boolNumber]) {
- if (Inventory.getCount(PURE_ESSENCE) >= minEssence) {
- for (Item i : Inventory.getItems()) {
- if (i.getId() == pouchID) {
- i.getWidgetChild().interact("Fill");
- hasClicked[boolNumber] = true;
- }
- }
- } else {
- withdraw(PURE_ESSENCE, "Withdraw-All");
- Time.sleep(Random.nextInt(800, 1200));
- fillPouch(pouchID, minEssence, boolNumber);
- }
- } else {
- return;
- }
- }
- @Override
- public boolean validate() {
- return guiInitialized && Widgets.get(762, 1).validate();
- }
- @Override
- public void run() {
- status = "banking";
- // log.info("dogf");
- if (needNewRing) {
- if (Inventory.getCount(2552) == 0) {
- withdraw(2552, "Withdraw-1");
- Time.sleep(Random.nextInt(300, 500));
- } else {
- log.info("New ring needed but didn't withdraw?");
- }
- needNewRing = false;
- }
- if (NEED_WITHDRAW_GRAAHK()) {
- withdraw(GRAAHK_POUCH, "Withdraw-1");
- }
- deposit(561, "Deposit-All");
- Time.sleep(Random.nextInt(1000, 2000));
- withdraw(PURE_ESSENCE, "Withdraw-All");
- Time.sleep(Random.nextInt(1000, 2000));
- status = "filling pouches";
- fillPouches();
- withdraw(PURE_ESSENCE, "Withdraw-All");
- Time.sleep(Random.nextInt(400, 700));
- Widgets.get(762, 45).click(true);
- }
- }
- private class WearRing extends Strategy implements Task {
- @Override
- public boolean validate() {
- return guiInitialized && Tabs.getCurrent() == Tabs.INVENTORY
- && Inventory.getCount(2552) > 0;
- }
- @Override
- public void run() {
- for (Item i : Inventory.getItems()) {
- if (i.getId() == 2552) {
- i.getWidgetChild().interact("Wear");
- break;
- }
- }
- Time.sleep(Random.nextInt(800, 1200));
- }
- }
- private class WalkingGeneral extends Strategy implements Task {
- @Override
- public boolean validate() {
- return guiInitialized
- && !AREA_BANK.contains(Players.getLocal().getLocation())
- && !AREA_ALTAR.contains(Players.getLocal().getLocation())
- && System.currentTimeMillis() - lastWalk > 600;
- }
- @Override
- public void run() {
- status = "walking to ruins";
- walkPath(pathToAltar);
- // altar.traverse();
- }
- }
- private class EnterRuins extends Strategy implements Task {
- @Override
- public boolean validate() {
- if (getRuins() != null) {
- return guiInitialized
- && !AREA_BANK
- .contains(Players.getLocal().getLocation())
- && !AREA_BANK
- .contains(Players.getLocal().getLocation())
- && Calculations.distance(Players.getLocal()
- .getLocation(), getRuins().getLocation()) < 6;
- } else {
- return false;
- }
- }
- @Override
- public void run() {
- status = "entering ruins";
- getRuins().interact("Enter");
- Time.sleep(Random.nextInt(1200, 2400));
- }
- }
- private class WalkAltar extends Strategy implements Task {
- @Override
- public boolean validate() {
- return guiInitialized
- && getAltar() != null
- && AREA_ALTAR.contains(Players.getLocal().getLocation())
- && Calculations.distance(getAltar().getLocation(), Players
- .getLocal().getLocation()) >= 4
- && !Players.getLocal().isMoving();
- }
- @Override
- public void run() {
- status = "walking to altar";
- Walking.walk(new Tile(2400, 4839, 0));
- Time.sleep(Random.nextInt(800, 1600));
- }
- }
- private class CraftRunes extends Strategy implements Task {
- private void emptyPouches() {
- for (int i : pouches.keySet()) {
- if (pouches.get(i)) {
- Item pouch = Inventory.getItem(i);
- while (!pouch.getWidgetChild().interact("Empty")) {
- Time.sleep(Random.nextInt(80, 120));
- }
- pouches.put(i, false);
- }
- }
- getAltar().interact("Craft-rune");
- }
- @Override
- public boolean validate() {
- return guiInitialized
- && AREA_ALTAR.contains(Players.getLocal().getLocation())
- && getAltar() != null
- && Calculations.distance(getAltar().getLocation(), Players
- .getLocal().getLocation()) < 4
- && !Players.getLocal().isMoving()
- && Inventory.getCount(PURE_ESSENCE) > 0
- && Players.getLocal().getAnimation() == -1;
- }
- @Override
- public void run() {
- status = "crafting runes";
- if (Tabs.getCurrent() != Tabs.INVENTORY) {
- Tabs.INVENTORY.open();
- }
- getAltar().interact("Craft-rune");
- Time.sleep(Random.nextInt(1800, 2200));
- emptyPouches();
- }
- }
- private class TeleportToBank extends Strategy implements Task {
- private boolean doneAllPouches() {
- int falses = 0;
- for (Map.Entry<Integer, Boolean> p : pouches.entrySet()) {
- if (!p.getValue()) {
- falses++;
- }
- }
- return falses == pouches.size();
- }
- @Override
- public boolean validate() {
- return guiInitialized
- && AREA_ALTAR.contains(Players.getLocal().getLocation())
- && doneAllPouches()
- && Inventory.getCount(PURE_ESSENCE) == 0;
- }
- @Override
- public void run() {
- status = "teleporting";
- Tabs.EQUIPMENT.open();
- Time.sleep(Random.nextInt(800, 1200));
- if (Widgets.get(387, 33).getChildId() != -1) {
- Widgets.get(387, 33).interact("Castle Wars");
- } else {
- stop();
- log.info("Script fucked up dogf");
- }
- Time.sleep(Random.nextInt(3000, 4000));
- Tabs.INVENTORY.open();
- crafted += getCount();
- }
- private int getCount() {
- for (Item i : Inventory.getItems()) {
- if (i.getId() == 561) {
- return i.getStackSize();
- }
- }
- return 0;
- }
- }
- public void walkPath(final Tile... path) {
- if (Walking.getEnergy() > Random.nextInt(30, 50)) {
- Walking.setRun(true);
- }
- for (int i = path.length - 1; i >= 0; i--) {
- if (Calculations.distanceTo(path[i]) >= 15) {
- continue;
- }
- if (Walking.walk(path[i])) {
- break;
- }
- }
- }
- public static int energyToTurnOn = 20;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement