Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.59 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Container;
  3. import java.awt.Dimension;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.awt.Insets;
  8. import java.awt.Point;
  9. import java.awt.Rectangle;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12.  
  13. import org.rsbot.script.wrappers.RSObject;
  14. import org.rsbot.script.methods.Game;
  15. import org.rsbot.script.methods.Skills;
  16. import org.rsbot.script.util.Filter;
  17. import org.rsbot.script.Script;
  18. import java.util.Random;
  19. import org.rsbot.script.wrappers.RSPlayer;
  20.  
  21. import java.awt.*;
  22. import javax.imageio.ImageIO;
  23. import javax.swing.DefaultComboBoxModel;
  24. import javax.swing.JButton;
  25. import javax.swing.JCheckBox;
  26. import javax.swing.JComboBox;
  27. import javax.swing.JFrame;
  28. import javax.swing.JLabel;
  29. import javax.swing.JPanel;
  30. import javax.swing.JSlider;
  31.  
  32. import java.io.IOException;
  33. import java.net.URL;
  34.  
  35. import java.awt.event.MouseEvent;
  36. import java.awt.event.MouseListener;
  37. import java.awt.event.MouseMotionListener;
  38.  
  39. import org.rsbot.event.events.MessageEvent;
  40. import org.rsbot.event.listeners.MessageListener;
  41. import org.rsbot.event.listeners.PaintListener;
  42. import org.rsbot.script.ScriptManifest;
  43. import org.rsbot.script.wrappers.RSArea;
  44. import org.rsbot.script.wrappers.RSItem;
  45. import org.rsbot.script.wrappers.RSNPC;
  46. import org.rsbot.script.wrappers.RSPath;
  47. import org.rsbot.script.wrappers.RSTile;
  48.  
  49. @ScriptManifest(authors = { "Wei Su" }, name = "Ultimate Spider Killer", version = 0.1, description = "Kills giant spider", keywords = {
  50. "", "", "" })
  51. /* Save as script.java - who could get that wrong! :) */
  52. public class UltimateSpiderKiller extends Script implements PaintListener,
  53. MessageListener, ActionListener, MouseMotionListener, MouseListener {
  54.  
  55. public int[] giantID = { 4400 };
  56. public int[] foodID = { 7946 };
  57. public int[] doorID = { 16090 };
  58. public int teleID = 8007;
  59. RSArea spiderArea1 = new RSArea(2144, 5302, 2156, 5310);
  60. RSArea spiderArea2 = new RSArea(2115, 5260, 2135, 5278);
  61. RSArea firstArea = new RSArea(2148, 5299, 2149, 5301);
  62. RSArea secondArea = new RSArea(2141, 5294, 2158, 5298);
  63. RSTile secondTile = new RSTile(2141, 5294);
  64. RSArea thirdArea = new RSArea(2138, 5294, 2140, 5295);
  65. RSArea fourthArea = new RSArea(2127, 5282, 2137, 5295);
  66. RSTile fourthTile = new RSTile(2132, 5282);
  67. RSArea fifthArea = new RSArea(2132, 5279, 2133, 5281);
  68. RSArea sixthArea = new RSArea(2117, 5261, 2137, 5278);
  69. RSTile sixthTile = new RSTile(2132, 5262);
  70. RSArea seventhArea = new RSArea(2132, 5257, 2133, 5259);
  71. RSArea eighthArea1 = new RSArea(2117, 5251, 2130, 5258);
  72. RSArea eighthArea2 = new RSArea(2129, 5252, 2132, 5256);
  73. RSTile eighthTile = new RSTile(2123, 5252);
  74.  
  75. private final RSTile doors[] = { new RSTile(2132, 5257),
  76. new RSTile(2132, 5260), new RSTile(2132, 5278),
  77. new RSTile(2132, 5281), new RSTile(2138, 5294),
  78. new RSTile(2141, 5294), new RSTile(2148, 5299),
  79. new RSTile(2148, 5302) };
  80. //first is last, last is [7]
  81.  
  82.  
  83. @Override
  84. public boolean onStart() {
  85. mouse.setSpeed(3);
  86. return true;
  87. }
  88.  
  89. public int loop() {
  90. RSObject ladder2 = objects.getNearest(16080);
  91. RSObject ladder3 = objects.getTopAt(new RSTile(1859, 5244));
  92. try {
  93.  
  94. if (checkAttack() && !checkEat() && atSpiders() && canEat()) {
  95. attack();
  96. log("Debugging: Attacking");
  97. }
  98.  
  99. if (checkEat() && canEat()) {
  100. eat();
  101. log("Debugging:Eating");
  102. }
  103.  
  104. if (spiderFloor() && !canEat()) {
  105. doBankingWalk();
  106. log("Debugging: Walking");
  107. }
  108.  
  109. if (!canEat() && ladder2.isOnScreen()){
  110. ladder2.doAction("Climb");
  111. log("debugging: ladder 2");
  112. sleep(random(2000,3000));
  113. }
  114.  
  115. if (!canEat() && ladder3.isOnScreen()){
  116. ladder3.doAction("Climb");
  117. log("Debugging ladder 3");
  118. sleep(random(2000,3000));
  119. }
  120.  
  121. } catch (Exception ignore) {
  122. }
  123.  
  124.  
  125. return random(50, 100);
  126.  
  127. }
  128.  
  129. public void doBankingWalk() {
  130. RSItem teleTab = inventory.getItem(teleID);
  131. if (inventory.contains(teleID)) {
  132. teleTab.doAction("Break");
  133. } else {
  134. walkToBank();
  135. }
  136. }
  137.  
  138. public void walkToBank() {
  139. RSObject door7 = objects.getTopAt(doors[7]);
  140. RSObject door6 = objects.getTopAt(doors[6]);
  141. RSObject door5 = objects.getTopAt(doors[5]);
  142. RSObject door4 = objects.getTopAt(doors[4]);
  143. RSObject door3 = objects.getTopAt(doors[3]);
  144. RSObject door2 = objects.getTopAt(doors[2]);
  145. RSObject door1 = objects.getTopAt(doors[1]);
  146. RSObject door0 = objects.getTopAt(doors[0]);
  147.  
  148. if(spiderArea1.contains(getMyPlayer().getLocation())){
  149. door7.doAction("Open");
  150. sleep(random(3000,3200));
  151. }
  152.  
  153. if(firstArea.contains(getMyPlayer().getLocation())){
  154. door6.doAction("Open");
  155. sleep(random(3000,3200));
  156. }
  157.  
  158. if(secondArea.contains(getMyPlayer().getLocation())){
  159. if(calc.distanceTo(door5) > 5){
  160. RSPath path = null;
  161. if (path == null) {
  162. path = walking.getPath(secondTile);
  163. }
  164. path.traverse();
  165. } else {
  166. door5.doAction("Open");
  167. sleep(random(3000,3200));
  168. }
  169. }
  170.  
  171. if(thirdArea.contains(getMyPlayer().getLocation())){
  172. door4.doAction("Open");
  173. sleep(random(3000,3200));
  174. }
  175.  
  176. if(fourthArea.contains(getMyPlayer().getLocation())){
  177. if(calc.distanceTo(door3) > 5){
  178. RSPath path = null;
  179. if (path == null) {
  180. path = walking.getPath(fourthTile);
  181. }
  182. path.traverse();
  183. } else {
  184. door3.doAction("Open");
  185. sleep(random(3000,3200));
  186. }
  187. }
  188.  
  189. if(fifthArea.contains(getMyPlayer().getLocation())){
  190. door2.doAction("Open");
  191. sleep(random(3000,3200));
  192. }
  193.  
  194. if(sixthArea.contains(getMyPlayer().getLocation())){
  195. if(calc.distanceTo(door1) > 5){
  196. RSPath path = null;
  197. if (path == null) {
  198. path = walking.getPath(sixthTile);
  199. }
  200. path.traverse();
  201. } else {
  202. door1.doAction("Open");
  203. sleep(random(3000,3200));
  204. }
  205. }
  206.  
  207. if(seventhArea.contains(getMyPlayer().getLocation())){
  208. door0.doAction("Open");
  209. sleep(random(3000,3200));
  210. }
  211.  
  212. if(eighthArea1.contains(getMyPlayer().getLocation()) || eighthArea2.contains(getMyPlayer().getLocation()) || getMyPlayer().getLocation() == new RSTile(2133, 5256)){
  213. RSObject ladder = objects.getTopAt(new RSTile(2123, 5251));
  214. if (calc.distanceTo(ladder) > 5){
  215. RSPath path = null;
  216. if (path == null) {
  217. path = walking.getPath(new RSTile(2125, 5253));
  218. }
  219. path.traverse();
  220. } else {
  221. ladder.doAction("Climb");
  222. sleep(random(2100,2300));
  223. }
  224. }
  225.  
  226.  
  227.  
  228. }
  229.  
  230. public void walkToSecondRoom() {
  231.  
  232. }
  233.  
  234.  
  235.  
  236. public boolean spiderFloor() {
  237. RSNPC spiders = getNpc();
  238. if (spiders != null) {
  239. return true;
  240. } else {
  241. return false;
  242. }
  243. }
  244.  
  245. public boolean atSpiders() {
  246. if (spiderArea1.contains(getMyPlayer().getLocation())
  247. || spiderArea2.contains(getMyPlayer().getLocation())) {
  248. return true;
  249. } else {
  250. return false;
  251. }
  252. }
  253.  
  254. public boolean canEat() {
  255. if (inventory.containsOneOf(foodID)) {
  256. return true;
  257. } else {
  258. return false;
  259. }
  260. }
  261.  
  262. public void eat() {
  263. RSItem food = inventory.getItem(foodID);
  264. food.doAction("Eat");
  265. sleep(random(100, 200));
  266. }
  267.  
  268. public int getLifePoints() {
  269. try {
  270. return ((int) ((Integer.parseInt(interfaces.get(748)
  271. .getComponent(8).getText().trim()) / (double) (skills
  272. .getRealLevel(Skills.CONSTITUTION) * 10)) * 100));
  273. } catch (Exception e) {
  274. return 100;
  275. }
  276. }
  277.  
  278. public boolean checkEat() {
  279. if (getLifePoints() <= 100) {
  280. return true;
  281. } else {
  282. return false;
  283. }
  284. }
  285.  
  286. public boolean checkAttack() {
  287. if (getMyPlayer().getAnimation() == -1
  288. && getMyPlayer().getInteracting() == null
  289. && !getMyPlayer().isInCombat()) {
  290. return true;
  291. } else {
  292. return false;
  293. }
  294. }
  295.  
  296. public void attack() {
  297. RSNPC spider = getNpc();
  298. spider.doAction("Attack");
  299. }
  300.  
  301. public RSNPC getNpc() {
  302. final Filter<RSNPC> filter = new Filter<RSNPC>() {
  303.  
  304. public boolean accept(RSNPC n) {
  305. return (validNpc(n) && (!n.isInCombat() && n.getInteracting() == null))
  306. && n.getHPPercent() != 0;
  307. }
  308. };
  309.  
  310. return npcs.getNearest(filter);
  311. }
  312.  
  313. public boolean validNpc(RSNPC n) {
  314. if (n != null) {
  315. for (int id : giantID) {
  316. if (id == n.getID())
  317. return true;
  318. }
  319.  
  320. if (n.getName().toLowerCase().contains("giant".toLowerCase()))
  321. return true;
  322.  
  323. }
  324. return false;
  325. }
  326.  
  327. @Override
  328. public void onFinish() {
  329.  
  330. }
  331.  
  332. // START: Code generated using Enfilade's Easel
  333.  
  334. public void mouseClicked(MouseEvent e) {// this is the mouse listener, it
  335. // listen's for the click.
  336.  
  337. }
  338.  
  339. // END: Code generated using Enfilade's Easel
  340.  
  341. @Override
  342. public void mouseEntered(MouseEvent arg0) {
  343. // TODO Auto-generated method stub
  344.  
  345. }
  346.  
  347. @Override
  348. public void mouseExited(MouseEvent arg0) {
  349. // TODO Auto-generated method stub
  350.  
  351. }
  352.  
  353. @Override
  354. public void mousePressed(MouseEvent arg0) {
  355. // TODO Auto-generated method stub
  356.  
  357. }
  358.  
  359. @Override
  360. public void mouseReleased(MouseEvent arg0) {
  361. // TODO Auto-generated method stub
  362.  
  363. }
  364.  
  365. @Override
  366. public void mouseDragged(MouseEvent arg0) {
  367. // TODO Auto-generated method stub
  368.  
  369. }
  370.  
  371. @Override
  372. public void mouseMoved(MouseEvent arg0) {
  373. // TODO Auto-generated method stub
  374.  
  375. }
  376.  
  377. @Override
  378. public void actionPerformed(ActionEvent arg0) {
  379. // TODO Auto-generated method stub
  380.  
  381. }
  382.  
  383. @Override
  384. public void messageReceived(MessageEvent arg0) {
  385.  
  386. }
  387.  
  388. @Override
  389. public void onRepaint(Graphics arg0) {
  390. // TODO Auto-generated method stub
  391.  
  392. }
  393.  
  394. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement