Last active
August 29, 2015 14:19
-
-
Save KarimiM/696599d70f899da9aacc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ikov.misc; | |
import java.util.ArrayList; | |
import org.rev317.min.Loader; | |
import org.rev317.min.api.methods.Game; | |
import org.rev317.min.api.methods.Menu; | |
import org.rev317.min.api.wrappers.Item; | |
public class Shop { | |
public final static int SHOP_INTERFACE = 3824; | |
/** | |
* Checks if a shop is open. | |
* @return true when shop is open | |
*/ | |
public static boolean isOpen() { | |
return Game.getOpenInterfaceId() == SHOP_INTERFACE; | |
} | |
/** | |
* Gets all shop item ids in a shop | |
* | |
* @return shop items | |
*/ | |
public static int[] getShopItemIDs() { | |
if (!isOpen()) { | |
return null; | |
} | |
return Loader.getClient().getInterfaceCache()[3900].getItems(); | |
} | |
/** | |
* Gets all stack sizes in a shop | |
* | |
* @return stack sizes | |
*/ | |
public static int[] getShopStacks() { | |
if (!isOpen()) { | |
return null; | |
} | |
return Loader.getClient().getInterfaceCache()[3900].getStackSizes(); | |
} | |
/** | |
* Gets all shop items in shop | |
* | |
* @return shop items | |
*/ | |
public static Item[] getShopItems() { | |
if (!isOpen()) { | |
return null; | |
} | |
ArrayList<Item> items = new ArrayList<Item>(); | |
int[] ids = getShopItemIDs(); | |
int[] stacks = getShopStacks(); | |
for (int i = 0; i < ids.length; i++) { | |
if (ids[i] > 0) { | |
items.add(new Item(ids[i], stacks[i], i)); | |
} | |
} | |
return (Item[]) items.toArray(new Item[items.size()]); | |
} | |
/** | |
* Gets shop item with given id | |
* | |
* @param id | |
* | |
* @return shop item | |
*/ | |
public static Item getItem(int id) { | |
if (!isOpen()) { | |
return null; | |
} | |
for (Item i : getShopItems()) { | |
if (i.getId() == id) { | |
return i; | |
} | |
} | |
return null; | |
} | |
/** | |
* Counts the amount of items with given id in shop | |
* | |
* @param id | |
* | |
* @return count | |
*/ | |
public static int getCount(int id) { | |
if (!isOpen()) { | |
return 0; | |
} | |
return getItem(id).getStackSize(); | |
} | |
/** | |
* Counts total amount of items in shop | |
* | |
* @return total amount of items | |
*/ | |
public static int getShopCount() { | |
if (!isOpen()) { | |
return 0; | |
} | |
return getShopItemIDs().length; | |
} | |
/** | |
* Closes the shop interface | |
*/ | |
public static void close() { | |
if (!isOpen()) { | |
return; | |
} | |
Menu.sendAction(200, -1, -1, 3902); | |
} | |
/** | |
* Buys a specific item from a shop | |
* @param itemId the item id to buy | |
*/ | |
public static void buy(int itemId, boolean buyOneHundred) { | |
if (!isOpen()) { | |
return; | |
} | |
Item i = getItem(itemId); | |
if (buyOneHundred) { | |
Menu.sendAction(53, i.getId() - 1, i.getSlot(), 3900); | |
} else { | |
Menu.sendAction(78, i.getId() - 1, i.getSlot(), 3900); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment