Guest User

Untitled

a guest
Jul 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.96 KB | None | 0 0
  1. /*
  2. *
  3. * Author lolbus of Roach Killer
  4. * lols
  5. * Report bug at powerbot or bear with it.
  6. *
  7. * Finished in less than 4hours.
  8. *
  9. *
  10. */
  11. import org.powerbot.game.api.methods.Tabs;
  12. import org.powerbot.game.api.methods.Walking;
  13. import org.powerbot.game.api.methods.Widgets;
  14. import org.powerbot.game.api.methods.input.Mouse;
  15. import org.powerbot.game.api.methods.node.GroundItems;
  16. import org.powerbot.game.api.methods.node.Locations;
  17. import org.powerbot.game.api.methods.node.Menu;
  18. import org.powerbot.game.api.methods.tab.Inventory;
  19. import org.powerbot.game.api.util.Time;
  20. import org.powerbot.concurrent.Task;
  21. import org.powerbot.concurrent.strategy.Strategy;
  22. import org.powerbot.game.api.ActiveScript;
  23. import org.powerbot.game.api.Manifest;
  24. import org.powerbot.game.api.methods.interactive.Npcs;
  25. import org.powerbot.game.api.methods.interactive.Players;
  26. import org.powerbot.game.api.methods.widget.Camera;
  27. import org.powerbot.game.api.methods.*;
  28. import org.powerbot.game.api.util.Filter;
  29. import org.powerbot.game.api.util.Random;
  30. import org.powerbot.game.api.wrappers.*;
  31. import org.powerbot.game.api.wrappers.interactive.Npc;
  32. import org.powerbot.game.api.wrappers.node.GroundItem;
  33. import org.powerbot.game.api.wrappers.node.Item;
  34. import org.powerbot.game.api.wrappers.node.Location;
  35.  
  36.  
  37. @Manifest(name = "RoachKillers", description = "kill roach till your sick of roach", version = 2.0, authors = {"lolbus"})
  38. public class RoachKiller extends ActiveScript {
  39. public final int foodID = 333;
  40. public final int quantity = 5;
  41. public final int eatWhenHp = 600;
  42.  
  43. private final Tile[] roachPath = {
  44. new Tile(3088,3488,0), new Tile(3084, 3485, 0), new Tile(3081, 3477,0),
  45. new Tile(3084,3465,0), new Tile(3079,3464,0)
  46.  
  47. };
  48. private final Tile[] homePath = {
  49. new Tile(3082,3466,0), new Tile(3082, 3475, 0), new Tile(3084, 3484,0),
  50. new Tile(3088,3491,0), new Tile(3093,3493,0)
  51.  
  52. };
  53. public boolean outOfRoach(){
  54. if(isInArea(3137,3170,4269,4273)){
  55. return true;
  56. } else
  57.  
  58. return false;
  59. }
  60. public boolean haveItem(int itemID){
  61. for(Item i : Inventory.getItems()){
  62. if (i.getId()==itemID)
  63. return true;
  64. }
  65. return false;
  66. }
  67. final public int drops[] = {448,450,563,447,565,1619,1617,1631,5304,5300,1185,1249,1247,12160,1333,995,12158,12163,12159,18778,560};
  68.  
  69.  
  70. public void log (String s){
  71. if(!s.isEmpty()){
  72. Time.sleep(80);
  73. log.info(s);
  74. }
  75. }
  76. public float distanceTo(Tile tile){
  77. return (float) Calculations.distance(Players.getLocal().getPosition(), tile);
  78. }
  79.  
  80.  
  81. public void turnCameraRandomly(){
  82. Camera.setAngle(Random.nextInt(0, 360));
  83. Time.sleep(500);
  84. }
  85. public void sleep(int min, int max){
  86. Time.sleep(Random.nextInt(min, max));
  87. }
  88.  
  89. public int random(int min, int max){
  90. return Random.nextInt(min, max);
  91. }
  92.  
  93.  
  94. public boolean isInArea(int minX, int maxX, int minY, int maxY){
  95. int myX = Players.getLocal().getPosition().getX();
  96. int myY = Players.getLocal().getPosition().getY();
  97. if(myX >= minX && myX <= maxX && myY >= minY && myY <= maxY){
  98. return true;
  99. }
  100. else
  101. return false;
  102. }
  103. public boolean nearCervice(){
  104.  
  105. return isInArea(3072, 3082, 3461, 3469);
  106. }
  107.  
  108. public boolean atBank(){
  109. return isInArea(3091, 3098, 3487, 3498);
  110.  
  111. }
  112. public boolean atTown(){
  113. return isInArea(3070, 3101, 3459, 3503);
  114.  
  115. }
  116. public boolean atRoach(){
  117. return isInArea(3146, 3160, 4274, 4281);
  118.  
  119. }
  120. public void handleCervice(){
  121. Location hole = Locations.getNearest(29728);
  122. if(hole!=null){
  123. if(!hole.isOnScreen()){
  124. Camera.turnTo(hole);
  125. }
  126. Mouse.click((int)hole.getCentralPoint().getX(), (int)hole.getCentralPoint().getY(), false);
  127. sleep(500,600);
  128. if(Menu.isOpen()){
  129. Menu.select("Enter");
  130. sleep(1000,1500);
  131. }
  132. }
  133.  
  134. }
  135. public int angleTo(Tile tile) {
  136. double ydif = tile.getY() - Players.getLocal().getPosition().getY();
  137. double xdif = tile.getX() - Players.getLocal().getPosition().getX();
  138. return (int) (Math.atan2(ydif, xdif) * 180 / Math.PI);
  139. }
  140. public boolean walkTileMM(Tile tile, int rnd) {
  141. double angle = angleTo(tile) - Camera.getAngleTo(0);
  142. double distance = distanceTo(tile);
  143. angle = angle * Math.PI / 180;
  144. int x = 627, y = 85;
  145. int dx = (int) (4 * (distance + Random.nextGaussian(0, rnd, 1)) * Math
  146. .cos(angle));
  147. int dy = (int) (4 * (distance + Random.nextGaussian(0, rnd, 1)) * Math
  148. .sin(angle));
  149. return Mouse.click(x + dx, y - dy, true);
  150. }
  151.  
  152. public void handleRope(){
  153. Location rope = Locations.getNearest(29729);
  154. if(rope!=null){
  155. if(distanceTo(rope.getPosition()) > 3){
  156. log.info("too far going nearer");
  157. walkTileMM(rope.getPosition(),0);
  158. sleep(900,1400);
  159. }
  160. if(!rope.isOnScreen()){
  161. Camera.turnTo(rope);
  162. log.info("tan cam");
  163. sleep(900,1400);
  164. }
  165. Mouse.click((int)rope.getCentralPoint().getX(), (int)rope.getCentralPoint().getY(), false);
  166. sleep(500,550);
  167. if(Menu.isOpen()){
  168. if(Menu.contains("Climb")){
  169. Menu.select("Climb");
  170. sleep(1900,2700);
  171. }
  172. }
  173.  
  174. } else if (rope ==null){
  175. log("ops rope is null");
  176. }
  177. }
  178.  
  179. private void walk(Tile[] fullTile) {
  180. if (Walking.getEnergy() > random(30, 50)) {
  181. Walking.setRun(true);
  182. }
  183. for (int i = fullTile.length - 1; i >= 0; i--) {
  184. if (Walking.walk(fullTile[i])) {
  185. break;
  186. }
  187. }
  188. }
  189.  
  190. public class toRoachs extends Strategy implements Task{
  191.  
  192. @Override
  193. public void run() {
  194. sleep(80,150);
  195. // TODO Auto-generated method stub
  196. if(!nearCervice() && atTown() && haveItem(foodID)){
  197.  
  198. walk(roachPath);
  199. } else if (nearCervice() && atTown() && haveItem(foodID)){
  200. handleCervice();
  201. }
  202. }
  203. @Override
  204. public boolean validate(){
  205. //log.info(""+(atTown()&&haveItem(foodID)));
  206. return (atTown()&&haveItem(foodID));
  207. }
  208. }
  209.  
  210. public class returnToBank extends Strategy implements Task{
  211.  
  212. @Override
  213. public void run() {
  214. sleep(100,200);
  215.  
  216. // TODO Auto-generated method stub
  217. if(atRoach()){
  218.  
  219. handleRope();
  220. } else if (atTown() &&!atBank()){
  221. walk(homePath);
  222. }
  223. }
  224. @Override
  225. public boolean validate(){
  226. //log.info(" returns to bank!"+!haveItem(foodID));
  227. return ((!haveItem(foodID) && !atRoach()) ||
  228. (atRoach() && !haveItem(foodID) && (Integer.parseInt(Widgets.get(748, 8).getText()) <= 120 + (Random.nextInt(-3, 3))))
  229.  
  230. );
  231. }
  232. }
  233.  
  234.  
  235. public boolean clickRandomRoach(){
  236. Npc target = Npcs.getNearest(new Filter<Npc>(){
  237. public boolean accept(Npc i){
  238. if(i.getId()== 7160 && i.getPosition().getY() >= 4274){
  239. return true;
  240. } else return false;
  241.  
  242. }
  243.  
  244. });
  245. if(target!=null){
  246. if(distanceTo(target.getPosition())> 3){
  247. walkTileMM(target.getPosition(), 0);
  248. sleep(600,800);
  249. }
  250. else if(!target.isOnScreen()){
  251. Camera.turnTo(target);
  252. } else {
  253. Mouse.click((int)target.getCentralPoint().getX(),(int)target.getCentralPoint().getY(), false);
  254. sleep(500,600);
  255. if(Menu.isOpen() && Menu.contains("Attack")){
  256. Menu.select("Attack");
  257. sleep(1500,2200);
  258. }
  259. }
  260.  
  261. }
  262.  
  263. return false;
  264. }
  265.  
  266.  
  267. public class fightRoach extends Strategy implements Task{
  268.  
  269. @Override
  270. public void run() {
  271. sleep(100,200);
  272.  
  273. // TODO Auto-generated method stub
  274. GroundItem loot = GroundItems.getNearest(new Filter <GroundItem>(){
  275. public boolean accept(GroundItem i){
  276. for(GroundItem a : GroundItems.getLoaded()){
  277. for(int z = 0; z < drops.length; z++){
  278. if(a.getGroundItem().getId()==drops[z]){
  279. return true;
  280. }
  281. }
  282. }
  283. return false;
  284. }
  285.  
  286. });
  287. if(loot!=null){
  288. if(distanceTo(loot.getPosition())>3){
  289. walkTileMM(loot.getPosition(),0);
  290. sleep(300,500);
  291. }
  292. if(!loot.isOnScreen()){
  293. Camera.turnTo(loot);
  294. sleep(300,500);
  295. }
  296. Mouse.click((int)loot.getCentralPoint().getX(), (int)loot.getCentralPoint().getY(), false);
  297. sleep(500,600);
  298. if(Menu.isOpen() && Menu.contains("Take")){
  299. Menu.select("Take");
  300. sleep(400,600);
  301. }
  302. } else {
  303. if(!Players.getLocal().isInCombat()){
  304. clickRandomRoach();
  305. sleep(400,600);
  306. } else {
  307. sleep(2000,3000);
  308. }
  309.  
  310. }
  311.  
  312. }
  313. @Override
  314. public boolean validate(){
  315. //log.info(" returns to bank!"+!haveItem(foodID));
  316. return ((Integer.parseInt(Widgets.get(748, 8).getText()) > 120 + (Random.nextInt(-3, 3))) && atRoach());
  317. }
  318. }
  319. public class basicNeeds extends Strategy implements Task{
  320.  
  321. @Override
  322. public void run() {
  323. if(outOfRoach()){
  324. walkTileMM(new Tile(3157,4277,0),0);
  325. sleep(1000,1500);
  326.  
  327. }
  328. sleep(80,150);
  329. if(Random.nextInt(1, 110)>95){
  330. // log.info("Antiban activated");
  331. wiggle();
  332. turnCameraRandomly();
  333.  
  334. }
  335.  
  336. if(Camera.getPitch()>0){
  337. Camera.setPitch(true);
  338. }
  339. // TODO Auto-generated method stub
  340.  
  341. }
  342.  
  343. public void wiggle() {
  344.  
  345. int x, y;
  346.  
  347. x = Random.nextInt(500, 650);
  348.  
  349. y = Random.nextInt(300, 420);
  350.  
  351. Mouse.move(x, y);
  352.  
  353. Time.sleep(Random.nextInt(25, 674));
  354.  
  355. x = Random.nextInt(500, 650);
  356.  
  357. y = Random.nextInt(300, 420);
  358.  
  359. Mouse.move(x, y);
  360.  
  361. Time.sleep(Random.nextInt(1, 240));
  362.  
  363. }
  364. @Override
  365. public boolean validate(){
  366. return true;
  367.  
  368. }
  369.  
  370.  
  371. }
  372.  
  373. public class eating extends Strategy implements Task {
  374.  
  375. @Override
  376. public void run() {
  377. sleep(100,150);
  378. // TODO Auto-generated method stub
  379. if(Tabs.getCurrent() != Tabs.INVENTORY)
  380. Tabs.INVENTORY.open();
  381. for (Item i : Inventory.getItems()){
  382.  
  383. if(i.getId() == foodID){
  384. i.getWidgetChild().click(true);
  385. sleep(800,1200);
  386. break;
  387. }
  388. }
  389.  
  390. }
  391. @Override
  392. public boolean validate(){
  393. return (haveItem(foodID) && Integer.parseInt(Widgets.get(748, 8).getText()) <= eatWhenHp);
  394.  
  395. }
  396.  
  397. }
  398.  
  399. public class banking extends Strategy implements Task{
  400.  
  401. @Override
  402. public void run() {
  403. sleep(80,150);
  404. // TODO Auto-generated method stub
  405. if(!bank.isOpen()){
  406. bank.openBank();
  407. sleep(1000,1200);
  408. } else if (Inventory.getCount()>0){
  409. bank.depositAll();
  410. sleep(500,600);
  411. } else {
  412. bank.withdraw(foodID, quantity);
  413. sleep(500,600);
  414. }
  415. }
  416. @Override
  417. public boolean validate(){
  418. return (!haveItem(foodID) && atBank());
  419.  
  420. }
  421.  
  422. }
  423.  
  424. @Override
  425. protected void setup() {
  426. basicNeeds z = new basicNeeds();
  427. Strategy DOES_BASIC = new Strategy(z, z);
  428. provide(DOES_BASIC);
  429.  
  430. banking b = new banking();
  431. Strategy BANKING = new Strategy(b, b);
  432. provide(BANKING);
  433.  
  434. toRoachs c = new toRoachs();
  435. Strategy TOWARDS_ROACH = new Strategy(c, c);
  436. provide(TOWARDS_ROACH);
  437.  
  438. fightRoach e = new fightRoach();
  439. Strategy FIGHT_ROACH = new Strategy(e, e);
  440. provide(FIGHT_ROACH);
  441.  
  442. eating x = new eating();
  443. Strategy EAT_FOOD = new Strategy(x, x);
  444. provide(EAT_FOOD);
  445.  
  446. returnToBank d = new returnToBank();
  447. Strategy BANK_RETURN = new Strategy(d, d);
  448. provide(BANK_RETURN);
  449.  
  450. }
  451. }
Add Comment
Please, Sign In to add comment