Guest User

TokenShielder

a guest
Oct 5th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.14 KB | None | 0 0
  1. package org.trent;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.text.DecimalFormat;
  7.  
  8. import org.osbot.script.Script;
  9. import org.osbot.script.ScriptManifest;
  10. import org.osbot.script.rs2.map.Position;
  11. import org.osbot.script.rs2.model.RS2Object;
  12. import org.osbot.script.rs2.skill.Skill;
  13. import org.osbot.script.rs2.ui.EquipmentSlot;
  14.  
  15. @ScriptManifest(name = "TokenShielder", author = "Titan", version = 1.0, info = "Does the defensive style token collection in the Warriors Guild.")
  16. public class TokenShielder extends Script {
  17.     long startTime;
  18.     int startXp;
  19.     int tokensGained;
  20.     ProtectionType oldType = ProtectionType.SLASH;
  21.     ProtectionType protType = ProtectionType.SLASH;
  22.     Position target = new Position(2842, 3545, 1);
  23.  
  24.     enum ProtectionType {
  25.         SLASH, MAGIC, STAB, BLUNT
  26.     }
  27.  
  28.     @Override
  29.     public void onStart() {
  30.         startTime = System.currentTimeMillis();
  31.         startXp = client.getSkills().getExperience(Skill.DEFENCE);
  32.     }
  33.  
  34.     @Override
  35.     public int onLoop() throws InterruptedException {
  36.         if (!myPlayer().getPosition().equals(target)) {
  37.             target.walkHere(bot);
  38.         } else if (myPlayer().getPosition().equals(target) && !equipmentTab.isWearingItem(EquipmentSlot.SHIELD, 8856)) {
  39.             if (client.getInventory().contains(8856)) {
  40.                 client.getInventory().interactWithId(8856, "Wield");
  41.             } else {
  42.                 log("Stopping script. Does not have a shield.");
  43.                 stop();
  44.             }
  45.         } else {
  46.             updateType();
  47.             if (typeChanged()) {
  48.                 sleep(600);
  49.                 clickType();
  50.             }
  51.         }
  52.         return random(200, 400);
  53.     }
  54.    
  55.     public void updateType() throws InterruptedException {
  56.         RS2Object magic = closestObject(6808);
  57.         RS2Object slash = closestObject(6810);
  58.         RS2Object blunt = closestObject(6809);
  59.         RS2Object stab = closestObject(5554);
  60.        
  61.         if (magic != null && magic.getPosition().getX() == 2840 && magic.getPosition().getY() == 3552) {
  62.             protType = ProtectionType.MAGIC;
  63.         } else if (slash != null && slash.getPosition().getX() == 2840 && slash.getPosition().getY() == 3552) {
  64.             protType = ProtectionType.SLASH;
  65.         } else if (blunt != null && blunt.getPosition().getX() == 2840 && blunt.getPosition().getY() == 3552) {
  66.             protType = ProtectionType.BLUNT;
  67.         } else if (stab != null && stab.getPosition().getX() == 2840 && stab.getPosition().getY() == 3552) {
  68.             protType = ProtectionType.STAB;
  69.         }
  70.     }
  71.    
  72.     public boolean typeChanged() throws InterruptedException {
  73.         return oldType != protType;
  74.     }
  75.    
  76.     public void clickType() throws InterruptedException {
  77.         oldType = protType;
  78.         if (client.getInterface(411) != null) {
  79.             switch(protType) {
  80.                 case MAGIC:
  81.                     client.getInterface(411).getChild(4).interact();
  82.                     break;
  83.                 case BLUNT:
  84.                     client.getInterface(411).getChild(2).interact();
  85.                     break;
  86.                 case SLASH:
  87.                     client.getInterface(411).getChild(3).interact();
  88.                     break;
  89.                 case STAB:
  90.                     client.getInterface(411).getChild(1).interact();
  91.                     break;
  92.             }
  93.         }
  94.     }
  95.    
  96.     @Override
  97.     public void onMessage(String message) throws InterruptedException {
  98.         if (message.contains("successfully"))
  99.             tokensGained++;
  100.     }
  101.  
  102.     @Override
  103.     public void onPaint(Graphics g) {
  104.         g.setFont(new Font("Arial", Font.PLAIN, 12));
  105.  
  106.         g.setColor(new Color(0, 0, 0, 150));
  107.         g.fillRect(6, 260, 200, 75);
  108.         g.setColor(Color.BLACK);
  109.         g.drawRect(6, 260, 200, 75);
  110.  
  111.         g.setColor(Color.GREEN);
  112.         g.drawString("TokenShielder By Titan", 8, 280);
  113.  
  114.         int xpGained = client.getSkills().getExperience(Skill.DEFENCE) - startXp;
  115.  
  116.         g.drawString("XP P/H: " + perHour(xpGained), 8, 290);
  117.         g.drawString("XP Gained: " + xpGained, 8, 300);
  118.         g.drawString("Tokens Gained: " + tokensGained, 8, 310);
  119.         g.drawString("Tokens P/H: " + perHour(tokensGained), 8, 320);
  120.         g.drawString("Protection Type: " + protType.name(), 8, 330);
  121.     }
  122.  
  123.     public String perHour(int gained) {
  124.         return formatNumber((int) ((gained) * 3600000D / (System.currentTimeMillis() - startTime)));
  125.     }
  126.  
  127.     public String formatNumber(int start) {
  128.         DecimalFormat nf = new DecimalFormat("0.0");
  129.         double i = start;
  130.         if (i >= 1000000) {
  131.             return nf.format((i / 1000000)) + "m";
  132.         }
  133.         if (i >= 1000) {
  134.             return nf.format((i / 1000)) + "k";
  135.         }
  136.         return "" + start;
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment