Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.46 KB | None | 0 0
  1. import com.rsbuddy.event.events.MessageEvent;
  2. import com.rsbuddy.event.listeners.MessageListener;
  3. import com.rsbuddy.event.listeners.PaintListener;
  4. import com.rsbuddy.script.ActiveScript;
  5. import com.rsbuddy.script.Manifest;
  6. import com.rsbuddy.script.methods.*;
  7. import com.rsbuddy.script.util.Random;
  8. import com.rsbuddy.script.util.Timer;
  9. import com.rsbuddy.script.wrappers.Item;
  10. import org.rsbuddy.widgets.Bank;
  11. import org.rsbuddy.net.GeItem.*;
  12. import org.rsbuddy.tabs.Inventory;
  13. import java.awt.*;
  14.  
  15. @Manifest(name = "EvilChocolate", version = 1.0, authors = "Eviltaco", description = "Crushes Chocolate Bars!")
  16. public class CrushingChampion extends ActiveScript implements PaintListener, MessageListener {
  17.  
  18. boolean developerMode = true;
  19. int failed = 0;
  20. private String status;
  21. private long startTime;
  22.  
  23. private int barsCrushed;
  24. private GrandExchange.Item geBar;
  25. private GrandExchange.Item geDust;
  26.  
  27. private static final int crushAnimation = 364;
  28.  
  29. private static final int knife = 946;
  30. private static final int chocolateBar = 1973;
  31. private static final int chocolateDust = 1975;
  32.  
  33. private static final int parentID = 905;
  34. private static final int childID = 14;
  35.  
  36. private int barPrice;
  37. private int dustPrice;
  38. private int totalProfit;
  39.  
  40. private enum ScriptState {
  41. STARTUP, OPENING_BANK, DEPOSITING_EXTRA, WITHDRAWING_SCALES,
  42. CLOSING_BANK, USING_ITEMS, CLICKING_WIDGET, CRUSHING_SCALES,
  43. STOPPING_SCRIPT, UNKNOWN
  44. }
  45.  
  46. private int random(int min, int max) {
  47. return Random.nextInt(min, max);
  48. }
  49.  
  50. private void dLog(String log) {
  51. if (developerMode) {
  52. log(log);
  53. }
  54. }
  55.  
  56. @Override
  57. public boolean onStart() {
  58. status = "Getting Chocolate Bar prices";
  59. geBar = GrandExchange.lookup(chocolateBar);
  60. barPrice = geBar.getGuidePrice();
  61.  
  62. status = "Getting Chocolate Dust prices";
  63. geDust = GrandExchange.lookup(chocolateDust);
  64. dustPrice = geDust.getGuidePrice();
  65.  
  66. totalProfit = dustPrice - barPrice;
  67. log("Assumed profit per crush: " + totalProfit);
  68.  
  69. startTime = System.currentTimeMillis();
  70. return super.onStart();
  71. }
  72.  
  73. public int profitPerHour() {
  74. return (int) ((totalProfit * barsCrushed) * 3600000D / (System.currentTimeMillis() - startTime));
  75. }
  76.  
  77. public boolean inventoryContainsExtra() {
  78. return (Inventory.getCountExcept(knife, chocolateBar) > 1);
  79. }
  80.  
  81. private boolean playerIsCrushing() {
  82. if (Players.getLocal().getAnimation() == crushAnimation) {
  83. return true;
  84. } else {
  85. return false;
  86. }
  87. }
  88.  
  89. private boolean crushing() {
  90. Timer t = new Timer(random(700, 800));
  91. while (t.isRunning() && Inventory.contains(chocolateBar)) {
  92. antiBan();
  93. if (Players.getLocal().getAnimation() == crushAnimation &&
  94. Inventory.contains(chocolateBar)) {
  95. t.reset();
  96. continue;
  97. }
  98. sleep(500, 700);
  99. antiBan();
  100. if (Players.getLocal().getAnimation() == crushAnimation &&
  101. Inventory.contains(chocolateBar)) {
  102. t.reset();
  103. continue;
  104. } else {
  105. continue;
  106. }
  107. }
  108. return false;
  109. }
  110.  
  111. private void antiBan() {
  112. int randomNumber = random(1, 2000);
  113. //log(randomNumber);
  114. if (randomNumber >= 0 && randomNumber <= 500) {
  115. return;
  116. } else if (randomNumber > 500 && randomNumber <= 502) {
  117. if (!status.contains("AB")) {
  118. status = status + "[AB]";
  119. }
  120. dLog(String.valueOf(randomNumber));
  121. Camera.setPitch(random(1, 101));
  122. Camera.setCompassAngle(random(1, 360));
  123. return;
  124. } else if (randomNumber > 503 && randomNumber <= 505) {
  125. if (!status.contains("AB")) {
  126. status = status + "[AB]";
  127. }
  128. dLog(String.valueOf(randomNumber));
  129. dLog(String.valueOf(Mouse.getLocation()));
  130. Mouse.moveSlightly();
  131. dLog(String.valueOf(Mouse.getLocation()));
  132. return;
  133. } else if (randomNumber == 999 && random(1, 5) == 2 &&
  134. random(1, 5) == 2) {
  135. if (!status.contains("AB")) {
  136. status = status + "[AB]";
  137. }
  138. dLog(String.valueOf(randomNumber));
  139. sleep(10000, 45000);
  140. return;
  141. }
  142. }
  143.  
  144. private ScriptState getScriptState() {
  145. if (playerIsCrushing() && Inventory.contains(chocolateBar)) {
  146. return ScriptState.CRUSHING_SCALES;
  147. } else if (!Inventory.isFull()) {
  148. if (Bank.isOpen()) {
  149. if (Bank.getItem(chocolateBar).getStackSize() == 0 ) {
  150. return ScriptState.STOPPING_SCRIPT;
  151. }
  152. if (inventoryContainsExtra()) {
  153. return ScriptState.DEPOSITING_EXTRA;
  154. } else if (Inventory.contains(chocolateBar)) {
  155. return ScriptState.CLOSING_BANK;
  156. } else if (!Inventory.contains(chocolateBar)) {
  157. return ScriptState.WITHDRAWING_SCALES;
  158. }
  159. } else if (!Bank.isOpen()) {
  160. if (!Inventory.contains(chocolateBar)) {
  161. return ScriptState.OPENING_BANK;
  162. } else if (Inventory.contains(chocolateBar) &&
  163. !Widgets.getComponent(parentID, childID).isValid()) {
  164. return ScriptState.USING_ITEMS;
  165. } else if (Inventory.contains(chocolateBar) &&
  166. Widgets.getComponent(parentID, childID).isValid()) {
  167. return ScriptState.CLICKING_WIDGET;
  168. }
  169. }
  170. } else if (Inventory.isFull()) {
  171. if (Bank.isOpen()) {
  172. if (inventoryContainsExtra()) {
  173. return ScriptState.DEPOSITING_EXTRA;
  174. } else if (Inventory.contains(chocolateBar)) {
  175. return ScriptState.CLOSING_BANK;
  176. } else if (!Inventory.contains(chocolateBar)) {
  177. return ScriptState.WITHDRAWING_SCALES;
  178. }
  179. }
  180. if (!Bank.isOpen()) {
  181. if (!inventoryContainsExtra()) {
  182. if (Widgets.getComponent(parentID, childID).isValid() &&
  183. Widgets.getComponent(parentID, childID).isVisible()) {
  184. return ScriptState.CLICKING_WIDGET;
  185. } else if (!Widgets.getComponent(parentID, childID).isValid() ||
  186. !Widgets.getComponent(parentID, childID).isVisible()) {
  187. return ScriptState.USING_ITEMS;
  188. }
  189. } else if (inventoryContainsExtra()) {
  190. return ScriptState.OPENING_BANK;
  191. }
  192. }
  193. }
  194. return ScriptState.UNKNOWN;
  195. }
  196.  
  197. public int loop() {
  198. switch (getScriptState()) {
  199. case STOPPING_SCRIPT:
  200. stop();
  201. return 0;
  202. case CRUSHING_SCALES:
  203. dLog("In CRUSHING_SCALES");
  204. status = "Crushing scales";
  205. while (crushing() && Inventory.contains(chocolateBar)) {
  206. antiBan();
  207. sleep(300, 500);
  208. }
  209. if (crushing()) {
  210. sleep(random(1000, 1500));
  211. }
  212. return 0;
  213. case USING_ITEMS:
  214. dLog("In USING_ITEMS");
  215. status = "Using Pestle with Scales";
  216. Item Knife = Inventory.getItem(knife);
  217. Item Bar = Inventory.getItem(chocolateBar);
  218. if (!Widgets.getComponent(parentID, childID).isValid() &&
  219. !Widgets.getComponent(parentID, childID).isVisible()) {
  220. if (Knife != null && Bar != null) {
  221. Inventory.useItem(Knife, Bar);
  222. }
  223. sleep(850, 950);
  224. }
  225. return 0;
  226. case CLICKING_WIDGET:
  227. dLog("In CLICKING_WIDGET");
  228. status = "Clicking 'Make All'";
  229. if (Widgets.getComponent(parentID, childID).isValid() &&
  230. Widgets.getComponent(parentID, childID).isVisible()) {
  231. Widgets.getComponent(parentID, childID).click();
  232. sleep(800, 1100);
  233. }
  234. return 0;
  235. case OPENING_BANK:
  236. status = "Opening bank";
  237. dLog("In OPENING_BANK");
  238. Bank.open();
  239. sleep(600, 800);
  240. while (Players.getLocal().isMoving()) {
  241. }
  242. return 0;
  243. case DEPOSITING_EXTRA:
  244. dLog("In DEPOSITING_EXTRA");
  245. status = "Depositing";
  246. if (inventoryContainsExtra() && Bank.isOpen()) {
  247. Bank.depositAllExcept(knife, chocolateBar);
  248. }
  249. return 0;
  250. case WITHDRAWING_SCALES:
  251. dLog("In WITHDRAWING_SCALES");
  252. status = "Withdrawing";
  253. if (Bank.isOpen()) {
  254. Bank.withdraw(chocolateBar, 0);
  255. }
  256. sleep(400, 600);
  257. return 0;
  258. case CLOSING_BANK:
  259. dLog("In CLOSING_BANK");
  260. status = "Closing bank";
  261. Bank.close();
  262. sleep(50, 80);
  263. return 0;
  264. default:
  265. failed++;
  266. if (failed >= 5) {
  267. log("Failed 5 times, stopping script");
  268. stop();
  269. }
  270. }
  271. return 0;
  272. }
  273.  
  274. public void messageReceived(MessageEvent messageEvent) {
  275. if (messageEvent.getMessage().contains("You grind down the")) {
  276. barsCrushed++;
  277. }
  278. }
  279.  
  280. //START: Code generated using Enfilade's Easel
  281. private final Color color1 = new Color(1, 1, 1, 110);
  282. private final Color color2 = new Color(0, 0, 0);
  283. private final Color color3 = new Color(1, 1, 1);
  284.  
  285. private final BasicStroke stroke1 = new BasicStroke(1);
  286.  
  287. private final Font font1 = new Font("Arial", 0, 11);
  288.  
  289. public void onRepaint(Graphics g1) {
  290. Graphics2D g = (Graphics2D) g1;
  291. g.setColor(color1);
  292. g.fillRect(350, 248, 165, 90);
  293. g.setColor(color2);
  294. g.setStroke(stroke1);
  295. g.drawRect(350, 248, 165, 90); //61
  296. g.setFont(font1);
  297. g.setColor(color3);
  298. g.drawString("EvilChocolate [v1.0]", 354, 260);
  299. g.drawString("Bars Crushed: " + barsCrushed + "(" +
  300. (profitPerHour() / totalProfit) + "/hour)", 354, 295);
  301. g.drawString("Assumed Profit: " + (barsCrushed * totalProfit) + "(" +
  302. profitPerHour() + "/hour)", 354, 310);
  303. g.drawString("Status: " + status, 354, 325);
  304. g.drawString("Time Running: " + Timer.format(startTime - System.currentTimeMillis()), 354, 280);
  305. }
  306.  
  307. //END: Code generated using Enfilade's Easel
  308. @Override
  309. public void onFinish() {
  310. Environment.saveScreenshot(true);
  311. super.onFinish();
  312. }
  313.  
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement