Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
TehRhio

Shopping API

Recommended Posts

package scripts.Utilities;

import java.awt.Rectangle;

import java.util.ArrayList;

import java.util.Arrays;

import org.tribot.api2007.Interfaces;

import org.tribot.api2007.Inventory;

import org.tribot.api2007.types.RSItem;

import org.tribot.api2007.types.RSItemDefinition;

public class Shopping {

/*

* @author TehRhio

* @description NPC Shop API

*/

public static boolean isShopOpen(){

return Interfaces.get(300, 76) != null;

}

public static String getShopName(){

if (isShopOpen()) {

return Interfaces.get(300, 76).getText();

}

return "";

}

public static boolean close(){

//Close the shop interface

if (isShopOpen()) {

return Interfaces.get(300, 91).click(new String[0]);

}

return false;

}

public static RSItem[] getAll(){

//Return an array of all items in the shop

if (isShopOpen()) {

return createRectangles(Interfaces.get(300, 75).getItems());

}

return new RSItem[0];

}

public static RSItem[] get(String... name){

//Return an array of items with specific names

ArrayList<RSItem> items = new ArrayList<RSItem>();

for (RSItem i : getAll()) {

RSItemDefinition definition = i.getDefinition();

if(definition != null

&& Arrays.asList(name).contains(definition.getName())){

items.add(i);

}

}

return items.toArray(new RSItem[items.size()]);

}

public static RSItem[] get(int... ids){

//Return an array of items with specific ids

ArrayList<RSItem> items = new ArrayList<RSItem>();

for (RSItem i : getAll()) {

if(Arrays.asList(ids).contains(i.getID())){

items.add(i);

}

}

return items.toArray(new RSItem[items.size()]);

}

public static int getCount(String... name){

//Return the amount of an item a shop has in-stock

int i = 0;

for (RSItem item : get(name)) {

i += item.getStack();

}

return i;

}

public static int getCount(int... id){

//Return the amount of an item a shop has in-stock

int i = 0;

for (RSItem item : get(id)) {

i += item.getStack();

}

return i;

}

private static RSItem[] createRectangles(RSItem[] items){

//Convert all items in the array to bank items

for(RSItem i : items){

int x = ((int) Math.ceil((i.getIndex()) % 8) * 47) + 80;

int y = ((int) ((Math.floor(i.getIndex()) / 8) % 5) * 47) + 69;

i.setArea(new Rectangle(x,y,31,31));

}

return items;

}

public static boolean buy(int count, String... names){

//Buy an item from the shop

for(RSItem item : get(names)){

if(item.getStack() > 0){

if(count >= 10){

return item.click("Buy 10");

}else if(count >= 5){

return item.click("Buy 5");

}else{

return item.click("Buy 1");

}

}

}

return false;

}

public static boolean buy(int count, int... ids){

//Buy an item from the shop

for(RSItem item : get(ids)){

if(item.getStack() > 0){

if(count >= 10){

return item.click("Buy 10");

}else if(count >= 5){

return item.click("Buy 5");

}else{

return item.click("Buy 1");

}

}

}

return false;

}

public static boolean sell(int count, String... names){

RSItem[] items = Inventory.find(names);

if(items.length > 0){

if(count >= 10){

return items[0].click("Buy 10");

}else if(count >= 5){

return items[0].click("Buy 5");

}else{

return items[0].click("Buy 1");

}

}

return false;

}

public static boolean sell(int count, int... ids){

RSItem[] items = Inventory.find(ids);

if(items.length > 0){

if(count >= 10){

return items[0].click("Buy 10");

}else if(count >= 5){

return items[0].click("Buy 5");

}else{

return items[0].click("Buy 1");

}

}

return false;

}

}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Our picks

    • This release will:

      Fix LG for both OSBuddy and RuneLite


      Fix issue where the resizable client isn't able to be made smaller (Thanks @JoeDezzy1)


      Fix detection of the logout game tab when resizable mode and side panels are enabled (Thanks @JoeDezzy1)


      Add initial support for Sentry to allow us to identify and easily debug exceptions happening with all TRiBot users


      Add methods to determine if the bank is actually loaded, and not just the overarching interface (Thanks @wastedbro)



      Upcoming updates:

      Improved CLI support


      Full Sentry support


      Much more
      • 50 replies
    • This release will:

      Fix NPE in Camera API (Thanks @wastedbro)


      Update deposit box interface ids (Thanks @Encoded)


      Add various bank methods (Thanks @wastedbro)


      Banking#getWithdrawXQuantity


      Banking#getDefaultWithdrawQuantity


      Banking#arePlaceholdersOn




      Fix resizeable minimap bug (Thanks @wastedbro)


      Remove Java 8 requirement


      Please note: TRiBot is not yet fully compatible with Java 10+




      Fix the break handler issues by ensuring the break handler thread never gets paused


      Fix broken settings hooks



      Upcoming updates:

      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
      • 68 replies
    • This release will:

      Add support for using custom F key bindings to switch between game tabs (Thanks @erickho123)


      Fix tab opening for "Skills" and "Kourend Tasks" (Thanks @erickho123)



      Note: If you are using LG, please restart both the RS client and TRiBot
      • 34 replies
    • This release will:

      Fix an issue where breaks would stop firing


      Fix Combat#getWildernessLevel, use dynamic search for text and cache ID for later calls


      Fix an NPE in the Combat API


      Fix Mouse#leaveGame bug where the mouse wouldn't actually leave the game screen
      • 21 replies
    • This release will:

      Add LG support for Runelite


      Fix NPCChat issues


      Fix a bug where the camera angle setter would just hold down a key for 5 seconds (the timeout)


      Slightly adjust the rotation via keys to be more accurate


      Add the ability for asynchronous camera movement via keys


      Make Camera rotation via mouse more fluid, with more antiban, and work much better in resizable mode


      Add a "Camera#setCamera" method, allowing the rotation and angle to be set in parallel


      Increase the likelihood of using the mouse for camera movements


      Add support for adjusting the camera to positionable entities (Positionable#adjustCameraTo)



      Upcoming updates:

      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Like
      • 59 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×