Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.61 KB | None | 0 0
  1. import org.rsbot.event.events.ServerMessageEvent;
  2. import org.rsbot.event.listeners.PaintListener;
  3. import org.rsbot.event.listeners.ServerMessageListener;
  4. import org.rsbot.script.Script;
  5. import org.rsbot.script.ScriptManifest;
  6. import org.rsbot.script.util.Timer;
  7. import org.rsbot.script.wrappers.RSComponent;
  8. import org.rsbot.script.wrappers.RSNPC;
  9. import org.rsbot.script.wrappers.RSObject;
  10. import org.rsbot.script.wrappers.RSTile;
  11.  
  12. import java.awt.*;
  13. import java.awt.event.*;
  14. import javax.swing.*;
  15.  
  16. @ScriptManifest(authors = {"zr0k5"}, keywords = "Money Making", name = "AlKharidTanner", version = 1.0,
  17. description = "Tans hides for money")
  18. public class AlKharidTanner extends Script implements PaintListener, ServerMessageListener {
  19.  
  20. private final double version = getClass().getAnnotation(
  21. ScriptManifest.class).version();
  22.  
  23. private final int[] HIDE_ID = { 1739,
  24. 1739, 1753, 1751, 1749, 1747 };
  25. private final int[] LEATHER_ID = { 1741,
  26. 1743, 1745, 2505, 2507, 2509 };
  27. private final int[] CHILD_ID = { 9,
  28. 10, 13, 14, 15, 16 };
  29.  
  30. private final RSTile[] TANNING_PATH = { new RSTile(3269, 3168),
  31. new RSTile(3277, 3175), new RSTile(3278, 3181),
  32. new RSTile(3281, 3191), new RSTile(3275, 3192) };
  33.  
  34. private final String[] NAMES = { "Cowhides",
  35. "Cowhides", "Green d'hides", "Blue d'hides",
  36. "Red d'hides", "Black d'hides" };
  37.  
  38. private final int BOOTH_ID = 35647;
  39. private final int TANNER_ID = 2824;
  40.  
  41. private RSTile lastStep = new RSTile(-1, -1);
  42.  
  43. private boolean noMoney;
  44.  
  45. private int index;
  46. private int profit;
  47. private int tanned;
  48.  
  49. private final Font font1 = new Font("Tahoma", Font.BOLD, 11);
  50. private final Font font2 = new Font("Tahoma", Font.PLAIN, 11);
  51. private final Color color1 = new Color(0, 0, 0, 180);
  52.  
  53. private long startTime;
  54. private long runTime;
  55.  
  56. private Timer cameraTimer = new Timer(random(90000, 230000));
  57. private Timer mouseTimer = new Timer(random(20000, 50000));
  58.  
  59. @Override
  60. public boolean onStart() {
  61. TannerGUI gui = new TannerGUI();
  62. gui.setVisible(true);
  63. while (!gui.isReady) {
  64. sleep(500);
  65. }
  66. gui.dispose();
  67. log.info("Loading prices...");
  68. profit = grandExchange.getMarketPrice(LEATHER_ID[index]) -
  69. grandExchange.getMarketPrice(HIDE_ID[index]);
  70. startTime = System.currentTimeMillis();
  71. return true;
  72. }
  73.  
  74. @Override
  75. public int loop() {
  76. if (!game.isLoggedIn()) {
  77. return random(800, 1200);
  78. }
  79. mouse.setSpeed(random(8, 11));
  80. if (noMoney) {
  81. log.info("No money left");
  82. stopScript(true);
  83. }
  84. antiban();
  85. if (inventory.contains(HIDE_ID[index])) {
  86. tan();
  87. } else {
  88. bank();
  89. }
  90. return random(100, 250);
  91. }
  92.  
  93. private void tan() {
  94. final RSComponent window = getTanningWindow();
  95. if (window != null) {
  96. final int count = inventory.getCount(HIDE_ID[index]);
  97. if (window.doAction("Tan All")) {
  98. waitForInventory(HIDE_ID[index], count, true);
  99. }
  100. } else {
  101. if (useTanner()) {
  102. for (int i = 0; i < 25; i++) {
  103. if (getMyPlayer().isMoving())
  104. i = 0;
  105. if (getTanningWindow() != null)
  106. break;
  107. sleep(100, 150);
  108. }
  109. }
  110. }
  111. }
  112.  
  113. private void bank() {
  114. if (bank.isOpen()) {
  115. final int count = inventory.getCount(HIDE_ID[index]);
  116. final int count2 = inventory.getCount(LEATHER_ID[index]);
  117. if (count2 > 0) {
  118. bank.deposit(LEATHER_ID[index], 0);
  119. waitForInventory(LEATHER_ID[index], count2, true);
  120. } else {
  121. if (bank.getCount(HIDE_ID[index]) < 1) {
  122. log.info("All hides tanned");
  123. stopScript(true);
  124. }
  125. bank.withdraw(HIDE_ID[index], 0);
  126. waitForInventory(HIDE_ID[index], count, false);
  127. }
  128. } else {
  129. if (useBooth()) {
  130. for (int i = 0; i < 25; i++) {
  131. if (getMyPlayer().isMoving())
  132. i = 0;
  133. if (bank.isOpen())
  134. break;
  135. sleep(100, 150);
  136. }
  137. }
  138. }
  139. }
  140.  
  141. private RSComponent getTanningWindow() {
  142. final RSComponent window = interfaces.getComponent(324, CHILD_ID[index]);
  143. if (window != null && window.isValid() && window.getArea().getX() > 0
  144. && window.getArea().getY() > 0 && window.getArea().width > 0 && window.getArea().height > 0)
  145. return window;
  146. return null;
  147. }
  148.  
  149. private boolean useBooth() {
  150. final RSObject booth = objects.getNearest(BOOTH_ID);
  151. if (booth != null && booth.isOnScreen()) {
  152. if (!getMyPlayer().isMoving())
  153. return booth.doAction("Use-quickly");
  154. } else {
  155. walkPath(walking.reversePath(TANNING_PATH));
  156. }
  157. return false;
  158. }
  159.  
  160. private boolean useTanner() {
  161. final RSNPC tanner = npcs.getNearest(TANNER_ID);
  162. if (tanner != null && tanner.isOnScreen()) {
  163. if (!getMyPlayer().isMoving())
  164. return tanner.doAction("Trade Ellis");
  165. } else {
  166. walkPath(TANNING_PATH);
  167. }
  168. return false;
  169. }
  170.  
  171. private void waitForInventory(final int id, final int count, final boolean less) {
  172. for (int i = 0; i < 25; i++) {
  173. final int thisCount = inventory.getCount(id);
  174. if ((less && thisCount < count) || (!less && thisCount > count))
  175. break;
  176. sleep(100, 150);
  177. }
  178. }
  179.  
  180.  
  181. private void walkPath(final RSTile[] path) {
  182. if (!walking.isRunEnabled() && walking.getEnergy() >= random(35, 50)) {
  183. walking.setRun(true);
  184. sleep(900, 1200);
  185. }
  186. if (!(getMyPlayer().isMoving() && lastStep.equals(path[path.length - 1]))) {
  187. final RSTile step = getNextTile(path);
  188. if (step != null) {
  189. if (!getMyPlayer().isMoving() || (step != null && !step.equals(lastStep))) {
  190. if (walking.walkTileMM(step, 2, 2)) {
  191. sleep(700, 900);
  192. lastStep = step;
  193. }
  194. }
  195. }
  196. }
  197. }
  198.  
  199. private RSTile getNextTile(final RSTile[] path) {
  200. for (int i = path.length - 1; i >= 0; i--) {
  201. if (calc.tileOnMap(path[i]))
  202. return path[i];
  203. }
  204. return null;
  205. }
  206.  
  207. private void antiban() {
  208. if (!mouseTimer.isRunning()) {
  209. if (random(0, 2) == 1) {
  210. mouse.moveSlightly();
  211. } else {
  212. mouse.moveRandomly(random(100, 350));
  213. }
  214. mouseTimer.setEndIn(random(20000, 50000));
  215. }
  216. if (!cameraTimer.isRunning()) {
  217. if (random(0, 10) < 9) {
  218. camera.setAngle(random(1, 360));
  219. }
  220. if (random(0, 6) == 1) {
  221. camera.setPitch(random(1, 100));
  222. }
  223. cameraTimer.setEndIn(random(90000, 230000));
  224. }
  225. }
  226.  
  227. @SuppressWarnings("serial")
  228. public class TannerGUI extends JFrame {
  229.  
  230. private boolean isReady;
  231.  
  232. public TannerGUI() {
  233. initComponents();
  234. }
  235.  
  236. private void button1ActionPerformed(ActionEvent e) {
  237. index = comboBox1.getSelectedIndex();
  238. isReady = true;
  239. }
  240.  
  241. private void initComponents() {
  242. comboBox1 = new JComboBox();
  243. button1 = new JButton();
  244.  
  245. setTitle("AlKharidTanner");
  246. setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  247. setResizable(false);
  248. setAlwaysOnTop(true);
  249. Container contentPane = getContentPane();
  250. contentPane.setLayout(null);
  251.  
  252. comboBox1.setModel(new DefaultComboBoxModel(new String[] {
  253. "Cowhide (soft)",
  254. "Cowhide (hard)",
  255. "Green dragonhide",
  256. "Blue dragonhide",
  257. "Red dragonhide",
  258. "Black dragonhide"
  259. }));
  260. contentPane.add(comboBox1);
  261. comboBox1.setBounds(10, 20, 170, 30);
  262.  
  263. button1.setText("Start");
  264. button1.addActionListener(new ActionListener() {
  265. @Override
  266. public void actionPerformed(ActionEvent e) {
  267. button1ActionPerformed(e);
  268. }
  269. });
  270. contentPane.add(button1);
  271. button1.setBounds(10, 65, 170, 25);
  272.  
  273. {
  274. Dimension preferredSize = new Dimension();
  275. for(int i = 0; i < contentPane.getComponentCount(); i++) {
  276. Rectangle bounds = contentPane.getComponent(i).getBounds();
  277. preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
  278. preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
  279. }
  280. Insets insets = contentPane.getInsets();
  281. preferredSize.width += insets.right;
  282. preferredSize.height += insets.bottom;
  283. contentPane.setMinimumSize(preferredSize);
  284. contentPane.setPreferredSize(preferredSize);
  285. }
  286. setSize(200, 125);
  287. setLocationRelativeTo(getOwner());
  288. }
  289. private JComboBox comboBox1;
  290. private JButton button1;
  291. }
  292.  
  293. @Override
  294. public void serverMessageRecieved(ServerMessageEvent e) {
  295. final String msg = e.getMessage();
  296. if (msg != null) {
  297. if (msg.startsWith("You haven't got enough")) {
  298. noMoney = true;
  299. } else if (msg.startsWith("The tanner tans")) {
  300. tanned += Integer.parseInt(msg.split(" ")[3]);
  301. }
  302. }
  303. }
  304.  
  305. private String formatTime(final long time) {
  306. final int sec = (int) (time / 1000), h = sec / 3600, m = sec / 60 % 60, s = sec % 60;
  307. return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":"
  308. + (s < 10 ? "0" + s : s);
  309. }
  310.  
  311. @Override
  312. public void onRepaint(Graphics g1) {
  313. final Graphics2D g2 = (Graphics2D) g1;
  314. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
  315. RenderingHints.VALUE_ANTIALIAS_ON);
  316. g2.setColor(color1);
  317. g2.fillRect(350, 5, 160, 115);
  318. g2.setColor(Color.WHITE);
  319. g2.setFont(font1);
  320. g2.drawString("AlKharidTanner v." + version, 355, 20);
  321. g2.setFont(font2);
  322. runTime = System.currentTimeMillis() - startTime;
  323. g2.drawString("Runtime: " + formatTime(runTime), 355, 35);
  324. g2.drawString("Tanning: " + NAMES[index], 355, 50);
  325. g2.drawString("Hides tanned: " + tanned, 355, 65);
  326. g2.drawString("Hides tanned/h: " + (int) ((3600000.0 / (double) runTime) * tanned), 355, 80);
  327. g2.drawString("Profit: " + (tanned * profit), 356, 95);
  328. g2.drawString("Profit/h: " + (int) ((3600000.0 / (double) runTime) * (tanned * profit)), 356, 110);
  329. }
  330.  
  331. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement