Guest User

Untitled

a guest
Jan 14th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.78 KB | None | 0 0
  1. import org.rsbot.event.events.MessageEvent;
  2. import org.rsbot.event.listeners.MessageListener;
  3. import org.rsbot.event.listeners.PaintListener;
  4. import org.rsbot.util.GlobalConfiguration;
  5. import org.rsbot.script.Script;
  6. import org.rsbot.script.ScriptManifest;
  7. import org.rsbot.script.methods.Game;
  8. import org.rsbot.script.methods.Skills;
  9. import org.rsbot.script.util.Timer;
  10. import org.rsbot.script.wrappers.RSComponent;
  11. import org.rsbot.script.wrappers.RSObject;
  12. import org.rsbot.script.wrappers.RSTile;
  13.  
  14.  
  15. import java.awt.Color;
  16. import java.awt.Graphics;
  17. import java.awt.Point;
  18.  
  19. @ScriptManifest(authors = "Jacmob", keywords = {"Crafting", "Money Making"}, name = "AutoSpinner", version = 2.6, description = "Lumbridge castle; flax at top of bank.")
  20. public class AutoSpinner extends Script implements PaintListener, MessageListener {
  21.  
  22. @Override
  23. public boolean onStart() {
  24. SPIN_INTERFACE = interfaces.get(905).getComponent(16);
  25.  
  26. return true;
  27. }
  28.  
  29. private enum State {
  30. WALKTOBANK, WALKTOSPIN, OPENBANK, OPENSPIN, CLIMBUP, BANK, SPIN
  31. }
  32.  
  33. public final int EMOTE_ID = 1563;
  34. public final int FLAX_ID = 1779;
  35. public final int BOW_STRING_ID = 1777;
  36. public final int[] BANK_AREA = { 3207, 3210, 3217, 3220 };
  37. public final RSTile BANK_TILE = new RSTile(3208, 3221);
  38. public final RSTile SPINNER_TILE = new RSTile(3209, 3212);
  39. public final RSTile BANK_WALK_TILE = new RSTile(3208, 3219);
  40. public final RSTile STAIRCASE_TILE = new RSTile(3205, 3208);
  41. public final RSTile STAIRCASE_GROUND_TILE = new RSTile(3204, 3208);
  42. public final RSTile SPINNER_STAIRCASE_TILE = new RSTile(3205,3209);
  43. public final RSTile STAIRCASE_GROUND_WALK_TILE = new RSTile(3207, 3210);
  44. public RSComponent SPIN_INTERFACE;
  45.  
  46. int SPINNER_STAIRCASE_ID = 36774;
  47.  
  48. private int scriptStartXP = 0;
  49. private int nextMinRunEnergy = random(20, 50);
  50. private int flaxSpun = 0;
  51. private int flaxPrice = 0;
  52. private int stringPrice = 0;
  53. private long scriptStartTime = 0;
  54.  
  55. private void antiBan(final int upperBound) {
  56. final int rand = random(0, upperBound);
  57. if (rand == 69) {
  58. if (game.getCurrentTab() == Game.TAB_STATS) {
  59. game.openTab(Game.TAB_INVENTORY);
  60. sleep(random(50, 1000));
  61. }
  62. final Point screenLoc = calc.tileToScreen(getMyPlayer()
  63. .getLocation());
  64. mouse.move(screenLoc, 3, 3, 5);
  65. sleep(random(50, 300));
  66. mouse.click(false);
  67. sleep(random(500, 2500));
  68. while (menu.isOpen()) {
  69. mouse.moveRandomly(700);
  70. sleep(random(100, 500));
  71. }
  72. } else if (rand == 68) {
  73. if (game.getCurrentTab() != Game.TAB_STATS) {
  74. game.openTab(Game.TAB_STATS);
  75. sleep(random(200, 400));
  76. interfaces.getComponent(Skills.INTERFACE_TAB_STATS, Skills.INTERFACE_CRAFTING).doHover();
  77. sleep(random(800, 1500));
  78. if (random(0, 2) == 0) {
  79. moveMouseAway(10);
  80. }
  81. sleep(random(200, 400));
  82. } else if (game.getCurrentTab() == Game.TAB_STATS) {
  83. game.openTab(Game.TAB_INVENTORY);
  84. sleep(random(800, 1200));
  85. }
  86. } else if (rand == 67) {
  87. final int rand2 = random(1, 3);
  88. for (int i = 0; i < rand2; i++) {
  89. mouse.move(random(100, 700), random(100, 500));
  90. sleep(random(200, 700));
  91. }
  92. mouse.move(random(0, 800), 647, 50, 100);
  93. sleep(random(100, 1500));
  94. mouse.move(random(75, 400), random(75, 400), 30);
  95. } else if (rand == 0) {
  96. rotateCamera();
  97. } else if (rand < 4) {
  98. waveMouse();
  99. }
  100. }
  101.  
  102. private State getState() {
  103. if (game.getPlane() == 0) {
  104. return State.CLIMBUP;
  105. } else if (inventory.contains(FLAX_ID)) {
  106. if (game.getPlane() == 2) {
  107. return State.WALKTOSPIN;
  108. } else if (SPIN_INTERFACE.isValid()) {
  109. return State.SPIN;
  110. } else {
  111. return State.OPENSPIN;
  112. }
  113. } else {
  114. if (game.getPlane() == 1) {
  115. return State.WALKTOBANK;
  116. } else if (bank.isOpen()) {
  117. return State.BANK;
  118. } else {
  119. return State.OPENBANK;
  120. }
  121. }
  122. }
  123.  
  124. @Override
  125. public int loop() {
  126. mouse.setSpeed(random(5,8));
  127. final State state = getState();
  128. int tries = 0;
  129. antiBan(65);
  130. switch (state) {
  131. case WALKTOSPIN:
  132. if (walking.getEnergy() > nextMinRunEnergy) {
  133. walking.setRun(true);
  134. nextMinRunEnergy = random(20, 50);
  135. }
  136. if (calc.tileOnScreen(STAIRCASE_TILE)) {
  137. if (bank.isOpen()) {
  138. bank.close();
  139. }
  140. if (!tiles.doAction(STAIRCASE_TILE, "Climb-down")
  141. && !getMyPlayer().isMoving()) {
  142. rotateCamera();
  143. }
  144. while (game.getPlane() != 1 && tries < 10) {
  145. tries++;
  146. sleep(random(100, 200));
  147. }
  148. } else {
  149. walkTileSmart(STAIRCASE_TILE);
  150. while (calc.distanceTo(STAIRCASE_TILE) > 4 && tries < 10) {
  151. tries++;
  152. sleep(random(400, 500));
  153. }
  154. }
  155. break;
  156. case WALKTOBANK:
  157. if (SPIN_INTERFACE.isValid()) {
  158. mouse.click(random(480, 485), random(42, 48), true);
  159. }
  160. walkUpSpinStaircase();
  161. rotateCamera();
  162. break;
  163. case OPENBANK:
  164. if (playerIsInArea(BANK_AREA)) {
  165. tiles.doAction(BANK_TILE, "Use-quickly");
  166. while (!bank.isOpen() && tries < 5) {
  167. tries++;
  168. sleep(random(400, 600));
  169. }
  170. } else {
  171. walkTileSmart(BANK_WALK_TILE);
  172. sleep(random(200, 700));
  173. while (!playerIsInArea(BANK_AREA) && tries < 10) {
  174. tries++;
  175. sleep(random(400, 600));
  176. }
  177. }
  178. break;
  179. case OPENSPIN:
  180. if (calc.tileOnScreen(SPINNER_TILE)) {
  181. if (tiles.doAction(SPINNER_TILE, "Spin")) {
  182. moveMouseAway(50);
  183. } else {
  184. break;
  185. }
  186. while (!SPIN_INTERFACE.isValid() && tries < 10) {
  187. if (getMyPlayer().isMoving()) {
  188. tries = 2;
  189. }
  190. tries++;
  191. sleep(random(400, 600));
  192. antiBan(65);
  193. }
  194. } else {
  195. camera.turnToTile(SPINNER_TILE, 20);
  196. }
  197. break;
  198. case SPIN:
  199. int stringsPreviouslyHeld = inventory.getCount(BOW_STRING_ID);
  200. if (SPIN_INTERFACE.doAction("Make All")) {
  201. if (random(0, 2) == 1) {
  202. moveMouseAway(50);
  203. }
  204. sleep(random(1000, 1200));
  205. if (SPIN_INTERFACE.isValid()) {
  206. break;
  207. }
  208. } else {
  209. break;
  210. }
  211. while (tries < 15 && inventory.contains(FLAX_ID)) {
  212. if (getMyPlayer().getAnimation() == EMOTE_ID) {
  213. tries = 0;
  214. } else {
  215. tries++;
  216. }
  217. sleep(random(300, 500));
  218. antiBan(80);
  219. flaxSpun += inventory.getCount(BOW_STRING_ID)
  220. - stringsPreviouslyHeld;
  221. stringsPreviouslyHeld = inventory.getCount(BOW_STRING_ID);
  222. }
  223. break;
  224. case BANK:
  225. if (inventory.getCount() > 0) {
  226. bank.depositAll();
  227. if (random(0, 5) == 0) {
  228. moveMouseAway(7);
  229. }
  230. return random(400, 600);
  231. }
  232. if (inventory.getCount(FLAX_ID) == 0) {
  233. if (bank.getItem(FLAX_ID) != null) {
  234. bank.getItem(FLAX_ID).doAction("Withdraw-All");
  235. sleep(random(50, 100));
  236. }
  237. if (random(0, 5) == 0) {
  238. moveMouseAway(7);
  239. sleep(random(1000, 1200));
  240. } else {
  241. sleep(random(1000, 1200));
  242. if (random(0, 5) == 0) {
  243. moveMouseAway(7);
  244. }
  245. }
  246. if (inventory.getCount(FLAX_ID) == 0 && bank.getItem(FLAX_ID) == null) {
  247. if (bank.isOpen()) {
  248. bank.close();
  249. sleep(random(200, 500));
  250. }
  251. log.info("No flax Found");
  252. stopScript();
  253. break;
  254. }
  255. }
  256. sleep(random(150, 400));
  257. if (inventory.getCount(FLAX_ID) > 0 && random(0, 3) == 0) {
  258. bank.close();
  259. }
  260. case CLIMBUP:
  261. if (calc.tileOnScreen(STAIRCASE_TILE)) {
  262. if (!tiles.doAction(STAIRCASE_GROUND_TILE, "Climb-up")
  263. && !getMyPlayer().isMoving()) {
  264. rotateCamera();
  265. }
  266. sleep(random(400, 600));
  267. } else {
  268. walking.walkTileMM(walking.getClosestTileOnMap(STAIRCASE_GROUND_WALK_TILE), 1, 1);
  269. sleep(random(1000, 2000));
  270. }
  271. break;
  272. default:
  273. break;
  274. }
  275. return random(400, 700);
  276. }
  277.  
  278. private void moveMouseAway(final int moveDist) {
  279. final Point pos = mouse.getLocation();
  280. mouse.move(pos.x - moveDist, pos.y - moveDist, moveDist * 2,
  281. moveDist * 2);
  282. }
  283.  
  284. @Override
  285. public void onFinish() {
  286. log.info(flaxSpun + " flax spun in " +
  287. Timer.format(System.currentTimeMillis() - scriptStartTime) + ".");
  288. }
  289.  
  290. public void serverMessageRecieved(MessageEvent e) {
  291. string msg = e.getMessage().toLowerCase();
  292. if (msg.contains("you've just")) {
  293. sleep(random(500, 1500));
  294. if (interfaces.canContinue()) {
  295. interfaces.clickContinue();
  296. }
  297. }
  298. }
  299.  
  300. public void onRepaint(final Graphics g) {
  301. if (game.isLoggedIn()
  302. && skills.getCurrentLevel(Skills.CRAFTING) > 1) {
  303. if (scriptStartTime == 0) {
  304. scriptStartTime = System.currentTimeMillis();
  305. scriptStartXP = skills
  306. .getCurrentExp(Skills.CRAFTING);
  307. }
  308.  
  309. final Color BG = new Color(50, 50, 50, 150);
  310. final Color TEXT = new Color(200, 255, 0, 255);
  311.  
  312. final int x = 13;
  313. int y = 26;
  314.  
  315. final int levelsGained = skills
  316. .getRealLevel(Skills.CRAFTING)
  317. - Skills.getLevelAt(scriptStartXP);
  318. final long runSeconds = (System.currentTimeMillis() - scriptStartTime) / 1000;
  319. g.setColor(BG);
  320. g.fill3DRect(x - 6, y, 211, 26, true);
  321. g.setColor(TEXT);
  322. g.drawString("AutoSpinner v2.6 by Jacmob", x, y += 17);
  323.  
  324. y += 20;
  325. g.setColor(BG);
  326. g.fill3DRect(x - 6, y, 211, 86, true);
  327.  
  328. y -= 3;
  329. g.setColor(TEXT);
  330. g.drawString("Runtime: "
  331. + Timer.format(System.currentTimeMillis()
  332. - scriptStartTime), x, y += 20);
  333. g.drawString("Spun: " + flaxSpun + " Flax", x, y += 20);
  334.  
  335. if (levelsGained < 0) {
  336. scriptStartXP = skills
  337. .getCurrentExp(Skills.CRAFTING);
  338. } else if (levelsGained == 1) {
  339. g
  340. .drawString(
  341. "Gained: "
  342. + (skills
  343. .getCurrentExp(Skills.CRAFTING) - scriptStartXP)
  344. + " XP (" + levelsGained + " lvl)", x,
  345. y += 20);
  346. } else {
  347. g
  348. .drawString(
  349. "Gained: "
  350. + (skills
  351. .getCurrentExp(Skills.CRAFTING) - scriptStartXP)
  352. + " XP (" + levelsGained + " lvls)", x,
  353. y += 20);
  354. }
  355.  
  356. if (runSeconds > 10 && flaxSpun > 0) {
  357. g.drawString("Averaging: " +
  358. (skills.getCurrentExp(Skills.CRAFTING) - scriptStartXP)
  359. * 3600 / runSeconds + " XP/hr", x, y += 20);
  360. if (flaxPrice != 0 && stringPrice != 0) {
  361. y += 20;
  362. g.setColor(BG);
  363. g.fill3DRect(x - 6, y, 211, 66, true);
  364. y -= 3;
  365. g.setColor(TEXT);
  366. final int profit = flaxSpun * (stringPrice - flaxPrice);
  367. g.drawString("Gained: " + profit + " GP", x, y += 20);
  368. g.drawString("Averaging: " + flaxSpun * 3600 / runSeconds
  369. + " spins/hr", x, y += 20);
  370. g.drawString("Averaging: " + profit * 3600 / runSeconds
  371. + " GP/hr", x, y += 20);
  372. }
  373. } else {
  374. g.drawString("Gathering Data...", x, y += 20);
  375. }
  376. }
  377. }
  378.  
  379.  
  380. private boolean playerIsInArea(final int[] bounds) {
  381. final RSTile pos = getMyPlayer().getLocation();
  382. return pos.getX() >= bounds[0] && pos.getX() <= bounds[1]
  383. && pos.getY() >= bounds[2] && pos.getY() <= bounds[3];
  384. }
  385.  
  386. private void rotateCamera() {
  387. int angle = camera.getAngle() + random(-40, 40);
  388. if (angle < 0) {
  389. angle += 359;
  390. }
  391. if (angle > 359) {
  392. angle -= 359;
  393. }
  394.  
  395. camera.setAngle(angle);
  396. }
  397.  
  398. private boolean walkTileSmart(final RSTile t) {
  399. if (calc.tileOnScreen(t)) {
  400. return tiles.doAction(t, "Walk");
  401. }
  402. return walking.walkTo(t);
  403. }
  404.  
  405. public void walkUpSpinStaircase() {
  406.  
  407. RSObject stairs = objects.getNearest(SPINNER_STAIRCASE_ID);
  408.  
  409. if(stairs != null)
  410. {
  411. if(stairs.isOnScreen() && calc.distanceTo(stairs.getLocation()) < 4)
  412. {
  413. stairs.doClick(false);
  414. sleep(500,600);
  415. menu.doAction("Climb-up");
  416. sleep(500,600);
  417. while(getMyPlayer().isMoving())
  418. {
  419. sleep(100,150);
  420. }
  421. }
  422. else
  423. {
  424. walking.walkTo(SPINNER_STAIRCASE_TILE);
  425. sleep(600,700);
  426. while(getMyPlayer().isMoving())
  427. {
  428. sleep(100,150);
  429. }
  430. }
  431. }
  432. }
  433.  
  434. private void waveMouse() {
  435. final Point curPos = mouse.getLocation();
  436. mouse.move(random(0, 750), random(0, 500), 20);
  437. sleep(random(100, 300));
  438. mouse.move(curPos, 20, 20);
  439. }
  440.  
  441. @Override
  442. public void messageReceived(MessageEvent e) {
  443. // TODO Auto-generated method stub
  444.  
  445. }
  446. }
Add Comment
Please, Sign In to add comment