Skip to content

Instantly share code, notes, and snippets.

@bespike
Forked from beaumitch/TehnoobSmelter
Created August 27, 2012 15:10
Show Gist options
  • Save bespike/3489362 to your computer and use it in GitHub Desktop.
Save bespike/3489362 to your computer and use it in GitHub Desktop.
AIO Smelter
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
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.Game;
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.Keyboard;
import org.powerbot.game.api.methods.input.Mouse;
import org.powerbot.game.api.methods.interactive.Players;
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.methods.widget.Bank;
import org.powerbot.game.api.methods.widget.Camera;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.util.Time;
import org.powerbot.game.api.util.Timer;
import org.powerbot.game.api.wrappers.Area;
import org.powerbot.game.api.wrappers.Tile;
import org.powerbot.game.api.wrappers.node.SceneObject;
import org.powerbot.game.api.wrappers.widget.WidgetChild;
import org.powerbot.game.bot.event.listener.PaintListener;
@Manifest(authors = { "beaumitch" }, name = "tehnoobSmelter", version = 2.8, description = "Smelts at all furnaces, making all bars or cannonballs.", website = "http://www.powerbot.org/community/topic/703184-beaumitchs-aio-smelter-bronze-rune-and-cannonballs-al-kharid/")
public class TehnoobSmelter extends ActiveScript implements PaintListener {
boolean guiDone = false;
boolean loggingOut = false;
Bars selectedBar = Bars.BRONZE;
Furnaces selectedFurnace = Furnaces.ALKHARID;
String BANK_PIN = "0000";
Timer bTimer = new Timer(2500);
Timer giftTimer = new Timer(0);
boolean gift = false;
Tile edgeBTile = new Tile(3096, 3496, 0);
public enum Bars {
BRONZE(new int[] { 438, 436 }, new int[] { 1, 1 }, 2349, 14),
IRON(new int[] { 440 }, new int[] { 1 }, 2351, 16),
SILVER(new int[] { 442 }, new int[] { 1 }, 2351, 17),
STEEL(new int[] {440, 453 }, new int[] { 1, 2 }, 2353, 18),
GOLD(new int[] { 444 }, new int[] { 1 }, 2357, 19),
MITHRIL(new int[] { 447, 453 }, new int[] { 1, 4 }, 2359, 20),
ADAMANT(new int[] { 449, 453 }, new int[] { 1, 6 }, 2361, 21),
RUNE(new int[] { 451, 453 }, new int[] { 1, 8 }, 2363, 22),
CANNONBALLS(new int[] { 2353 }, new int[] { 1 }, 2, 14);
private final int[] ore;
private final int[] oreAmount;
private final int bar;
private final int barWidget;
Bars(final int[] ore, final int[] oreAmount, final int bar,
final int barWidget) {
this.ore = ore;
this.oreAmount = oreAmount;
this.bar = bar;
this.barWidget = barWidget;
}
public int[] getOre() {
return this.ore;
}
public int[] getOreAmount() {
return this.oreAmount;
}
public int getBar() {
return this.bar;
}
public WidgetChild getBarWidget() {
return Widgets.get(905, barWidget);
}
}
public enum Furnaces {
ALKHARID(new Area(new Tile(3280, 3189, 0), new Tile(3271, 3183, 0)),
new Area(new Tile(3273, 3174, 0), new Tile(3264, 3160, 0)),
11666, new Tile(3274, 3186, 0)),
/*
* TODO increase size of edgeville area to reduce misclicks
*
*/
EDGEVILLE(new Area(new Tile(3105, 3496, 0), new Tile(3112, 3503, 0)),
new Area(new Tile(3099, 3495, 0), new Tile(3094, 3500, 0)),
26814, new Tile(3109, 3501, 0)),
PORT_PHASMATYS(new Area(new Tile(3681, 3476, 0), new Tile(3690, 3482, 0)),
new Area(new Tile(3685, 3470, 0), new Tile(3692, 3465, 0)),
11666, new Tile(3687, 3479, 0));
private final Area furnaceArea;
private final Area bankArea;
private final int furnaceId;
private final Tile smeltTile;
Furnaces(final Area furnaceArea, final Area bankArea,
final int furnaceId, final Tile smeltTile) {
this.furnaceArea = furnaceArea;
this.bankArea = bankArea;
this.furnaceId = furnaceId;
this.smeltTile = smeltTile;
}
public Area getArea() {
return this.furnaceArea;
}
public Area getBankArea() {
return this.bankArea;
}
public int getFurnaceId() {
return this.furnaceId;
}
public Tile getSmeltTile() {
return this.smeltTile;
}
}
final String[] furnaceName = { "Al-Kharid" };
final String[] barName = { "Bronze", "Iron", "Silver", "Steel", "Gold",
"Mithril", "Adamant", "Rune", "Cannonball" };
String status = "";
Timer smeltTimer = new Timer(3400);
// Statistics/Paint variables //
int smelted = 0;
Timer timeRun = new Timer(0);
int startExp = 0;
int prevExp = 0;
@Override
protected void setup() {
status = "Setting up...";
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
(new SmelterGUI()).setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
DoorHandler handle = new DoorHandler();
provide(new Strategy(handle, handle));
Smelter smelt = new Smelter();
provide(new Strategy(smelt, smelt));
Banker bank = new Banker();
provide(new Strategy(bank, bank));
Walker walk = new Walker();
provide(new Strategy(walk, walk));
Antiban ab = new Antiban();
provide(new Strategy(ab, ab));
BankPin p = new BankPin();
provide(new Strategy(p, p));
provide(new LogOut());
}
private class Smelter extends Strategy implements Task {
public boolean validate() {
return guiDone
&& (selectedFurnace.getArea().contains(
Players.getLocal().getLocation())
&& hasOre() && !isSmelting() && !needPin());
}
public void run() {
SceneObject furnace = SceneEntities.getNearest(selectedFurnace
.getFurnaceId());
WidgetChild option = selectedBar.getBarWidget();
if (!Tabs.INVENTORY.open(false)) {
return;
}
if (selectedBar == Bars.CANNONBALLS && !option.validate()) {
log.info("Doing cannonball method..");
if (Inventory.getCount(selectedBar.ore) > 0 ) {
if (isSmelting()) {
return;
}
if (Inventory.getSelectedItem() != null && Inventory.getSelectedItem().getId() == Bars.CANNONBALLS.getOre()[0]) {
if (furnace.interact("Use", "Steel Bar -> Furnace")) {
Timer t = new Timer(900);
while (t.isRunning() && selectedBar.getBarWidget() != null && !selectedBar.getBarWidget().validate()) {
Time.sleep(30);
}
}
return;
}
Inventory.getItem(Bars.CANNONBALLS.getOre())
.getWidgetChild().click(true);
Timer count = new Timer(300);
while (count.isRunning() && Inventory.getSelectedItem().getId() == Bars.CANNONBALLS.getOre()[0]) {
Time.sleep(20);
}
}
return;
}
if (option != null && !option.validate()) {
furnace.interact("Smelt");
status = "Interacting with furnace...";
} else {
option.interact("Make All");
Time.sleep(selectedBar == Bars.CANNONBALLS ? 3600 : 1800);
status = "Clicking 'Make All'...";
}
}
}
private class Banker extends Strategy implements Task {
public boolean validate() {
return guiDone
&& selectedFurnace.getBankArea().contains(Players.getLocal())
&& !hasOre()
&& !needPin();
}
public void run() {
if (!Tabs.INVENTORY.open()) {
return;
}
final int giftBoxId = 14664;
if (Inventory.getCount(giftBoxId) > 0 && gift) {
if (giftTimer.isRunning()) {
return;
} else {
if (Bank.isOpen()) {
Bank.close();
return;
}
gift = !Inventory.getItem(giftBoxId).getWidgetChild().interact("Drop");
return;
}
} else if (Inventory.getCount(giftBoxId) > 0) {
gift = true;
giftTimer.setEndIn(15000);
}
if (!Bank.isOpen() && !bTimer.isRunning()) {
Bank.open();
//log.info("Opening bank...");
bTimer.setEndIn(Random.nextInt(3000, 4500));
return;
} else if (!Bank.isOpen()) {
return;
}
if (Inventory.getCount(true) > 0 && !hasOre()) {
Bank.depositInventory();
status = "Depositing entire inventory...";
return;
}
int oreSum = 0;
for (int i : selectedBar.getOreAmount()) {
oreSum += i;
}
if (oreSum < 1) {
//log.info("Amount of ores needed per bar is 0?");
return;
}
final int oreMult = 28 / oreSum;
final int oreCount[] = new int[selectedBar.getOre().length];
for (int i = 0; i < oreCount.length; i++) {
oreCount[i] = oreMult * selectedBar.getOreAmount()[i];
}
for (int i = 0; i < selectedBar.getOre().length; i++) {
if (Inventory.getCount(selectedBar.getOre()[i]) < oreCount[i]) {
log.info("Trying to withdraw " + oreCount[i] + " of ID "
+ selectedBar.getOre()[i] + " ore.");
/* TODO testing of logout methods - reliability of Bank#getItemCount()
if (Bank.getItemCount(selectedBar.getOre()[i]) == 0) {
loggingOut = true;
Bank.close();
return;
}
*/
if (i == selectedBar.getOre().length - 1) {
if (!Bank.withdraw(selectedBar.getOre()[i], 0)) {
Time.sleep(150);
break;
}
Time.sleep(150);
continue;
}
if (!Bank.withdraw(selectedBar.getOre()[i], oreCount[i]
- Inventory.getCount(selectedBar.getOre()[i]))) {
Time.sleep(150);
break;
}
Time.sleep(300);
}
}
}
}
private class Walker extends Strategy implements Task {
public boolean validate() {
return guiDone && !needPin();
}
public void run() {
if (Walking.getEnergy() > Random.nextInt(20, 50))
Walking.setRun(true);
if (needWalk()) {
status = "Walking to furnace...";
if (Walking.getDestination() != null &&
Calculations.distance(Walking.getDestination(), Walking.findPath(selectedFurnace.getArea().getCentralTile())
.getNext()) < 5) {
return;
} else {
if (selectedFurnace != Furnaces.EDGEVILLE)
Walking.walk(Walking.findPath(selectedFurnace.getSmeltTile()).getNext().randomize(1, 1));
else
Walking.walk(Walking.findPath(selectedFurnace.getArea().getCentralTile()).getNext().randomize(1, 1));
}
bTimer.setEndIn(4500);
return;
}
if (!Tabs.INVENTORY.open(false)) {
return;
}
if (!hasOre() && !bTimer.isRunning()
&& !selectedFurnace.getBankArea().contains(
Players.getLocal().getLocation())) {
status = "Walking to bank...";
if (Walking.getDestination() != null &&
Calculations.distance(Walking.getDestination(), Walking.findPath(selectedFurnace.getBankArea().getCentralTile())
.getNext()) < 5) {
return;
} else {
if (!selectedFurnace.equals(Furnaces.EDGEVILLE))
Walking.walk(Walking.findPath(selectedFurnace.getBankArea().getCentralTile())
.getNext().randomize(1, 1));
else
Walking.walk(Walking.findPath(edgeBTile)
.getNext().randomize(1, 1));
return;
}
}
}
}
private class Antiban extends Strategy implements Task {
public boolean validate() {
return guiDone
&& (Random.nextInt(0, 500) == 5 && !Bank.isOpen() && !needPin());
}
public void run() {
if (isSmelting()) {
log.info("AntiBan triggered:");
final int r = Random.nextInt(0, 2);
switch (r) {
case 0:
log.info("Examining a random item");
Inventory.getItems()[Random
.nextInt(0, Inventory.getCount())].getWidgetChild()
.interact("Examine");
break;
case 1:
log.info("Turning the camera randomly");
Camera.setAngle(Random.nextInt(0, 360));
break;
case 2:
String[] randTextOptions = { "Lol", "Rofl", "Lmao",
"Smithing lvls?", ":D", ":(", "So many bots here",
"Stupid bots", "Anyone here not botting rofl",
"Uhg", "Wtf", "Omg" };
String randText = randTextOptions[Random.nextInt(0,
randTextOptions.length - 1)];
log.info("Sending random text: " + randText);
Keyboard.sendText(randText, true);
break;
}
} else {
log.info("AntiBan triggered:");
final int r = Random.nextInt(0, 3);
switch (r) {
case 0:
log.info("Examining a random item");
Inventory.getItems()[Random
.nextInt(0, Inventory.getCount())].getWidgetChild()
.interact("Examine");
break;
case 1:
log.info("Turning camera randomly");
Camera.setAngle(Random.nextInt(0, 360));
break;
case 2:
log.info("Hovering over smithing skill");
Tabs.STATS.open();
Skills.getWidgetChild(Skills.SMITHING).hover();
break;
case 3:
String[] randTextOptions = { "Lol", "Rofl", "Lmao",
"Smithing lvls?", ":D", ":(", "So many bots here",
"Stupid bots", "Anyone here not botting rofl",
"Uhg", "Wtf", "Omg" };
String randText = randTextOptions[Random.nextInt(0,
randTextOptions.length - 1)];
log.info("Sending random text: " + randText);
Keyboard.sendText(randText, true);
}
}
}
}
private class BankPin extends Strategy implements Task {
public boolean validate() {
return guiDone && needPin();
}
public void run() {
log.info("Entering pin!");
final int relativity = 6;
WidgetChild textWidget = Widgets.get(13, 28);
int n = -1;
if (textWidget.getText().contains("FIRST")) {
n = 0;
}
if (textWidget.getText().contains("SECOND")) {
n = 1;
}
if (textWidget.getText().contains("THIRD")) {
n = 2;
}
if (textWidget.getText().contains("FOURTH")) {
n = 3;
}
if (n == -1) {
log.info("Text was null.");
return;
}
log.info("Character: " + n);
log.info("" + BANK_PIN.toCharArray()[n]);
Widgets.get(
13,
relativity
+ Integer.parseInt(Character.toString(BANK_PIN
.toCharArray()[n]))).interact("Select");
}
}
private class LogOut extends Strategy implements Task {
public boolean validate() {
return loggingOut;
}
public void run() {
if (Bank.isOpen()) {
Bank.close();
}
Game.logout(true);
}
}
public boolean isSmelting() {
final int animation = 3243;
final int cannonballAnimation = 827;
if (Players.getLocal().getAnimation() == animation) {
smeltTimer.reset();
return true;
}
if (Players.getLocal().getAnimation() == cannonballAnimation) {
smeltTimer.setEndIn(5000);
}
return (smeltTimer.isRunning());
}
public boolean needPin() {
WidgetChild pinWindow = Widgets.get(13, 0);
return pinWindow.validate();
}
public boolean hasOre() {
Tabs.INVENTORY.open();
for (int i = 0; i < selectedBar.getOre().length; i++) {
if (Inventory.getCount(selectedBar.getOre()[i]) < selectedBar
.getOreAmount()[i]) {
return false;
}
}
return true;
}
public boolean needWalk() {
return (hasOre() && !selectedFurnace.getArea().contains(
Players.getLocal().getLocation()));
}
private class DoorHandler extends Strategy implements Task {
public boolean validate() {
return (selectedFurnace.equals(Furnaces.PORT_PHASMATYS) && !isSmelting());
}
public void run() {
final int doorId = 5244;
final Tile doorTile = new Tile(3684, 3476, 0);
if (!selectedFurnace.getBankArea().contains(Players.getLocal().getLocation())
|| Walking.findPath(selectedFurnace.getSmeltTile()).getNext() == null) {
SceneObject door = SceneEntities.getAt(doorTile, doorId);
if (door != null && door.isOnScreen()) {
door.interact("Open");
} else if (door != null) {
Walking.walk(door);
}
}
}
}
private final Color color1 = new Color(153, 255, 255, 148);
private final Color color2 = new Color(153, 255, 255, 80);
private final Color color3 = new Color(0, 0, 0);
private final BasicStroke stroke1 = new BasicStroke(1);
private final Font font1 = new Font("Arial", 1, 14);
private final Font font2 = new Font("Arial", 0, 12);
public void onRepaint(Graphics g) {
if (startExp == 0) {
startExp = Skills.getExperience(Skills.SMITHING);
prevExp = startExp;
}
if (prevExp != Skills.getExperience(Skills.SMITHING)) {
smelted++;
prevExp = Skills.getExperience(Skills.SMITHING);
}
g.setColor(color1);
g.fillRoundRect(554, 377, 176, 82, 16, 16);
g.setColor(color2);
((Graphics2D) g).setStroke(stroke1);
g.drawRoundRect(554, 377, 176, 82, 16, 16);
g.setFont(font1);
g.setColor(color3);
g.drawString("Beaumitch's Smelter", 570, 393);
g.setFont(font2);
g.drawString("Time run: " + timeRun.toElapsedString(), 558, 406);
String t = null;
if (selectedBar.equals(Bars.CANNONBALLS)) {
t = "Cannonballs made: " + (smelted * 4);
} else {
t = selectedBar.toString().toCharArray()[0] + selectedBar.toString().substring(1).toLowerCase() + " bars made: " + smelted;
}
g.drawString(t, 558, 419);
double perSec = (smelted) / (double) (timeRun.getElapsed() / 1000);
int perHour = (int) Math.round(perSec * 3600);
g.drawString("Bars per hour: " + perHour, 558, 431);
g.drawString("Exp gained: "
+ (Skills.getExperience(Skills.SMITHING) - startExp), 558, 443);
perSec = (Skills.getExperience(Skills.SMITHING) - startExp)
/ (double) (timeRun.getElapsed() / 1000);
perHour = (int) Math.round(perSec * 3600);
g.drawString("Exp per hour: " + perHour, 558, 455);
g.setColor(Color.BLACK);
g.drawLine(0, Mouse.getY(), (int) Game.getDimensions().getWidth(),
Mouse.getY());
g.drawLine(Mouse.getX(), 0, Mouse.getX(), (int) Game.getDimensions()
.getHeight());
}
public class SmelterGUI extends JFrame {
private static final long serialVersionUID = 1L;
public SmelterGUI() {
initComponents();
}
private void okButtonMouseClicked(MouseEvent e) {
selectedBar = (Bars) comboBox1.getItemAt(comboBox1.getSelectedIndex());
selectedFurnace = (Furnaces) comboBox2.getItemAt(comboBox2.getSelectedIndex());
BANK_PIN = textField1.getText();
guiDone = true;
this.dispose();
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY
// //GEN-BEGIN:initComponents
// Generated using JFormDesigner Evaluation license - beaumitch beau
okButton = new JButton();
label1 = new JLabel();
panel1 = new JPanel();
label2 = new JLabel();
comboBox1 = new JComboBox();
label3 = new JLabel();
comboBox2 = new JComboBox();
label4 = new JLabel();
textField1 = new JTextField();
// ======== this ========
setAlwaysOnTop(true);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
// ---- okButton ----
okButton.setText("Start!");
okButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
okButtonMouseClicked(e);
}
});
contentPane.add(okButton, BorderLayout.SOUTH);
// ---- label1 ----
label1.setText("Tehnoob AIO Smelter");
label1.setFont(label1.getFont().deriveFont(
label1.getFont().getSize() + 9f));
label1.setHorizontalAlignment(SwingConstants.CENTER);
contentPane.add(label1, BorderLayout.NORTH);
// ======== panel1 ========
{
// JFormDesigner evaluation mark
panel1.setBorder(new javax.swing.border.CompoundBorder(
new javax.swing.border.TitledBorder(
new javax.swing.border.EmptyBorder(0, 0, 0, 0),
"", javax.swing.border.TitledBorder.CENTER,
javax.swing.border.TitledBorder.BOTTOM,
new java.awt.Font("Dialog", java.awt.Font.BOLD,
12), java.awt.Color.red), panel1
.getBorder()));
panel1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent e) {
if ("border".equals(e.getPropertyName()))
throw new RuntimeException();
}
});
panel1.setLayout(new GridBagLayout());
// ---- label2 ----
label2.setText("What to smelt: ");
label2.setFont(label2.getFont().deriveFont(
label2.getFont().getSize() + 3f));
panel1.add(label2, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));
// ---- comboBox1 ----
comboBox1
.setModel(new DefaultComboBoxModel(Bars.values()));
comboBox1.setFont(comboBox1.getFont().deriveFont(
comboBox1.getFont().getSize() + 3f));
panel1.add(comboBox1, new GridBagConstraints(1, 0, 1, 1, 0.0,
0.0, GridBagConstraints.CENTER,
GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0));
// ---- label3 ----
label3.setText("What furnace: ");
label3.setFont(label3.getFont().deriveFont(
label3.getFont().getSize() + 3f));
panel1.add(label3, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 5), 0, 0));
// ---- comboBox2 ----
comboBox2.setModel(new DefaultComboBoxModel(Furnaces
.values()));
comboBox2.setFont(comboBox2.getFont().deriveFont(
comboBox2.getFont().getSize() + 3f));
panel1.add(comboBox2, new GridBagConstraints(1, 1, 1, 1, 0.0,
0.0, GridBagConstraints.CENTER,
GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0));
// ---- label4 ----
label4.setText("Bank pin: ");
label4.setFont(label4.getFont().deriveFont(
label4.getFont().getSize() + 3f));
panel1.add(label4, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 5), 0, 0));
// ---- textField1 ----
textField1.setFont(textField1.getFont().deriveFont(
textField1.getFont().getSize() + 3f));
textField1.setText("0000");
panel1.add(textField1, new GridBagConstraints(1, 2, 1, 1, 0.0,
0.0, GridBagConstraints.CENTER,
GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
}
contentPane.add(panel1, BorderLayout.CENTER);
setSize(230, 180);
setLocationRelativeTo(getOwner());
// JFormDesigner - End of component initialization
// //GEN-END:initComponents
}
// JFormDesigner - Variables declaration - DO NOT MODIFY
// //GEN-BEGIN:variables
// Generated using JFormDesigner Evaluation license - beaumitch beau
private JButton okButton;
private JLabel label1;
private JPanel panel1;
private JLabel label2;
private JComboBox comboBox1;
private JLabel label3;
private JComboBox comboBox2;
private JLabel label4;
private JTextField textField1;
// JFormDesigner - End of variables declaration //GEN-END:variables
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment