Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.rares;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.net.URL;
- import java.util.Iterator;
- import javax.swing.ImageIcon;
- import org.osbot.script.Script;
- import org.osbot.script.rs2.Client;
- import org.osbot.script.rs2.def.NPCDefinition;
- import org.osbot.script.rs2.model.NPC;
- import org.osbot.script.rs2.ui.WorldHopper;
- public class RareFinder extends Script
- {
- public RareFinder()
- {
- hops = 0;
- rares = 0;
- }
- public void onStart()
- {
- try
- {
- background = (new ImageIcon(new URL("http://i.imgur.com/qJQDfb4.png"))).getImage();
- showPaint = true;
- startedScript = System.currentTimeMillis();
- if(client.getLoginState() != 30)
- hopWorld();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- public int onLoop()
- throws InterruptedException
- {
- NPC npc = findClosestNpcWithAction("Take");
- if(npc == null)
- {
- if(loggedIn <= 0L)
- loggedIn = System.currentTimeMillis();
- else
- if(System.currentTimeMillis() - loggedIn > (long)random(8000, 12000))
- hopWorld();
- } else
- if(npc.interact("take"))
- {
- rares++;
- return random(3000, 5000);
- }
- return 0;
- }
- public void hopWorld()
- throws InterruptedException
- {
- int world;
- for(world = random(301, 378); !isValidWorld(world); world = random(301, 378));
- loggedIn = -1L;
- hops++;
- worldHopper.hopWorld(world);
- }
- private boolean isValidWorld(int world)
- {
- int arr$[] = blocked;
- int len$ = arr$.length;
- for(int i$ = 0; i$ < len$; i$++)
- {
- int w = arr$[i$];
- if(world == w)
- return false;
- }
- return world != client.getCurrentWorld();
- }
- public void onPaint(Graphics g1d)
- {
- Graphics2D g = (Graphics2D)g1d.create();
- if(showPaint)
- {
- g.drawImage(background, 3, 340, null);
- g.setColor(Color.WHITE);
- g.translate(160, 357);
- g.translate(235, 0);
- g.drawString(format(System.currentTimeMillis() - startedScript), 0, 45);
- if(loggedIn >= 1L)
- g.drawString(format(System.currentTimeMillis() - loggedIn), 0, 59);
- else
- g.drawString(format(0L), 0, 59);
- g.drawString((new StringBuilder()).append("").append(rares).append(" (").append(perHour(rares)).append(" P/H)").toString(), 0, 73);
- g.drawString((new StringBuilder()).append("").append(hops).append(" (").append(perHour(hops)).append(" P/H)").toString(), 0, 87);
- g.drawString((new StringBuilder()).append("").append(client.getCurrentWorld()).toString(), 0, 101);
- }
- }
- private int perHour(int actions)
- {
- return (int)((3600000D / (double)(System.currentTimeMillis() - startedScript)) * (double)actions);
- }
- public String format(long milliSeconds)
- {
- long secs = milliSeconds / 1000L;
- return String.format("%02d:%02d:%02d", new Object[] {
- Long.valueOf(secs / 3600L), Long.valueOf((secs % 3600L) / 60L), Long.valueOf(secs % 60L)
- });
- }
- private NPC findClosestNpcWithAction(String action)
- {
- java.util.List NPCs = client.getLocalNPCs();
- if(NPCs == null || NPCs.size() <= 0)
- return null;
- for(Iterator i$ = NPCs.iterator(); i$.hasNext();)
- {
- NPC npc = (NPC)i$.next();
- if(npc != null && containsAction(npc, action))
- return npc;
- }
- return null;
- }
- private boolean containsAction(NPC entity, String action)
- {
- if(entity == null)
- return false;
- if(entity.getDefinition() == null)
- return false;
- if(entity.getDefinition().getActions() == null)
- return false;
- String arr$[] = entity.getDefinition().getActions();
- int len$ = arr$.length;
- for(int i$ = 0; i$ < len$; i$++)
- {
- String a = arr$[i$];
- if(a != null && action != null && a.equals(action))
- return true;
- }
- return false;
- }
- private Image background;
- private long startedScript;
- private long loggedIn;
- private boolean showPaint;
- private int hops;
- private int rares;
- private int blocked[] = {
- 301, 302, 307, 308, 315, 316, 323, 324, 331, 332,
- 339, 340, 347, 348, 355, 356, 363, 364, 371, 372
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment