Advertisement
Guest User

NPC_Beggar

a guest
Jun 8th, 2016
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.57 KB | None | 0 0
  1. import org.osbot.rs07.api.map.Area;
  2. import org.osbot.rs07.api.model.NPC;
  3. import org.osbot.rs07.script.Script;
  4. import org.osbot.rs07.script.ScriptManifest;
  5. import org.osbot.rs07.utility.ConditionalSleep;
  6. import java.awt.*;
  7. import java.util.concurrent.TimeUnit;
  8.  
  9. @ScriptManifest(name = "NPC_Beggar", author = "Aibanker", version = 1.0, info = "Begs for GP", logo = "http://i.imgur.com/04lPr43.png")
  10. public class NPC_Beggar extends Script {
  11.     Area loot = new Area(2963, 3209, 2970, 3217).setPlane(1);
  12.     private long timeBegan;
  13.     private long timeRan;
  14.     private long CoinsCollected;
  15.     private long prevInvCount;
  16.     private long coinshour;
  17.  
  18.     @Override
  19.     public void onStart() {
  20.         this.log("Starting script");
  21.         this.timeBegan = System.currentTimeMillis();
  22.     }
  23.  
  24.     private String ft(long duration) {
  25.         String res = "";
  26.         long days = TimeUnit.MILLISECONDS.toDays(duration);
  27.         long hours = TimeUnit.MILLISECONDS.toHours(duration)
  28.                 - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
  29.         long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
  30.                 - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration));
  31.         long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
  32.                 - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration));
  33.         if (days == 0) {
  34.             res = (hours + ":" + minutes + ":" + seconds);
  35.         } else {
  36.             res = (days + ":" + hours + ":" + minutes + ":" + seconds);
  37.         }
  38.         return res;
  39.     }
  40.  
  41.     private enum State {
  42.         walk, talk, wait;
  43.     };
  44.  
  45.     private State getState() {
  46.         NPC anja = this.getNpcs().closest("Anja");
  47.         if (!loot.contains(myPlayer()))
  48.             return State.walk;
  49.         if (anja != null)
  50.             return State.talk;
  51.         return State.wait;
  52.     }
  53.  
  54.     @Override
  55.     public void onExit() {
  56.  
  57.     }
  58.  
  59.     @Override
  60.     public int onLoop() throws InterruptedException {
  61.         long invCount = getInventory().getAmount("Coins");
  62.         if (invCount > prevInvCount)
  63.             CoinsCollected += (invCount - prevInvCount);
  64.         prevInvCount = invCount;
  65.         switch (getState()) {
  66.         case walk:
  67.             if (!this.loot.contains(myPlayer()))
  68.                 this.log("You are not at the looting area");
  69.             this.getWalking().webWalk(loot);
  70.             this.log("Walking to looting area");
  71.             break;
  72.         case talk:
  73.             NPC anja = this.getNpcs().closest("Anja");
  74.             if (this.loot.contains(myPlayer()) && anja != null)
  75.  
  76.                 if (!this.getDialogues().inDialogue()) {
  77.                     this.log("Talking to npc");
  78.                     anja.interact("Talk-to");
  79.                     new ConditionalSleep(2000) {
  80.  
  81.                         @Override
  82.                         public boolean condition() throws InterruptedException {
  83.                             return getDialogues().inDialogue();
  84.                         }
  85.  
  86.                     }.sleep();
  87.                 }
  88.             if (getDialogues().inDialogue())
  89.                 getDialogues().completeDialogue("I was hoping");
  90.  
  91.             break;
  92.         case wait:
  93.             break;
  94.         }
  95.  
  96.         return 700;
  97.     }
  98.  
  99.     @Override
  100.     public void onPaint(Graphics2D g) {
  101.         Point mP = getMouse().getPosition();
  102.         g.drawLine(mP.x - 5, mP.y + 5, mP.x + 5, mP.y - 5);
  103.         g.drawLine(mP.x + 5, mP.y + 5, mP.x - 5, mP.y - 5);
  104.         Font font = new Font("Comic Sans", Font.PLAIN, 13);
  105.         g.setFont(font);
  106.         g.setFont(g.getFont().deriveFont(13.0f));
  107.         timeRan = System.currentTimeMillis() - this.timeBegan;
  108.         g.drawString(ft(timeRan), 150, 50);
  109.         g.drawString(String.valueOf(CoinsCollected), 150, 70);
  110.         g.drawString(String.valueOf(coinshour), 150, 90);
  111.         coinshour = (int) (CoinsCollected / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
  112.         g.drawString("Time:", 15, 50);
  113.         g.drawString("Coins", 15, 70);
  114.         g.drawString("Coins/hr", 15, 90);
  115.         g.drawString("Status", 15, 110);
  116.         g.drawString(this.getState().toString(), 150, 110);
  117.         g.setColor(Color.decode("#FFFFFF"));
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement