Advertisement
Guest User

Spinner Source

a guest
Jul 29th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.27 KB | None | 0 0
  1. package com.chandler.spinner;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics2D;
  5. import java.awt.Point;
  6. import java.util.List;
  7.  
  8. import org.dreambot.api.methods.Calculations;
  9. import org.dreambot.api.methods.filter.Filter;
  10. import org.dreambot.api.methods.map.Tile;
  11. import org.dreambot.api.methods.skills.Skill;
  12. import org.dreambot.api.methods.tabs.Tab;
  13. import org.dreambot.api.script.AbstractScript;
  14. import org.dreambot.api.script.Category;
  15. import org.dreambot.api.script.ScriptManifest;
  16. import org.dreambot.api.utilities.Timer;
  17. import org.dreambot.api.utilities.impl.Condition;
  18. import org.dreambot.api.wrappers.interactive.GameObject;
  19. import org.dreambot.api.wrappers.widgets.WidgetChild;
  20. import org.dreambot.api.wrappers.widgets.message.Message;
  21. import org.dreambot.api.wrappers.widgets.message.MessageType;
  22.  
  23. @ScriptManifest(author = "Chandler", category = Category.CRAFTING, name = "Chandler's Improved Spinner", version = 1.2)
  24. public class SpinnerMain extends AbstractScript {
  25.  
  26. public String status = "Starting...";
  27. public long lastIdle = 0;
  28. public int numSpun = 0;
  29. public Timer timer = new Timer();
  30. public int profit = 100;
  31. public double tiredness = 0.0;
  32. public long loopCount = 0L;
  33. public double tMultiplier;
  34.  
  35. public Filter<GameObject> stairs1Filter = new Filter<GameObject>() {
  36. @Override
  37. public boolean match(GameObject obj) {
  38. return obj.getName().equals("Staircase") && obj.getY() == 3208;
  39. }
  40. };
  41.  
  42. public Filter<GameObject> doorFilter = new Filter<GameObject>() {
  43. @Override
  44. public boolean match(GameObject obj) {
  45. return obj.getName().equals("Door") && obj.getX() == 3207 && obj.getY() == 3214;
  46. }
  47. };
  48.  
  49. @Override
  50. public void onMessage(Message m) {
  51. if(m.getType() == MessageType.GAME && m.getMessage().contains("run out of")) {
  52. numSpun += getInventory().count("Bow string");
  53. }
  54. }
  55.  
  56. @Override
  57. public void onStart() {
  58. getSkillTracker().start(Skill.CRAFTING);
  59. tMultiplier = Calculations.random(0.1D, 0.4D);
  60. }
  61.  
  62. @Override
  63. public void onPaint(Graphics2D g) {
  64. g.setColor(Color.BLACK);
  65. g.fillRect(5, 30, 210, 105);
  66. g.setColor(Color.RED);
  67. g.drawString("Chandler's Better Spinner", 10, 45);
  68. g.drawString("Status: " + status, 10, 60);
  69. g.drawString("Runtime: " + Timer.formatTime(timer.elapsed()), 10, 75);
  70. g.drawString("BS Spun (Hr.): " + (getSkillTracker().getGainedExperience(Skill.CRAFTING) / 15) + " (" + timer.getHourlyRate((int)(getSkillTracker().getGainedExperience(Skill.CRAFTING) / 15)) + ")", 10, 90);
  71. g.drawString("XP Gained (Hr.): " + getSkillTracker().getGainedExperience(Skill.CRAFTING) + " (" + getSkillTracker().getGainedExperiencePerHour(Skill.CRAFTING) + ")", 10, 105);
  72. g.drawString("Profit (Hr.): " + ((getSkillTracker().getGainedExperience(Skill.CRAFTING) / 15)*100) + " (" + timer.getHourlyRate((int)((getSkillTracker().getGainedExperience(Skill.CRAFTING) / 15)*100)), 10, 120);
  73. g.drawString("Tiredness: " + tiredness, 10, 135);
  74. }
  75.  
  76. @Override
  77. public int onLoop() {
  78. loopCount++;
  79. if(getCamera().getPitch() < 180) {
  80. getCamera().rotateToPitch(250 + Calculations.random(130));
  81. }
  82. if(getFloor() == 1) {
  83. if(getInventory().count("Flax") == 0) {
  84. if(getGameObjects().closest(doorFilter) != null && d2Spinner() < 2) {
  85. status = "Opening the door";
  86. openDoor();
  87. } else {
  88. if(d2Stairs2() < 5) {
  89. if(stairs1IsVisible()) {
  90. status = "Going up stairs";
  91. goUpStairs();
  92. } else {
  93. status = "Turning to stairs";
  94. turnTowardsStairs1();
  95. }
  96. } else {
  97. status = "Walking to stairs";
  98. getCloserToStairs1();
  99. }
  100. }
  101. } else {
  102. if(d2Spinner() < 5) {
  103. if(getGameObjects().closest(doorFilter) != null && d2Spinner() > 1) {
  104. status = "Opening door";
  105. openDoor();
  106. }
  107. //does nothing.
  108. /*if(isLevelUp()) {
  109. status = "Clicking continue";
  110. getKeyboard().type(" ", false);
  111. AbstractScript.sleepUntil(new Condition(){
  112. @Override
  113. public boolean verify() {
  114. return !isLevelUp();
  115. }
  116. }, 2000);
  117. return 500;
  118. }*/
  119. if(isSpinInterfaceUp()) {
  120. //click make x
  121. status = "Clicking widget";
  122. lastIdle = 0;
  123. clickMakeX();
  124. AbstractScript.sleepUntil(new Condition(){
  125. @Override
  126. public boolean verify() {
  127. return isEnterAmountUp();
  128. }
  129. }, 4000);
  130. if(isEnterAmountUp()) {
  131. status = "Inputting 28";
  132. getKeyboard().type("28");
  133. }
  134. return Calculations.random(4000);
  135. } else {
  136. if(getPlayers().localPlayer().getAnimation() == -1) {
  137. if(lastIdle != 0) {
  138. if(System.currentTimeMillis() - lastIdle > 2000) {
  139. getGameObjects().closest("Spinning wheel").interactForceLeft("Spin");
  140. lastIdle = 0;
  141. status = "Using wheel";
  142. }
  143. } else {
  144. lastIdle = System.currentTimeMillis();
  145. }
  146. } else {
  147. status = "Spinning";
  148. doAntiBan();
  149. lastIdle = 0;
  150. }
  151. }
  152. } else {
  153. getCloseToSpinner();
  154. }
  155. }
  156. } else if(getFloor() == 2) {
  157. if(bankIsOpen()) {
  158. if(getInventory().count("Bow string") > 0) {
  159. status = "Depositing bow strings";
  160. depositBowstrings();
  161. }
  162. if(getInventory().getEmptySlots() > 0) {
  163. status = "Withdrawing flax";
  164. withdrawFlax();
  165. }
  166. if(getInventory().count("Flax") > 0) {
  167. status = "Closing bank";
  168. closeBank();
  169. }
  170. } else {
  171. if(getInventory().count("Bow string") > 0 ||
  172. (getInventory().count("Bow string") == 0 & getInventory().count("Flax") == 0)) {
  173. if(d2Bank() < 5) {
  174. if(bankIsVisible()) {
  175. status = "Opening bank";
  176. openBank();
  177. } else {
  178. status = "Turning to bank";
  179. turnTowardsBank();
  180. }
  181. } else {
  182. status = "Going to bank";
  183. getCloser();
  184. }
  185. } else {
  186. if(d2Stairs1() < 5) {
  187. if(stairs1IsVisible()) {
  188. status = "Going down stairs";
  189. goDownStairs();
  190. } else {
  191. status = "Turning to stairs";
  192. turnTowardsStairs1();
  193. }
  194. } else {
  195. status = "Going to stairs";
  196. getCloserToStairs1();
  197. }
  198. }
  199. }
  200. }
  201. //TODO implement tiredness?
  202. return Calculations.random(400, 750) + (int)tiredness;
  203. }
  204.  
  205. public double getTired() {
  206. if(tiredness < 2500) { //if not too tired
  207. tiredness = Math.pow(loopCount/30, 2) * tMultiplier;
  208. }
  209. return tiredness;
  210. }
  211.  
  212. private void doAntiBan() {
  213. if(getPercent(90)) {
  214. status = "Acting natural";
  215. switch(Calculations.random(3)) {
  216. case 0:
  217. //Check something off screen
  218. getMouse().moveMouseOutsideScreen();
  219. break;
  220. case 1:
  221. //Check open stats
  222. if(getInventory().count("Flax") > 2) {
  223. getTabs().open(Tab.STATS);
  224. sleep(Calculations.random(3000, 5000));
  225. getTabs().open(Tab.INVENTORY);
  226. }
  227. break;
  228. case 2:
  229. //Move the camera a bit
  230. getCamera().rotateToYaw(getCamera().getYaw() + Calculations.random(30));
  231. break;
  232. case 3:
  233. //Move the mouse a little
  234. getMouse().move(new Point(getMouse().getX() + Calculations.random(10), getMouse().getY() + Calculations.random(10)));
  235. break;
  236. }
  237. }
  238. }
  239.  
  240. private boolean isLevelUp() {
  241. List<WidgetChild> children = getWidgets().getWidgetChildrenContainingText("just advanced a Crafting");
  242. List<WidgetChild> c2 = getWidgets().getWidgetChildrenContainingText("to continue");
  243. return children.size() > 0 && children.get(0).isVisible() && c2.size() > 0 && c2.get(0).isVisible();
  244. }
  245.  
  246.  
  247.  
  248. private boolean isEnterAmountUp() {
  249. List<WidgetChild> children = getWidgets().getWidgetChildrenContainingText("Enter amount:");
  250. return children.size() > 0 && children.get(0).isVisible();
  251. }
  252.  
  253. private boolean isSpinInterfaceUp() {
  254. List<WidgetChild> children = getWidgets().getWidgetChildrenContainingText("Bow String");
  255. return children.size() > 0 && children.get(0).isVisible();
  256. }
  257.  
  258. private void clickMakeX() {
  259. List<WidgetChild> children = getWidgets().getWidgetChildrenContainingText("Bow String");
  260. if(children.size() > 0 && children.get(0).isVisible()) {
  261. children.get(0).interact("Make X");
  262. }
  263. }
  264.  
  265. private void getCloseToSpinner() {
  266. if(getPercent(80)) {
  267. if(getGameObjects().closest("Spinning wheel").isOnScreen()) {
  268. getGameObjects().closest("Spinning wheel").interactForceLeft("Spin");
  269. }
  270. } else {
  271. Tile random = new Tile(getGameObjects().closest("Spinning wheel").getTile().getX()+ Calculations.random(1), getGameObjects().closest("Spinning wheel").getTile().getY()+1 + Calculations.random(1));
  272. getWalking().clickTileOnMinimap(random);
  273. }
  274. AbstractScript.sleepUntil(new Condition() {
  275. @Override
  276. public boolean verify() {
  277. return d2Spinner() < 5;
  278. }
  279. }, 6000);
  280. }
  281.  
  282. private void getCloserToStairs1() {
  283. GameObject stairs = getGameObjects().closest(stairs1Filter);
  284. getWalking().clickTileOnMinimap(stairs.getTile());
  285. AbstractScript.sleepUntil(new Condition(){
  286. @Override
  287. public boolean verify(){
  288. return d2Stairs1() < 3;
  289. }
  290. }, 6000);
  291. }
  292.  
  293. private void goDownStairs() {
  294. GameObject stairs = getGameObjects().closest(stairs1Filter);
  295. getMouse().move(stairs);
  296. stairs.interact("Climb-down");
  297. AbstractScript.sleepUntil(new Condition(){
  298. @Override
  299. public boolean verify() {
  300. return getPlayers().localPlayer().getZ() == 1;
  301. }
  302. }, 4000);
  303. }
  304.  
  305. private void goUpStairs() {
  306. GameObject stairs = getGameObjects().closest(stairs1Filter);
  307. getMouse().move(stairs);
  308. stairs.interact("Climb-up");
  309. AbstractScript.sleepUntil(new Condition(){
  310. @Override
  311. public boolean verify() {
  312. return getPlayers().localPlayer().getZ() == 2;
  313. }
  314. }, 4000);
  315. }
  316.  
  317. private void turnTowardsStairs1() {
  318. GameObject stairs = getGameObjects().closest(stairs1Filter);
  319. getCamera().rotateToEntity(stairs);
  320. getCamera().rotateToYaw(getCamera().getYaw() + Calculations.random(30));
  321. }
  322.  
  323. private int getCloser() {
  324. GameObject booth = getGameObjects().closest("Bank booth");
  325. Tile t = new Tile(booth.getTile().getX(), booth.getTile().getY() - 2);
  326. getWalking().clickTileOnMinimap(t);
  327. AbstractScript.sleepUntil(new Condition(){
  328. @Override
  329. public boolean verify(){
  330. return d2Bank() < 3;
  331. }
  332. }, 6000);
  333. return 500;
  334. }
  335.  
  336. public int depositBowstrings() {
  337. getBank().depositAllItems();
  338. AbstractScript.sleepUntil(new Condition(){
  339. @Override
  340. public boolean verify() {
  341. return getInventory().getEmptySlots() == 28;
  342. }
  343. }, 3000);
  344. return 500;
  345. }
  346.  
  347. public int withdrawFlax() {
  348. if(getBank().count("Flax") > 0) {
  349. getBank().withdraw("Flax", 28);
  350. AbstractScript.sleepUntil(new Condition(){
  351. @Override
  352. public boolean verify(){
  353. return getInventory().count("Flax") > 0;
  354. }
  355. }, 2500);
  356. return 500;
  357. } else {
  358. getBank().close();
  359. getTabs().logout();
  360. log("Out of flax. Logging out! Don't wanna stand there and look suspicious, do we?");
  361. stop();
  362. }
  363. return 0;
  364. }
  365.  
  366. public int openDoor() {
  367. getGameObjects().closest(doorFilter).interact("Open");
  368. Timer t = new Timer();
  369. while(t.elapsed() < 6000 && getGameObjects().closest(doorFilter).exists()) {
  370. sleep(Calculations.random(50, 100));
  371. }
  372. return 0;
  373. }
  374.  
  375. public boolean getPercent(int percent) {
  376. return Calculations.random(100) > percent;
  377. }
  378.  
  379. public int closeBank() {
  380. if(getPercent(85)) {
  381. Tile random = new Tile(getPlayers().localPlayer().getTile().getX() + Calculations.random(2),
  382. getPlayers().localPlayer().getTile().getY() + Calculations.random(2));
  383. getWalking().clickTileOnMinimap(random);
  384. } else {
  385. getBank().close();
  386. }
  387. AbstractScript.sleepUntil(new Condition(){
  388. @Override
  389. public boolean verify() {
  390. return !getBank().isOpen();
  391. }
  392. }, 2000);
  393. return 450;
  394. }
  395.  
  396. public double d2Spinner() {
  397. return Calculations.distance(getPlayers().localPlayer().getTile(), getGameObjects().closest("Spinning wheel").getTile());
  398. }
  399.  
  400. public double d2Bank() {
  401. return Calculations.distance(getPlayers().localPlayer().getTile(), getGameObjects().closest("Bank booth").getTile());
  402. }
  403.  
  404. public double d2Stairs1() {
  405. return Calculations.distance(getPlayers().localPlayer().getTile(), getGameObjects().closest(stairs1Filter).getTile());
  406. }
  407.  
  408. public double d2Stairs2() {
  409. return Calculations.distance(getPlayers().localPlayer().getTile(), getGameObjects().closest(stairs1Filter).getTile());
  410. }
  411.  
  412. public int turnTowardsBank() {
  413. GameObject booth = getGameObjects().closest("Bank booth");
  414. getCamera().rotateToEntity(booth);
  415. getCamera().rotateToYaw(getCamera().getYaw() + Calculations.random(20));
  416. return 0;
  417. }
  418.  
  419. public boolean stairs1IsVisible() {
  420. return getGameObjects().closest(stairs1Filter).isOnScreen();
  421. }
  422.  
  423. public boolean bankIsVisible() {
  424. return getGameObjects().closest("Bank booth").isOnScreen();
  425. }
  426.  
  427. public int openBank() {
  428. GameObject booth = getGameObjects().closest("Bank booth");
  429. getMouse().move(booth);
  430. if(getPercent(75)) {
  431. booth.interactForceLeft("Bank");
  432. } else {
  433. booth.interact("Bank");
  434. }
  435. AbstractScript.sleepUntil(new Condition(){
  436. @Override
  437. public boolean verify() {
  438. return getBank().isOpen();
  439. }
  440. }, 3000);
  441. return 500;
  442. }
  443.  
  444. public boolean bankIsOpen() {
  445. return getBank().isOpen();
  446. }
  447.  
  448. public int getFloor() {
  449. return getPlayers().localPlayer().getZ();
  450. }
  451. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement