Guest User

Untitled

a guest
Jun 17th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. package scripts.rares;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Image;
  7. import java.net.URL;
  8. import java.util.Iterator;
  9. import javax.swing.ImageIcon;
  10. import org.osbot.script.Script;
  11. import org.osbot.script.rs2.Client;
  12. import org.osbot.script.rs2.def.NPCDefinition;
  13. import org.osbot.script.rs2.model.NPC;
  14. import org.osbot.script.rs2.ui.WorldHopper;
  15.  
  16. public class RareFinder extends Script
  17. {
  18.  
  19. public RareFinder()
  20. {
  21. hops = 0;
  22. rares = 0;
  23. }
  24.  
  25. public void onStart()
  26. {
  27. try
  28. {
  29. background = (new ImageIcon(new URL("http://i.imgur.com/qJQDfb4.png"))).getImage();
  30. showPaint = true;
  31. startedScript = System.currentTimeMillis();
  32. if(client.getLoginState() != 30)
  33. hopWorld();
  34. }
  35. catch(Exception e)
  36. {
  37. e.printStackTrace();
  38. }
  39. }
  40.  
  41. public int onLoop()
  42. throws InterruptedException
  43. {
  44. NPC npc = findClosestNpcWithAction("Take");
  45. if(npc == null)
  46. {
  47. if(loggedIn <= 0L)
  48. loggedIn = System.currentTimeMillis();
  49. else
  50. if(System.currentTimeMillis() - loggedIn > (long)random(8000, 12000))
  51. hopWorld();
  52. } else
  53. if(npc.interact("take"))
  54. {
  55. rares++;
  56. return random(3000, 5000);
  57. }
  58. return 0;
  59. }
  60.  
  61. public void hopWorld()
  62. throws InterruptedException
  63. {
  64. int world;
  65. for(world = random(301, 378); !isValidWorld(world); world = random(301, 378));
  66. loggedIn = -1L;
  67. hops++;
  68. worldHopper.hopWorld(world);
  69. }
  70.  
  71. private boolean isValidWorld(int world)
  72. {
  73. int arr$[] = blocked;
  74. int len$ = arr$.length;
  75. for(int i$ = 0; i$ < len$; i$++)
  76. {
  77. int w = arr$[i$];
  78. if(world == w)
  79. return false;
  80. }
  81.  
  82. return world != client.getCurrentWorld();
  83. }
  84.  
  85. public void onPaint(Graphics g1d)
  86. {
  87. Graphics2D g = (Graphics2D)g1d.create();
  88. if(showPaint)
  89. {
  90. g.drawImage(background, 3, 340, null);
  91. g.setColor(Color.WHITE);
  92. g.translate(160, 357);
  93. g.translate(235, 0);
  94. g.drawString(format(System.currentTimeMillis() - startedScript), 0, 45);
  95. if(loggedIn >= 1L)
  96. g.drawString(format(System.currentTimeMillis() - loggedIn), 0, 59);
  97. else
  98. g.drawString(format(0L), 0, 59);
  99. g.drawString((new StringBuilder()).append("").append(rares).append(" (").append(perHour(rares)).append(" P/H)").toString(), 0, 73);
  100. g.drawString((new StringBuilder()).append("").append(hops).append(" (").append(perHour(hops)).append(" P/H)").toString(), 0, 87);
  101. g.drawString((new StringBuilder()).append("").append(client.getCurrentWorld()).toString(), 0, 101);
  102. }
  103. }
  104.  
  105. private int perHour(int actions)
  106. {
  107. return (int)((3600000D / (double)(System.currentTimeMillis() - startedScript)) * (double)actions);
  108. }
  109.  
  110. public String format(long milliSeconds)
  111. {
  112. long secs = milliSeconds / 1000L;
  113. return String.format("%02d:%02d:%02d", new Object[] {
  114. Long.valueOf(secs / 3600L), Long.valueOf((secs % 3600L) / 60L), Long.valueOf(secs % 60L)
  115. });
  116. }
  117.  
  118. private NPC findClosestNpcWithAction(String action)
  119. {
  120. java.util.List NPCs = client.getLocalNPCs();
  121. if(NPCs == null || NPCs.size() <= 0)
  122. return null;
  123. for(Iterator i$ = NPCs.iterator(); i$.hasNext();)
  124. {
  125. NPC npc = (NPC)i$.next();
  126. if(npc != null && containsAction(npc, action))
  127. return npc;
  128. }
  129.  
  130. return null;
  131. }
  132.  
  133. private boolean containsAction(NPC entity, String action)
  134. {
  135. if(entity == null)
  136. return false;
  137. if(entity.getDefinition() == null)
  138. return false;
  139. if(entity.getDefinition().getActions() == null)
  140. return false;
  141. String arr$[] = entity.getDefinition().getActions();
  142. int len$ = arr$.length;
  143. for(int i$ = 0; i$ < len$; i$++)
  144. {
  145. String a = arr$[i$];
  146. if(a != null && action != null && a.equals(action))
  147. return true;
  148. }
  149.  
  150. return false;
  151. }
  152.  
  153. private Image background;
  154. private long startedScript;
  155. private long loggedIn;
  156. private boolean showPaint;
  157. private int hops;
  158. private int rares;
  159. private int blocked[] = {
  160. 301, 302, 307, 308, 315, 316, 323, 324, 331, 332,
  161. 339, 340, 347, 348, 355, 356, 363, 364, 371, 372
  162. };
  163. }
Advertisement
Add Comment
Please, Sign In to add comment