Advertisement
wafflecat

asdg4h

Feb 23rd, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.72 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5.  
  6. import com.rarebot.event.events.MessageEvent;
  7. import com.rarebot.event.listeners.MessageListener;
  8. import com.rarebot.event.listeners.PaintListener;
  9. import com.rarebot.script.Script;
  10. import com.rarebot.script.ScriptManifest;
  11. import com.rarebot.script.methods.Bank;
  12. import com.rarebot.script.util.Filter;
  13. import com.rarebot.script.wrappers.RSGroundItem;
  14. import com.rarebot.script.wrappers.RSItem;
  15. import com.rarebot.script.wrappers.RSNPC;
  16. import com.rarebot.script.wrappers.RSObject;
  17. import com.rarebot.script.wrappers.RSTile;
  18.  
  19.  
  20. @ScriptManifest(authors = "Aron", name = "SpiceGetter", version = 1.0, description = "Gets spices from evil dave's hellcats!")
  21. public class spiceGetter extends Script implements PaintListener, MessageListener{
  22.  
  23. private RSNPC cat = null;
  24. ArrayList<Integer> spices = new ArrayList<Integer>();
  25. private String status = "Starting..";
  26. private int emptySpice = 7496;
  27. private boolean guiDone = false;
  28. private RSTile mainTile = new RSTile( 3079, 9886 );
  29. private int[][] combinableSpices = new int[4][3];
  30. private boolean returning = true;
  31. private long sendTime;
  32. private long antibanTime;
  33. private int[] fullSpices = { 7480, 7484, 7492, 7488 };
  34.  
  35. //Credits to Foulwerp
  36. private RSNPC interactingNPC() {
  37. return npcs.getNearest(new Filter<RSNPC>() {
  38. public boolean accept(RSNPC n) {
  39. if (n.getInteracting() == null) {
  40. return false;
  41. }
  42. String[] acts = n.getActions();
  43. if (acts == null) {
  44. return false;
  45. }
  46. for (String a : acts) {
  47. if (a == null || !a.contains("Pick-up")) {
  48. continue;
  49. }
  50. return n.getInteracting().equals(players.getMyPlayer()) && (n.getName().contains("cat") || n.getName().contains("kitten"));
  51. }
  52. return false;
  53. }
  54. });
  55. }
  56.  
  57. private RSItem inventoryContainsCat() {
  58. RSItem[] inv = inventory.getCachedItems();
  59. for (int i = 0; i < inv.length; i++){
  60. if (inv[i].getName().contains("cat") || inv[i].getName().contains("kitten"))
  61. return inv[i];
  62. }
  63. return null;
  64. }
  65.  
  66. private RSGroundItem getLoot() {
  67. return groundItems.getNearest(new Filter<RSGroundItem>(){
  68. public boolean accept(RSGroundItem item) {
  69. for (int s : spices) {
  70. if (item.getItem().getID() == s){
  71. return true;
  72. }
  73. }
  74. return false;
  75. }});
  76. }
  77.  
  78. private boolean hasLoot() {
  79. return getLoot() != null;
  80. }
  81.  
  82. @SuppressWarnings("deprecation")
  83. private int lootStuff() {
  84. if (getLoot() != null){
  85. final RSGroundItem loot = getLoot();
  86. if (loot != null){
  87. if (!getMyPlayer().isMoving()){
  88. if(loot.isOnScreen()){
  89. loot.doAction("Take " + loot.getItem().getName());
  90. return random(500, 900);
  91. } else{
  92. walking.walkTileMM(walking.getClosestTileOnMap(walking.randomizeTile(loot.getLocation(), 1, 1)));
  93. return random(500, 1500);
  94. }
  95. } else if(!loot.isOnScreen()){
  96. camera.turnToTile(loot.getLocation(), 20);
  97. }
  98. }
  99. }
  100. return 0;
  101. }
  102.  
  103. private int canCombine() {
  104. int[][] spiceLoad = new int[4][4];
  105. for (int i = 0; i < spices.size(); i++){
  106. if (i <= 3){
  107. spiceLoad[0][i] = inventory.getCount(spices.get(i));
  108. } else if(i <= 7){
  109. spiceLoad[1][i - 4] = inventory.getCount(spices.get(i));
  110. } else if(i <= 11){
  111. spiceLoad[2][i - 8] = inventory.getCount(spices.get(i));
  112. } else if(i <= 15){
  113. spiceLoad[3][i - 12] = inventory.getCount(spices.get(i));
  114. }
  115. }
  116. for (int i = 0; i < 4; i++){
  117. if (hasMultiple(spiceLoad[i])) return (i);
  118. }
  119. return - 1;
  120. }
  121.  
  122.  
  123. private boolean hasMultiple(int[] load) {
  124. int k = 0;
  125. for (int i = 0; i < 3; i++){
  126. if (load[i] != 0) k+= load[i];
  127. }
  128. return k > 1;
  129. }
  130.  
  131. private int combineSpices(int index) {
  132. RSItem item1 = inventory.getItem(combinableSpices[index]);
  133. RSItem item2 = null;
  134. RSItem[] spiceArray = inventory.getItems(combinableSpices[index]);
  135. for (int i = 0; i < spiceArray.length; i++){
  136. if (spiceArray[i].getComponent().getAbsoluteX() != item1.getComponent().getAbsoluteX()){
  137. item2 = spiceArray[i];
  138. continue;
  139. }
  140. }
  141. if (item1 == null || item2 == null || item1.getComponent().getAbsoluteX() == item2.getComponent().getAbsoluteX()) return 0;
  142. while (!inventory.useItem(item2, item1)){
  143. sleep(200, 500);
  144. }
  145. return random(400, 700);
  146. }
  147.  
  148. private int antiban() {
  149. status = "Antiban";
  150. if (random(1, 10) > 3){
  151. camera.moveRandomly(random(500, 1500));
  152. antibanTime = System.currentTimeMillis() + random(-10000, -5000);
  153. return random(200, 700);
  154. }
  155. switch(random(1, 10)){
  156. case 1: mouse.moveRandomly(50, 120);
  157. antibanTime = System.currentTimeMillis() + random(-5000, 5000);
  158. case 2: mouse.moveRandomly(10, 50);
  159. antibanTime = System.currentTimeMillis() + random(-5000, 5000);
  160. case 3: mouse.moveOffScreen();
  161. antibanTime = System.currentTimeMillis() + random(-5000, 5000);
  162. case 4: camera.moveRandomly(random(1000, 3000));
  163. antibanTime = System.currentTimeMillis() + random(-5000, 5000);
  164. case 5: camera.turnToTile(cat.getLocation());
  165. antibanTime = System.currentTimeMillis() + random(-5000, 5000);
  166. case 6: mouse.moveSlightly();
  167. antibanTime = System.currentTimeMillis() + random(-5000, 5000);
  168. case 7: mouse.setSpeed(random(7, 9));
  169. antibanTime = System.currentTimeMillis() + random(-5000, 5000);
  170. case 8: antibanTime = System.currentTimeMillis() + random(5000, 15000);
  171. case 9: if (groundItems.getAll()[0] != null)
  172. groundItems.getAll()[0].getItem().doClick(false);
  173. antibanTime = System.currentTimeMillis() + random(-5000, 5000);
  174. case 10: if (getLoot() != null)
  175. camera.turnToTile(getLoot().getLocation());
  176. antibanTime = System.currentTimeMillis() + random(-5000, 5000);
  177. }
  178. return random(200, 700);
  179. }
  180.  
  181.  
  182. public boolean onStart(){
  183. form form = new form();
  184. form.setVisible(true);
  185. mouse.setSpeed(8);
  186. while(!guiDone){
  187. sleep(1);
  188. }
  189. for (int i = 0; i < 4; i++){
  190. for (int k = 0; k < 3; k++){
  191. combinableSpices[i][k] = spices.get(i * 4 + k);
  192. }
  193. }
  194. if (inventoryContainsCat() != null || (interactingNPC() != null && (interactingNPC().getName().contains("cat") || interactingNPC().getName().contains("kitten"))))
  195. return true;
  196. log("Start with Cat/kitten in inv/on ground.");
  197. return false;
  198. }
  199.  
  200. public void onFinish(){
  201.  
  202. }
  203.  
  204.  
  205. @Override
  206. public int loop() {
  207. //Start - stuff
  208. if (inventoryContainsCat() != null && cat == null) {
  209. inventoryContainsCat().doAction("Drop");
  210. return random(3000, 4500);
  211. }
  212. if (interactingNPC() != null)
  213. cat = interactingNPC();
  214. //"Real" loop
  215. if (cat == null){
  216. log("Something wrong with your cat..");
  217. stopScript();
  218. }
  219. if (inventory.getCount(fullSpices) > 26 && !inventory.containsOneOf(emptySpice)){
  220. if (!getMyPlayer().isMoving()){
  221. return bank();
  222. } else if(walking.getDestination() != null && calc.distanceBetween(getMyPlayer().getLocation(), walking.getDestination()) < 4){
  223. return bank();
  224. }
  225. }
  226. if (!inventory.containsOneOf(fullSpices) && npcs.getNearest(3382) == null)
  227. if (!getMyPlayer().isMoving()){
  228. return back();
  229. } else if(walking.getDestination() != null && calc.distanceBetween(getMyPlayer().getLocation(), walking.getDestination()) < 4){
  230. return back();
  231. }
  232. if (npcs.getNearest(3382) != null && inventory.getCount() < 28){
  233. if (getMyPlayer().isMoving()){
  234. return random(200, 500);
  235. }
  236. if (calc.distanceBetween(getMyPlayer().getLocation(), mainTile) > 6 && !hasLoot()){
  237. walking.walkTileMM(new RSTile(mainTile.getX() + random(-1, 1), mainTile.getY() + random(-1, 1)), 1, 1);
  238. return random(1000, 1500);
  239. }
  240. if (interfaces.getComponent(230, 3).isValid()){
  241. interfaces.getComponent(230, 3).doClick();
  242. return random(1000, 2000);
  243. }
  244. if (System.currentTimeMillis() - antibanTime > 24000)
  245. return antiban();
  246. if (!returning){
  247. if (System.currentTimeMillis() - sendTime < 10000){
  248. status = "Waiting for your cat to return";
  249. return (int) (calc.distanceBetween(cat.getLocation(), getMyPlayer().getLocation()) * random(100, 200));
  250. } else if (returning && !cat.isMoving() && calc.distanceBetween(cat.getLocation(), getMyPlayer().getLocation()) > 2)
  251. summoning.doAction("Call Follower");
  252. return random(300, 600);
  253. }
  254.  
  255. if (hasLoot()) {
  256. status = "Looting";
  257. return lootStuff();
  258. }
  259. if (canCombine() != - 1){
  260. status = "Combining Spices";
  261. combineSpices(canCombine());
  262. }
  263. if (inventory.containsOneOf(emptySpice)){
  264. status = "Dropping empty Spices";
  265. if(!inventory.getItem(emptySpice).doAction("Drop"))
  266. return random(100, 300);
  267. return random(800, 1300);
  268. }
  269. status = "Go on puss.. Kill that rat!";
  270. if (menu.isOpen())
  271. mouse.moveRandomly(50);
  272. if (!cat.doAction("Interact-with " + cat.getName()))
  273. return random(100, 300);
  274. return random(900, 1300);
  275. }
  276. return 0;
  277. }
  278.  
  279.  
  280. @SuppressWarnings("deprecation")
  281. private int back() {
  282. status = "Walking back";
  283. RSObject stairs = objects.getNearest(12266);
  284. RSObject closedDoor = objects.getNearest(24381);
  285. RSObject openDoor = objects.getNearest(24379);
  286. if (openDoor != null && !openDoor.isOnScreen()){
  287. walking.walkTileMM(walking.randomizeTile(openDoor.getLocation(), 1, 1));
  288. return random(1400, 2100);
  289. }
  290. if (closedDoor != null){
  291. if (closedDoor.isOnScreen())
  292. closedDoor.doAction("Open ");
  293. else
  294. walking.walkTileMM(walking.randomizeTile(closedDoor.getLocation(), 1, 1));
  295. return random(1200, 2100);
  296. }
  297. if (stairs != null && openDoor != null){
  298. if (!stairs.isOnScreen()){
  299. walking.walkTileMM(walking.randomizeTile(stairs.getLocation(), 1, 1));
  300. return random(1200, 2100);
  301. }
  302. stairs.doHover();
  303. if (menu.contains("Go-down")){
  304. if(!stairs.doAction("Go-down"))
  305. return random(100, 300);
  306. return random(1200, 2100);
  307. } else if (menu.contains("Open")){
  308. if(!stairs.doAction("Open"))
  309. return random(100, 300);
  310. return random(1200, 2100);
  311. }
  312. }
  313. return 0;
  314. }
  315.  
  316. @SuppressWarnings("deprecation")
  317. private int bank() {
  318. status = "Banking";
  319. RSObject stairs = objects.getNearest(12265);
  320. RSObject closedDoor = objects.getNearest(24381);
  321. RSObject openDoor = objects.getNearest(24379);
  322. if (bank.isOpen()){
  323. if(!bank.depositAll())
  324. return random(200, 500);
  325. return random(1200, 2100);
  326. }
  327. if (openDoor != null && objects.getNearest(Bank.BANK_BOOTHS) != null){
  328. if (objects.getNearest(Bank.BANK_BOOTHS).isOnScreen())
  329. objects.getNearest(Bank.BANK_BOOTHS).doAction("Use-quickly ");
  330. else
  331. walking.walkTileMM(walking.randomizeTile(objects.getNearest(Bank.BANK_BOOTHS).getLocation(), 1, 1));
  332. return random(1200, 2100);
  333. }
  334. if (closedDoor != null){
  335. if (closedDoor.isOnScreen())
  336. closedDoor.doAction("Open ");
  337. else
  338. walking.walkTileMM(walking.randomizeTile(closedDoor.getLocation(), 1, 1));
  339. return random(1200, 2100);
  340. }
  341. if (stairs != null){
  342. if (stairs.isOnScreen())
  343. stairs.doAction("Climb ");
  344. else
  345. walking.walkTileMM(walking.randomizeTile(stairs.getLocation(), 1, 1));
  346. return random(1200, 2100);
  347. }
  348. return 0;
  349. }
  350.  
  351. @Override
  352. public void messageReceived(MessageEvent m) {
  353. if (m.getSender() == getMyPlayer().getName()){
  354. if (m.getMessage().contains("Go on puss")){
  355. returning = false;
  356. sendTime = System.currentTimeMillis();
  357. } else if (m.getMessage().contains("Hey well done")){
  358. returning = true;
  359. }
  360. } else if (m.getID() == MessageEvent.MESSAGE_SERVER){
  361. if (m.getMessage().contains("Your cat cannot get to its prey"))
  362. returning = true;
  363. }
  364. }
  365.  
  366. //PAINT
  367. @Override
  368. public void onRepaint(Graphics g) {
  369. g.setColor(new Color(0, 0, 0, 200));
  370. g.setFont(new Font("Arial", 0, 11));
  371. g.drawString(status, 110, 470);
  372. if (canCombine() != -1){
  373. int index = canCombine();
  374. RSItem item1 = inventory.getItem(combinableSpices[index]);
  375. RSItem item2 = null;
  376. RSItem[] spiceArray = inventory.getItems(combinableSpices[index]);
  377. for (int i = 0; i < spiceArray.length; i++){
  378. if (spiceArray[i].getComponent().getAbsoluteX() != item1.getComponent().getAbsoluteX()){
  379. item2 = spiceArray[i];
  380. continue;
  381. }
  382. }
  383. if (item1 != null && item2 != null /*&& item1.getComponent().getAbsoluteX() != item2.getComponent().getAbsoluteX()*/){
  384. g.setColor(new Color(0, 70, 70, 200));
  385. g.drawRect(item1.getComponent().getAbsoluteX(), item1.getComponent().getAbsoluteY(), item1.getComponent().getWidth(), item1.getComponent().getHeight());
  386. g.setColor(new Color(0 , 150, 150, 200));
  387. g.drawRect(item2.getComponent().getAbsoluteX(), item2.getComponent().getAbsoluteY(), item2.getComponent().getWidth(), item2.getComponent().getHeight());
  388. g.setColor(new Color(0, 0, 0, 200));
  389. g.drawLine(item1.getComponent().getAbsoluteX(), item1.getComponent().getAbsoluteY(), item2.getComponent().getAbsoluteX(), item2.getComponent().getAbsoluteY());
  390. }
  391.  
  392. }
  393. if (cat != null){
  394. drawModel(cat.getModel().getTriangles(), g);
  395. g.setColor(new Color(0, 0, 0, 150));
  396. g.fillOval(cat.getModel().getPoint().x, cat.getModel().getPoint().y, 3, 3);
  397. }
  398.  
  399. }
  400.  
  401.  
  402.  
  403.  
  404. private void drawModel(Polygon[] model, Graphics g) {
  405. int i = 0;
  406. for (Polygon p : model) {
  407. if (i >= 1) {
  408. g.setColor(new Color(255, 255, 255, 150));
  409. g.drawPolygon(p);
  410. i = -5;
  411. }
  412. i++;
  413. }
  414. }
  415.  
  416.  
  417.  
  418.  
  419. //GUI
  420.  
  421. @SuppressWarnings("serial")
  422. public class form extends JFrame {
  423. public form() {
  424. initComponents();
  425. }
  426.  
  427. private void button1ActionPerformed(ActionEvent e) {
  428. if (checkBox1.isSelected()){
  429. spices.add(7491);
  430. spices.add(7490);
  431. spices.add(7489);
  432. spices.add(7488);
  433.  
  434. } else {
  435. for (int i = 0; i < 4; i++){
  436. spices.add(0);
  437. }
  438. }
  439. if (checkBox2.isSelected()){
  440. spices.add(7495);
  441. spices.add(7494);
  442. spices.add(7493);
  443. spices.add(7492);
  444. } else {
  445. for (int i = 0; i < 4; i++){
  446. spices.add(0);
  447. }
  448. }
  449. if (checkBox3.isSelected()){
  450. spices.add(7487);
  451. spices.add(7486);
  452. spices.add(7485);
  453. spices.add(7484);
  454. } else {
  455. for (int i = 0; i < 4; i++){
  456. spices.add(0);
  457. }
  458. }
  459. if (checkBox4.isSelected()){
  460. spices.add(7483);
  461. spices.add(7482);
  462. spices.add(7481);
  463. spices.add(7480);
  464. } else {
  465. for (int i = 0; i < 4; i++){
  466. spices.add(0);
  467. }
  468. }
  469. setVisible(false);
  470. guiDone = true;
  471. }
  472.  
  473. private void initComponents() {
  474. checkBox1 = new JCheckBox();
  475. checkBox2 = new JCheckBox();
  476. checkBox3 = new JCheckBox();
  477. checkBox4 = new JCheckBox();
  478. button1 = new JButton();
  479.  
  480. //======== this ========
  481. setTitle("Spice");
  482. Container contentPane = getContentPane();
  483. contentPane.setLayout(null);
  484.  
  485. //---- checkBox1 ----
  486. checkBox1.setText("Brown spice");
  487. contentPane.add(checkBox1);
  488. checkBox1.setBounds(new Rectangle(new Point(10, 10), checkBox1.getPreferredSize()));
  489.  
  490. //---- checkBox2 ----
  491. checkBox2.setText("Yellow spice");
  492. contentPane.add(checkBox2);
  493. checkBox2.setBounds(new Rectangle(new Point(10, 30), checkBox2.getPreferredSize()));
  494.  
  495. //---- checkBox3 ----
  496. checkBox3.setText("Orange spice");
  497. contentPane.add(checkBox3);
  498. checkBox3.setBounds(new Rectangle(new Point(10, 50), checkBox3.getPreferredSize()));
  499.  
  500. //---- checkBox4 ----
  501. checkBox4.setText("Red spice");
  502. contentPane.add(checkBox4);
  503. checkBox4.setBounds(new Rectangle(new Point(10, 70), checkBox4.getPreferredSize()));
  504.  
  505. //---- button1 ----
  506. button1.setText("Start");
  507. button1.addActionListener(new ActionListener() {
  508. @Override
  509. public void actionPerformed(ActionEvent e) {
  510. button1ActionPerformed(e);
  511. }
  512. });
  513. contentPane.add(button1);
  514. button1.setBounds(15, 100, 115, button1.getPreferredSize().height);
  515.  
  516. { // compute preferred size
  517. Dimension preferredSize = new Dimension();
  518. for(int i = 0; i < contentPane.getComponentCount(); i++) {
  519. Rectangle bounds = contentPane.getComponent(i).getBounds();
  520. preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
  521. preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
  522. }
  523. Insets insets = contentPane.getInsets();
  524. preferredSize.width += insets.right;
  525. preferredSize.height += insets.bottom;
  526. contentPane.setMinimumSize(preferredSize);
  527. contentPane.setPreferredSize(preferredSize);
  528. }
  529. pack();
  530. setLocationRelativeTo(getOwner());
  531. }
  532. private JCheckBox checkBox1;
  533. private JCheckBox checkBox2;
  534. private JCheckBox checkBox3;
  535. private JCheckBox checkBox4;
  536. private JButton button1;
  537. }
  538.  
  539.  
  540. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement