Advertisement
Guest User

Untitled

a guest
Jan 13th, 2015
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.53 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7.  
  8. import org.tribot.api.General;
  9. import org.tribot.api.Timing;
  10. import org.tribot.api2007.Banking;
  11. import org.tribot.api2007.Game;
  12. import org.tribot.api2007.GameTab;
  13. import org.tribot.api2007.GameTab.TABS;
  14. import org.tribot.api2007.Objects;
  15. import org.tribot.api2007.Skills.SKILLS;
  16. import org.tribot.api2007.Inventory;
  17. import org.tribot.api2007.Magic;
  18. import org.tribot.api2007.Player;
  19. import org.tribot.api2007.Skills;
  20. import org.tribot.api2007.Walking;
  21. import org.tribot.api2007.WebWalking;
  22. import org.tribot.api2007.types.RSItem;
  23. import org.tribot.api2007.types.RSObject;
  24. import org.tribot.script.Script;
  25. import org.tribot.script.interfaces.Arguments;
  26. import org.tribot.script.interfaces.Painting;
  27.  
  28. public class TrollSuperheater extends Script implements Painting, Arguments{
  29.  
  30. public static boolean running = false;
  31.  
  32.  
  33. //Script
  34. private State state;
  35. private Bar bar;
  36. private int actionsLoop = 0;
  37. private int lastAmountBarsMade = 0;
  38.  
  39. public static TrollSuperheaterGUI gui = new TrollSuperheaterGUI();
  40.  
  41. //GUI
  42. private String oreName;
  43. private int oreNeeded;
  44. private int coalNeeded;
  45. private int barsMade = 0;
  46. public static int natsToWithdraw;
  47. public static ArrayList<String> barArrayList = new ArrayList<String>();
  48. public static ArrayList<Integer> stoppingConditionList = new ArrayList<Integer>();
  49. public String args;
  50.  
  51. //Painting
  52. private final int START_LEVEL = Skills.getActualLevel(SKILLS.SMITHING);
  53. private final int START_XP = Skills.getXP(SKILLS.SMITHING);
  54. private final long START_TIME = System.currentTimeMillis();
  55. private final double VERSION = 1;
  56. private int currentLevel;
  57. private long currentXP;
  58.  
  59. @Override
  60. public void run() {
  61. initialiseScript();
  62. for(;actionsLoop<barArrayList.size();actionsLoop++)
  63. {
  64. bar = setBar(barArrayList.get(actionsLoop));
  65. int barsToMake = stoppingConditionList.get(actionsLoop);
  66. lastAmountBarsMade = barsMade;
  67. setVariables();
  68. while(barsMade - lastAmountBarsMade < barsToMake)
  69. {
  70. state = getState();
  71. executeAction();
  72. }
  73. }
  74. }
  75.  
  76. private void setVariables()
  77. {
  78. switch(bar)
  79. {
  80. case IRON:
  81. oreName = "Iron ore";
  82. oreNeeded = 27;
  83. coalNeeded = 0;
  84. break;
  85. case STEEL:
  86. oreName = "Iron ore";
  87. oreNeeded = 9;
  88. coalNeeded = 18;
  89. break;
  90. case SILVER:
  91. oreName = "Silver ore";
  92. oreNeeded = 27;
  93. coalNeeded = 0;
  94. break;
  95. case GOLD:
  96. oreName = "Gold ore";
  97. oreNeeded = 27;
  98. coalNeeded = 0;
  99. break;
  100. case MITHRIL:
  101. oreName = "Mithril ore";
  102. oreNeeded = 5;
  103. coalNeeded = 20;
  104. break;
  105. case ADAMANTITE:
  106. oreName = "Adamantite ore";
  107. oreNeeded = 3;
  108. coalNeeded = 18;
  109. break;
  110. case RUNITE:
  111. oreName = "Runite ore";
  112. oreNeeded = 3;
  113. coalNeeded = 18;
  114. break;
  115. }
  116. }
  117.  
  118. private void executeAction()
  119. {
  120. RSItem[] inventoryItems;
  121. long timeout;
  122. switch(state)
  123. {
  124. case WITHDRAW_NATURES:
  125. Banking.withdraw(natsToWithdraw, "Nature rune");
  126. timeout = System.currentTimeMillis();
  127. while(timeout + 3000 > System.currentTimeMillis()
  128. && Inventory.getCount("Nature rune") == 0)
  129. {
  130. sleep(50, 100);
  131. }
  132. break;
  133. case DEPOSIT_ALL_EXCEPT_NATURES:
  134. inventoryItems = Inventory.getAll();
  135. for(int i = 0;i<inventoryItems.length;i++)
  136. {
  137. if(inventoryItems[i].getDefinition().getName().contains("bar"))
  138. {
  139. barsMade+=1;
  140. }
  141. }
  142. Banking.depositAllExcept("Nature rune");
  143. timeout = System.currentTimeMillis();
  144. while(timeout + 3000 > System.currentTimeMillis()
  145. && Inventory.getAll().length > 1)
  146. {
  147. sleep(50, 100);
  148. }
  149. break;
  150. case DEPOSIT_ALL_EXCEPT_COAL_NATURES:
  151. inventoryItems = Inventory.getAll();
  152. for(int i = 0;i<inventoryItems.length;i++)
  153. {
  154. if(inventoryItems[i].getDefinition().getName().contains("bar"))
  155. {
  156. barsMade+=1;
  157. }
  158. }
  159. Banking.depositAllExcept("Nature rune", "Coal");
  160. timeout = System.currentTimeMillis();
  161. while(timeout + 3000 > System.currentTimeMillis()
  162. && Inventory.getAll().length > 1)
  163. {
  164. sleep(50, 100);
  165. }
  166. break;
  167. case WITHDRAW_ORE:
  168. Banking.withdraw(oreNeeded, oreName);
  169. timeout = System.currentTimeMillis();
  170. while(timeout + 3000 > System.currentTimeMillis()
  171. && Inventory.getCount(oreName) < oreNeeded)
  172. {
  173. sleep(5, 10);
  174. }
  175. break;
  176. case CLOSE_BANK:
  177. Banking.close();
  178. timeout = System.currentTimeMillis();
  179. while(timeout + 3000 > System.currentTimeMillis()
  180. && Banking.isBankScreenOpen())
  181. {
  182. sleep(50, 100);
  183. }
  184. break;
  185. case OPEN_BANK:
  186. Banking.openBank();
  187. timeout = System.currentTimeMillis();
  188. while(timeout + 3000 > System.currentTimeMillis()
  189. && !Banking.isBankScreenOpen())
  190. {
  191. sleep(50, 100);
  192. }
  193. break;
  194. case WITHDRAW_COAL:
  195. Banking.withdraw(0, "Coal");
  196. timeout = System.currentTimeMillis();
  197. while(timeout + 3000 > System.currentTimeMillis()
  198. && !Inventory.isFull())
  199. {
  200. sleep(5, 10);
  201. }
  202. break;
  203. case CLICK_SUPERHEAT:
  204. clickSuperheat();
  205. break;
  206. case SLEEP:
  207. sleep(20, 30);
  208. break;
  209. case CLICK_ORE:
  210. TrollUtil.clickInventoryItem(oreName, "Cast Superheat Item -> " + oreName);
  211. timeout = System.currentTimeMillis();
  212. while(timeout + 3000 > System.currentTimeMillis()
  213. && GameTab.getOpen() == TABS.INVENTORY)
  214. {
  215. sleep(50, 100);
  216. }
  217. break;
  218. case CLICK_MAGIC_TAB:
  219. GameTab.open(TABS.MAGIC);
  220. timeout = System.currentTimeMillis();
  221. while(timeout + 3000 > System.currentTimeMillis()
  222. && GameTab.getOpen() != TABS.MAGIC)
  223. {
  224. sleep(50, 100);
  225. }
  226. break;
  227. case WALK_TO_BANK:
  228. WebWalking.walkToBank();
  229. while(Player.isMoving())
  230. {
  231. sleep(50, 100);
  232. }
  233. }
  234. }
  235.  
  236. enum State
  237. {
  238. WITHDRAW_NATURES,
  239. DEPOSIT_ALL_EXCEPT_NATURES,
  240. DEPOSIT_ALL_EXCEPT_COAL_NATURES,
  241. WITHDRAW_ORE,
  242. CLOSE_BANK,
  243. OPEN_BANK,
  244. WITHDRAW_COAL,
  245. CLICK_SUPERHEAT,
  246. SLEEP,
  247. CLICK_ORE,
  248. CLICK_MAGIC_TAB,
  249. WALK_TO_BANK
  250. }
  251.  
  252. private State getState()
  253. {
  254. if(isInBank())
  255. {
  256. if(Banking.isBankScreenOpen())
  257. {
  258. if(Inventory.getCount("Nature rune") == 0)
  259. {
  260. if(Inventory.isFull())
  261. {
  262. return State.DEPOSIT_ALL_EXCEPT_NATURES;
  263. }
  264. else
  265. {
  266. return State.WITHDRAW_NATURES;
  267. }
  268. }
  269. else
  270. {
  271. if(Inventory.getCount(oreName) == 0)
  272. {
  273. if(Inventory.getAll().length + oreNeeded > 28)
  274. {
  275. return State.DEPOSIT_ALL_EXCEPT_NATURES;
  276. }
  277. else
  278. {
  279. if(Inventory.getAll().length != Inventory.getCount("Coal") + 1)
  280. {
  281. println(Inventory.getCount("Coal") + Inventory.getCount("Nature rune"));
  282. return State.DEPOSIT_ALL_EXCEPT_COAL_NATURES;
  283. }
  284. else
  285. {
  286. return State.WITHDRAW_ORE;
  287. }
  288. }
  289. }
  290. else
  291. {
  292. if(Inventory.getCount("Coal") >= coalNeeded)
  293. {
  294. return State.CLOSE_BANK;
  295. }
  296. else
  297. {
  298. if(Inventory.getAll().length + coalNeeded > 28)
  299. {
  300. return State.DEPOSIT_ALL_EXCEPT_NATURES;
  301. }
  302. else
  303. {
  304. return State.WITHDRAW_COAL;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. else
  311. {
  312. if(Inventory.getCount(oreName) == 0 || (Inventory.getCount("Coal") < coalNeeded/oreNeeded && coalNeeded > 0) || Inventory.getCount("Nature rune") == 0)
  313. {
  314. return State.OPEN_BANK;
  315. }
  316. else
  317. {
  318. if(GameTab.getOpen() == TABS.MAGIC)
  319. {
  320. return State.CLICK_SUPERHEAT;
  321. }
  322. else
  323. {
  324. if(GameTab.getOpen() == TABS.INVENTORY && Game.getUptext().contains("Cast Superheat Item"))
  325. {
  326. if(GameTab.getOpen() == TABS.INVENTORY)
  327. {
  328. return State.CLICK_ORE;
  329. }
  330. else
  331. {
  332. return State.SLEEP;
  333. }
  334. }
  335. else
  336. {
  337. return State.CLICK_MAGIC_TAB;
  338. }
  339. }
  340. }
  341. }
  342. }
  343. else
  344. {
  345. return State.WALK_TO_BANK;
  346. }
  347. }
  348.  
  349. private void initialiseScript()
  350. {
  351. General.useAntiBanCompliance(true);
  352. if(args.equals(""))
  353. {
  354. gui.setVisible(true);
  355. while(!running)
  356. {
  357. sleep(20, 50);
  358. }
  359. }
  360. else
  361. {
  362. String[] splitArgs = args.split(",", -1);
  363. println(splitArgs);
  364. natsToWithdraw = Integer.parseInt(splitArgs[0]);
  365. for(int i = 1;i<splitArgs.length;i=i+2)
  366. {
  367. barArrayList.add(splitArgs[i]);
  368. }
  369. for(int j = 2;j<splitArgs.length;j=j+2)
  370. {
  371. stoppingConditionList.add(Integer.parseInt(splitArgs[j]));
  372. }
  373. }
  374.  
  375. }
  376.  
  377. enum Bar {
  378. BRONZE,
  379. IRON,
  380. STEEL,
  381. MITHRIL,
  382. ADAMANTITE,
  383. RUNITE,
  384. SILVER,
  385. GOLD;
  386. }
  387.  
  388. private Bar setBar(String string)
  389. {
  390. switch(string)
  391. {
  392. case "Bronze Bar":
  393. println("This bot does not support bronze bars");
  394. return Bar.BRONZE;
  395. case "Iron Bar":
  396. return Bar.IRON;
  397. case "Steel Bar":
  398. return Bar.STEEL;
  399. case "Mithril Bar":
  400. return Bar.MITHRIL;
  401. case "Adamantite Bar":
  402. return Bar.ADAMANTITE;
  403. case "Runite Bar":
  404. return Bar.RUNITE;
  405. }
  406. return Bar.RUNITE;
  407. }
  408.  
  409. private void clickSuperheat()
  410. {
  411. if(Magic.isSpellSelected())
  412. {
  413. Walking.clickTileMS(Player.getPosition(), 1);
  414. }
  415. else
  416. {
  417. Magic.selectSpell("Superheat Item");
  418. long timeout = System.currentTimeMillis();
  419. while(timeout + 3000 > System.currentTimeMillis()
  420. && GameTab.getOpen() == TABS.MAGIC)
  421. {
  422. sleep(50, 100);
  423. }
  424. }
  425. }
  426.  
  427. private boolean isAnimating()
  428. {
  429. long timeout = System.currentTimeMillis();
  430. while(timeout + 1000 > System.currentTimeMillis()
  431. && Player.getAnimation() == -1)
  432. {
  433. sleep(50, 100);
  434. }
  435. return Player.getAnimation() != -1;
  436. }
  437.  
  438. private boolean isInBank()
  439. {
  440. RSObject[] objects = Objects.getAll(10);
  441. if(objects.length > 0 && objects != null)
  442. {
  443. for(RSObject currObject:objects)
  444. {
  445. String name = currObject.getDefinition().getName().toLowerCase();
  446. if(name.contains("bank"))
  447. {
  448. return true;
  449. }
  450. }
  451. }
  452. return false;
  453. }
  454.  
  455. @Override
  456. public void onPaint(Graphics g) {
  457. currentXP = Skills.getXP(SKILLS.SMITHING);
  458. currentLevel = Skills.getActualLevel(SKILLS.SMITHING);
  459. long timeRan = System.currentTimeMillis() - START_TIME;
  460. long xpGained = currentXP - START_XP;
  461. double multiplier = timeRan / 3600000D;
  462. int xpPerHour = (int) (xpGained / multiplier);
  463. int barsPerHour = (int) (barsMade / multiplier);
  464. int levelsGained = currentLevel - START_LEVEL;
  465. g.setColor(Color.WHITE);
  466. g.drawString("ITryNotToTroll's Smither", 10, 70);
  467. g.drawString("Bar Being Smelted: " + bar, 10, 90);
  468. g.drawString("Running for: " + Timing.msToString(timeRan), 10, 110);
  469. g.drawString("Levels Gained: " + levelsGained, 10, 130);
  470. g.drawString("Xp gained: " + xpGained + " (" + xpPerHour + "/h)", 10,
  471. 150);
  472. g.drawString("Bars made: " + barsMade + " (" + barsPerHour + "/h)",
  473. 10, 170);
  474. g.drawString("State: " + state, 10, 190);
  475.  
  476. g.drawString("Actions left", 10, 210);
  477. g.drawString(barArrayList.get(0) + ", " + (stoppingConditionList.get(0) - (barsMade - lastAmountBarsMade)), 10, 230);
  478. for(int i = actionsLoop + 1;i<barArrayList.size();i++)
  479. {
  480. g.drawString(barArrayList.get(i) + ", " + stoppingConditionList.get(i), 10, 250 + (20* (i-actionsLoop)) );
  481. }
  482.  
  483. }
  484.  
  485. @Override
  486. public void passArguments(HashMap<String, String> arguments) {
  487. args = arguments.get("custom_input");
  488. if(arguments.get("custom_input") == null)
  489. {
  490. args = arguments.get("client_starter");
  491. if(arguments.get("client_starter") == null)
  492. {
  493. args = arguments.get("autostart");
  494. }
  495. }
  496. }
  497.  
  498. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement