NissanNut

Superheater.java 0.2

Nov 27th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.82 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Graphics2D;
  4. import java.awt.Point;
  5. import java.awt.Rectangle;
  6. import java.util.ArrayList;
  7.  
  8. import org.veloxbot.api.ActiveScript;
  9. import org.veloxbot.api.Manifest;
  10. import org.veloxbot.api.Validatable;
  11. import org.veloxbot.api.methods.Bank;
  12. import org.veloxbot.api.methods.Bank.Slot;
  13. import org.veloxbot.api.methods.Game;
  14. import org.veloxbot.api.methods.Inventory;
  15. import org.veloxbot.api.methods.Keyboard;
  16. import org.veloxbot.api.methods.Log;
  17. import org.veloxbot.api.methods.Magic;
  18. import org.veloxbot.api.methods.Menu;
  19. import org.veloxbot.api.methods.Mouse;
  20. import org.veloxbot.api.methods.OCR;
  21. import org.veloxbot.api.utils.Random;
  22. import org.veloxbot.api.wrappers.DTM;
  23.  
  24. @Manifest(authors = { "Nissan Nut", "Velox" },
  25. name = "Nissan's Superheater",
  26. version = 0.2,
  27. description= "Basic Superheater.")
  28.  
  29. /**
  30. * Simple Superheater Script
  31. * 11/10/2012 Dev Started
  32. * @author Tanner (Nissan Nut)
  33. */
  34.  
  35. public class Superheater extends ActiveScript{
  36.  
  37. private ArrayList<Strategy> tasks = new ArrayList<Strategy>();
  38. private SuperheaterUI UI = new SuperheaterUI();
  39. private boolean antiban = true;
  40. private int widthdraw = 0, angle, mouseSpeed, heats = 0, startExp, exp;
  41. private long START_TIME;
  42. private String status;
  43.  
  44. private DTM ore, ore2, bar;
  45. private final DTM NATURE_RUNE = DTM.fromString("17_123_20_5/103_99_98_-11_-5_5/74_71_71_-2_10_5/147_140_140_9_-3_5"),
  46. COAL = DTM.fromString("38_38_29_5/92_74_52_-12_2_5/92_74_52_-3_8_5/38_38_29_8_5_5/105_84_59_10_-5_5"),
  47. IRON_ORE = DTM.fromString("54_32_24_5/86_69_48_-13_3_5/94_76_53_-3_10_5/54_32_24_7_6_5/103_82_57_10_-4_5"),
  48. MITHRIL_ORE = DTM.fromString("54_55_81_5/100_81_57_-11_3_5/90_72_51_-5_10_5/46_46_69_7_5_5/109_87_61_11_-6_5"),
  49. ADAMANTITE_ORE = DTM.fromString("64_74_64_5/98_79_56_-11_2_5/92_74_52_-5_11_5/62_71_62_8_6_5/109_87_61_11_-5_5"),
  50. RUNITE_ORE = DTM.fromString("71_85_92_5/87_70_49_-15_3_5/98_79_56_-5_10_5/55_66_71_7_5_5/105_84_59_9_-6_5"),
  51. GOLD_ORE = DTM.fromString("190_151_28_5/98_79_56_-11_2_5/87_70_49_-7_10_5/172_137_25_7_6_5/100_81_57_11_-4_5"),
  52. SILVER_ORE = DTM.fromString("126_127_132_5/95_76_52_-11_4_5/91_72_50_-3_11_5/103_82_57_12_-4_1"),
  53. COPPER_ORE = DTM.fromString("189_108_57_5/97_77_54_-10_1_5/91_72_50_-4_7_5/105_84_58_10_-6_5"),
  54. TIN_ORE = DTM.fromString("105_101_101_5/82_65_45_-14_4_5/97_77_54_-3_10_5/99_79_55_12_-4_5"),
  55. BRONZE_BAR = DTM.fromString("79_59_35_5/59_45_26_-8_-2_5/33_25_14_-13_5_5/81_61_36_-1_6_5"),
  56. IRON_BAR = DTM.fromString("83_80_80_5/39_38_38_-14_5_5/26_25_25_-14_11_5/86_82_82_-1_7_5"),
  57. STEEL_BAR = DTM.fromString("128_123_123_5/99_95_94_-8_1_5/39_38_38_-15_11_5/132_127_126_-1_8_5"),
  58. MITHRIL_BAR = DTM.fromString("66_66_99_5/49_50_74_-8_-3_5/28_29_43_-10_5_5/67_68_101_0_4_5"),
  59. ADAMANT_BAR = DTM.fromString("72_83_72_5/53_62_54_-7_1_5/28_33_29_-13_6_5/72_83_72_-1_7_5"),
  60. RUNE_BAR = DTM.fromString("81_97_105_5/62_75_81_-7_1_5/37_45_48_-11_7_5/82_99_107_0_6_5"),
  61. SILVER_BAR = DTM.fromString("165_165_172_5/128_128_134_-9_-1_5/75_75_79_-15_3_5/168_168_176_-1_6_5"),
  62. GOLD_BAR = DTM.fromString("207_165_29_5/159_126_22_-8_-2_5/90_72_13_-11_4_5/212_169_30_0_6_5");
  63.  
  64. @Override
  65. public boolean onStart(){
  66. Log.log(this.manifest.name() + " v" + this.manifest.version() + " by " + this.manifest.authors()[0] + " + " + this.manifest.authors()[1]);
  67. status = "Start-up";
  68. UI.setVisible(true);
  69.  
  70. while (UI.isVisible())
  71. sleep(10);
  72.  
  73. switch (UI.list.getSelectedIndex()){
  74. case 0:
  75. ore = TIN_ORE;
  76. ore2 = COPPER_ORE;
  77. bar = BRONZE_BAR;
  78. widthdraw = 13;
  79. break;
  80. case 1:
  81. ore = IRON_ORE;
  82. bar = IRON_BAR;
  83. break;
  84. case 2:
  85. ore = IRON_ORE;
  86. ore2 = COAL;
  87. bar = STEEL_BAR;
  88. widthdraw = 9;
  89. break;
  90. case 3:
  91. ore = SILVER_ORE;
  92. bar = SILVER_BAR;
  93. break;
  94. case 4:
  95. ore = GOLD_ORE;
  96. bar = GOLD_BAR;
  97. break;
  98. case 5:
  99. ore = MITHRIL_ORE;
  100. ore2 = COAL;
  101. bar = MITHRIL_BAR;
  102. widthdraw = 6;
  103. break;
  104. case 6:
  105. ore = ADAMANTITE_ORE;
  106. ore2 = COAL;
  107. bar = ADAMANT_BAR;
  108. widthdraw = 5;
  109. break;
  110. case 7:
  111. ore = RUNITE_ORE;
  112. ore2 = COAL;
  113. bar = RUNE_BAR;
  114. widthdraw = 4;
  115. }
  116.  
  117. if (UI.boxNorth.isSelected())
  118. angle = 0;
  119. else if (UI.boxEast.isSelected())
  120. angle = 90;
  121. else if (UI.boxSouth.isSelected())
  122. angle = 180;
  123. else if (UI.boxWest.isSelected())
  124. angle = 270;
  125.  
  126. mouseSpeed = UI.slider.getValue();
  127.  
  128. tasks.add(new Banking());
  129. tasks.add(new Superheat());
  130.  
  131. START_TIME = System.currentTimeMillis();
  132. return UI.start;
  133. }
  134.  
  135. @Override
  136. public long loop() {
  137. if (antiban)
  138. Mouse.setMultiplier(Random.nextDouble(mouseSpeed - 1, mouseSpeed + 1)*.1);
  139.  
  140. for(Strategy s : tasks){
  141. if (s.validate()){
  142. s.run();
  143. Log.log(s.getStatus());
  144. }
  145. }
  146.  
  147. return 15;
  148. }
  149.  
  150.  
  151.  
  152. @Override
  153. public void onRepaint(Graphics G){
  154. Graphics2D g = (Graphics2D) G;
  155.  
  156. g.setColor(Color.BLACK);
  157. g.fillRect(0, 0, 765, 50);
  158.  
  159. g.setColor(Color.WHITE);
  160. g.drawString("Nissan's Superheater... Runtime: " + toString(getRuntime()) + "... Approx heats: " + heats, 15, 20);
  161. g.drawString("Please post and describe all bugs on the forums, script is in testing stages, all feedback is appreciated.", 15, 40);
  162.  
  163.  
  164.  
  165. }
  166.  
  167. /**
  168. * Credits to Velox
  169. * @param angle
  170. * @param distance
  171. * @return the point
  172. */
  173. public static Point getPointNearPlayer(final int angle, final int distance) {
  174. final double rads = Math.toRadians(angle + 90 - Game.getCompassAngle());
  175. return new Point((int) (Game.VIEWPORT_CENTER.x - distance * Math.cos(rads)), (int) (Game.VIEWPORT_CENTER.y - distance * Math.sin(rads)));
  176. }
  177.  
  178.  
  179. private class Banking extends Strategy{
  180. final Rectangle BOUNDS = new Rectangle(23, 135, 472, 208);
  181.  
  182. public void run(){
  183.  
  184. for (int i = 0; i < 5 && !Bank.isOpen(); i++){
  185. i++;
  186. final Point LOCATION = getPointNearPlayer(angle + Random.nextInt(-5, 5), 30 + Random.nextInt(-2, 2));
  187. Mouse.click(LOCATION, false);
  188. sleep(750, 1500);
  189. Menu.clickIndex(0);
  190. sleep(1500, 2000);
  191. }
  192.  
  193. deposit(bar);
  194. sleep(500, 800);
  195.  
  196. withdrawTemp(ore, widthdraw);
  197.  
  198. if (ore2 != null){
  199. withdrawTemp(ore2, 0);
  200. sleep(1000, 1500);
  201. }
  202.  
  203. if (new Failsafe().validate()){
  204. new Failsafe().run();
  205. }
  206.  
  207. Bank.close();
  208. }
  209.  
  210. private void deposit(DTM bar) {
  211. Inventory.Slot s = Inventory.getSlotWith(bar);
  212. if (s != null){
  213. Mouse.click(new Point((int) s.getBounds().getCenterX(), (int) s.getBounds().getCenterY()), false);
  214. sleep(1000, 1500);
  215. if (Menu.isOpen()){
  216. Menu.clickIndex(5);
  217. }
  218. }
  219.  
  220. }
  221.  
  222. @Override
  223. public boolean validate() {
  224. if (Game.Tab.INVENTORY.isOpen())
  225. return Inventory.getCount(bar) >= widthdraw || Inventory.getCount() == 1;
  226. return false;
  227. }
  228.  
  229. @Override
  230. public String getStatus() {
  231. return "Banking";
  232. }
  233.  
  234. public Bank.Slot[] getSlotsWithDTM(final DTM d){
  235. ArrayList<Bank.Slot> slots = new ArrayList<Bank.Slot>();
  236. for (Point p : d.getAll(BOUNDS)){
  237. for (Bank.Slot s : Bank.Slot.values()){
  238. if (s.getBounds().contains(p)){
  239. slots.add(s);
  240. }
  241. }
  242. }
  243. return (Slot[]) slots.toArray();
  244.  
  245. }
  246.  
  247. public Bank.Slot getSlotWithDTM(final DTM d){
  248. for (Point p : d.getAll(BOUNDS)){
  249. for (Bank.Slot s : Bank.Slot.values()){
  250. if (s.getBounds().contains(p)){
  251. return s;
  252. }
  253. }
  254. }
  255. return null;
  256.  
  257. }
  258.  
  259. public void withdrawTemp(final DTM d, final Integer num){
  260. Slot s = getSlotWithDTM(d);
  261.  
  262. if (s != null){
  263. Mouse.click(s.getBounds(), false);
  264. sleep(1250, 1750);
  265. }
  266.  
  267. if (num == 0){
  268. Menu.clickIndex(Random.nextInt(5, 6));
  269. } else{
  270. Menu.clickIndex(4);
  271. sleep(1250, 1750);
  272. Keyboard.sendString(num.toString());
  273. }
  274.  
  275. }
  276.  
  277. public void withdraw(final DTM d, final Integer num){
  278. Slot s = getSlotWithDTM(d);
  279.  
  280. if (s != null){
  281. Mouse.click(s.getBounds(), false);
  282. sleep(1250, 1750);
  283. }
  284.  
  285. if (num == 0){
  286. Menu.interact("Withdraw-All");
  287. } else{
  288. if (!Menu.interact("Withdraw-" + num)){
  289. Menu.interact("Withdraw-X", true);
  290. sleep(1250, 1750);
  291. Keyboard.sendString(num.toString());
  292. }
  293. }
  294.  
  295. }
  296.  
  297. private class Failsafe extends Strategy{
  298.  
  299. @Override
  300. public boolean validate() {
  301. return !((Inventory.getCount(ore) == widthdraw || widthdraw == 0) && Inventory.isFull());
  302. }
  303.  
  304. @Override
  305. public void run() {
  306. deposit(ore);
  307. if (ore2 != null)
  308. deposit(ore2);
  309. }
  310.  
  311. @Override
  312. public String getStatus() {
  313. return "Checking Inventory";
  314. }
  315.  
  316. }
  317.  
  318. }
  319.  
  320. private class Superheat extends Strategy{
  321. private final DTM SUPERHEAT_ITEM = DTM.fromString("232_117_45_5/250_180_71_-7_13_5/236_125_119_3_13_5");
  322. private final DTM MAGIC = DTM.fromString("26_54_97_3/19_19_19_-1_-13_3/10_24_60_11_-14_3/46_59_75_17_-1_3");
  323. private final DTM MAGIC_SELECTED = DTM.fromString("24_50_121_3/50_50_50_-3_-13_3/50_50_50_17_-12_3/54_26_85_16_0_3");
  324. private final DTM SKILLS = DTM.fromString("180_144_42_3/201_151_42_0_19_3/32_101_50_13_17_3/99_114_132_13_2_3/18_18_18_7_6_3");
  325. private final DTM SKILLS_SELECTED = DTM.fromString("201_151_42_3/201_151_42_0_18_3/32_101_50_14_15_3/101_112_126_14_0_3/20_184_253_23_-8_3/69_69_69_-8_21_3");
  326. private String status = "Superheating";
  327. private ArrayList<Strategy> tasks = new ArrayList<Strategy>();
  328.  
  329.  
  330. public void run(){
  331. this.tasks.add(new Heat());
  332. this.tasks.add(new ClickOre());
  333.  
  334. for(Strategy s : this.tasks){
  335. if (s.validate()){
  336. s.run();
  337. status = s.getStatus();
  338. }
  339. }
  340. }
  341.  
  342. @Override
  343. public boolean validate() {
  344. if (Game.Tab.INVENTORY.isOpen())
  345. return Inventory.getCount(bar) <= widthdraw;
  346. return true;
  347. }
  348.  
  349. @Override
  350. public String getStatus() {
  351. return status;
  352. }
  353.  
  354. private class ClickOre extends Strategy{
  355.  
  356. @Override
  357. public boolean validate() {
  358. return Game.Tab.INVENTORY.isOpen();
  359. }
  360.  
  361. @Override
  362. public void run() {
  363. String s = OCR.getUptext();
  364. if (s.contains("Cast") || s.contains("Super") || s.contains("Item")){
  365. Inventory.Slot s1 = Inventory.getSlotWith(ore);
  366. if (s1 != null){
  367. s1.click(true);
  368. heats++;
  369. sleep(500, 1000);
  370. } else if (Inventory.getCount(bar) >= widthdraw){
  371. Mouse.click(Magic.BOUNDS, true);
  372. new Banking().run();
  373. }
  374.  
  375. } else {
  376. Game.Tab.MAGIC.open(false);
  377. sleep(250, 750);
  378. }
  379. }
  380.  
  381. @Override
  382. public String getStatus() {
  383. return "Clicked Superheat";
  384. }
  385.  
  386. }
  387.  
  388. private class Heat extends Strategy{
  389.  
  390. @Override
  391. public boolean validate() {
  392. return Game.Tab.MAGIC.isOpen();
  393. }
  394.  
  395. @Override
  396. public void run() {
  397. Point p = SUPERHEAT_ITEM.getFirst(Magic.BOUNDS);
  398. if (p != null){
  399. Mouse.click(p, true);
  400. }else{
  401. Point p3 = MAGIC.getFirst(Magic.BOUNDS);
  402. if (p3 != null){
  403. Mouse.click(p3, true);
  404. sleep(250, 500);
  405. }
  406. Point p4 = SKILLS.getFirst(Magic.BOUNDS);
  407. if (p4!= null)
  408. Mouse.click(p4, true);
  409. }
  410. sleep(250, 750);
  411. }
  412.  
  413. @Override
  414. public String getStatus() {
  415. return "Clicking Superheat";
  416. }
  417.  
  418. }
  419.  
  420. }
  421.  
  422. abstract class Strategy implements Validatable{
  423. public Strategy() {}
  424.  
  425. public abstract void run();
  426. public abstract String getStatus();
  427. }
  428.  
  429. private Long getRuntime(){
  430. return System.currentTimeMillis() - START_TIME;
  431. }
  432.  
  433. /**
  434. * Converts milliseconds to readable time in a string.
  435. * @param ms The time in milliseconds.
  436. * @return the time as a string <tt>0:0:0</tt>
  437. */
  438. public static String toString(final Long ms){
  439. long s = ms/1000;
  440. long sec = s % 60;
  441. long min = (s % 3600) / 60;
  442. long hrs = s / 3600;
  443. return hrs + ":" + min + ":" + sec;
  444. }
  445.  
  446. }
Advertisement
Add Comment
Please, Sign In to add comment