Last active
December 16, 2015 13:48
-
-
Save gh0sti/5443879 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package timebomb; | |
import java.awt.Container; | |
import java.awt.Dimension; | |
import java.awt.Graphics; | |
import java.awt.Insets; | |
import java.awt.Rectangle; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.lang.reflect.InvocationTargetException; | |
import java.util.ArrayList; | |
import javax.swing.DefaultComboBoxModel; | |
import javax.swing.JButton; | |
import javax.swing.JComboBox; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.JPanel; | |
import javax.swing.SwingUtilities; | |
import org.powerbot.core.event.events.MessageEvent; | |
import org.powerbot.core.event.listeners.MessageListener; | |
import org.powerbot.core.event.listeners.PaintListener; | |
import org.powerbot.core.script.ActiveScript; | |
import org.powerbot.core.script.job.Task; | |
import org.powerbot.core.script.job.state.Node; | |
import org.powerbot.game.api.Manifest; | |
import org.powerbot.game.api.methods.Widgets; | |
import org.powerbot.game.api.methods.tab.Inventory; | |
import org.powerbot.game.api.methods.widget.Bank; | |
import org.powerbot.game.api.util.Random; | |
import org.powerbot.game.api.util.Timer; | |
import org.powerbot.game.api.wrappers.node.Item; | |
import org.powerbot.game.api.wrappers.widget.WidgetChild; | |
@Manifest(authors = { "TimeBomb" }, name = "PrimePotionMaker", description = "Makes unf potions") | |
public class PrimePotionMaker extends ActiveScript implements PaintListener, MessageListener { | |
private ArrayList<Node> nodes = new ArrayList<Node>(); | |
private final int VIAL_ID = 227; | |
private Potions potion; | |
private boolean started = false; | |
Timer runTime = new Timer(0); | |
public void onStart() { | |
try { | |
SwingUtilities.invokeAndWait(new Runnable() { | |
public void run() { | |
new unfPotionMaker().setVisible(true); | |
} | |
}); | |
} catch (InvocationTargetException | InterruptedException e) { | |
e.printStackTrace(); | |
} | |
nodes.add(new BankHandler()); | |
nodes.add(new MakePotions()); | |
} | |
@Override | |
public int loop() { | |
for (Node node : nodes) { | |
if (node.activate()) node.execute(); | |
} | |
return Random.nextInt(20, 80); | |
} | |
public class MakePotions extends Node { | |
public void execute() { | |
Item brew = Inventory.getItem(potion.getHerbId()); | |
Item flask = Inventory.getItem(VIAL_ID); | |
WidgetChild widget = Widgets.get(1370, 37); | |
if (widget.validate() && widget.visible()) { | |
if (widget.click(true)) { | |
Timer sleep = new Timer(17500); | |
while (sleep.isRunning() && Inventory.getCount(potion.getHerbId()) > 0) { | |
Task.sleep(100); | |
} | |
} | |
} else { | |
if (brew != null && flask != null) { | |
if (Inventory.selectItem(flask)) { | |
Task.sleep(300, 500); | |
if (brew.getWidgetChild().click(true)) { | |
Task.sleep(900, 1100); | |
} | |
} | |
} | |
} | |
} | |
public boolean activate() { | |
return started && !Bank.isOpen() && Inventory.getCount(potion.getHerbId()) > 0 && Inventory.getCount(VIAL_ID) > 0; | |
} | |
} | |
public class BankHandler extends Node { | |
public void execute() { | |
if (Bank.isOpen()) { | |
if (Bank.depositInventory()) { | |
Task.sleep(600, 1000); | |
} | |
if (Inventory.getCount(VIAL_ID) < 10) { | |
if (Bank.getItemCount(VIAL_ID) > 0) { | |
Bank.withdraw(VIAL_ID, 14); | |
} else { | |
stop(); | |
} | |
} | |
if (Bank.getItemCount(potion.getHerbId()) > 0) { | |
if (Bank.withdraw(potion.getHerbId(), 0)) { | |
Task.sleep(100, 400); | |
if (Bank.close()) { | |
} | |
} | |
} else { | |
stop(); | |
} | |
} else { | |
Bank.open(); | |
} | |
} | |
public boolean activate() { | |
return started && (Inventory.getItem(VIAL_ID) == null || Inventory.getCount(potion.getHerbId()) < 1); | |
} | |
} | |
public enum Potions { | |
GUAM(249, 91, -1), | |
MARRENTILL(251, 93, -1), | |
TARROMIN(253, 95, -1), | |
HARRALANDER(255, 97, -1), | |
RANARR(257, 99, -1), | |
SPIRIT_WEED(12172, 12181, -1), | |
WERGALI(14854, 14856, -1), | |
IRIT(259, 101, -1), | |
AVANTOE(261, 103, -1), | |
KWUARM(263, 105, -1), | |
SNAPDRAGON(3000, 3004, -1), | |
CADANTINE(265, 107, -1), | |
LANTADYME(2481, 2483, -1), | |
DWARF_WEED(267, 109, -1), | |
TORSTOL(269, 111, -1), | |
FELLSTALK(21624, 21628, -1), | |
TOADFLAX (2998, 3002, -1), | |
NONE(-1, -1, -1); | |
int herbId; | |
int potionId; | |
int profit; | |
Potions(int herbId, int potionId, int profit) { | |
this.herbId = herbId; | |
this.profit = profit; | |
this.potionId = potionId; | |
} | |
public int getHerbId() { | |
return this.herbId; | |
} | |
public int getPotionId() { | |
return this.potionId; | |
} | |
public int getProfit() { | |
return this.profit; | |
} | |
public void setProfit(int profit) { | |
this.profit = profit; | |
} | |
} | |
public class unfPotionMaker extends JFrame { | |
private static final long serialVersionUID = 1L; | |
public unfPotionMaker() { | |
initComponents(); | |
} | |
private void button1ActionPerformed(ActionEvent e) { | |
potion = Potions.values()[comboBox1.getSelectedIndex()]; | |
started = true; | |
dispose(); | |
} | |
private void initComponents() { | |
label1 = new JLabel(); | |
comboBox1 = new JComboBox<String>(); | |
button1 = new JButton(); | |
vSpacer1 = new JPanel(null); | |
hSpacer1 = new JPanel(null); | |
//======== this ======== | |
Container contentPane = getContentPane(); | |
contentPane.setLayout(null); | |
//---- label1 ---- | |
label1.setText("What potion do you want to make?: "); | |
contentPane.add(label1); | |
label1.setBounds(5, 5, label1.getPreferredSize().width, 22); | |
//---- comboBox1 ---- | |
comboBox1.setModel(new DefaultComboBoxModel<String>(new String[] { "Guam potion", "Marrentill potion", "Tarromin potion", | |
"Harralander potion", "Ranarr potion", "Spirit weed potion", "Wergali potion", | |
"Irit potion", "Avantoe potion", "Kwuarm potion", "Snapdragon potion", "Cadantine potion", | |
"Lantadyme potion", "Dwarf weed potion", "Torstol potion", "Fellstalk potion", "Toadflax potion" })); | |
contentPane.add(comboBox1); | |
comboBox1.setBounds(215, 5, 200, comboBox1.getPreferredSize().height); | |
//---- button1 ---- | |
button1.setText("Start script"); | |
button1.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
button1ActionPerformed(e); | |
} | |
}); | |
contentPane.add(button1); | |
button1.setBounds(5, 30, 410, button1.getPreferredSize().height); | |
contentPane.add(vSpacer1); | |
vSpacer1.setBounds(10, 50, 10, 8); | |
contentPane.add(hSpacer1); | |
hSpacer1.setBounds(412, 40, 8, hSpacer1.getPreferredSize().height); | |
{ // compute preferred size | |
Dimension preferredSize = new Dimension(); | |
for (int i = 0; i < contentPane.getComponentCount(); i++) { | |
Rectangle bounds = contentPane.getComponent(i).getBounds(); | |
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); | |
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); | |
} | |
Insets insets = contentPane.getInsets(); | |
preferredSize.width += insets.right; | |
preferredSize.height += insets.bottom; | |
contentPane.setMinimumSize(preferredSize); | |
contentPane.setPreferredSize(preferredSize); | |
} | |
pack(); | |
setLocationRelativeTo(getOwner()); | |
} | |
private JLabel label1; | |
private JComboBox<String> comboBox1; | |
private JButton button1; | |
private JPanel vSpacer1; | |
private JPanel hSpacer1; | |
} | |
int herbPrice; | |
int vialPrice; | |
int potionsMade; | |
int totalProfit; | |
int profit; | |
double profithr; | |
double potionsMadehr; | |
public void onRepaint(Graphics g) { | |
totalProfit = (potionsMade != 0) ? (potionsMade * potion.getProfit()) - (herbPrice + vialPrice) : 0; | |
profit = (herbPrice != 0) ? potion.getProfit() - (herbPrice + vialPrice) : 0; | |
profithr = (potionsMade != 0) ? ((totalProfit * 3600000D) / runTime.getElapsed()) : 0; | |
potionsMadehr = (potionsMade != 0) ? ((potionsMade * 3600000D) / runTime.getElapsed()) : 0; | |
g.drawString("Time ran: " + runTime.toElapsedString(), 10, 25); | |
g.drawString("Potions Made: " + potionsMade + " (hr: " + (int) potionsMadehr + ")", 10, 40); | |
g.drawString("Profit: " + totalProfit + " (hr: " + (int) profithr + ")", 10, 55); | |
g.drawString("Profit per: " + profit, 10, 70); | |
} | |
public void messageReceived(MessageEvent e) { | |
String msg = e.getMessage(); | |
if (msg.contains("into the vial of water")) { | |
potionsMade++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment