Advertisement
iant06

Untitled

Sep 17th, 2015
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. package scripts.moneymaking.iplankfarmer.sawmill;
  2.  
  3. import org.tribot.api.General;
  4. import org.tribot.api.Timing;
  5. import org.tribot.api2007.Interfaces;
  6. import org.tribot.api2007.Inventory;
  7. import org.tribot.api2007.Player;
  8. import org.tribot.api2007.WebWalking;
  9. import org.tribot.api2007.types.RSInterface;
  10. import org.tribot.api2007.types.RSNPC;
  11.  
  12. import scripts.methods.Methods;
  13. import scripts.moneymaking.iplankfarmer.Script;
  14. import scripts.moneymaking.iplankfarmer.types.Plank;
  15. import scripts.moneymaking.iplankfarmer.types.ScriptTask;
  16. import scripts.moneymaking.iplankfarmer.types.State;
  17. import scripts.moneymaking.iplankfarmer.utils.Constants;
  18. import scripts.moneymaking.iplankfarmer.utils.Locations;
  19.  
  20. public class Sawmill {
  21.  
  22. private Script script;
  23.  
  24. public Sawmill(Script script) {
  25. setScript(script);
  26. }
  27.  
  28. public void setScript(Script main) {
  29. this.script = main;
  30. }
  31.  
  32. public Script getScript() {
  33. return script;
  34. }
  35.  
  36. public boolean walkToOperator() {
  37. if(getScript().getAxe().isAxeBroken()) {
  38. getScript().setState(State.WALKING_TO_BOB);
  39. return false;
  40. }
  41. final ScriptTask TASK = getScript().getTask();
  42. final Plank PLANK = getScript().getPlank();
  43. if(TASK.equals(ScriptTask.MAKE_PLANKS) || PLANK.equals(Plank.TEAK)) {
  44. if(getScript().getData().getCurrentTripTime() == 0) {
  45. getScript().getData().setCurrentTripTime(System.currentTimeMillis());
  46. }
  47. }
  48. Methods.performAntiBan(getScript());
  49. getScript().getData().checkPlayerRun();
  50. WebWalking.walkTo(Locations.SAWMILL_TILE);
  51. if(isInSawmill(3000)) {
  52. getScript().setState(State.MAKING_PLANKS);
  53. return true;
  54. }
  55. return false;
  56. }
  57.  
  58. private boolean isInSawmill(int i) {
  59. long t = System.currentTimeMillis();
  60. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  61. if (Player.getPosition().equals(Locations.SAWMILL_TILE)) {
  62. return true;
  63. }
  64. if (!Player.isMoving()) {
  65. return false;
  66. }
  67. getScript().sleep(50, 150);
  68. }
  69. return false;
  70. }
  71.  
  72. public void performSawmillTask() {
  73. RSNPC operator = Methods.findNPCByModelPoints(new int[]{Constants.SAWMILL_OPERATOR});
  74. if(operator != null) {
  75. operator.click("Buy-plank");
  76. if(isInterfaceOpen(1000)) {
  77. RSInterface button = Interfaces.get(Constants.PLANK_INTERFACE, getScript().getPlank().getChildId());
  78. if(button != null) {
  79. button.click("Buy All");
  80.  
  81. if(isFinished(2500)) {
  82. int plankAmount = Inventory.getCount(getScript().getPlank().getId());
  83. int planksMade = getScript().getData().getPlanksMade();
  84. double moneySpent = getScript().getData().getMoneySpent();
  85. double moneyMade = getScript().getData().getMoneyMade();
  86. final ScriptTask TASK = getScript().getTask();
  87. double logCost = TASK.equals(ScriptTask.MAKE_PLANKS) ? getScript().getLogPrice() : 0;
  88. logCost = logCost * plankAmount;
  89. getScript().getData().setMoneySpent(moneySpent + (plankAmount * getScript().getPlank().getPricePerPlank()) + logCost);
  90. getScript().getData().setPlanksMade(planksMade + plankAmount);
  91. getScript().getData().setMoneyMade(moneyMade + (plankAmount * getScript().getPlankPrice()));
  92. }
  93. }
  94. }
  95. }
  96. }
  97.  
  98. private boolean isFinished(int i) {
  99. long t = System.currentTimeMillis();
  100. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  101. if (isFinished()) {
  102. return true;
  103. }
  104. getScript().sleep(50, 150);
  105. }
  106. return false;
  107. }
  108.  
  109. private boolean isInterfaceOpen(int i) {
  110. long t = System.currentTimeMillis();
  111. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  112. RSInterface plankInterface = Interfaces.get(Constants.PLANK_INTERFACE);
  113. if (plankInterface != null) {
  114. return true;
  115. }
  116. getScript().sleep(50, 150);
  117. }
  118. return false;
  119. }
  120.  
  121. public boolean isFinished() {
  122. if(Inventory.getCount(Constants.GOLD) < getScript().getPlank().getPricePerPlank()) {
  123. return true;
  124. }
  125. if(Inventory.getCount(getScript().getPlank().getLogId()) <= 0) {
  126. return true;
  127. }
  128. return false;
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement