Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Container;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowEvent;
- import java.util.ArrayList;
- import java.util.Arrays;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.WindowConstants;
- import org.powerbot.core.event.listeners.PaintListener;
- import org.powerbot.core.script.ActiveScript;
- import org.powerbot.core.script.job.Task;
- import org.powerbot.game.api.wrappers.Entity;
- import org.powerbot.game.api.wrappers.Identifiable;
- import org.powerbot.game.api.wrappers.Locatable;
- import org.powerbot.game.api.wrappers.Tile;
- import org.powerbot.game.api.wrappers.interactive.NPC;
- 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.api.Manifest;
- import org.powerbot.game.api.methods.interactive.NPCs;
- import org.powerbot.game.api.methods.interactive.Players;
- import org.powerbot.game.api.methods.Walking;
- import org.powerbot.game.api.util.Filter;
- import org.powerbot.game.api.util.Random;
- import org.powerbot.game.api.util.Timer;
- import org.powerbot.game.api.methods.Game;
- import org.powerbot.game.api.methods.Calculations;
- import org.powerbot.game.api.methods.Widgets;
- import org.powerbot.game.api.methods.input.Mouse;
- import org.powerbot.game.api.methods.tab.Inventory;
- import org.powerbot.game.api.methods.node.SceneEntities;
- import org.powerbot.game.api.methods.tab.Skills;
- import org.powerbot.game.api.wrappers.map.Path;
- @Manifest(authors = {"MGakowski(Jake)"},
- name = "Power Miner",
- version = .1,
- description = "Mines and banks: Clay, Copper, Tin, Iron")
- public class PowerMiner10 extends ActiveScript implements PaintListener {
- double version = getClass().getAnnotation(Manifest.class).version();
- private double hours, minutes, seconds;
- private long starttime, display_hours, display_minutes, display_seconds;
- private int ore_objectIDs[], oreID;
- private int clay_objectIDs[] = {15504, 2419, 2108, 2109, 14904, 14905};
- private int copper_objectIDs[] = {11937, 11960, 11961, 11962};
- private int tin_objectIDs[] = {11933, 11934, 11935, 11957, 11958, 11959 };
- private int iron_objectIDs[] = {11954, 11955, 11956, 2092, 2093, 37307, 37308, 37309};
- private int clay_oreID = 434,copper_oreID = 436, tin_oreID = 438, iron_oreID = 440;
- int[] strangerockIDs = {15532};
- String ore_type;
- String displayname;
- final static Tile NearBank = new Tile(3169, 3424, 0);
- final static Tile Mine = new Tile(3183, 3378, 0);
- //Path
- Tile[] ToMine = new Tile[] { new Tile(3176, 3434, 0), new Tile(3170, 3425, 0), new Tile(3167, 3407, 0),
- new Tile(3176, 3383, 0), new Tile(3179, 3380, 0), new Tile(3183, 3380, 0),
- new Tile(3182, 3378, 0) };
- private static Path path = null;
- int startinglevel;
- double startingexperience;
- int currentlevel;
- int levelsgained;
- double currentexperience;
- double experiencegained;
- double experienceperhour;
- double experiencetonextlevel;
- int percenttonextlevel;
- private GUI mygui;
- boolean onstartHasRan = false;
- public void onStart() {
- mygui = new GUI();
- mygui.setVisible(true);
- while (mygui.isVisible() && isActive()) {
- Task.sleep(1000);
- }
- mygui.dispose();
- startinglevel = Skills.getRealLevel(Skills.MINING);
- startingexperience = Skills.getExperience(Skills.MINING);
- starttime = System.currentTimeMillis();
- onstartHasRan = true;
- }
- //main loop
- public int loop() {
- if (!onstartHasRan) {
- return 100;
- }
- managerunmode();
- if (Players.getLocal().isIdle()) {
- if (Inventory.isFull()) {
- walkTo(NearBank);
- bank();
- destroystrangerocks();
- }else{
- SceneObject rock = SceneEntities.getNearest(ore_objectIDs);
- if (rock != null) {
- if (Calculations.distanceTo(rock) < 4) {
- rock.interact("Mine", rock.getDefinition().getName());
- Task.sleep(700, 1000);
- }else{
- Walking.walk(rock.getLocation());
- Task.sleep(500, 800);
- }if (Calculations.distanceTo(rock) > 4){
- toMine();
- }
- }
- }
- }
- return Random.nextInt(300, 500);
- }
- //My Other Methods
- private void toBank() {
- walkTo(NearBank);
- }
- private void toMine() {
- walkTo(Mine);
- }
- private void bank() {
- open();
- depositInventory();
- }
- private static boolean walkTo(final Tile NearBank) {
- if (path == null) {
- path = Walking.findPath(NearBank);
- }
- if (!path.validate()) {
- path = null;
- } else {
- return path.traverse();
- }
- return false;
- }
- public static boolean close() {
- if (!isOpen()) {
- return true;
- }
- final WidgetChild closeButton = Widgets.get(WIDGET_BANK, WIDGET_BUTTON_CLOSE_BANK);
- return closeButton != null && closeButton.interact("Close");
- }
- public static boolean isOpen() {
- final Widget bank = getWidget();
- return bank != null && bank.validate();
- }
- public static boolean depositInventory() {
- if (!isOpen()) {
- return false;
- }
- if (Inventory.getCount() == 0) {
- return true;
- }
- final WidgetChild child = Widgets.get(WIDGET_BANK, WIDGET_BUTTON_DEPOSIT_INVENTORY);
- final int invCount = Inventory.getCount();
- if (child != null && child.click(true)) {
- final Timer t = new Timer(2000);
- while (t.isRunning() && Inventory.getCount() == invCount) {
- Task.sleep(5);
- }
- }
- return invCount != Inventory.getCount();
- }
- public static boolean open() {
- if (isOpen()) {
- return true;
- }
- final Entity bank = getNearest();
- if (bank == null) {
- return false;
- }
- if (!bank.isOnScreen() && (!Players.getLocal().isMoving()
- || Calculations.distance(Walking.getDestination(), ((Locatable) bank).getLocation()) > 4)) {
- Walking.walk((Locatable) bank);
- Task.sleep(200, 400);
- }
- if (bank.isOnScreen()) {
- boolean interacted = false;
- if (isBanker((Identifiable) bank)) {
- interacted = bank.interact("Bank");
- }
- //other identifiable
- final Widget bankpin = Widgets.get(WIDGET_BANKPIN);
- final Timer t = new Timer(4000);
- while (t.isRunning() && interacted && !isOpen() && (bankpin == null || !bankpin.validate())) {
- Task.sleep(10);
- }
- }
- return isOpen();
- }
- private static boolean isBanker(final Identifiable identifiable) {
- Arrays.sort(BANK_NPC_IDS);
- return identifiable instanceof NPC && Arrays.binarySearch(BANK_NPC_IDS, identifiable.getId()) >= 0;
- }
- public static final int[] BANK_NPC_IDS = new int[]{
- 44, 45, 166, 494, 495, 496, 497, 498, 499, 553, 909, 953, 958, 1036, 1360, 1702, 2163, 2164, 2354, 2355,
- 2568, 2569, 2570, 2617, 2618, 2619, 2718, 2759, 3046, 3198, 3199, 3293, 3416, 3418, 3824, 4456, 4457,
- 4458, 4459, 4519, 4907, 5257, 5258, 5259, 5260, 5488, 5776, 5777, 5901, 6200, 6362, 7049, 7050, 7605,
- 8948, 9710, 13932, 14707, 14923, 14924, 14925, 15194
- };
- public static final int[] BANKERS = new int[]{
- 44, 45, 166, 494, 495, 496, 497, 498, 499, 553, 909, 953, 958, 1036, 1360, 1702, 2163, 2164, 2354, 2355,
- 2568, 2569, 2570, 2617, 2618, 2619, 2718, 2759, 3046, 3198, 3199, 3293, 3416, 3418, 3824, 4456, 4457,
- 4458, 4459, 4519, 4907, 5257, 5258, 5259, 5260, 5488, 5776, 5777, 5901, 6200, 6362, 7049, 7050, 7605,
- 8948, 9710, 13932, 14707, 14923, 14924, 14925, 15194
- };
- public static Entity getNearest() {
- final Locatable[] banks = getLoadedBanks();
- Locatable nearest = null;
- for (final Locatable bank : banks) {
- if (ALL_FILTER.accept((Identifiable) bank) && ((Entity) bank).validate()) {
- if ((nearest == null || Calculations.distanceTo(bank) < Calculations.distanceTo(nearest))) {
- nearest = bank;
- }
- }
- }
- return (Entity) nearest;
- }
- private static final Filter<Identifiable> ALL_FILTER = new Filter<Identifiable>() {
- @Override
- public boolean accept(final Identifiable bank) {
- if ((!isBanker(bank))) {
- return false;
- }
- for (final Tile badTile : UNREACHABLE_BANK_TILES) {
- if (((Locatable) bank).getLocation().equals(badTile)) {
- return false;
- }
- }
- return true;
- }
- };
- private static Locatable[] getLoadedBanks() {
- final ArrayList<Locatable> banks = new ArrayList<Locatable>();
- final NPC[] loadedNPCs = NPCs.getLoaded(BANK_NPC_IDS);
- for (final NPC npc : loadedNPCs) {
- if (npc.validate() && ALL_FILTER.accept(npc)) {
- banks.add(npc);
- }
- }
- //SceneObject BU
- return banks.toArray(new Locatable[banks.size()]);
- }
- public static Widget getWidget() {
- return Widgets.get(WIDGET_BANK);
- }
- public static final int WIDGET_BANK = 762;
- public static final int WIDGET_SLOTS_CONTAINER = 95;
- public static final int WIDGET_SCROLLBAR = 116;
- public static final int WIDGET_BUTTON_CLOSE_BANK = 45;
- public static final int WIDGET_BUTTON_DEPOSIT_INVENTORY = 34;
- public static final int WIDGET_BUTTON_DEPOSIT_EQUIPMENT = 38;
- public static final int WIDGET_BUTTON_DEPOSIT_FAMILIAR = 40;
- public static final int WIDGET_BUTTON_DEPOSIT_POUCH = 36;
- public static final int WIDGET_BUTTON_SEARCH = 18;
- public static final int WIDGET_BUTTON_WITHDRAW_NOTED = 20;
- public static final int WIDGET_BANKPIN = 13;
- public static final int SETTING_WITHDRAWAL_MODE = 160;
- public static final int SETTING_BANK_TAB = 110;
- public static final Tile[] UNREACHABLE_BANK_TILES = new Tile[]{
- new Tile(3191, 3445, 0), new Tile(3180, 3433, 0)
- };
- //My Other Methods End
- private void destroystrangerocks() {
- while (Inventory.getCount(strangerockIDs) > 0 && isActive() && Game.isLoggedIn()) {
- if (widgetisValid(1183, 17)) {
- click_widget(1183, 17);
- Task.sleep(700, 1000);
- }else{
- Inventory.getItem(strangerockIDs).getWidgetChild().interact("Destroy");
- Task.sleep(1000, 1300);
- }
- }
- }
- public static boolean widgetisValid(int parentID, int childID) {
- Widget parent = Widgets.get(parentID);
- if (parent != null) {
- WidgetChild child = parent.getChild(childID);
- if (child != null && child.validate()) {
- return true;
- }
- }
- return false;
- }
- public void click_widget(int parentID, int childID) {
- Widget parent = Widgets.get(parentID);
- if (parent != null) {
- WidgetChild child = parent.getChild(childID);
- if (child != null) {
- child.click(true);
- }
- }
- }
- public boolean widget_contains_text(int parentID, int childID, String text) {
- Widget parent = Widgets.get(parentID);
- if (parent != null) {
- WidgetChild child = parent.getChild(childID);
- if (child != null) {
- if (child.getText() != null && child.getText().contains(text)) {
- return true;
- }
- }
- }
- return false;
- }
- private void managerunmode() {
- if (!Walking.isRunEnabled() && Walking.getEnergy() >= Random.nextInt(50, 80)) {
- Task.sleep(300, 500);
- Walking.setRun(true);
- Task.sleep(900, 1300);
- }
- }
- public void onFinish() {
- System.out.println(displayname + " Stopped after " + display_hours + " Hours and " + display_minutes + " minutes of play");
- System.out.println("Levels Gained: " + levelsgained);
- System.out.println("Experience Gained: " + experiencegained);
- System.out.println("Experience / Hour: " + formatdouble(experienceperhour));
- }
- public void onRepaint(Graphics g) {
- if (!onstartHasRan) {
- return;
- }
- Point m = Mouse.getLocation();
- g.setColor(Color.cyan);
- g.drawRoundRect(m.x - 6, m.y, 15, 3, 5, 5);
- g.drawRoundRect(m.x, m.y - 6, 3, 15, 5, 5);
- g.fillRoundRect(m.x - 6, m.y, 15, 3, 5, 5);
- g.fillRoundRect(m.x, m.y - 6, 3, 15, 5, 5);
- //draw background
- g.setColor(new Color(0, 0, 0, 180));
- g.fillRect(350, 5, 165, 168);
- g.setColor(Color.white);
- g.setFont(new Font("Tahoma", Font.BOLD, 11));
- g.drawString("Power Miner " + version, 355, 20);
- g.setColor(Color.red);
- g.setFont(new Font("Tahoma", Font.PLAIN, 11));
- double milliseconds = System.currentTimeMillis() - starttime;
- seconds = milliseconds / 1000;
- minutes = seconds / 60;
- hours = minutes / 60;
- display_hours = (long)seconds / 3600;
- long remaining_seconds = (long)seconds - ( display_hours * 3600 );
- display_minutes = remaining_seconds / 60;
- display_seconds = remaining_seconds - ( display_minutes * 60 );
- g.drawString("Time: " + display_hours + ":" + display_minutes + ":" + display_seconds , 355, 35);
- g.setColor(Color.red);
- g.setFont(new Font("Tahoma", Font.PLAIN, 11));
- currentlevel = Skills.getRealLevel(Skills.MINING);
- levelsgained = currentlevel - startinglevel;
- currentexperience = Skills.getExperience(Skills.MINING);
- experiencegained = currentexperience - startingexperience;
- experienceperhour = experiencegained / hours;
- experiencetonextlevel = Skills.getExperienceToLevel(Skills.MINING, Skills.getLevel(Skills.MINING) + 1);
- //percenttonextlevel = Skills.getPercentToNextLevel(Skills.MINING);
- //fill red bar
- g.fillRect(355, 163, 100, 4);
- g.drawString("Mining: " + ore_type, 355, 50);
- g.drawString("Current level: " + currentlevel, 355, 65);
- g.drawString("Levels Gained: " + levelsgained, 355, 80);
- g.drawString("Current Exp: " + currentexperience, 355, 95);
- g.drawString("Exp Gained: " + experiencegained, 355, 110);
- g.drawString("Exp / Hour: " + formatdouble(experienceperhour), 355, 125);
- g.drawString("Exp TNL: " + experiencetonextlevel, 355, 140);
- double experience_per_millisecond = ( (double)experiencegained ) / milliseconds;
- if (experiencegained == 0) {
- g.drawString("Time TNL: ", 355, 155);
- }else{
- double milliseconds_to_next_level = (experiencetonextlevel / experience_per_millisecond);
- g.drawString("Time TNL: " + formatTime(milliseconds_to_next_level), 355, 155);
- }
- //fillgreenbar
- g.setColor(Color.GREEN);
- g.fillRect(355, 163, percenttonextlevel, 4);
- }
- private String formatTime(double time) {
- final int sec = (int) (time / 1000), h = sec / 3600, m = sec / 60 % 60, s = sec % 60;
- return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":"
- + (s < 10 ? "0" + s : s);
- }
- private String formatdouble(double input) {
- //should round to 2 decemal places before format
- String formattedmoney;
- formattedmoney = String.format("%.0f", (input));
- if (input >= 1000 & input < 1000000) {
- input = input / 1000;
- formattedmoney = String.format("%.1fk", (input));
- }
- if (input >= 1000000) {
- input = input / 1000000;
- formattedmoney = String.format("%.1fm", (input));
- }
- return formattedmoney;
- }
- @SuppressWarnings("serial")
- public class GUI extends JFrame {
- public GUI() {
- initComponents();
- }
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private void initComponents() {
- foodbox = new JComboBox();
- button1 = new JButton();
- setTitle("GUI");
- setAlwaysOnTop(true);
- setResizable(false);
- setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
- Container contentPane = getContentPane();
- contentPane.setLayout(null);
- addWindowListener(new java.awt.event.WindowAdapter() {
- public void windowClosing(WindowEvent winEvt) {
- setVisible(false);
- stop();
- }
- });
- contentPane.add(foodbox);
- foodbox.setModel(new DefaultComboBoxModel(new String[] {
- "Clay", "Iron", "Copper", "Tin", "Rocks"}));
- foodbox.setBounds(5, 5, 130, foodbox.getPreferredSize().height);
- contentPane.add(button1);
- button1.setText("Start");
- button1.setBounds(5, 93, 125, button1.getPreferredSize().height);
- button1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if (foodbox.getSelectedItem().equals("Copper")) {
- oreID = copper_oreID;
- ore_objectIDs = copper_objectIDs;
- ore_type = "Copper";
- } else if (foodbox.getSelectedItem().equals("Tin")) {
- oreID = tin_oreID;
- ore_objectIDs = tin_objectIDs;
- ore_type = "Tin";
- } else if (foodbox.getSelectedItem().equals("Iron")) {
- oreID = iron_oreID;
- ore_objectIDs = iron_objectIDs;
- ore_type = "Iron";
- } else if (foodbox.getSelectedItem().equals("Clay")) {
- oreID = clay_oreID;
- ore_objectIDs = clay_objectIDs;
- ore_type = "Clay";
- } else if (foodbox.getSelectedItem().equals("Rocks")) {
- oreID = clay_oreID;
- ore_objectIDs = clay_objectIDs;
- ore_type = "Clay";
- }
- setVisible(false);
- }
- });
- setSize(150, 150);
- setLocationRelativeTo(getOwner());
- }
- @SuppressWarnings("rawtypes")
- private JComboBox foodbox;
- private JButton button1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement