wafflecat

qwey3y

Feb 24th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.68 KB | None | 0 0
  1. import java.awt.BasicStroke;
  2. import java.awt.Color;
  3. import java.awt.Cursor;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.text.DecimalFormat;
  8.  
  9. import com.rarebot.event.events.MessageEvent;
  10. import com.rarebot.event.listeners.MessageListener;
  11. import com.rarebot.event.listeners.PaintListener;
  12. import com.rarebot.script.Script;
  13. import com.rarebot.script.ScriptManifest;
  14. import com.rarebot.script.methods.Skills;
  15. import com.rarebot.script.util.Filter;
  16. import com.rarebot.script.util.Timer;
  17. import com.rarebot.script.wrappers.RSItem;
  18. import com.rarebot.script.wrappers.RSNPC;
  19. import com.rarebot.script.wrappers.RSObject;
  20. import com.rarebot.script.wrappers.RSPath;
  21. import com.rarebot.script.wrappers.RSTile;
  22.  
  23. @ScriptManifest(authors = { "Boolean" }, name = "Bandit Fighter", keywords = { "Combat" }, description = "Fights bandits at Bandits' Camp.", version = 1.00)
  24. public class BanditFighter extends Script implements PaintListener,
  25. MessageListener {
  26.  
  27. RSTile storeTile = new RSTile(3176, 2987);
  28. int storeID = 1917;
  29. private static final int[] skill = { 0, 1, 2, 3 };
  30. private static final String[] skillNames = { "Attack", "Defence",
  31. "Strength", "Constitution" };
  32. private int[] startXP;
  33. private static final DecimalFormat k = new DecimalFormat("#.#");
  34. int banditID = 1931;
  35. boolean guiExit, guiWait = true;
  36. int foodID, notedFoodID;
  37. int eatAt;
  38. long start;
  39. Timer timer;
  40. BanditGUI gui;
  41.  
  42. public boolean onStart() {
  43. gui = new BanditGUI();
  44. while (guiWait) {
  45. sleep(10);
  46. }
  47. if (guiExit) {
  48. notedFoodID = foodID + 1;
  49. startXP = new int[4];
  50. for (int i = 0; i < skill.length; i++) {
  51. startXP[i] = skills.getCurrentExp(skill[i]);
  52. }
  53. start = System.currentTimeMillis();
  54. timer = new Timer(0);
  55. }
  56. return guiExit;
  57. }
  58.  
  59. public double version() {
  60. return BanditFighter.class.getAnnotation(ScriptManifest.class)
  61. .version();
  62. }
  63.  
  64. public String[] author() {
  65. return BanditFighter.class.getAnnotation(ScriptManifest.class)
  66. .authors();
  67. }
  68.  
  69. public enum actions {
  70. EAT, ATTACK, ANTIBAN, USE_STORE, STOP
  71. }
  72.  
  73. public actions actions() {
  74. if (inventory.contains(foodID)) {
  75. if (getMyPlayer().getHPPercent() > eatAt) {
  76. if (getMyPlayer().isInCombat()) {
  77. status = "Fighting";
  78. return actions.ANTIBAN;
  79. } else {
  80. status = "Attacking";
  81. return actions.ATTACK;
  82. }
  83. } else {
  84. status = "Healing";
  85. return actions.EAT;
  86. }
  87. } else {
  88. if (inventory.contains(notedFoodID)) {
  89. status = "Exchanging food";
  90. return actions.USE_STORE;
  91. } else {
  92. status = "Stopping, WTF?!";
  93. return actions.STOP;
  94. }
  95. }
  96. }
  97.  
  98. @Override
  99. public void messageReceived(MessageEvent arg0) {
  100. String msg = arg0.getMessage();
  101. if (msg.contains("eat")) {
  102. eaten++;
  103. }
  104. }
  105.  
  106. private final Color color1 = new Color(0, 0, 0);
  107. private final Color color2 = new Color(0, 204, 204);
  108.  
  109. private final BasicStroke stroke1 = new BasicStroke(1);
  110.  
  111. private final Font font1 = new Font("Comic Sans MS", 0, 12);
  112. private final Font font2 = new Font("Comic Sans MS", 0, 9);
  113.  
  114. String status = "Nothing";
  115. int eaten = 0;
  116.  
  117. public void onRepaint(Graphics g1) {
  118. double eph;
  119. int exp;
  120. int x = 190, y = 345, a = 195, b = 358;
  121. int eating = (int) (skills.getRealLevel(Skills.CONSTITUTION) * 10)
  122. / 100 * eatAt;
  123. Graphics2D g = (Graphics2D) g1;
  124. g.setColor(color1);
  125. g.fillRect(361, 345, 134, 96);
  126. g.setColor(color2);
  127. g.setStroke(stroke1);
  128. g.drawRect(361, 345, 134, 96);
  129. g.setFont(font1);
  130. g.drawString("Bandit Fighter v" + version() + "0", 366, 360);
  131. g.setFont(font2);
  132. g.drawString("Runtime: " + timer.toElapsedString(), 366, 375);
  133. g.drawString("Status: " + status, 366, 390);
  134. g.drawString("Food eaten: " + eaten, 366, 405);
  135. g.drawString("Author: Boolean", 366, 435);
  136. g.drawString("Eating when around: " + eating + " LP", 366, 420);
  137. for (int i = 0; i < 4; i++) {
  138. exp = (skills.getCurrentExp(skill[i]) - startXP[i]);
  139. if (exp > 0) {
  140. eph = (exp * 3600000D / (System.currentTimeMillis() - start));
  141. g.setFont(font2);
  142. g.setColor(color1);
  143. g.fillRect(x, y, 171, 20);
  144. g.setColor(color2);
  145. g.drawRect(x, y, 171, 20);
  146. g.drawString(skillNames[i] + " | Exp: " + k.format(exp / 1000D)
  147. + "K | P/H: " + k.format(eph / 1000D) + "K", a, b);
  148. b += 20;
  149. y += 20;
  150. }
  151. }
  152. }
  153.  
  154. private RSNPC interactingNPC() {
  155. return npcs.getNearest(new Filter<RSNPC>() {
  156. public boolean accept(RSNPC n) {
  157. return n.getInteracting() != null
  158. && n.getInteracting().equals(players.getMyPlayer());
  159. }
  160. });
  161. }
  162.  
  163. public RSNPC nextBandit() {
  164. RSNPC interacting = interactingNPC();
  165. return interacting != null ? interacting : npcs
  166. .getNearest(new Filter<RSNPC>() {
  167. public boolean accept(RSNPC npc) {
  168. return (npc.getID() == banditID && !npc.isInCombat() && npc
  169. .getHPPercent() > 0);
  170. }
  171. });
  172. }
  173.  
  174. public boolean atDoor() {
  175. RSObject door = objects.getNearest(1528);
  176. return door != null && door.isOnScreen();
  177. }
  178.  
  179. @Override
  180. public int loop() {
  181. RSNPC bandit = nextBandit();
  182. RSObject door = objects.getNearest(1528);
  183. switch (actions()) {
  184. case ATTACK:
  185. if (bandit != null) {
  186. if (bandit.isOnScreen()) {
  187. if (!atDoor()) {
  188. bandit.doAction("Attack");
  189. for (int w = 0; w < 300 && !getMyPlayer().isInCombat(); w++) {
  190. sleep(10);
  191. }
  192. } else {
  193. if (store.isOpen()) {
  194. store.close();
  195. } else {
  196. door.doAction("Open");
  197. for (int w = 0; w < 300 && atDoor(); w++) {
  198. sleep(10);
  199. }
  200. }
  201. }
  202. } else {
  203. if (atDoor()) {
  204. door.doAction("Open");
  205. for (int w = 0; w < 300 && atDoor(); w++) {
  206. sleep(10);
  207. }
  208. } else {
  209. if (calc.distanceTo(bandit) < 7) {
  210. camera.turnTo(bandit);
  211. } else {
  212. walking.walkTo(bandit.getLocation());
  213. }
  214. }
  215. }
  216. } else {
  217. return 300;
  218. }
  219. break;
  220. case ANTIBAN:
  221. break;
  222. case EAT:
  223. RSItem food = inventory.getItem(foodID);
  224. food.doAction("Eat");
  225. sleep(2000);
  226. case USE_STORE:
  227. RSNPC owner = npcs.getNearest(storeID);
  228. boolean atOwner = owner != null && owner.isOnScreen();
  229. if (atOwner) {
  230. if (store.isOpen()) {
  231. RSItem foods = store.getItem(foodID);
  232. if (foods != null) {
  233. store.buy(foodID, 10);
  234. for (int w = 0; w < 300 && !inventory.contains(foodID); w++) {
  235. sleep(10);
  236. }
  237. } else {
  238. inventory.getItem(notedFoodID).doAction("Sell 10");
  239. for (int w = 0; w < 300 && foods == null; w++) {
  240. sleep(10);
  241. }
  242. }
  243. } else {
  244. owner.doAction("Trade");
  245. for (int w = 0; w < 300 && !store.isOpen(); w++) {
  246. sleep(10);
  247. }
  248. }
  249. } else {
  250. if (!atDoor()) {
  251. RSPath web = walking.getPath(storeTile);
  252. web.traverse();
  253. } else {
  254. door.doAction("Open");
  255. for (int w = 0; w < 300 && atDoor(); w++) {
  256. sleep(10);
  257. }
  258. }
  259. }
  260. }
  261. return 1000;
  262. }
  263.  
  264. public class BanditGUI extends javax.swing.JFrame {
  265.  
  266. /**
  267. *
  268. */
  269. private static final long serialVersionUID = 1L;
  270.  
  271. public BanditGUI() {
  272. initComponents();
  273. }
  274.  
  275. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  276. eatAt = Integer.parseInt(jTextField2.getText());
  277. foodID = Integer.parseInt(jTextField1.getText());
  278. guiWait = false;
  279. guiExit = true;
  280. dispose();
  281. }
  282.  
  283. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  284. guiWait = false;
  285. guiExit = false;
  286. }
  287.  
  288. private void initComponents() {
  289.  
  290. jLabel1 = new javax.swing.JLabel();
  291. jButton1 = new javax.swing.JButton();
  292. jButton2 = new javax.swing.JButton();
  293. jLabel2 = new javax.swing.JLabel();
  294. jTextField1 = new javax.swing.JTextField();
  295. jLabel3 = new javax.swing.JLabel();
  296. jTextField2 = new javax.swing.JTextField();
  297. jLabel4 = new javax.swing.JLabel();
  298. jLabel5 = new javax.swing.JLabel();
  299.  
  300. this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  301. this.setAlwaysOnTop(true);
  302. this.setVisible(true);
  303. this.setTitle("GUI");
  304. this.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
  305.  
  306. jLabel1.setFont(new java.awt.Font("Trebuchet MS", 1, 14));
  307. jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  308. jLabel1.setText("Bandit Fighter");
  309.  
  310. jButton1.setText("Start");
  311. jButton1.addActionListener(new java.awt.event.ActionListener() {
  312. public void actionPerformed(java.awt.event.ActionEvent evt) {
  313. jButton1ActionPerformed(evt);
  314. }
  315. });
  316.  
  317. jButton2.setText("Cancel");
  318. jButton2.addActionListener(new java.awt.event.ActionListener() {
  319. public void actionPerformed(java.awt.event.ActionEvent evt) {
  320. jButton2ActionPerformed(evt);
  321. }
  322. });
  323.  
  324. jLabel2.setText("Food ID:");
  325.  
  326. jLabel3.setText("Eat when below:");
  327.  
  328. jTextField2.setText("50");
  329.  
  330. jTextField1.setText("373");
  331.  
  332. jLabel4.setText("% HP");
  333.  
  334. jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  335. jLabel5.setText("Report bugs at Powerbot.org");
  336.  
  337. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
  338. getContentPane());
  339. getContentPane().setLayout(layout);
  340. layout.setHorizontalGroup(layout
  341. .createParallelGroup(
  342. javax.swing.GroupLayout.Alignment.LEADING)
  343. .addGroup(
  344. layout.createSequentialGroup()
  345. .addContainerGap()
  346. .addGroup(
  347. layout.createParallelGroup(
  348. javax.swing.GroupLayout.Alignment.LEADING)
  349. .addComponent(
  350. jLabel5,
  351. javax.swing.GroupLayout.DEFAULT_SIZE,
  352. 214,
  353. Short.MAX_VALUE)
  354. .addComponent(
  355. jLabel1,
  356. javax.swing.GroupLayout.DEFAULT_SIZE,
  357. 214,
  358. Short.MAX_VALUE)
  359. .addGroup(
  360. javax.swing.GroupLayout.Alignment.TRAILING,
  361. layout.createSequentialGroup()
  362. .addGroup(
  363. layout.createParallelGroup(
  364. javax.swing.GroupLayout.Alignment.LEADING)
  365. .addGroup(
  366. layout.createSequentialGroup()
  367. .addGroup(
  368. layout.createParallelGroup(
  369. javax.swing.GroupLayout.Alignment.TRAILING)
  370. .addComponent(
  371. jLabel2,
  372. javax.swing.GroupLayout.Alignment.LEADING,
  373. javax.swing.GroupLayout.DEFAULT_SIZE,
  374. 103,
  375. Short.MAX_VALUE)
  376. .addComponent(
  377. jButton1,
  378. javax.swing.GroupLayout.DEFAULT_SIZE,
  379. 103,
  380. Short.MAX_VALUE))
  381. .addPreferredGap(
  382. javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
  383. .addGroup(
  384. layout.createSequentialGroup()
  385. .addComponent(
  386. jLabel3)
  387. .addGap(33,
  388. 33,
  389. 33)))
  390. .addGroup(
  391. layout.createParallelGroup(
  392. javax.swing.GroupLayout.Alignment.LEADING)
  393. .addGroup(
  394. layout.createParallelGroup(
  395. javax.swing.GroupLayout.Alignment.LEADING,
  396. false)
  397. .addComponent(
  398. jTextField1)
  399. .addComponent(
  400. jButton2,
  401. javax.swing.GroupLayout.DEFAULT_SIZE,
  402. 101,
  403. Short.MAX_VALUE))
  404. .addGroup(
  405. layout.createSequentialGroup()
  406. .addComponent(
  407. jTextField2,
  408. javax.swing.GroupLayout.PREFERRED_SIZE,
  409. 50,
  410. javax.swing.GroupLayout.PREFERRED_SIZE)
  411. .addPreferredGap(
  412. javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  413. .addComponent(
  414. jLabel4)))))
  415. .addContainerGap()));
  416. layout.setVerticalGroup(layout
  417. .createParallelGroup(
  418. javax.swing.GroupLayout.Alignment.LEADING)
  419. .addGroup(
  420. layout.createSequentialGroup()
  421. .addContainerGap()
  422. .addComponent(
  423. jLabel1,
  424. javax.swing.GroupLayout.PREFERRED_SIZE,
  425. 39,
  426. javax.swing.GroupLayout.PREFERRED_SIZE)
  427. .addPreferredGap(
  428. javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  429. .addGroup(
  430. layout.createParallelGroup(
  431. javax.swing.GroupLayout.Alignment.BASELINE)
  432. .addComponent(jLabel2)
  433. .addComponent(
  434. jTextField1,
  435. javax.swing.GroupLayout.PREFERRED_SIZE,
  436. javax.swing.GroupLayout.DEFAULT_SIZE,
  437. javax.swing.GroupLayout.PREFERRED_SIZE))
  438. .addPreferredGap(
  439. javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  440. .addGroup(
  441. layout.createParallelGroup(
  442. javax.swing.GroupLayout.Alignment.BASELINE)
  443. .addComponent(jLabel3)
  444. .addComponent(
  445. jTextField2,
  446. javax.swing.GroupLayout.PREFERRED_SIZE,
  447. javax.swing.GroupLayout.DEFAULT_SIZE,
  448. javax.swing.GroupLayout.PREFERRED_SIZE)
  449. .addComponent(jLabel4))
  450. .addGap(18, 18, 18)
  451. .addComponent(jLabel5)
  452. .addPreferredGap(
  453. javax.swing.LayoutStyle.ComponentPlacement.RELATED,
  454. 20, Short.MAX_VALUE)
  455. .addGroup(
  456. layout.createParallelGroup(
  457. javax.swing.GroupLayout.Alignment.BASELINE)
  458. .addComponent(jButton1)
  459. .addComponent(jButton2))
  460. .addContainerGap()));
  461.  
  462. pack();
  463. }
  464.  
  465. public void main(String args[]) {
  466. java.awt.EventQueue.invokeLater(new Runnable() {
  467. public void run() {
  468. new BanditGUI().setVisible(true);
  469. }
  470. });
  471. }
  472.  
  473. private javax.swing.JButton jButton1;
  474. private javax.swing.JButton jButton2;
  475. private javax.swing.JLabel jLabel1;
  476. private javax.swing.JLabel jLabel2;
  477. private javax.swing.JLabel jLabel3;
  478. private javax.swing.JLabel jLabel4;
  479. private javax.swing.JLabel jLabel5;
  480. private javax.swing.JTextField jTextField1;
  481. private javax.swing.JTextField jTextField2;
  482. }
  483.  
  484. }
Advertisement
Add Comment
Please, Sign In to add comment