Guest User

Untitled

a guest
Jul 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.88 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.FontMetrics;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Point;
  7. import java.awt.RenderingHints;
  8. import java.awt.event.KeyEvent;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. import org.rsbot.bot.Bot;
  13. import org.rsbot.event.events.ServerMessageEvent;
  14. import org.rsbot.event.listeners.PaintListener;
  15. import org.rsbot.event.listeners.ServerMessageListener;
  16. import org.rsbot.script.Constants;
  17. import org.rsbot.script.Script;
  18. import org.rsbot.script.ScriptManifest;
  19. import org.rsbot.script.Skills;
  20. import org.rsbot.script.wrappers.RSInterface;
  21. import org.rsbot.script.wrappers.RSItemTile;
  22. import org.rsbot.script.wrappers.RSNPC;
  23. import org.rsbot.script.wrappers.RSPlayer;
  24. import org.rsbot.script.wrappers.RSTile;
  25.  
  26. @ScriptManifest(authors = { "Nobody" }, category = "Combat", name = "Ogre Ranger", version = 1.5, description = "<html><head><style type=\"text/css\"> hr {color: white} p {margin-left: 20px} body {margin: 5px; font-family: Arial}</style></head><body><center><b><font size=\"4\" color=\"red\">Ogre Ranger v1.5</font></b><br /><b><font size=\"4\" color=\"red\">By Nobody</font></b><br /><table border=\"0\"><tr><td colspan=\"2\"><center><font size=\"3\"><b>Say Tnx</b></font></center></td></tr><tr><td colspan=\"2\"></td></tr><tr><td></table></center></body></html>")
  27. public class OgreCageRanger extends Script implements PaintListener,
  28. ServerMessageListener {
  29.  
  30. public int currenttab;
  31. public int GambleInt;
  32. public int checkTime, checkTime1 = random(240000, 480000);
  33. public int speed = 150;
  34. public int walkSpeed = 200;
  35. public long lastCheck = -1, lastcheck1 = -1, lastCheck2,
  36. lastCheck3 = System.currentTimeMillis();
  37. public Point mousePos;
  38. private final Color backgroundBottom = new Color(72, 62, 51, 160),
  39. text = new Color(180, 150, 90, 160),
  40. black = new Color(0, 0, 0, 160);
  41. private final int DEFENSIVE_STYLE = 2, DAMAGE_CUTOFF = 3000;
  42. private Font defaultFont;
  43. private long lastXPChange;
  44. private int lastXP, lastMode;
  45. private double totalDamage;
  46. public long startTime = System.currentTimeMillis();
  47. int startxp = skills.getCurrentSkillExp(Skills.getStatIndex("range"));
  48. int startlvl = skills.getCurrentSkillLevel(Skills.getStatIndex("range"));
  49. public RSTile orgespot = new RSTile(2527, 3372);
  50. int seed = 0;
  51.  
  52. public boolean activateCondition() {
  53. if (getMyPlayer().isMoving()) {
  54. return random(1, walkSpeed) == 1;
  55. } else {
  56. return random(1, speed) == 1;
  57. }
  58. }
  59.  
  60. public int antiban() {
  61. setRun(true);
  62. if (!bank.getInterface().isValid()) {
  63. if (System.currentTimeMillis() - lastCheck2 >= checkTime) {
  64. lastCheck2 = System.currentTimeMillis();
  65. checkTime = random(300000, 600000);
  66. turnCamera();
  67. wait(random(300, 500));
  68. mousePos = getMouseLocation();
  69. currenttab = getCurrentTab();
  70. openTab(random(0, 13));
  71. wait(random(300, 500));
  72. turnCamera();
  73. wait(random(300, 500));
  74. openTab(currenttab);
  75. wait(random(300, 500));
  76. moveMouse(mousePos, 7, 7);
  77. wait(random(100, 200));
  78. }
  79. GambleInt = random(1, 9);
  80. switch (GambleInt) {
  81. case 1: // Camera Rotation
  82. turnCamera();
  83. return -1;
  84.  
  85. case 2: // Move mouse & come back to original mouse location &
  86. // Camera Rotation
  87. final int xA = random(0, 750);
  88. final int yA = random(0, 500);
  89. mousePos = getMouseLocation();
  90. moveMouse(xA, yA);
  91. wait(random(300, 500));
  92. moveMouse(mousePos, 7, 7);
  93. wait(random(100, 200));
  94. turnCamera();
  95. return -1;
  96.  
  97. case 3: // Inventory Tab Selection & Camera Rotation
  98. if (getCurrentTab() != Constants.TAB_INVENTORY) {
  99. currenttab = getCurrentTab();
  100. openTab(Constants.TAB_INVENTORY);
  101. wait(random(300, 500));
  102. turnCamera();
  103. }
  104. return -1;
  105.  
  106. case 4: // Player right click
  107. mousePos = getMouseLocation();
  108. final RSPlayer p = getNearestPlayerByLevel(1, 130);
  109. if (p != null && p.isValid()) {
  110. moveMouse(p.getScreenLocation(), 5, 5);
  111. wait(random(300, 500));
  112. clickMouse(false);
  113. wait(random(1000, 1500));
  114. moveMouse(mousePos, 7, 7);
  115. }
  116. return -1;
  117.  
  118. case 5: // Camera Rotation & Move mouse & come back to original
  119. // mouse location
  120. turnCamera();
  121. wait(random(300, 500));
  122. final int xB = random(0, 750);
  123. final int yB = random(0, 500);
  124. mousePos = getMouseLocation();
  125. moveMouse(xB, yB);
  126. wait(random(300, 500));
  127. moveMouse(mousePos, 7, 7);
  128. return -1;
  129.  
  130. case 6: // Camera Rotation
  131. turnCamera();
  132. return -1;
  133.  
  134. case 7: // Open different tab and go back to original tab
  135. mousePos = getMouseLocation();
  136. currenttab = getCurrentTab();
  137. openTab(random(0, 13));
  138. wait(random(300, 500));
  139. openTab(currenttab);
  140. wait(random(300, 500));
  141. moveMouse(mousePos, 7, 7);
  142. return -1;
  143.  
  144. case 8: // Move mouse && come back to original mouse location
  145. mousePos = getMouseLocation();
  146. moveMouse(random(0, 450), random(0, 450));
  147. wait(random(300, 500));
  148. moveMouse(mousePos, 7, 7);
  149. return -1;
  150. }
  151. }
  152. return -1;
  153. }
  154.  
  155. public void checkXP() {
  156. final int curXP = skills.getCurrentSkillExp(Constants.STAT_RANGE);
  157. if (lastXP != curXP || isRanging()) {
  158. if (System.currentTimeMillis() - lastXPChange > DAMAGE_CUTOFF) {
  159. totalDamage = 0;
  160. System.currentTimeMillis();
  161. }
  162. totalDamage += (curXP - lastXP) / getDenominator();
  163. lastXP = curXP;
  164. lastXPChange = System.currentTimeMillis();
  165. }
  166. }
  167.  
  168. private boolean clickNPC(final RSNPC npc, final String action) {
  169. try {
  170. int a;
  171. final StringBuffer npcCommandBuf = new StringBuffer();
  172. npcCommandBuf.append(action);
  173. npcCommandBuf.append(" ");
  174. npcCommandBuf.append(npc.getName());
  175. final String npcCommand = npcCommandBuf.toString();
  176. for (a = 10; a-- >= 0;) {
  177. if (npc.getInteracting() != null
  178. && !npc.isInteractingWithLocalPlayer()) {
  179. return false;
  180. }
  181. final List<String> menuItems = getMenuItems();
  182. if (menuItems.size() > 1) {
  183. if (listContainsString(menuItems, npcCommand)) {
  184. if (menuItems.get(0).contains(npcCommand)) {
  185. clickMouse(true);
  186. return true;
  187. } else {
  188. clickMouse(false);
  189. wait(random(230, 520));
  190. return atMenu(npcCommand);
  191. }
  192. }
  193. }
  194. final Point screenLoc = npc.getScreenLocation();
  195. if (!pointOnScreen(screenLoc)) {
  196. return false;
  197. }
  198. final Point randomP = new Point(random(screenLoc.x - 15,
  199. screenLoc.x + 15), random(screenLoc.y - 15,
  200. screenLoc.y + 15));
  201. if (randomP.x >= 0 && randomP.y >= 0) {
  202. moveMouse(randomP);
  203. }
  204. }
  205. return false;
  206. } catch (final Exception e) {
  207. System.out.print("clickNPC(RSNPC, String) error: " + e);
  208. return false;
  209. }
  210. }
  211.  
  212. public String convertToShorthand(final int number) {
  213. if (number >= 10000000) {
  214. return number / 1000000 + "M";
  215. }
  216. if (number >= 10000) {
  217. return number / 1000 + "K";
  218. }
  219. return number + "";
  220. }
  221.  
  222. public void drawStringWithShadow(final String text, final int x,
  223. final int y, final Graphics g) {
  224. final Color bef = g.getColor();
  225. g.setColor(black);
  226. g.drawString(text, x + 1, y + 1);
  227. g.setColor(bef);
  228. g.drawString(text, x, y);
  229. }
  230.  
  231. private double getDenominator() {
  232. return lastMode == DEFENSIVE_STYLE ? 2.0 : 4.0;
  233. }
  234.  
  235. public ArrayList<RSItemTile> getGroundItemsByID(final int... ids) {
  236. final ArrayList<RSItemTile> itemsList = new ArrayList<RSItemTile>();
  237. final int pX = getMyPlayer().getLocation().getX();
  238. final int pY = getMyPlayer().getLocation().getY();
  239. final int minX = pX - 35;
  240. final int minY = pY - 35;
  241. final int maxX = pX + 35;
  242. final int maxY = pY + 35;
  243. for (int x = minX; x <= maxX; x++) {
  244. for (int y = minY; y <= maxY; y++) {
  245. final RSItemTile[] items = getGroundItemsAt(x, y);
  246. for (final RSItemTile item : items) {
  247. final int iId = item.getItem().getID();
  248. for (final int id : ids) {
  249. if (iId == id) {
  250. itemsList.add(item);
  251. }
  252. }
  253. }
  254. }
  255. }
  256. return itemsList;
  257. }
  258.  
  259. @Override
  260. protected int getMouseSpeed() {
  261. return random(5, 7);
  262. }
  263.  
  264. /*
  265. * public void antiban() { setRun(true); getEat(); zomgtele(); }
  266. */
  267.  
  268. public boolean isRanging() {
  269. final int id = getMyPlayer().getAnimation();
  270. return id == 426 || id == 4230 || id == 1074;
  271. }
  272.  
  273.  
  274. private boolean listContainsString(final List<String> list,
  275. final String string) {
  276. try {
  277. int a;
  278. for (a = list.size() - 1; a-- >= 0;) {
  279. if (list.get(a).contains(string)) {
  280. return true;
  281. }
  282. }
  283. } catch (final Exception e) {
  284. }
  285. return false;
  286. }
  287.  
  288. @Override
  289. public int loop() {
  290. if (distanceTo(orgespot) > 5) {
  291. if (distanceTo(orgespot) > 10) {
  292. log("lost, ending script");
  293. return -1;
  294. }
  295. walkTileMM(orgespot);
  296. return random(500, 1500);
  297. }
  298. checkForLevelUpMessage();
  299. if (getMyPlayer().getInteracting() == null) {
  300. final RSNPC ogre = getNearestFreeNPCByID(2801);
  301. if (ogre != null) {
  302. clickNPC(ogre, "Attack");
  303. return random(500, 1500);
  304. }
  305. } else {
  306. final RSTile ranarr = getGroundItemByID(5295);
  307. if (ranarr != null) {
  308. openTab(Constants.TAB_MAGIC);
  309. atInterface(192, 20);
  310. atTile(ranarr, "Grab -> Ranarr");
  311. wait(random(2000, 2500));
  312. seed++;
  313. }
  314. }
  315. {
  316. final RSTile ranarr = getGroundItemByID(5300);
  317. if (ranarr != null) {
  318. openTab(Constants.TAB_MAGIC);
  319. atInterface(192, 20);
  320. atTile(ranarr, "Grab -> Snapdragon");
  321. wait(random(2000, 2500));
  322. seed++;
  323. }
  324. }
  325. {
  326. final RSTile water = getGroundItemByID(5321);
  327. if (water != null) {
  328. openTab(Constants.TAB_MAGIC);
  329. atInterface(192, 20);
  330. atTile(water, "Grab -> Watermelon");
  331. wait(random(2000, 2500));
  332. seed++;
  333. }
  334. }
  335. {
  336. antiban();
  337. }
  338. return random(500, 1500);
  339. }
  340.  
  341. @Override
  342. public void onFinish() {
  343. Bot.getEventManager().removeListener(PaintListener.class, this);
  344. Bot.getEventManager().removeListener(ServerMessageListener.class, this);
  345. }
  346.  
  347. public void onRepaint(final Graphics render) {
  348. long millis = System.currentTimeMillis() - startTime;
  349. final int XPChange = skills.getCurrentSkillExp(Skills
  350. .getStatIndex("range"))
  351. - startxp;
  352. final long hours = millis / (1000 * 60 * 60);
  353. millis -= hours * 1000 * 60 * 60;
  354. final long minutes = millis / (1000 * 60);
  355. millis -= minutes * 1000 * 60;
  356. final long seconds = millis / 1000;
  357.  
  358. float expPerSec = 0;
  359. if ((minutes > 0 || hours > 0 || seconds > 0) && XPChange > 0) {
  360. expPerSec = (float) XPChange
  361. / (float) (seconds + minutes * 60 + hours * 60 * 60);
  362. }
  363. final float expPerMin = expPerSec * 60;
  364. final float expPerHour = expPerMin * 60;
  365. final Graphics2D g = (Graphics2D) render;
  366. g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
  367. RenderingHints.VALUE_ANTIALIAS_ON);
  368. if (defaultFont == null) {
  369. defaultFont = g.getFont();
  370. }
  371. g.setColor(backgroundBottom);
  372. g.fillRect(4, 318, 511, 20);
  373. g.setColor(black);
  374. g.drawRect(4, 317, 511, 21);
  375. g.setColor(new Color(180, 119, 22, 160));
  376. g.setFont(new Font(defaultFont.getName(), defaultFont.getStyle(), 10));
  377. g
  378. .fillRect(
  379. 36,
  380. 323,
  381. (int) (skills
  382. .getPercentToNextLevel(Constants.STAT_RANGE) / 100.0 * 123),
  383. 11);
  384. g.setColor(black);
  385. g.drawRect(35, 322, 125, 12);
  386. final FontMetrics fontMetrics = g.getFontMetrics(g.getFont());
  387. final String percentText = skills
  388. .getPercentToNextLevel(Constants.STAT_RANGE)
  389. + "%";
  390. g.drawString(skills.getXPToNextLevel(Constants.STAT_RANGE) + "",
  391. 36 + (125 - (int) fontMetrics.getStringBounds(percentText, g)
  392. .getWidth()) / 2, 332);
  393. if (styleChanged()) {
  394. totalDamage = 0;
  395. }
  396. checkXP();
  397. if (System.currentTimeMillis() - lastXPChange < DAMAGE_CUTOFF) {
  398. System.currentTimeMillis();
  399. }
  400. g.setColor(text);
  401. drawStringWithShadow(percentText, 30 - (int) fontMetrics
  402. .getStringBounds(percentText, g).getWidth(), 331, g);
  403. drawStringWithShadow("Time: " + hours + ":" + minutes + ":" + seconds,
  404. 165, 331, g);
  405. drawStringWithShadow("Gained: " + XPChange + " Xp", 245, 331, g);
  406. drawStringWithShadow("Xp Per Hour: " + (int) expPerHour, 340, 331, g);
  407. drawStringWithShadow("Seeds:" + seed, 450, 331, g);
  408. g.setColor(new Color(255, 255, 255, 25));
  409. g.fillRect(5, 318, 510, 10);
  410. }
  411.  
  412. public boolean onStart() {
  413. skills.getCurrentSkillExp(Skills.getStatIndex("range"));
  414. skills.getCurrentSkillLevel(Skills.getStatIndex("range"));
  415. defaultFont = null;
  416. lastXP = skills.getCurrentSkillExp(Constants.STAT_RANGE);
  417. lastXPChange = System.currentTimeMillis() - DAMAGE_CUTOFF;
  418. lastMode = getSetting(Constants.SETTING_COMBAT_STYLE);
  419. totalDamage = 0;
  420. return true;
  421. }
  422.  
  423. public void serverMessageRecieved(final ServerMessageEvent e) {
  424. final String mes = e.getMessage();
  425. if (mes.contains("There is no ammo left in your quiver.")) {
  426. logout();
  427. stopScript();
  428. }
  429. if (mes.contains("That was your last one!")) {
  430. log("Out of knives! Stopping script!");
  431. logout();
  432. stopScript();
  433. }
  434. }
  435.  
  436. private boolean styleChanged() {
  437. if (lastMode != getSetting(Constants.SETTING_COMBAT_STYLE)) {
  438. lastMode = getSetting(Constants.SETTING_COMBAT_STYLE);
  439. return true;
  440. }
  441. return false;
  442. }
  443.  
  444. public void turnCamera() {
  445. final char[] LR = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT };
  446. final char[] UD = new char[] { KeyEvent.VK_DOWN, KeyEvent.VK_UP };
  447. final char[] LRUD = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT,
  448. KeyEvent.VK_UP, KeyEvent.VK_UP };
  449. final int random2 = random(0, 2);
  450. final int random1 = random(0, 2);
  451. final int random4 = random(0, 4);
  452.  
  453. if (random(0, 3) == 0) {
  454. Bot.getInputManager().pressKey(LR[random1]);
  455. try {
  456. Thread.sleep(random(100, 400));
  457. } catch (final Exception e) {
  458. }
  459. Bot.getInputManager().pressKey(UD[random2]);
  460. try {
  461. Thread.sleep(random(300, 600));
  462. } catch (final Exception e) {
  463. }
  464. Bot.getInputManager().releaseKey(UD[random2]);
  465. try {
  466. Thread.sleep(random(100, 400));
  467. } catch (final Exception e) {
  468. }
  469. Bot.getInputManager().releaseKey(LR[random1]);
  470. } else {
  471. Bot.getInputManager().pressKey(LRUD[random4]);
  472. if (random4 > 1) {
  473. try {
  474. Thread.sleep(random(300, 600));
  475. } catch (final Exception e) {
  476. }
  477. } else {
  478. try {
  479. Thread.sleep(random(500, 900));
  480. } catch (final Exception e) {
  481. }
  482. }
  483. Bot.getInputManager().releaseKey(LRUD[random4]);
  484. }
  485. }
  486.  
  487. public void checkForLevelUpMessage() {
  488. if (RSInterface.getInterface(INTERFACE_LEVELUP).isValid()) {
  489. wait(random(800, 2000));
  490. atInterface(INTERFACE_LEVELUP, 3);
  491. wait(random(1000, 2000));
  492. }
  493. }
  494.  
  495. public boolean activateCondition1() {
  496. long timeSinceClick = Bot.getClient().getMouse().getMousePressTime();
  497. if ( timeSinceClick > System.currentTimeMillis() - 600) {
  498. Point d = getMouseLocation();
  499. moveMouse(d.x - 9, d.y - 9, 18, 18);
  500. }
  501. return false;
  502. }
  503. }
Add Comment
Please, Sign In to add comment