Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BasicStroke;
- import java.awt.Color;
- import java.awt.Cursor;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.text.DecimalFormat;
- import com.rarebot.event.events.MessageEvent;
- import com.rarebot.event.listeners.MessageListener;
- import com.rarebot.event.listeners.PaintListener;
- import com.rarebot.script.Script;
- import com.rarebot.script.ScriptManifest;
- import com.rarebot.script.methods.Skills;
- import com.rarebot.script.util.Filter;
- import com.rarebot.script.util.Timer;
- import com.rarebot.script.wrappers.RSItem;
- import com.rarebot.script.wrappers.RSNPC;
- import com.rarebot.script.wrappers.RSObject;
- import com.rarebot.script.wrappers.RSPath;
- import com.rarebot.script.wrappers.RSTile;
- @ScriptManifest(authors = { "Boolean" }, name = "Bandit Fighter", keywords = { "Combat" }, description = "Fights bandits at Bandits' Camp.", version = 1.00)
- public class BanditFighter extends Script implements PaintListener,
- MessageListener {
- RSTile storeTile = new RSTile(3176, 2987);
- int storeID = 1917;
- private static final int[] skill = { 0, 1, 2, 3 };
- private static final String[] skillNames = { "Attack", "Defence",
- "Strength", "Constitution" };
- private int[] startXP;
- private static final DecimalFormat k = new DecimalFormat("#.#");
- int banditID = 1931;
- boolean guiExit, guiWait = true;
- int foodID, notedFoodID;
- int eatAt;
- long start;
- Timer timer;
- BanditGUI gui;
- public boolean onStart() {
- gui = new BanditGUI();
- while (guiWait) {
- sleep(10);
- }
- if (guiExit) {
- notedFoodID = foodID + 1;
- startXP = new int[4];
- for (int i = 0; i < skill.length; i++) {
- startXP[i] = skills.getCurrentExp(skill[i]);
- }
- start = System.currentTimeMillis();
- timer = new Timer(0);
- }
- return guiExit;
- }
- public double version() {
- return BanditFighter.class.getAnnotation(ScriptManifest.class)
- .version();
- }
- public String[] author() {
- return BanditFighter.class.getAnnotation(ScriptManifest.class)
- .authors();
- }
- public enum actions {
- EAT, ATTACK, ANTIBAN, USE_STORE, STOP
- }
- public actions actions() {
- if (inventory.contains(foodID)) {
- if (getMyPlayer().getHPPercent() > eatAt) {
- if (getMyPlayer().isInCombat()) {
- status = "Fighting";
- return actions.ANTIBAN;
- } else {
- status = "Attacking";
- return actions.ATTACK;
- }
- } else {
- status = "Healing";
- return actions.EAT;
- }
- } else {
- if (inventory.contains(notedFoodID)) {
- status = "Exchanging food";
- return actions.USE_STORE;
- } else {
- status = "Stopping, WTF?!";
- return actions.STOP;
- }
- }
- }
- @Override
- public void messageReceived(MessageEvent arg0) {
- String msg = arg0.getMessage();
- if (msg.contains("eat")) {
- eaten++;
- }
- }
- private final Color color1 = new Color(0, 0, 0);
- private final Color color2 = new Color(0, 204, 204);
- private final BasicStroke stroke1 = new BasicStroke(1);
- private final Font font1 = new Font("Comic Sans MS", 0, 12);
- private final Font font2 = new Font("Comic Sans MS", 0, 9);
- String status = "Nothing";
- int eaten = 0;
- public void onRepaint(Graphics g1) {
- double eph;
- int exp;
- int x = 190, y = 345, a = 195, b = 358;
- int eating = (int) (skills.getRealLevel(Skills.CONSTITUTION) * 10)
- / 100 * eatAt;
- Graphics2D g = (Graphics2D) g1;
- g.setColor(color1);
- g.fillRect(361, 345, 134, 96);
- g.setColor(color2);
- g.setStroke(stroke1);
- g.drawRect(361, 345, 134, 96);
- g.setFont(font1);
- g.drawString("Bandit Fighter v" + version() + "0", 366, 360);
- g.setFont(font2);
- g.drawString("Runtime: " + timer.toElapsedString(), 366, 375);
- g.drawString("Status: " + status, 366, 390);
- g.drawString("Food eaten: " + eaten, 366, 405);
- g.drawString("Author: Boolean", 366, 435);
- g.drawString("Eating when around: " + eating + " LP", 366, 420);
- for (int i = 0; i < 4; i++) {
- exp = (skills.getCurrentExp(skill[i]) - startXP[i]);
- if (exp > 0) {
- eph = (exp * 3600000D / (System.currentTimeMillis() - start));
- g.setFont(font2);
- g.setColor(color1);
- g.fillRect(x, y, 171, 20);
- g.setColor(color2);
- g.drawRect(x, y, 171, 20);
- g.drawString(skillNames[i] + " | Exp: " + k.format(exp / 1000D)
- + "K | P/H: " + k.format(eph / 1000D) + "K", a, b);
- b += 20;
- y += 20;
- }
- }
- }
- private RSNPC interactingNPC() {
- return npcs.getNearest(new Filter<RSNPC>() {
- public boolean accept(RSNPC n) {
- return n.getInteracting() != null
- && n.getInteracting().equals(players.getMyPlayer());
- }
- });
- }
- public RSNPC nextBandit() {
- RSNPC interacting = interactingNPC();
- return interacting != null ? interacting : npcs
- .getNearest(new Filter<RSNPC>() {
- public boolean accept(RSNPC npc) {
- return (npc.getID() == banditID && !npc.isInCombat() && npc
- .getHPPercent() > 0);
- }
- });
- }
- public boolean atDoor() {
- RSObject door = objects.getNearest(1528);
- return door != null && door.isOnScreen();
- }
- @Override
- public int loop() {
- RSNPC bandit = nextBandit();
- RSObject door = objects.getNearest(1528);
- switch (actions()) {
- case ATTACK:
- if (bandit != null) {
- if (bandit.isOnScreen()) {
- if (!atDoor()) {
- bandit.doAction("Attack");
- for (int w = 0; w < 300 && !getMyPlayer().isInCombat(); w++) {
- sleep(10);
- }
- } else {
- if (store.isOpen()) {
- store.close();
- } else {
- door.doAction("Open");
- for (int w = 0; w < 300 && atDoor(); w++) {
- sleep(10);
- }
- }
- }
- } else {
- if (atDoor()) {
- door.doAction("Open");
- for (int w = 0; w < 300 && atDoor(); w++) {
- sleep(10);
- }
- } else {
- if (calc.distanceTo(bandit) < 7) {
- camera.turnTo(bandit);
- } else {
- walking.walkTo(bandit.getLocation());
- }
- }
- }
- } else {
- return 300;
- }
- break;
- case ANTIBAN:
- break;
- case EAT:
- RSItem food = inventory.getItem(foodID);
- food.doAction("Eat");
- sleep(2000);
- case USE_STORE:
- RSNPC owner = npcs.getNearest(storeID);
- boolean atOwner = owner != null && owner.isOnScreen();
- if (atOwner) {
- if (store.isOpen()) {
- RSItem foods = store.getItem(foodID);
- if (foods != null) {
- store.buy(foodID, 10);
- for (int w = 0; w < 300 && !inventory.contains(foodID); w++) {
- sleep(10);
- }
- } else {
- inventory.getItem(notedFoodID).doAction("Sell 10");
- for (int w = 0; w < 300 && foods == null; w++) {
- sleep(10);
- }
- }
- } else {
- owner.doAction("Trade");
- for (int w = 0; w < 300 && !store.isOpen(); w++) {
- sleep(10);
- }
- }
- } else {
- if (!atDoor()) {
- RSPath web = walking.getPath(storeTile);
- web.traverse();
- } else {
- door.doAction("Open");
- for (int w = 0; w < 300 && atDoor(); w++) {
- sleep(10);
- }
- }
- }
- }
- return 1000;
- }
- public class BanditGUI extends javax.swing.JFrame {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- public BanditGUI() {
- initComponents();
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- eatAt = Integer.parseInt(jTextField2.getText());
- foodID = Integer.parseInt(jTextField1.getText());
- guiWait = false;
- guiExit = true;
- dispose();
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- guiWait = false;
- guiExit = false;
- }
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jLabel2 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jLabel3 = new javax.swing.JLabel();
- jTextField2 = new javax.swing.JTextField();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- this.setAlwaysOnTop(true);
- this.setVisible(true);
- this.setTitle("GUI");
- this.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
- jLabel1.setFont(new java.awt.Font("Trebuchet MS", 1, 14));
- jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- jLabel1.setText("Bandit Fighter");
- jButton1.setText("Start");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("Cancel");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jLabel2.setText("Food ID:");
- jLabel3.setText("Eat when below:");
- jTextField2.setText("50");
- jTextField1.setText("373");
- jLabel4.setText("% HP");
- jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- jLabel5.setText("Report bugs at Powerbot.org");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
- getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(layout
- .createParallelGroup(
- javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(
- layout.createParallelGroup(
- javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(
- jLabel5,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- 214,
- Short.MAX_VALUE)
- .addComponent(
- jLabel1,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- 214,
- Short.MAX_VALUE)
- .addGroup(
- javax.swing.GroupLayout.Alignment.TRAILING,
- layout.createSequentialGroup()
- .addGroup(
- layout.createParallelGroup(
- javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- layout.createSequentialGroup()
- .addGroup(
- layout.createParallelGroup(
- javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(
- jLabel2,
- javax.swing.GroupLayout.Alignment.LEADING,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- 103,
- Short.MAX_VALUE)
- .addComponent(
- jButton1,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- 103,
- Short.MAX_VALUE))
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
- .addGroup(
- layout.createSequentialGroup()
- .addComponent(
- jLabel3)
- .addGap(33,
- 33,
- 33)))
- .addGroup(
- layout.createParallelGroup(
- javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- layout.createParallelGroup(
- javax.swing.GroupLayout.Alignment.LEADING,
- false)
- .addComponent(
- jTextField1)
- .addComponent(
- jButton2,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- 101,
- Short.MAX_VALUE))
- .addGroup(
- layout.createSequentialGroup()
- .addComponent(
- jTextField2,
- javax.swing.GroupLayout.PREFERRED_SIZE,
- 50,
- javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(
- jLabel4)))))
- .addContainerGap()));
- layout.setVerticalGroup(layout
- .createParallelGroup(
- javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(
- jLabel1,
- javax.swing.GroupLayout.PREFERRED_SIZE,
- 39,
- javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(
- layout.createParallelGroup(
- javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(
- jTextField1,
- javax.swing.GroupLayout.PREFERRED_SIZE,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(
- layout.createParallelGroup(
- javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(
- jTextField2,
- javax.swing.GroupLayout.PREFERRED_SIZE,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel4))
- .addGap(18, 18, 18)
- .addComponent(jLabel5)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement.RELATED,
- 20, Short.MAX_VALUE)
- .addGroup(
- layout.createParallelGroup(
- javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addContainerGap()));
- pack();
- }
- public void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new BanditGUI().setVisible(true);
- }
- });
- }
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment