- import java.awt.Color;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Insets;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.RenderingHints;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import java.math.BigInteger;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.text.DecimalFormat;
- import java.text.DecimalFormatSymbols;
- import java.util.Map;
- import javax.imageio.ImageIO;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import org.rsbot.event.listeners.PaintListener;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.methods.Skills;
- import org.rsbot.script.wrappers.RSComponent;
- import org.rsbot.script.wrappers.RSInterface;
- import org.rsbot.script.wrappers.RSItem;
- import org.rsbot.script.wrappers.RSObject;
- @ScriptManifest(authors = { "A_C" }, category = "Magic", name = "The Enchanter", version = 0.1, description = "Setting are in the GUI")
- public class Enchanter extends Script implements PaintListener {
- //Jewellery ID's -- Credits to Black Ice
- //0=ring, 1=neck, 2=ammulet
- int[] sapphireUn = {1637, 1656, 1694};
- int[] sapphireE = {2550, 3853, 1727};
- int[] emeraldUn = {1639, 1658, 1696};
- int[] emeraldE = {2552, 5521, 1729};
- int[] rubyUn = {1641, -1, 1698};
- int[] rubyE = {2568, -1, 1725};
- int[] diamondUn = {1643, 1662, 1700};
- int[] diamondE = {2570, 11090, 1731};
- int[] dstoneUn = {1645, 1664, 1702};
- int[] dstoneE = {2572, 11105, 1712};
- //Other ID's
- int spell;
- int chest = 42192;
- int jewellery;
- int enchanted;
- //Paint
- int startLvl = 0;
- int startXp = 0;
- private long timeStarted = 0;
- double xpCast;
- String status;
- BufferedImage normal = null;
- BufferedImage clicked = null;
- //Other Stuff
- boolean canStart = false;
- public boolean onStart(Map<String, String> map) {
- status = "Loading mouse images";
- try {
- final URL cursorURL = new URL(
- "http://i48.tinypic.com/313623n.png");
- final URL cursor80URL = new URL(
- "http://i46.tinypic.com/9prjnt.png");
- normal = ImageIO.read(cursorURL);
- clicked = ImageIO.read(cursor80URL);
- } catch (MalformedURLException e) {
- log("Unable to buffer cursor.");
- } catch (IOException e) {
- log("Unable to open cursor image.");
- }
- status = "Loading GUI";
- timeStarted = System.currentTimeMillis();
- EnchanterGUI gui = new EnchanterGUI();
- gui.setVisible(true);
- return true;
- }
- @Override
- public int loop() {
- if (canStart) {
- if (getMyPlayer().getAnimation() != -1) {
- return 0;
- }
- if (!inventory.contains(564)) {
- log("You ran out of runes!");
- return -1;
- }
- int antiban = random(0,4);
- if (antiban == 4) {
- camera.moveRandomly(random(100,500));
- }
- mouse.setSpeed(random(5,7));
- if (!inventory.contains(jewellery)) {
- status = "Banking";
- if (!bank.isOpen()) {
- RSObject bChest = objects.getNearest(chest);
- if (bChest != null) {
- bChest.doAction("Use");
- return random(1000,1500);
- }
- } else {
- if (bank.getCount(jewellery) == 0) {
- log("You have no more jewellery, stopping script");
- return -1;
- }
- if (inventory.contains(enchanted)) {
- bank.deposit(enchanted, 0);
- return random(1000,1500);
- }
- if (!inventory.contains(jewellery)) {
- bank.withdraw(jewellery, 0);
- return random(1000,1500);
- }
- }
- } else {
- if (bank.isOpen()) {
- status = "Closing bank";
- bank.close();
- return random(250,500);
- }
- if (!magic.isSpellSelected()) {
- status = "Enchanting";
- magic.castSpell(spell);
- return random(250,500);
- } else if (magic.isSpellSelected()) {
- RSItem cast = inventory.getItem(jewellery);
- if (cast != null)
- cast.doClick(true);
- return random(250,500);
- }
- }
- }
- return 0;
- }
- @Override
- public void onRepaint(Graphics render) {
- RSComponent inv = interfaces.get(149).getComponent(0);
- if (game.isLoggedIn() && inv != null) {
- int paintX = inv.getAbsoluteX() + 5;
- int paintY = inv.getAbsoluteY() + 17;
- ((Graphics2D) render).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- long run = System.currentTimeMillis() - timeStarted;
- double hour = (double) run / 1000 / 60 / 60;
- if (startLvl == 0) {
- startLvl = skills.getCurrentLevel(Skills.MAGIC);
- }
- if (startXp == 0) {
- startXp = skills.getCurrentExp(Skills.MAGIC);
- }
- final int mouse_x = mouse.getClientLocation().x;
- final int mouse_y = mouse.getClientLocation().y;
- final int mouse_x2 = mouse.getClientPressLocation().x;
- final int mouse_y2 = mouse.getClientPressLocation().y;
- final long mpt = System.currentTimeMillis()
- - mouse.getClientPressTime();
- if (mouse.getClientPressTime() == -1 || mpt >= 1000) {
- render.drawImage(normal, mouse_x - 8, mouse_y - 8, null); //this show the mouse when its not clicked
- }
- if (mpt < 1000) {
- render.drawImage(clicked, mouse_x2 - 8, mouse_y2 - 8, null); //this show the four squares where you clicked.
- render.drawImage(normal, mouse_x - 8, mouse_y - 8, null); //this show the mouse as normal when its/just clicked
- }
- Color transBlack = new Color(0, 0, 0, 170);
- render.setColor(transBlack);
- render.drawRoundRect(paintX - 17, paintY - 20, 181, 250, 20, 20);
- render.fillRoundRect(paintX - 17, paintY - 20, 181, 250, 20, 20);
- render.setColor(Color.WHITE);
- render.setFont(new Font("Lucida", 0, 14));
- render.drawString("A_C's Enchanter", paintX, paintY);
- render.setFont(new Font("Lucida", 0, 11));
- paintY += 15;
- render.drawString("Ran for: " + getFormattedTimeElapsed(), paintX, paintY);
- paintY += 15;
- render.drawString("Status: " + status, paintX, paintY);
- paintY += 15;
- render.drawString("Casts: " + format((int)((skills.getCurrentExp(Skills.MAGIC) - startXp)/(xpCast))), paintX, paintY);
- paintY += 15;
- render.drawString("Casts p/hr : " + format((int)((skills.getCurrentExp(Skills.MAGIC) - startXp)/(xpCast)/hour)), paintX, paintY);
- paintY += 30;
- render.drawString("Magic xp gained: " + format(skills.getCurrentExp(Skills.MAGIC) - startXp), paintX, paintY);
- paintY += 15;
- render.drawString("Magic xp to next level: " + format(skills.getExpToNextLevel(Skills.MAGIC)), paintX, paintY);
- paintY += 15;
- render.drawString("Current magic Level: " +(skills.getCurrentLevel(Skills.MAGIC)) + " (" + (skills.getCurrentLevel(Skills.MAGIC) - startLvl) + ")", paintX, paintY);
- paintY += 15;
- render.drawString("Magic XP/Hour: " + format((int)((skills.getCurrentExp(Skills.MAGIC) - startXp)/hour)), paintX, paintY);
- paintY += 15;
- try {
- render.drawString("TTNL: " + getTimeToLevel((int)((skills.getCurrentExp(Skills.MAGIC) - startXp)/hour), ((skills.getCurrentLevel(Skills.MAGIC)) +1), Skills.MAGIC), paintX, paintY);
- paintY += 15;
- } catch (InterruptedException e) {}
- render.drawString("Percent to next level: " + skills.getPercentToNextLevel(Skills.MAGIC) + "%", paintX, paintY);
- paintY += 10;
- drawProgressBar(render, (int)skills.getPercentToNextLevel(Skills.MAGIC), paintX, paintY);
- /*render.setColor(Color.GREEN);
- if (startLvl == 0) {
- startLvl = skills.getCurrentLevel(Skills.MAGIC);
- }
- if (startXp == 0) {
- startXp = skills.getCurrentExp(Skills.MAGIC);
- }
- render.drawString("Exp Gained: " + (skills.getCurrentExp(Skills.MAGIC) - startXp), 20, 135);
- render.drawString("Lvls Gained: " + (skills.getCurrentLevel(Skills.MAGIC) - startLvl), 20, 150);*/
- }
- }
- //-----Methods-----
- public void drawProgressBar(Graphics g, int percent, int x, int y) {
- Color forestGreen = new Color(34, 139, 34);
- Color limeGreen = new Color(50, 205, 50);
- Color gold = new Color(255, 215, 0);
- Color darkOrange = new Color(255, 140, 0);
- Color orangeRed = new Color (255, 69, 0);
- Color red = new Color(255, 0, 0);
- g.setColor(Color.white);
- g.drawRect(x - 1, y - 1, 100 + 1, 11);
- if (percent <= 33) {
- g.setColor(red);
- } else if (percent <= 66) {
- g.setColor(darkOrange);
- } else if (percent > 66) {
- g.setColor(forestGreen);
- }
- g.fillRect(x, y, 1 * percent, 10);
- if (percent <= 33) {
- g.setColor(orangeRed);
- } else if (percent <= 66) {
- g.setColor(gold);
- } else if (percent > 66) {
- g.setColor(limeGreen);
- }
- g.fillRect(x, y, 1 * percent, 5);
- }
- public long getTimeElapsed() {
- return System.currentTimeMillis() - timeStarted;
- }
- public String getFormattedTimeElapsed() {
- final long runTime = getTimeElapsed();
- final long seconds = runTime / 1000;
- final long minutes = seconds / 60;
- final long hours = minutes / 60;
- final long days = hours / 24;
- final int s = (int) seconds % 60;
- final int m = (int) minutes % 60;
- final int h = (int) hours % 60;
- if (h >= 24) {
- final int d = (int) days % 24;
- return String.format("%0,2d:%0,2d:%0,2d:%0,2d", d, h, m, s);
- }
- return String.format("%0,2d:%0,2d:%0,2d", h, m, s);
- }
- public String format(int num) {
- DecimalFormat df = new DecimalFormat();
- DecimalFormatSymbols dfs = new DecimalFormatSymbols();
- dfs.setGroupingSeparator(',');
- df.setDecimalFormatSymbols(dfs);
- return df.format(num);
- }
- public String getTimeToLevel(int xpPerHour, int targetLevel, int theSkill) throws InterruptedException {
- if (xpPerHour <= 0) {
- return "00:00:00";
- }
- String timeToLevel = "";
- int remainingXP = skills.getExpToNextLevel(theSkill);
- BigInteger secondsToLevel = BigInteger.valueOf(remainingXP).multiply(BigInteger.valueOf(3600)).divide(
- BigInteger.valueOf(xpPerHour));
- BigInteger hoursToLevel = secondsToLevel.divide(BigInteger.valueOf(3600));
- secondsToLevel = secondsToLevel.subtract(hoursToLevel.multiply(BigInteger.valueOf(3600)));
- BigInteger minutesToLevel = secondsToLevel.divide(BigInteger.valueOf(60));
- secondsToLevel = secondsToLevel.subtract(minutesToLevel.multiply(BigInteger.valueOf(60)));
- if (hoursToLevel.compareTo(BigInteger.TEN) < 0) {
- timeToLevel += "0";
- }
- timeToLevel += hoursToLevel + ":";
- if (minutesToLevel.compareTo(BigInteger.TEN) < 0) {
- timeToLevel += "0";
- }
- timeToLevel += minutesToLevel + ":";
- if (secondsToLevel.compareTo(BigInteger.TEN) < 0) {
- timeToLevel += "0";
- }
- timeToLevel += secondsToLevel;
- return timeToLevel;
- }
- //-----GUI-----
- public class EnchanterGUI extends JFrame {
- private static final long serialVersionUID = 1L;
- public EnchanterGUI() {
- initComponents();
- }
- private void button1ActionPerformed(ActionEvent e) {
- if (e.getActionCommand().equals("Start")) {
- if (comboBox1.getSelectedItem().equals("Please Select...") || comboBox2.getSelectedItem().equals("Please Select...")) {
- log("Please select Stone and Jewellery type!");
- }
- if (comboBox1.getSelectedItem().equals("Sapphire")) {
- if (comboBox2.getSelectedItem().equals("Ring")) {
- jewellery = sapphireUn[0];
- enchanted = sapphireE[0];
- spell = magic.SPELL_LVL1_ENCHANT;
- xpCast = 17.5;
- }
- if (comboBox2.getSelectedItem().equals("Necklace")) {
- jewellery = sapphireUn[1];
- enchanted = sapphireE[1];
- spell = magic.SPELL_LVL1_ENCHANT;
- xpCast = 17.5;
- }
- if (comboBox2.getSelectedItem().equals("Amulet")) {
- jewellery = sapphireUn[2];
- enchanted = sapphireE[2];
- spell = magic.SPELL_LVL1_ENCHANT;
- xpCast = 17.5;
- }
- }
- if (comboBox1.getSelectedItem().equals("Emerald")) {
- if (comboBox2.getSelectedItem().equals("Ring")) {
- jewellery = emeraldUn[0];
- enchanted = emeraldE[0];
- spell = magic.SPELL_LVL2_ENCHANT;
- xpCast = 37.0;
- }
- if (comboBox2.getSelectedItem().equals("Necklace")) {
- jewellery = emeraldUn[1];
- enchanted = emeraldE[1];
- spell = magic.SPELL_LVL2_ENCHANT;
- xpCast = 37.0;
- }
- if (comboBox2.getSelectedItem().equals("Amulet")) {
- jewellery = emeraldUn[2];
- enchanted = emeraldE[2];
- spell = magic.SPELL_LVL2_ENCHANT;
- xpCast = 37.0;
- }
- }
- if (comboBox1.getSelectedItem().equals("Ruby")) {
- if (comboBox2.getSelectedItem().equals("Ring")) {
- jewellery = rubyUn[0];
- enchanted = rubyE[0];
- spell = magic.SPELL_LVL3_ENCHANT;
- xpCast = 59.0;
- }
- if (comboBox2.getSelectedItem().equals("Necklace")) {
- jewellery = rubyUn[1];
- enchanted = rubyE[1];
- spell = magic.SPELL_LVL3_ENCHANT;
- xpCast = 59.0;
- }
- if (comboBox2.getSelectedItem().equals("Amulet")) {
- jewellery = rubyUn[2];
- enchanted = rubyE[2];
- spell = magic.SPELL_LVL3_ENCHANT;
- xpCast = 59.0;
- }
- }
- if (comboBox1.getSelectedItem().equals("Diamond")) {
- if (comboBox2.getSelectedItem().equals("Ring")) {
- jewellery = diamondUn[0];
- enchanted = diamondE[0];
- spell = magic.SPELL_LVL4_ENCHANT;
- xpCast = 67.0;
- }
- if (comboBox2.getSelectedItem().equals("Necklace")) {
- jewellery = diamondUn[1];
- enchanted = diamondE[1];
- spell = magic.SPELL_LVL4_ENCHANT;
- xpCast = 67.0;
- }
- if (comboBox2.getSelectedItem().equals("Amulet")) {
- jewellery = diamondUn[2];
- enchanted = diamondE[2];
- spell = magic.SPELL_LVL4_ENCHANT;
- xpCast = 67.0;
- }
- }
- if (comboBox1.getSelectedItem().equals("Dragonstone")) {
- if (comboBox2.getSelectedItem().equals("Ring")) {
- jewellery = dstoneUn[0];
- enchanted = dstoneE[0];
- spell = magic.SPELL_LVL5_ENCHANT;
- xpCast = 78.0;
- }
- if (comboBox2.getSelectedItem().equals("Necklace")) {
- jewellery = dstoneUn[1];
- enchanted = dstoneE[1];
- spell = magic.SPELL_LVL5_ENCHANT;
- xpCast = 78.0;
- }
- if (comboBox2.getSelectedItem().equals("Amulet")) {
- jewellery = dstoneUn[2];
- enchanted = dstoneE[2];
- spell = magic.SPELL_LVL5_ENCHANT;
- xpCast = 78.0;
- }
- }
- }
- log("Enchanting " + comboBox1.getSelectedItem().toString() + " " + comboBox2.getSelectedItem().toString());
- canStart = true;
- setVisible(false);
- }
- private void initComponents() {
- // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
- label1 = new JLabel();
- comboBox1 = new JComboBox();
- label2 = new JLabel();
- label3 = new JLabel();
- comboBox2 = new JComboBox();
- button1 = new JButton();
- //======== this ========
- Container contentPane = getContentPane();
- contentPane.setLayout(null);
- //---- label1 ----
- label1.setText("A_C's Jewelery Enchanter");
- contentPane.add(label1);
- label1.setBounds(0, 0, 185, label1.getPreferredSize().height);
- //---- comboBox1 ----
- comboBox1.setModel(new DefaultComboBoxModel(new String[] {
- "Please Select...",
- "Sapphire",
- "Emerald",
- "Ruby",
- "Diamond",
- "Dragonstone"
- }));
- contentPane.add(comboBox1);
- comboBox1.setBounds(new Rectangle(new Point(55, 15), comboBox1.getPreferredSize()));
- //---- label2 ----
- label2.setText("Stone:");
- label2.setLabelFor(comboBox1);
- contentPane.add(label2);
- label2.setBounds(0, 15, label2.getPreferredSize().width, 25);
- //---- label3 ----
- label3.setText("Jewelery:");
- label3.setLabelFor(comboBox2);
- contentPane.add(label3);
- label3.setBounds(0, 40, label3.getPreferredSize().width, 25);
- //---- comboBox2 ----
- comboBox2.setModel(new DefaultComboBoxModel(new String[] {
- "Please Select...",
- "Ring",
- "Necklace",
- "Amulet"
- }));
- contentPane.add(comboBox2);
- comboBox2.setBounds(new Rectangle(new Point(55, 40), comboBox2.getPreferredSize()));
- //---- button1 ----
- button1.setText("Start");
- button1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- button1ActionPerformed(e);
- }
- });
- contentPane.add(button1);
- button1.setBounds(0, 65, 185, button1.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());
- // JFormDesigner - End of component initialization //GEN-END:initComponents
- }
- public void ShowComponents() {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new EnchanterGUI().setVisible(true);
- }
- });
- }
- // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
- private JLabel label1;
- private JComboBox comboBox1;
- private JLabel label2;
- private JLabel label3;
- private JComboBox comboBox2;
- private JButton button1;
- // JFormDesigner - End of variables declaration //GEN-END:variables
- }
- }