Advertisement
Guest User

some help please

a guest
Mar 20th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. package jugfiller;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics2D;
  6. import java.util.List;
  7. import java.util.Random;
  8.  
  9. import org.osbot.rs07.api.map.Position;
  10. import org.osbot.rs07.api.model.Player;
  11. import org.osbot.rs07.api.model.RS2Object;
  12. import org.osbot.rs07.api.ui.Message;
  13. import org.osbot.rs07.api.ui.Message.MessageType;
  14. import org.osbot.rs07.script.MethodProvider;
  15. import org.osbot.rs07.script.Script;
  16. import org.osbot.rs07.utility.Area;
  17.  
  18. public class JugFiller extends Script
  19. {
  20.  
  21. Position[] PATH_TO_BANK = { new Position(3281,3180,0),
  22. new Position(3270,3167,0) };
  23.  
  24. Position[] PATH_TO_FOUNTAIN = { new Position(3281,3180,0),
  25. new Position(3292,3175,0) };
  26. int fountainTimes = 0;
  27. private Area AlKharidBank = new Area(3268,3163,3272,3171);
  28. private Area AlKharidFountain = new Area(3290,3170,3295,3175);
  29. private String State = "";
  30. long startTime;
  31.  
  32. private enum state
  33. {
  34. BANK_JUGS, //als hij geen jugs meer heeft maar WEL water, en in bank is
  35. FILL_JUGS; //als hij empty jugs heeft en in de area fountain is
  36. }
  37.  
  38. public void onStop() {}
  39. public void onStart()
  40. {
  41. State = "Starting up...wait a moment";
  42. startTime = System.currentTimeMillis();
  43. }
  44.  
  45. public int onLoop() throws InterruptedException {
  46. switch(getState())
  47. {
  48. case BANK_JUGS:
  49. bank();
  50. break;
  51. case FILL_JUGS:
  52. fill();
  53. break;
  54. default:
  55. break;
  56.  
  57. }
  58. return 0;
  59. }
  60.  
  61. private void bank() {
  62. try {
  63. if (AlKharidBank.contains(myPlayer())) {
  64. this.State = "BANKING_JUGS";
  65. if (!this.bank.isOpen()) {
  66. this.bank.open();
  67. withdrawJugs();
  68. } else
  69. withdrawJugs();
  70. } else if (AlKharidFountain.contains(myPlayer())) {
  71. this.State = "WALKING_TO_BANK";
  72. this.localWalker.walkPath(this.PATH_TO_BANK);
  73. EXECUTE_ANTIBAN();
  74. }
  75. } catch (Exception exception) {
  76. exception.printStackTrace();
  77. }
  78. }
  79.  
  80. public void fill() {
  81. try {
  82. if (AlKharidFountain.contains(myPlayer())) {
  83. this.State = "FILLING_JUGS";
  84. RS2Object fountain = (RS2Object)this.objects.closest(new String[] { "Fountain" });
  85. if (fountain != null) {
  86. getInventory().getItem(new String[] { "Jug" }).interact(new String[] { "Use" });
  87. fountain.interact(" -> ");
  88. MethodProvider.sleep(random(18000, 20000));
  89. }
  90. } else if (AlKharidBank.contains(myPlayer())) {
  91. this.State = "WALKING_TO_FOUNTAIN";
  92. this.localWalker.walkPath(this.PATH_TO_FOUNTAIN);
  93. EXECUTE_ANTIBAN();
  94. }
  95. } catch (Exception exception) {
  96. exception.printStackTrace();
  97. }
  98. }
  99.  
  100. private void withdrawJugs() throws InterruptedException {
  101. this.bank.depositAll();
  102. this.bank.withdrawAll("Jug");
  103. this.bank.close();
  104. }
  105.  
  106. private void EXECUTE_ANTIBAN() throws InterruptedException {
  107. Random r1 = new Random();
  108. float chance = r1.nextFloat();
  109. if (chance <= 0.4F) {
  110. antiban();
  111. }
  112. }
  113.  
  114. public void antiban() throws InterruptedException {
  115. int select = random(3, 6);
  116. switch (select) {
  117. case 3:
  118. int pitch = random(22, 67);
  119. getCamera().movePitch(pitch);
  120. break;
  121.  
  122. case 4:
  123. int yaw = random(1, 360);
  124. getCamera().moveYaw(yaw);
  125. break;
  126.  
  127. case 5:
  128. List<Player> p = getPlayers().getAll();
  129. if (p != null) {
  130. int randomNum = Script.random(0, p.size() - 1);
  131. Player randomPlayer = (Player) p.get(randomNum);
  132. if (randomPlayer != null) {
  133. randomPlayer.hover();
  134. getMouse().click(true);
  135. sleep(random(200, 500));
  136. }
  137. }
  138.  
  139. break;
  140.  
  141. case 6:
  142. List<Player> pl = getPlayers().getAll();
  143. if (pl != null) {
  144. int randomNum = Script.random(0, pl.size() - 1);
  145. Player randomPlayer = (Player) pl.get(randomNum);
  146. if (randomPlayer != null) {
  147. randomPlayer.hover();
  148. }
  149. }
  150.  
  151. break;
  152. }
  153. }
  154.  
  155. public void onPaint(Graphics2D g) {
  156. long elapsed = System.currentTimeMillis() - startTime;
  157. g.setColor(Color.BLACK);
  158. g.setFont(new Font("Arial", Font.PLAIN, 10));
  159. g.drawString("Visited fountain: "+fountainTimes+" times", 320, 290);
  160. g.drawString("run time: "+format(elapsed)+" times", 320, 315);
  161. g.drawString("current state: "+State+"", 320, 330);
  162. }
  163.  
  164. public void onMessage(Message c) {
  165. if (c.getType() == MessageType.GAME) {
  166. String m = c.getMessage().toLowerCase();
  167. try {
  168. if(m.contains("fill")) {
  169. fountainTimes++;
  170. }
  171. } catch (Exception exception) {
  172. exception.printStackTrace();
  173. }
  174. }
  175. }
  176.  
  177. private state getState()
  178. {
  179. if(this.equipment.contains(1935) && AlKharidFountain.contains(myPlayer()))
  180. {
  181. return state.FILL_JUGS;
  182. }
  183.  
  184. if(!this.equipment.contains(1935) && this.equipment.contains(1937) && AlKharidBank.contains(myPlayer()))
  185. {
  186. return state.BANK_JUGS;
  187. }
  188.  
  189. return null;
  190. }
  191.  
  192. public String format(long time) {
  193. StringBuilder string = new StringBuilder();
  194. long totalSeconds = time / 1000L;
  195. long totalMinutes = totalSeconds / 60L;
  196. long totalHours = totalMinutes / 60L;
  197. int seconds = (int) totalSeconds % 60;
  198. int minutes = (int) totalMinutes % 60;
  199. int hours = (int) totalHours % 24;
  200. if (hours > 0) {
  201. string.append(hours + "h ");
  202. }
  203. if (minutes > 0) {
  204. string.append(minutes + "m ");
  205. }
  206. string.append(seconds + "s");
  207. return string.toString();
  208. }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement