Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.06 KB | None | 0 0
  1. package priv.hashy.flax;
  2.  
  3. import org.dreambot.api.script.listener.*;
  4. import org.dreambot.api.script.*;
  5. import org.dreambot.api.wrappers.widgets.*;
  6. import org.dreambot.api.utilities.*;
  7. import org.dreambot.api.methods.map.*;
  8. import javax.swing.*;
  9. import org.dreambot.api.randoms.*;
  10. import org.dreambot.api.methods.skills.*;
  11. import org.dreambot.api.methods.*;
  12. import org.dreambot.api.methods.container.impl.bank.*;
  13. import org.dreambot.api.methods.tabs.*;
  14. import org.dreambot.api.wrappers.interactive.*;
  15. import org.dreambot.api.wrappers.items.*;
  16. import java.awt.*;
  17. import org.dreambot.api.wrappers.widgets.message.*;
  18. import org.dreambot.api.methods.world.*;
  19.  
  20. @ScriptManifest(category = Category.MONEYMAKING, name = "PrivFlaxSpinner", author = "Hashtag", version = 1.0)
  21. public class Main extends AbstractScript implements InventoryListener, MessageListener
  22. {
  23. private WidgetChild widget;
  24. private WidgetChild craftWidget;
  25. private WidgetChild type;
  26. private Timer timer;
  27. private long nextDo;
  28. private long nextSpin;
  29. private long nextAB;
  30. private long nextMule;
  31. private long nextHop;
  32. private static final Tile SPIN_TILE;
  33. private int remaining;
  34. private String mule;
  35. private int spinned;
  36. private Main.State currentState;
  37. private boolean activeStairs;
  38.  
  39. public Main() {
  40. this.remaining = 5;
  41. this.mule = "";
  42. }
  43.  
  44. public void onStart() {
  45. this.timer = new Timer();
  46. this.mule = JOptionPane.showInputDialog(null, "Input mule's name");
  47. this.nextHop = this.timer.elapsed() + 2700000L;
  48. this.getMouse().getMouseSettings().setWordsPerMinute(100.0);
  49. this.getRandomManager().disableSolver(RandomEvent.DISMISS);
  50. this.getRandomManager().unregisterSolver(RandomEvent.DISMISS);
  51. this.getRandomManager().registerSolver((RandomSolver)new CustomDismissSolver(this.getClient().getInstance()));
  52. }
  53.  
  54. public void onStart(final String... args) {
  55. this.timer = new Timer();
  56. this.mule = args[0].replace("_", " ");
  57. this.nextHop = this.timer.elapsed() + 2700000L;
  58. this.getRandomManager().disableSolver(RandomEvent.DISMISS);
  59. this.getRandomManager().unregisterSolver(RandomEvent.DISMISS);
  60. this.getRandomManager().registerSolver((RandomSolver)new CustomDismissSolver(this.getClient().getInstance()));
  61. }
  62.  
  63. private WidgetChild getBestCraftable() {
  64. final int lvl = this.getSkills().getRealLevel(Skill.CRAFTING);
  65. if (lvl >= 9) {
  66. return this.getWidgets().getWidgetChild(new int[] { 154, 137 });
  67. }
  68. if (lvl >= 7) {
  69. return this.getWidgets().getWidgetChild(new int[] { 154, 129 });
  70. }
  71. return this.getWidgets().getWidgetChild(new int[] { 154, 127 });
  72. }
  73.  
  74. public int onLoop() {
  75. final int[] $SwitchMap$priv$hashy$flax$Main$State = Main.Main$1.$SwitchMap$priv$hashy$flax$Main$State;
  76. final Main.State state = this.getState();
  77. this.currentState = state;
  78. switch ($SwitchMap$priv$hashy$flax$Main$State[state.ordinal()]) {
  79. case 1: {
  80. if (this.getBank().isOpen()) {
  81. if (this.shouldDo() && this.getBank().close()) {
  82. this.nextDo(2000);
  83. break;
  84. }
  85. break;
  86. }
  87. else if (this.shouldSpin()) {
  88. if (!this.isCraftWidgetOpen()) {
  89. final Item needle = this.getInventory().get("Needle");
  90. if (needle != null && needle.useOn("Leather")) {
  91. this.nextSpin(1000);
  92. }
  93. break;
  94. }
  95. if (!this.getClient().getMenu().isMenuVisible()) {
  96. final WidgetChild best = this.getBestCraftable();
  97. if (best != null && best.isVisible() && this.getMouse().click(best.getRectangle(), true)) {
  98. this.nextSpin(700);
  99. }
  100. break;
  101. }
  102. if (this.getClient().getMenu().getMenuCount() >= 3) {
  103. if (this.getClient().getMenu().clickIndex(3)) {
  104. this.nextSpin(2500);
  105. break;
  106. }
  107. break;
  108. }
  109. else {
  110. if (this.getClient().getMenu().close()) {
  111. this.nextSpin(500);
  112. break;
  113. }
  114. break;
  115. }
  116. }
  117. else {
  118. if (this.getMouse().isMouseInScreen() && this.getLocalPlayer().isAnimating()) {
  119. this.getMouse().moveMouseOutsideScreen();
  120. break;
  121. }
  122. if (this.timer.elapsed() > this.nextAB) {
  123. this.getCamera().rotateTo(Calculations.random(0, 2000), Calculations.random(100, 300));
  124. this.nextAB = this.timer.elapsed() + Calculations.random(1, 4) * 10 * 1000;
  125. break;
  126. }
  127. break;
  128. }
  129. break;
  130. }
  131. case 2: {
  132. if (!this.shouldDo()) {
  133. break;
  134. }
  135. if (this.getBank().isOpen()) {
  136. if (this.getSkills().getRealLevel(Skill.CRAFTING) >= 10) {
  137. if (!this.getInventory().isEmpty()) {
  138. if (this.getBank().depositAllItems()) {
  139. this.nextDo(300);
  140. break;
  141. }
  142. break;
  143. }
  144. else if (this.getBank().contains("Flax")) {
  145. if (this.getBank().getWithdrawMode().equals((Object)BankMode.ITEM)) {
  146. if (this.getBank().withdrawAll("Flax")) {
  147. this.activeStairs = (Calculations.random(3) == 1);
  148. this.nextDo(700);
  149. break;
  150. }
  151. break;
  152. }
  153. else {
  154. if (this.getBank().setWithdrawMode(BankMode.ITEM)) {
  155. this.nextDo(700);
  156. break;
  157. }
  158. break;
  159. }
  160. }
  161. else {
  162. if (this.getBank().close()) {
  163. this.getTabs().logout();
  164. this.stop();
  165. break;
  166. }
  167. break;
  168. }
  169. }
  170. else if (this.getBank().getWithdrawMode().equals((Object)BankMode.ITEM)) {
  171. if (!this.getInventory().contains("Needle")) {
  172. if (this.getBank().withdrawAll("Needle")) {
  173. this.nextDo(700);
  174. break;
  175. }
  176. break;
  177. }
  178. else if (!this.getInventory().contains("Thread")) {
  179. if (this.getBank().withdrawAll("Thread")) {
  180. this.nextDo(700);
  181. break;
  182. }
  183. break;
  184. }
  185. else if (!this.getInventory().onlyContains(new String[] { "Needle", "Thread" })) {
  186. if (this.getBank().depositAllExcept(new String[] { "Needle", "Thread" })) {
  187. this.nextDo(700);
  188. break;
  189. }
  190. break;
  191. }
  192. else {
  193. if (this.getBank().withdrawAll("Leather")) {
  194. this.nextDo(700);
  195. break;
  196. }
  197. break;
  198. }
  199. }
  200. else {
  201. if (this.getBank().setWithdrawMode(BankMode.ITEM)) {
  202. this.nextDo(700);
  203. break;
  204. }
  205. break;
  206. }
  207. }
  208. else {
  209. if (this.isWidgetOpen()) {
  210. this.getKeyboard().closeInterfaceWithESC();
  211. sleep(350 + Calculations.random(150));
  212. break;
  213. }
  214. if (this.getLocalPlayer().getZ() != 1 || !this.getClient().getMenu().isMenuVisible()) {
  215. final int z = this.getLocalPlayer().getZ();
  216. if ((this.getWalking().getDestinationDistance() < 4 && z == 2) || ((z == 1 || z == 0) && !this.getLocalPlayer().isMoving())) {
  217. if ((z == 1 && this.getMap().canReach(new Tile(3206, 3211, 1))) || z != 1) {
  218. if (this.getBank().openClosest()) {
  219. sleepUntil(() -> this.getBank().isOpen() || z != this.getLocalPlayer().getZ(), 2000L);
  220. }
  221. }
  222. else if (this.getWalking().walk(new Tile(3206, 3211, 1))) {
  223. sleepUntil(() -> this.getLocalPlayer().isMoving(), 2000L);
  224. }
  225. }
  226. break;
  227. }
  228. if (this.getClient().getMenu().contains("Climb-up")) {
  229. if (this.getClient().getMenu().clickAction("Climb-up")) {
  230. this.nextDo(2000);
  231. break;
  232. }
  233. break;
  234. }
  235. else {
  236. if (this.getClient().getMenu().close()) {
  237. this.nextDo(500);
  238. break;
  239. }
  240. break;
  241. }
  242. }
  243. break;
  244. }
  245. case 3: {
  246. if (this.getLocalPlayer().getZ() != 1) {
  247. if (this.getWalking().getDestinationDistance() < 3 && this.shouldDo() && this.getTabs().open(Tab.INVENTORY)) {
  248. final GameObject stairs = (GameObject)this.getGameObjects().closest(go -> go != null && go.getName().equals("Staircase") && go.getY() < 3210);
  249. if (this.getLocalPlayer().distance((Entity)stairs) < 7.0 && stairs.interact("Climb-" + ((this.getLocalPlayer().getZ() == 0) ? "up" : "down"))) {
  250. this.nextDo(2000);
  251. }
  252. else if (this.getWalking().walk(this.randomTileFrom(stairs.getTile(), 4))) {
  253. sleep(300);
  254. this.getCamera().mouseRotateToEntity((Entity)stairs);
  255. this.nextDo(2000);
  256. }
  257. break;
  258. }
  259. break;
  260. }
  261. else if (this.isWidgetOpen()) {
  262. if (this.shouldDo()) {
  263. final int c = this.getInventory().count("Flax");
  264. final String action = (c > 10) ? "Make X" : ((c > 5) ? "Make 10" : ((c > 1) ? "Make 5" : "Make 1"));
  265. if (this.widget.interact(action)) {
  266. this.nextDo(700);
  267. }
  268. break;
  269. }
  270. break;
  271. }
  272. else if (this.shouldSpin()) {
  273. if (this.shouldType()) {
  274. this.remaining = Calculations.random(3, 7);
  275. this.nextAB = this.timer.elapsed() + Calculations.random(1, 4) * 10 * 1000;
  276. this.getKeyboard().type((Object)Calculations.random(30, 999), true);
  277. this.nextDo(2000);
  278. this.nextSpin(2000);
  279. break;
  280. }
  281. final GameObject wheel = (GameObject)this.getGameObjects().closest(new String[] { "Spinning wheel" });
  282. if (wheel != null && !this.getLocalPlayer().isMoving() && !this.getLocalPlayer().isAnimating()) {
  283. if (this.getLocalPlayer().distance((Entity)wheel) < 7.0 && this.getMap().canReach(Main.SPIN_TILE)) {
  284. if (wheel.interact("Spin")) {
  285. this.nextSpin(2500);
  286. }
  287. }
  288. else if (this.getWalking().walk((Entity)wheel)) {
  289. this.nextSpin(1000);
  290. }
  291. }
  292. break;
  293. }
  294. else {
  295. if (this.getInventory().count("Flax") <= this.remaining) {
  296. break;
  297. }
  298. if (this.getMouse().isMouseInScreen() && this.getLocalPlayer().isAnimating()) {
  299. if (this.remaining % 2 == 0) {
  300. this.getCamera().mouseRotateTo(Calculations.random(0, 2000), Calculations.random(100, 300));
  301. }
  302. this.getMouse().moveMouseOutsideScreen();
  303. break;
  304. }
  305. if (this.timer.elapsed() > this.nextAB) {
  306. this.getCamera().rotateTo(Calculations.random(0, 2000), Calculations.random(100, 300));
  307. this.nextAB = this.timer.elapsed() + Calculations.random(1, 4) * 10 * 1000;
  308. break;
  309. }
  310. break;
  311. }
  312. break;
  313. }
  314. case 4: {
  315. if (!this.shouldDo()) {
  316. break;
  317. }
  318. if (this.getTrade().isOpen() || this.getInventory().contains(i -> i != null && i.isNoted() && i.getName().equals("Bow string"))) {
  319. if (this.getBank().isOpen()) {
  320. if (this.getBank().close()) {
  321. this.nextDo(700);
  322. break;
  323. }
  324. break;
  325. }
  326. else if (this.getClient().getCurrentWorld() == this.getFriends().getFriend(this.mule).getWorld()) {
  327. if (!this.getTrade().isOpen()) {
  328. break;
  329. }
  330. if (this.getTrade().getMyItems() == null || this.getTrade().getMyItems().length == 0) {
  331. if (this.getTrade().addItem("Bow string", this.getInventory().count("Bow string"))) {
  332. this.nextDo(1000);
  333. break;
  334. }
  335. break;
  336. }
  337. else {
  338. if (this.getTrade().acceptTrade()) {
  339. this.nextDo(2000);
  340. break;
  341. }
  342. break;
  343. }
  344. }
  345. else {
  346. if (this.getWorldHopper().quickHop(this.getFriends().getFriend(this.mule).getWorld())) {
  347. this.nextDo(2000);
  348. break;
  349. }
  350. break;
  351. }
  352. }
  353. else if (this.getBank().isOpen()) {
  354. if (this.getInventory().contains("Bow string")) {
  355. if (this.getBank().depositAllItems()) {
  356. this.nextDo(700);
  357. break;
  358. }
  359. break;
  360. }
  361. else if (this.getBank().getWithdrawMode().equals((Object)BankMode.NOTE)) {
  362. if (this.getBank().withdrawAll("Bow string")) {
  363. this.nextDo(700);
  364. break;
  365. }
  366. break;
  367. }
  368. else {
  369. if (this.getBank().setWithdrawMode(BankMode.NOTE)) {
  370. this.nextDo(700);
  371. break;
  372. }
  373. break;
  374. }
  375. }
  376. else if (this.getLocalPlayer().getZ() == 1 && this.getClient().getMenu().isMenuVisible()) {
  377. if (this.getClient().getMenu().clickAction("Climb-up")) {
  378. this.nextDo(2000);
  379. break;
  380. }
  381. break;
  382. }
  383. else {
  384. if (!this.getLocalPlayer().isMoving() && this.getBank().openClosest()) {
  385. this.nextDo(2000);
  386. break;
  387. }
  388. break;
  389. }
  390. break;
  391. }
  392. case 5: {
  393. if (this.getWorldHopper().hopWorld(this.getWorlds().getRandomWorld(w -> w != null && w.isMembers() && !w.isDeadmanMode() && !w.isLastManStanding() && !w.isPVP() && w.getMinimumLevel() == 0))) {
  394. this.nextDo(2000);
  395. this.nextHop = this.timer.elapsed() + 2700000L;
  396. break;
  397. }
  398. break;
  399. }
  400. }
  401. return 200;
  402. }
  403.  
  404. private Tile randomTileFrom(final Tile t, final int max) {
  405. return new Tile(t.getX(), t.getY() + Calculations.random(max), t.getZ());
  406. }
  407.  
  408. public void onPaint(final Graphics g) {
  409. if (!this.hasAttackOptionsHidden()) {
  410. g.setColor(Color.RED);
  411. g.setFont(new Font("Helvetica", 1, 15));
  412. g.drawString("WARNING: Hide NPC attack options from the ingame settings!", 10, 50);
  413. }
  414. if (!this.hasESCEnabled()) {
  415. g.drawString("TIP: Enable ESC closes interfaces from the ingame settings!", 10, 65);
  416. }
  417. g.setColor(Color.WHITE);
  418. g.setFont(new Font("Helvetica", 1, 12));
  419. g.drawString("Time: " + this.timer.formatTime(), 10, 80);
  420. g.drawString("Spinned: " + this.spinned, 10, 95);
  421. g.drawString("Hourly: " + this.timer.getHourlyRate(this.spinned), 10, 110);
  422. g.drawString("Mule: " + this.mule, 10, 125);
  423. g.drawString("State: " + this.currentState, 10, 140);
  424. }
  425.  
  426. public void onItemChange(final Item[] items) {
  427. for (final Item i : items) {
  428. if (i != null) {
  429. if (i.getName().equals("Flax")) {
  430. if (i.getAmount() < 0) {
  431. ++this.spinned;
  432. this.nextSpin(3000);
  433. if (this.activeStairs && this.getInventory().count("Flax") < this.remaining) {
  434. if (!this.getClient().getMenu().isMenuVisible()) {
  435. final GameObject stairs = (GameObject)this.getGameObjects().closest(new String[] { "Staircase" });
  436. if (stairs != null && this.getMap().canReach((Entity)stairs)) {
  437. while (!this.getDialogues().inDialogue() && this.getInventory().contains("Flax") && !this.getClient().getMenu().isMenuVisible()) {
  438. if (stairs.isOnScreen()) {
  439. if (stairs.getBoundingBox().contains(this.getMouse().getPosition())) {
  440. this.getMouse().click(true);
  441. }
  442. else {
  443. this.getMouse().move(stairs.getClickablePoint());
  444. }
  445. }
  446. else {
  447. this.getCamera().rotateToEntity((Entity)stairs);
  448. }
  449. this.nextSpin(2500);
  450. sleep(300);
  451. }
  452. }
  453. }
  454. else if (!this.getClient().getMenu().isMouseOnAction("Climb-up")) {
  455. if (this.getClient().getMenu().contains("Climb-up")) {
  456. this.getClient().getMenu().mouseOverAction("Climb-up");
  457. }
  458. else {
  459. this.getClient().getMenu().close();
  460. this.getCamera().rotateTo(Calculations.random(0, 2000), Calculations.random(100, 300));
  461. }
  462. }
  463. }
  464. }
  465. else {
  466. this.nextDo(50);
  467. }
  468. }
  469. else if (i.getName().equals("Leather") && i.getAmount() < 0) {
  470. this.nextSpin(2500);
  471. }
  472. }
  473. }
  474. }
  475.  
  476. private Main.State getState() {
  477. if (this.getSkills().getRealLevel(Skill.CRAFTING) >= 10) {
  478. if (this.getWorlds().getWorld(this.getClient().getCurrentWorld()).isF2P()) {
  479. return Main.State.HOP;
  480. }
  481. if (this.getInventory().contains(i -> i != null && i.getName().equals("Flax") && !i.isNoted())) {
  482. return Main.State.SPIN;
  483. }
  484. if (this.mule != null && this.timer.elapsed() > this.nextMule && this.getFriends().getFriend(this.mule) != null && this.getFriends().getFriend(this.mule).isOnline()) {
  485. return Main.State.TO_MULE;
  486. }
  487. if (this.timer.elapsed() > this.nextHop) {
  488. return Main.State.HOP;
  489. }
  490. }
  491. else if (this.getInventory().contains("Leather")) {
  492. return Main.State.CRAFT;
  493. }
  494. return Main.State.WITHDRAW;
  495. }
  496.  
  497. private boolean shouldType() {
  498. final WidgetChild widgetChild = this.getWidgets().getWidgetChild(new int[] { 162, 32 });
  499. this.type = widgetChild;
  500. return widgetChild != null && this.type.isVisible();
  501. }
  502.  
  503. private boolean isWidgetOpen() {
  504. final WidgetChild widgetChild = this.getWidgets().getWidgetChild(new int[] { 459, 95 });
  505. this.widget = widgetChild;
  506. return widgetChild != null && this.widget.isVisible();
  507. }
  508.  
  509. private boolean isCraftWidgetOpen() {
  510. final WidgetChild widgetChild = this.getWidgets().getWidgetChild(new int[] { 154, 0 });
  511. this.craftWidget = widgetChild;
  512. return widgetChild != null && this.craftWidget.isVisible();
  513. }
  514.  
  515. private boolean hasAttackOptionsHidden() {
  516. return this.getPlayerSettings().getConfig(1306) == 3;
  517. }
  518.  
  519. private boolean hasESCEnabled() {
  520. return this.getPlayerSettings().getConfig(1224) < 0;
  521. }
  522.  
  523. private boolean shouldDo() {
  524. return this.timer.elapsed() > this.nextDo;
  525. }
  526.  
  527. private void nextDo(final int next) {
  528. this.nextDo = this.timer.elapsed() + next;
  529. }
  530.  
  531. private boolean shouldSpin() {
  532. return this.timer.elapsed() > this.nextSpin;
  533. }
  534.  
  535. private void nextSpin(final int next) {
  536. this.nextSpin = this.timer.elapsed() + next;
  537. }
  538.  
  539. public void onGameMessage(final Message message) {
  540. if (message.getMessage().contains("Accepted trade")) {
  541. this.nextMule = this.timer.elapsed() + 600000L;
  542. }
  543. }
  544.  
  545. public void onPlayerMessage(final Message message) {
  546. }
  547.  
  548. public void onTradeMessage(final Message message) {
  549. if (message.getMessage().contains("wishes to trade") && message.getUsername().toLowerCase().equals(this.mule.toLowerCase()) && this.getTrade().tradeWithPlayer(message.getUsername())) {
  550. this.nextDo(2000);
  551. }
  552. }
  553.  
  554. public void onPrivateInMessage(final Message message) {
  555. }
  556.  
  557. public void onPrivateOutMessage(final Message message) {
  558. }
  559.  
  560. static {
  561. SPIN_TILE = new Tile(3209, 3213, 1);
  562. }
  563. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement