Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BasicStroke;
- 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.MouseEvent;
- import java.awt.event.MouseListener;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPasswordField;
- import javax.swing.JScrollPane;
- import javax.swing.JSlider;
- import javax.swing.JTextField;
- import javax.swing.JTextPane;
- import javax.swing.SwingConstants;
- import javax.swing.SwingUtilities;
- import scripts.Script;
- import scripts.ScriptManifest;
- import com.bsbot.api.Calculations;
- import com.bsbot.api.TilePath;
- import com.bsbot.wrappers.RSGroundItem;
- import com.bsbot.wrappers.RSItem;
- import com.bsbot.wrappers.RSNPC;
- import com.bsbot.wrappers.RSTile;
- @ScriptManifest(authors = { "Kenneh" }, name = "kennehfighter", version = 1, description = "Fights anything")
- public class AIOFighter extends Script implements MouseListener {
- Calculations c;
- MousePaint mt = new MousePaint();
- private RSTile startTile = null;
- private RSGroundItem loot = null;
- private String foodName = "", PASS = "z", USER = "z";
- private int startLvl = 0, startXp = 0, xpGained = 0, eatPercent = 50;
- private long startTime = 0;
- private boolean buryBones = false;
- private int strXpS, defXpS, rngXpS, mageXpS, attXpS, strLvlS, defLvlS, rngLvlS, mageLvlS, attLvlS;
- private final Color color1 = new Color(255, 255, 255), color2 = new Color(0, 0, 0), color3 = new Color(0, 0, 0, 145);
- private final BasicStroke stroke1 = new BasicStroke(1);
- private final Font font1 = new Font("Arial", 0, 9);
- Rectangle rect = new Rectangle(456, 312, 59, 25);
- ArrayList<String> npcList = new ArrayList<String>();
- ArrayList<String> lootList = new ArrayList<String>();
- public String[] lootItems() {
- return lootList.toArray(new String[lootList.size()]);
- }
- public String[] mobNames() {
- return npcList.toArray(new String[npcList.size()]);
- }
- public void doLogin() {
- if (USER != null && PASS != null) {
- mouse.clickMouse(new Point(286, 191), true);
- keyboard.sendKeys(USER);
- sleep(500);
- mouse.clickMouse(new Point(286, 247), true);
- keyboard.sendKeys(PASS);
- sleep(7000);
- mouse.clickMouse(new Point(383, 341), true);
- sleep(2500);
- }
- return;
- }
- public String getSkillName() {
- if(getSkill() == skills.STRENGTH) {
- return "Strength Lvl: ";
- }
- if(getSkill() == skills.DEFENSE) {
- return "Defense Lvl: ";
- }
- if(getSkill() == skills.RANGED) {
- return "Ranged Lvl: ";
- }
- if(getSkill() == skills.MAGIC){
- return "Magic Lvl: ";
- }
- if(getSkill() == skills.ATTACK){
- return "Attack Lvl: ";
- }
- return "NaN";
- }
- public int getSkill() {
- int strXp = skills.getExperience(skills.STRENGTH);
- int defXp = skills.getExperience(skills.DEFENSE);
- int rngXp = skills.getExperience(skills.RANGED);
- int mageXp = skills.getExperience(skills.MAGIC);
- int attXp = skills.getExperience(skills.ATTACK);
- if(strXp > strXpS) {
- startXp = strXpS;
- startLvl = strLvlS;
- return skills.STRENGTH;
- }
- if(defXp > defXpS) {
- startXp = defXpS;
- startLvl = defLvlS;
- return skills.DEFENSE;
- }
- if(rngXp > rngXpS) {
- startXp = rngXpS;
- startLvl = rngLvlS;
- return skills.RANGED;
- }
- if(mageXp > mageXpS) {
- startXp = mageXpS;
- startLvl = mageLvlS;
- return skills.MAGIC;
- }
- if(attXp > attXpS) {
- startXp = attXpS;
- startLvl = attLvlS;
- return skills.ATTACK;
- }
- return 0;
- }
- public enum State {
- Fight, Eat, Loot, Sleep, OpenCasket, Walkback, Bury,Login
- }
- public State getStage() {
- if(isLoggedIn() && startTile == null){
- startTile = getMyPlayer().getLocation();
- }
- if(!isLoggedIn() && !USER.equals("z") && !PASS.equals("z")) {
- return State.Login;
- }
- if(Calculations.distanceBetween(getMyPlayer().getLocation(), startTile) > 15) {
- return State.Walkback;
- }
- if(inventory.containsItem("Casket")) {
- return State.OpenCasket;
- }
- if(buryBones && inventory.containsItem("Bones") || inventory.containsItem("Big bones") && inventory.isFull()) {
- return State.Bury;
- }
- if(getMyPlayer().getHpPercent() <= eatPercent) {
- return State.Eat;
- }
- for(String i : lootItems()) {
- loot = grounditems.getNearest(i);
- if(loot != null && !getMyPlayer().isInCombat()) {
- if(c.distanceTo(loot.getLocation()) <= 15) {
- return State.Loot;
- }
- }
- }
- if(getMyPlayer().getAnimation() == -1) {
- if(!getMyPlayer().isInCombat()) {
- if(getMyPlayer().getHpPercent() >= eatPercent) {
- return State.Fight;
- }
- }
- }
- return State.Sleep;
- }
- @Override
- public int loop() {
- switch(getStage()) {
- case Fight:
- RSNPC mob = null;
- for(String i : mobNames()) {
- mob = getNearestNpc(i);
- }
- if(mob != null) {
- if(!mob.isInCombat()) {
- camera.turnTo(mob);
- if(mob.isOnScreen()) {
- mob.interact("Attack");
- return 500;
- }
- }
- }
- break;
- case Eat:
- if(inventory.containsItem(foodName)) {
- RSItem food = inventory.getItem(foodName);
- if(food != null) {
- food.interact("Eat");
- return 500;
- }
- } else {
- System.out.println("No food, stopping script!");
- stop();
- }
- break;
- case Walkback:
- TilePath a = createTilePath(startTile);
- a.traverse();
- break;
- case Loot:
- if(!inventory.isFull()) {
- TilePath i = createTilePath(loot.getLocation());
- if(Calculations.distanceBetween(getMyPlayer().getLocation(), loot.getLocation()) > 5) {
- i.traverse();
- }
- loot.interact("Take");
- return 500;
- } else {
- if(inventory.containsItem(foodName)) {
- RSItem food = inventory.getItem(foodName);
- if(food != null) {
- food.interact("Eat");
- return 500;
- }
- }
- }
- break;
- case OpenCasket:
- RSItem i = inventory.getItem("Casket");
- i.interact("Open");
- break;
- case Bury:
- RSItem[] i2 = inventory.getItems();
- for(RSItem i3 : i2) {
- if(i3.getName().toLowerCase().contains("bones")) {
- i3.interact("Bury");
- }
- }
- case Sleep:
- return 1000;
- }
- return 0;
- }
- @Override
- public void onBegin() {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- afpGUI i = new afpGUI();
- i.setVisible(true);
- }
- });
- startTime = System.currentTimeMillis();
- strXpS = skills.getExperience(skills.STRENGTH);
- defXpS = skills.getExperience(skills.DEFENSE);
- rngXpS = skills.getExperience(skills.RANGED);
- mageXpS = skills.getExperience(skills.MAGIC);
- attXpS = skills.getExperience(skills.ATTACK);
- strLvlS = skills.getLevel(skills.STRENGTH);
- defLvlS = skills.getLevel(skills.DEFENSE);
- rngLvlS = skills.getLevel(skills.RANGED);
- mageLvlS = skills.getLevel(skills.MAGIC);
- attLvlS = skills.getLevel(skills.ATTACK);
- }
- @Override
- public void onFinish() {
- }
- public String runtime(long start) {
- long millis = System.currentTimeMillis() - start;
- long hours = millis / (1000 * 60 * 60);
- millis -= hours * (1000 * 60 * 60);
- long minutes = millis / (1000 * 60);
- millis -= minutes * (1000 * 60);
- long seconds = millis / 1000;
- return "Time Running: "+ hours + ":" + minutes + ":" + seconds;
- }
- public String formatNumber(int start) {
- DecimalFormat nf = new DecimalFormat("0.0");
- double i = start;
- if(i >= 1000000) {
- return nf.format((i / 1000000)) + "m";
- }
- if(i >= 1000) {
- return nf.format((i / 1000)) + "k";
- }
- return ""+start;
- }
- public String perHour(int gained) {
- return formatNumber((int) ((gained) * 3600000D / (System.currentTimeMillis() - startTime)));
- }
- public void drawCharInfo(Graphics g, int y, Graphics2D g1) {
- if(getMyPlayer() != null) {
- g.setColor(Color.WHITE);
- g.drawString("AIOFighter by Kenneh", 7, y);
- y = y + 15;
- g.drawString(runtime(startTime), 7, y);
- y = y + 15;
- g.drawString("State: " + getStage().toString(), 7, y);
- y = y + 15;
- g.drawString(getSkillName() + skills.getLevel(getSkill())+"(+"+(skills.getLevel(getSkill()) - startLvl) + ")",7 , y);
- y = y + 15;
- g.drawString("Exp /hr: " + perHour(xpGained) + "(+" + formatNumber(xpGained) + ")", 7, y);
- y = y + 15;
- y = y + 15;
- for(String i : mobNames()) {
- g.drawString("Fighting: " + i, 7, y);
- y = y + 15;
- }
- y = y + 15;
- for(String i : lootItems()) {
- g.drawString("Looting: " + i, 7, y);
- y = y + 15;
- }
- g.setColor(color3);
- g.fillRect(3, 35, 149, y - 30);
- g.setColor(color2);
- g1.setStroke(stroke1);
- g.drawRect(3, 35, 149, y - 30);
- }
- }
- @Override
- public void paint(Graphics g) {
- Graphics2D g1 = (Graphics2D)g;
- g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
- g1.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- xpGained = skills.getExperience(getSkill()) - startXp;
- drawCharInfo(g, 65, g1);
- g.setColor(color1);
- g.fillRect(456, 312, 59, 25);
- g.setColor(color2);
- g1.setStroke(stroke1);
- g.drawRect(456, 312, 59, 25);
- g.setFont(font1);
- g.drawString("Add loot", 468, 330);
- mt.add(mouse.getLocation());
- mt.drawCursor(g);
- mt.drawTrail(g);
- }
- @Override
- public void mouseClicked(MouseEvent arg0) {
- Point p = arg0.getPoint();
- if(rect.contains(p)) {
- String loot1 = JOptionPane.showInputDialog(null, "Enter the items you want to loot seperated by a comma");
- String[] loot2 = loot1.split(",");
- for(String loot3:loot2) {
- lootList.add(loot3.trim());
- }
- }
- }
- @Override
- public void mouseEntered(MouseEvent arg0) {
- }
- @Override
- public void mouseExited(MouseEvent arg0) {
- }
- @Override
- public void mousePressed(MouseEvent arg0) {
- }
- @Override
- public void mouseReleased(MouseEvent arg0) {
- }
- public class afpGUI extends JFrame {
- /**
- *
- */
- private static final long serialVersionUID = -5606088774883000944L;
- public afpGUI() {
- initComponents();
- }
- @SuppressWarnings("deprecation")
- private void button1ActionPerformed(ActionEvent e) {
- foodName = comboBox1.getSelectedItem().toString();
- String loot1 = textPane2.getText();
- String[] loot2 = loot1.split(",");
- for(String loot3 : loot2) {
- lootList.add(loot3.trim());
- }
- String npc1 = textPane1.getText();
- String[] npc2 = npc1.split(",");
- for(String npc3 : npc2) {
- npcList.add(npc3.trim());
- }
- eatPercent = slider1.getValue();
- buryBones = checkBox1.isSelected();
- checkBox2.isSelected();
- PASS = passwordField1.getText();
- USER = textField1.getText();
- System.out.println("Food name: "+ foodName);
- System.out.println("Eat percent: " + eatPercent);
- System.out.println("Burying bones: " + buryBones);
- dispose();
- }
- private void initComponents() {
- label1 = new JLabel();
- scrollPane1 = new JScrollPane();
- textPane1 = new JTextPane();
- label2 = new JLabel();
- scrollPane2 = new JScrollPane();
- textPane2 = new JTextPane();
- button1 = new JButton();
- label3 = new JLabel();
- slider1 = new JSlider();
- label4 = new JLabel();
- comboBox1 = new JComboBox<Object>();
- checkBox1 = new JCheckBox();
- checkBox2 = new JCheckBox();
- label5 = new JLabel();
- textField1 = new JTextField();
- label6 = new JLabel();
- passwordField1 = new JPasswordField();
- //======== this ========
- setTitle("AutoFighterPro GUI");
- setBackground(Color.black);
- Container contentPane = getContentPane();
- contentPane.setLayout(null);
- //---- label1 ----
- label1.setText("Enter mob names");
- label1.setHorizontalAlignment(SwingConstants.CENTER);
- contentPane.add(label1);
- label1.setBounds(10, 10, 105, 15);
- //======== scrollPane1 ========
- {
- scrollPane1.setViewportView(textPane1);
- }
- contentPane.add(scrollPane1);
- scrollPane1.setBounds(5, 25, 115, 50);
- //---- label2 ----
- label2.setText("Enter loot names");
- label2.setHorizontalAlignment(SwingConstants.CENTER);
- contentPane.add(label2);
- label2.setBounds(145, 10, 99, label2.getPreferredSize().height);
- //======== scrollPane2 ========
- {
- scrollPane2.setViewportView(textPane2);
- }
- contentPane.add(scrollPane2);
- scrollPane2.setBounds(140, 25, 110, 50);
- //---- button1 ----
- button1.setText("Start Script");
- button1.addActionListener(new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- button1ActionPerformed(evt);
- }
- });
- contentPane.add(button1);
- button1.setBounds(0, 285, 255, 35);
- //---- label3 ----
- label3.setText("Enter percent to eat at");
- contentPane.add(label3);
- label3.setBounds(new Rectangle(new Point(65, 85), label3.getPreferredSize()));
- //---- slider1 ----
- slider1.setMinorTickSpacing(5);
- contentPane.add(slider1);
- slider1.setBounds(new Rectangle(new Point(25, 105), slider1.getPreferredSize()));
- //---- label4 ----
- label4.setText("Choose what food to eat");
- contentPane.add(label4);
- label4.setBounds(new Rectangle(new Point(60, 135), label4.getPreferredSize()));
- contentPane.add(comboBox1);
- String[] food = {"Monkfish", "Shark", "Lobster", "Manta Ray", "Swordfish"};
- comboBox1.setModel(new DefaultComboBoxModel<Object>(food));
- comboBox1.setBounds(30, 155, 195, comboBox1.getPreferredSize().height);
- //---- checkBox1 ----
- checkBox1.setText("Bury bones");
- contentPane.add(checkBox1);
- checkBox1.setBounds(new Rectangle(new Point(10, 195), checkBox1.getPreferredSize()));
- //---- checkBox2 ----
- checkBox2.setText("Use potions");
- checkBox2.setEnabled(false);
- contentPane.add(checkBox2);
- checkBox2.setBounds(new Rectangle(new Point(155, 195), checkBox2.getPreferredSize()));
- //---- label5 ----
- label5.setText("Username");
- contentPane.add(label5);
- label5.setBounds(10, 225, 60, 20);
- contentPane.add(textField1);
- textField1.setBounds(85, 225, 150, 25);
- //---- label6 ----
- label6.setText("Password");
- contentPane.add(label6);
- label6.setBounds(10, 255, label6.getPreferredSize().width, 20);
- contentPane.add(passwordField1);
- passwordField1.setBounds(85, 255, 150, 25);
- //passwordField1.setBounds(85, 255, 150, passwordField1.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 JScrollPane scrollPane1;
- private JTextPane textPane1;
- private JLabel label2;
- private JScrollPane scrollPane2;
- private JTextPane textPane2;
- private JButton button1;
- private JLabel label3;
- private JSlider slider1;
- private JLabel label4;
- private JComboBox<Object> comboBox1;
- private JCheckBox checkBox1;
- private JCheckBox checkBox2;
- private JLabel label5;
- private JTextField textField1;
- private JLabel label6;
- private JPasswordField passwordField1;
- }
- private class MousePaint {
- /**
- * Length of the trail
- */
- private final int SIZE = 50;
- /**
- * Gets the color of the trail depending on the SIZE
- */
- private final float rainbowStep = (float) (1.0/SIZE);
- /**
- * Gets the alpha of the trail depending on the SIZE
- */
- private final double alphaStep = (255.0/SIZE);
- /**
- * Declares the mouse points
- */
- private Point[] points;
- /**
- * Counts up the points
- */
- private int index;
- /**
- * Trail offset
- */
- private float offSet = 0.05f;
- /**
- * Trail start
- */
- private float start = 0;
- /**
- * Construter for MousePaint()
- */
- public MousePaint() {
- points = new Point[SIZE];
- index = 0;
- }
- /**
- * Adds the current mouse location as a point to draw the trail
- * @param p MouseLocation()
- */
- public void add(Point p) {
- points[index++] = p;
- index %= SIZE;
- }
- /**
- * Draws the cursor on the screen
- * @param graphics
- */
- public void drawCursor(Graphics graphics) {
- int x = (int)mouse.getLocation().getX();
- int y = (int)mouse.getLocation().getY();
- Graphics2D g2D = (Graphics2D) graphics;
- graphics.setColor(new Color((int) (Math.random() * 256), (int) (Math.random() * 256), (int) (Math.random() * 256)));
- Graphics2D spinner = (Graphics2D) g2D.create();
- spinner.rotate(System.currentTimeMillis() % 2000d / 2000d * (360d) * 2 * Math.PI / 180.0, x, y);
- spinner.drawLine(x - 6, y, x + 6, y);
- spinner.drawLine(x, y - 6, x, y +6);
- }
- /**
- * Draws the trail on screen
- * @param graphics
- */
- public void drawTrail(Graphics graphics) {
- Graphics2D g2D = (Graphics2D) graphics;
- g2D.setStroke(new BasicStroke(1F));
- double alpha = 0;
- float rainbow = start;
- start += offSet;
- if (start > 1) {
- start -= 1;
- }
- for (int i = index; i != (index == 0 ? SIZE-1 : index-1); i = (i+1)%SIZE) {
- if (points[i] != null && points[(i+1)%SIZE] != null) {
- int rgb = Color.HSBtoRGB(rainbow, 0.9f, 0.9f);
- rainbow += rainbowStep;
- if (rainbow > 1) {
- rainbow -= 1;
- }
- g2D.setColor(new Color((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff, (int)alpha));
- g2D.drawLine(points[i].x, points[i].y, points[(i+1)%SIZE].x, points[(i+1)%SIZE].y);
- alpha += alphaStep;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment