Equinox

EquinoxSeller.java

Mar 13th, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.80 KB | None | 0 0
  1. import org.rsbot.script.Script;
  2. import org.rsbot.script.ScriptManifest;
  3. import org.rsbot.script.util.Filter;
  4. import org.rsbot.script.wrappers.RSItem;
  5. import org.rsbot.script.wrappers.RSNPC;
  6.  
  7. @ScriptManifest(authors = { "Equinox_" }, name = "Equinox Seller", description = "Sells everything in your inventory to the general store.")
  8. public class EquinoxSeller extends Script {
  9.     public static final int[] TRADER_IDS = { 520, 521 };
  10.     public static final int COINS_ID = 995;
  11.     public static final Filter<RSNPC> TRADER_FILTER = new Filter<RSNPC>() {
  12.         public boolean accept(RSNPC t) {
  13.             for (int id : TRADER_IDS)
  14.                 if (t.getID() == id)
  15.                     return true;
  16.             if (t.getName() != null)
  17.                 if (t.getName().equalsIgnoreCase("shopkeeper")
  18.                         || t.getName().equalsIgnoreCase("shop assistant"))
  19.                     return true;
  20.             return false;
  21.         }
  22.  
  23.     };
  24.     public int startMoney = 0;
  25.     public int soldItems = 0;
  26.  
  27.     public boolean onStart() {
  28.         if (npcs.getNearest(TRADER_FILTER) == null) {
  29.             log.severe("Start near a general store!");
  30.             return false;
  31.         }
  32.         startMoney = inventory.getCount(true, COINS_ID);
  33.         return true;
  34.     }
  35.  
  36.     public void onFinish() {
  37.         log.info("Thanks for using Equinox Seller!");
  38.         log.info("You sold: " + soldItems + " items and got "
  39.                 + (inventory.getCount(true, COINS_ID) - startMoney) + " gp!");
  40.     }
  41.  
  42.     public RSItem getInventoryItem() {
  43.         for (RSItem i : inventory.getItems())
  44.             if (i != null)
  45.                 if (i.getID() != COINS_ID && i.getID() > 0)
  46.                     return i;
  47.         return null;
  48.     }
  49.  
  50.     public int loop() {
  51.         mouse.setSpeed(random(4,6));
  52.         RSItem inv = getInventoryItem();
  53.         RSNPC npc = npcs.getNearest(TRADER_FILTER);
  54.         if (inv == null) {
  55.             log.info("Out of items!");
  56.             stopScript(true);
  57.         }
  58.         if (store.isOpen())
  59.             sell();
  60.         else if (npc != null)
  61.             openStore();
  62.         return 0;
  63.     }
  64.  
  65.     void openStore() {
  66.         RSNPC npc = npcs.getNearest(TRADER_FILTER);
  67.         if (npc != null) {
  68.             for (byte b = 0; b < 150 && !npc.isOnScreen(); b++) {
  69.                 if (walking.getDestination() == null
  70.                         || calc.distanceTo(walking.getDestination()) < 4)
  71.                     walking.walkTo(npc.getLocation());
  72.                 sleep(100, 150);
  73.             }
  74.             if (npc.isOnScreen())
  75.                 if (npc.doAction("Trade Shop"))
  76.                     for (byte b = 0; b < 50 && !store.isOpen(); b++)
  77.                         sleep(100, 125);
  78.         }
  79.     }
  80.  
  81.     void sell() {
  82.         int count = inventory.getCountExcept(true, COINS_ID);
  83.         RSItem inv = getInventoryItem();
  84.         if (store.isOpen() && inv != null)
  85.             inv.doAction("Sell "
  86.                     + getOpt(inventory.getCount(true, inv.getID())));
  87.         for (byte b = 0; b<35 && count==inventory.getCountExcept(true, COINS_ID); b++)
  88.             sleep(50,75);
  89.         soldItems += count-inventory.getCountExcept(true, COINS_ID);
  90.     }
  91.  
  92.     int getOpt(int count) {
  93.         if (count <= 1)
  94.             return 1;
  95.         else if (count <= 5)
  96.             return 5;
  97.         else if (count <= 10)
  98.             return 10;
  99.         return 50;
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment