Skip to content

Instantly share code, notes, and snippets.

@phl0w
Created June 18, 2012 13:50
Show Gist options
  • Select an option

  • Save phl0w/2948464 to your computer and use it in GitHub Desktop.

Select an option

Save phl0w/2948464 to your computer and use it in GitHub Desktop.
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.awt.event.ActionEvent;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.LayoutStyle;
import javax.swing.SwingUtilities;
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.Widgets;
import org.powerbot.game.api.methods.input.Mouse;
import org.powerbot.game.api.methods.interactive.Players;
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.wrappers.node.Item;
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 = "iTPotionMixer", description = "Mix potions! Follow instructions on GUI.", version = 1.5, website = "http://www.powerbot.org/community/topic/674277-potionmixer-mix-potions-for-you/")
public class iTPotionMixer extends ActiveScript implements MessageListener,
PaintListener {
private int primary, secondary, startXp, startLevel, made;
private boolean guiInitialized, abSupport, paintSupport = true;
private String status = "waiting for gui";
private long startTime;
private Object[][] potData = { { 227, 249, "Unfinished Guam" },
{ 227, 251, "Unfinished Marrentill" },
{ 227, 253, "Unfinished Tarromin" },
{ 227, 255, "Unfinished Harralander" },
{ 227, 257, "Unfinished Ranarr" },
{ 227, 12224, "Unfinished Spirit Weed" },
{ 227, 14886, "Unfinished Wergali" },
{ 227, 259, "Unfinished Irit" },
{ 227, 211, "Unfinished Avantoe" },
{ 227, 263, "Unfinished Kwuarm" },
{ 227, 3000, "Unfinished Snapdragon" },
{ 227, 265, "Unfinished Cadantine" },
{ 227, 2535, "Unfinished Lantadyme" },
{ 227, 267, "Unfinished Dwarf Weed" },
{ 227, 271, "Unfinished Torstol" },
{ 227, 21676, "Unfinished Fellstalk" },
{ 91, 221, "Attack Potion" }, { 93, 235, "Antipoison" },
{ 95, 225, "Strength Potion" }, { 97, 223, "Restore Potion" },
{ 97, 1975, "Energy Potion" }, { 99, 239, "Defence Potion" },
{ 3002, 2152, "Agility Potion" }, { 97, 9736, "Combat Potion" },
{ 99, 231, "Prayer Potion" }, { 101, 221, "Super Attack Potion" },
{ 101, 235, "Super Antipoison" }, { 103, 231, "Fishing Potion" },
{ 103, 2970, "Super Energy Potion" },
{ 103, 10111, "Hunter Potion" },
{ 105, 225, "Super Strength Potion" },
{ 14856, 11525, "Fletching Potion" },
{ 105, 241, "Weapon Poison" },
{ 3004, 223, "Super Restore Potion" },
{ 107, 239, "Super Defence" }, { 2483, 241, "Antifire" },
{ 109, 245, "Ranging Potion" }, { 2483, 3138, "Magic Potion" },
{ 111, 247, "Zamorak Brew" }, { 3002, 6693, "Saradomin Brew" },
{ 21628, 21622, "Prayer Renewal" }, { 95, 592, "Serum 207" },
{ 145, 261, "Extreme Attack" }, { 157, 267, "Extreme Strength" },
{ 163, 2481, "Extreme Defence" },
{ 169, 12539, "Extreme Ranging" }, { 3042, 9594, "Extreme Magic" },
{ 15309, 15313, "Overload" } };
private int[] getIngredients(String potion) {
for (int i = 0; i < potData.length; i++) {
if (potData[i][2].equals(potion)) {
return new int[] { (Integer) potData[i][0],
(Integer) potData[i][1] };
}
}
return new int[] { -1, -1 };
}
@Override
public void messageReceived(MessageEvent arg0) {
String msg = arg0.getMessage();
if (msg.contains("you put the") || msg.contains("into the vial")
|| msg.contains("mix the") || msg.contains("serum 207")) {
made++;
}
}
@Override
protected void setup() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame ui = new GUI();
ui.setVisible(true);
}
});
provide(new AntiBan());
provide(new Mix());
provide(new ItemOnItem());
provide(new Banking());
startTime = System.currentTimeMillis();
startXp = Skills.getExperiences()[15];
startLevel = Skills.getLevels()[15];
}
private AlphaComposite makeComposite(float alpha) {
int type = AlphaComposite.SRC_OVER;
return (AlphaComposite.getInstance(type, alpha));
}
@Override
public void onRepaint(Graphics g) {
if (!paintSupport) {
return;
}
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.MAGENTA);
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.HERBLORE] - startXp;
int expHour = (int) ((expGained) * 3600000D / (System
.currentTimeMillis() - startTime));
int madeHour = (int) ((made) * 3600000D / (System.currentTimeMillis() - startTime));
g2d.setFont(title);
g2d.drawString("iTPotionMixer", 20, 50);
g2d.setFont(author);
g2d.drawString("By: _phl0w", 20, 65);
g2d.setFont(info);
g2d.drawString("Herblore level: " + Skills.getLevels()[Skills.HERBLORE]
+ "/" + startLevel + ".", 20, 85);
g2d.drawString("Herblore experience gained: " + expGained + ".", 20,
100);
g2d.drawString("Herblore experience/hour: " + expHour + ".", 20, 115);
g2d.drawString("Successfully made " + made + " potions.", 20, 130);
g2d.drawString("Making " + madeHour + " potions per hour.", 20, 145);
g2d.drawString("Status: " + status + ".", 20, 160);
g2d.drawString(
"Time running: "
+ Time.format(System.currentTimeMillis() - startTime)
+ ".", 20, 175);
}
private class AntiBan extends Strategy implements Task {
@Override
public boolean validate() {
return abSupport && guiInitialized
&& Players.getLocal().getAnimation() != -1;
}
@Override
public void run() {
if (Random.nextInt(1, 15) <= 2) {
executeAntiBan();
}
Time.sleep(1000);
}
private final void executeAntiBan() {
Camera.setAngle(Random.nextInt(20, 300));
}
}
private class Mix extends Strategy implements Task {
@Override
public boolean validate() {
return guiInitialized && Widgets.get(905, 14).visible();
}
@Override
public void run() {
Widgets.get(905, 14).click(true);
status = "mixing";
Time.sleep(Random.nextInt(400, 900));
}
}
private class ItemOnItem extends Strategy implements Task {
public boolean isMixing() {
int x = 0;
for (int i = 0; i < 10; i++) {
x += (Players.getLocal().getAnimation() == -1) ? -1 : 1;
Time.sleep(50);
}
return x > 0;
}
@Override
public boolean validate() {
return guiInitialized && !Widgets.get(905, 14).visible()
&& !isMixing() && Inventory.getCount(primary) > 0;
}
@Override
public void run() {
Item prim = Inventory.getItem(primary);
Item sec = Inventory.getItem(secondary);
Mouse.hop(
prim.getWidgetChild().getAbsoluteX() + Random.nextInt(0, 7),
prim.getWidgetChild().getAbsoluteY() + Random.nextInt(0, 7));
Mouse.click(true);
Mouse.hop(
sec.getWidgetChild().getAbsoluteX() + Random.nextInt(0, 7),
sec.getWidgetChild().getAbsoluteY() + Random.nextInt(0, 7));
Mouse.click(true);
while (!Widgets.get(905, 14).visible()) {
Time.sleep(50, 100);
}
}
}
private class Banking extends Strategy implements Task {
@Override
public boolean validate() {
log.info("val");
return (Inventory.getCount(primary) == 0 || Inventory
.getCount(secondary) == 0)
&& guiInitialized
&& !Bank.isOpen();
}
@Override
public void run() {
Bank.open();
Time.sleep(300, 600);
Mouse.hop(
Widgets.get(Bank.WIDGET_BANK,
Bank.WIDGET_BUTTON_DEPOSIT_INVENTORY)
.getAbsoluteX(),
Widgets.get(Bank.WIDGET_BANK,
Bank.WIDGET_BUTTON_DEPOSIT_INVENTORY)
.getAbsoluteY());
Mouse.click(true);
if (primary == 15309 && secondary == 15313) { // Overloads
Bank.withdraw(primary, 4);
Bank.withdraw(secondary, 4);
Bank.withdraw(15317, 4);
Bank.withdraw(15321, 4);
Bank.withdraw(15325, 4);
Bank.withdraw(269, 4);
}
Bank.withdraw(primary, primary == 169 ? 0 : 14);
if (secondary != 12539) {
Bank.withdraw(secondary, 14);
}
Time.sleep(800, 1000);
Mouse.hop(
Widgets.get(Bank.WIDGET_BANK, Bank.WIDGET_BUTTON_CLOSE_BANK)
.getAbsoluteX(),
Widgets.get(Bank.WIDGET_BANK, Bank.WIDGET_BUTTON_CLOSE_BANK)
.getAbsoluteY());
Mouse.click(true);
}
}
public class GUI extends JFrame {
private static final long serialVersionUID = 1L;
public GUI() {
try {
initComponents();
} catch (Exception e) {
log.info("Ignored");
}
}
private void initComponents() {
jCheckBox1 = new JCheckBox();
jButton1 = new JButton();
jCheckBox2 = new JCheckBox();
jLabel1 = new JLabel();
jRadioButton1 = new JRadioButton();
jRadioButton2 = new JRadioButton();
jComboBox1 = new JComboBox();
jLabel4 = new JLabel();
setTitle("PotionMixer");
jCheckBox1.setSelected(true);
jCheckBox1.setText("Enable antiban?");
jButton1.setText("Start");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jCheckBox2.setSelected(true);
jCheckBox2.setText("Enable paint?");
jLabel1.setText("Squeal spin ticket options:");
jRadioButton1.setSelected(true);
jRadioButton1.setEnabled(false);
jRadioButton1.setText("Claim ticket");
jRadioButton1
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(
java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
jRadioButton2.setText("Destroy ticket");
jRadioButton2.setEnabled(false);
jRadioButton2
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(
java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
jComboBox1.setModel(new DefaultComboBoxModel(new String[] {
"Agility Potion", "Antifire", "Antipoison",
"Attack Potion", "Combat Potion", "Crafting Potion",
"Defence Potion", "Energy Potion", "Fishing Potion",
"Fletching Potion", "Hunter Potion", "Magic Potion",
"Prayer Potion", "Prayer Renewal", "Ranging Potion",
"Restore Potion", "Saradomin Brew", "Serum 207",
"Strength Potion", "Super Antipoison",
"Super Attack Potion", "Super Defence",
"Super Energy Potion", "Super Restore Potion",
"Super Strength Potion", "Weapon Poison", "Zamorak Brew",
"Extreme Attack", "Extreme Strength", "Extreme Defence",
"Extreme Ranging", "Extreme Magic", "Overload",
"Unfinished Avantoe", "Unfinished Cadantine",
"Unfinished Dwarf Weed", "Unfinished Fellstalk",
"Unfinished Guam", "Unfinished Harralander",
"Unfinished Irit", "Unfinished Kwuarm",
"Unfinished Lantadyme", "Unfinished Marrentill",
"Unfinished Ranarr", "Unfinished Snapdragon",
"Unfinished Spirit Weed", "Unfinished Tarromin",
"Unfinished Torstol", "Unfinished Wergali" }));
jLabel4.setText("Select potion:");
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(
layout.createSequentialGroup()
.addContainerGap()
.addGroup(
layout.createParallelGroup(
GroupLayout.Alignment.LEADING)
.addGroup(
GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGap(0,
0,
Short.MAX_VALUE)
.addComponent(
jButton1,
GroupLayout.PREFERRED_SIZE,
260,
GroupLayout.PREFERRED_SIZE))
.addGroup(
layout.createSequentialGroup()
.addGroup(
layout.createParallelGroup(
GroupLayout.Alignment.LEADING)
.addComponent(
jLabel1)
.addGroup(
layout.createSequentialGroup()
.addComponent(
jRadioButton1)
.addGap(60,
60,
60)
.addComponent(
jRadioButton2))
.addComponent(
jLabel4)
.addGroup(
layout.createParallelGroup(
GroupLayout.Alignment.TRAILING,
false)
.addComponent(
jComboBox1,
0,
GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGroup(
layout.createSequentialGroup()
.addComponent(
jCheckBox1,
GroupLayout.PREFERRED_SIZE,
137,
GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
jCheckBox2))))
.addGap(0,
0,
Short.MAX_VALUE)))
.addContainerGap()));
layout.setVerticalGroup(layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(
layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel4)
.addGap(1, 1, 1)
.addComponent(jComboBox1,
GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addGroup(
layout.createParallelGroup(
GroupLayout.Alignment.LEADING)
.addGroup(
layout.createSequentialGroup()
.addGap(7,
7,
7)
.addComponent(
jCheckBox1))
.addGroup(
layout.createSequentialGroup()
.addPreferredGap(
LayoutStyle.ComponentPlacement.RELATED,
GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(
jCheckBox2)))
.addPreferredGap(
LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addPreferredGap(
LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout.createParallelGroup(
GroupLayout.Alignment.BASELINE)
.addComponent(jRadioButton1)
.addComponent(jRadioButton2))
.addPreferredGap(
LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addContainerGap(GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
pack();
}
private void jButton1ActionPerformed(ActionEvent evt) {
primary = getIngredients(jComboBox1.getSelectedItem().toString())[0];
secondary = getIngredients(jComboBox1.getSelectedItem().toString())[1];
abSupport = jCheckBox1.isSelected();
paintSupport = jCheckBox2.isSelected();
guiInitialized = true;
log.info("GUI done.");
dispose();
}
private void jRadioButton1ActionPerformed(ActionEvent evt) {
jRadioButton1.setSelected(true);
jRadioButton2.setSelected(false);
}
private void jRadioButton2ActionPerformed(ActionEvent evt) {
jRadioButton1.setSelected(false);
jRadioButton2.setSelected(true);
}
private JButton jButton1;
private JCheckBox jCheckBox1;
private JCheckBox jCheckBox2;
private JComboBox jComboBox1;
private JLabel jLabel1;
private JLabel jLabel4;
private JRadioButton jRadioButton1;
private JRadioButton jRadioButton2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment