Merge pull request #35 from Parabot/Interface-Class

[TASK] Added features to Interface
This commit is contained in:
Jeroen Ketelaar
2016-01-10 15:18:04 +01:00
2 changed files with 123 additions and 16 deletions
@@ -7,6 +7,7 @@ import org.rev317.min.accessors.Client;
import org.rev317.min.accessors.Deque;
import org.rev317.min.accessors.Node;
import org.rev317.min.api.wrappers.GroundItem;
import org.rev317.min.api.wrappers.Tile;
import java.util.ArrayList;
import java.util.Arrays;
@@ -37,9 +38,9 @@ public class GroundItems {
private static HashMap<String, Integer> settings = Context.getInstance().getServerProviderInfo().getSettings();
/**
* Gets all loaded ground items
* Gets all loaded GroundItems within an radius of 52 Tiles.
*
* @return ground item array
* @return GroundItem array
*/
public final static GroundItem[] getGroundItems(
final Filter<GroundItem> filter) {
@@ -63,12 +64,12 @@ public class GroundItems {
}
/**
* Gets a ground item
* Gets GroundItems at a specific tile using x and y location.
*
* @param x - local region x
* @param y - local region y
*
* @return ground item array
* @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest.
*/
public static final GroundItem[] getGroundItemsAt(final int x, final int y) {
try {
@@ -95,21 +96,61 @@ public class GroundItems {
return null;
}
/**
* Gets GroundItems at a specific tile using x and y location.
*
* @param tile Tile to get the GroundItems from.
* @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest.
*/
public static final GroundItem[] getGroundItemsAt(final Tile tile) {
return getGroundItemsAt(tile.getX(),tile.getY());
}
/**
* Gets all ground items in game
*
* @return ground items
* @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest.
*/
public static final GroundItem[] getGroundItems() {
return getGroundItems(ALL_FILTER);
}
/**
* Returns array of GroundItems with the first index to be the nearest
* Gets the closest GroundItem which matches the given filter.
*
* @param filter
* @param filter Filter that should be applied to the GroundItem.
*
* @return GroundItems
* @return closest GroundItem
*/
public static final GroundItem getClosest(final Filter<GroundItem> filter) {
GroundItem[] objects = getNearest(filter);
if (objects == null || objects.length == 0) {
return null;
}
return objects[0];
}
/**
* Gets the closest GroundItems which matches the given ids.
*
* @param ids ID's of the GroundItems to look for.
*
* @return closest GroundItems
*/
public static final GroundItem getClosest(int... ids) {
GroundItem[] objects = getNearest(ids);
if (objects == null || objects.length == 0) {
return null;
}
return objects[0];
}
/**
* Returns Array of GroundItems with the first index to be the nearest.
*
* @param filter Filter that should be applied to the GroundItem.
*
* @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest.
*/
public static final GroundItem[] getNearest(Filter<GroundItem> filter) {
final GroundItem[] objects = getGroundItems(filter);
@@ -118,20 +159,20 @@ public class GroundItems {
}
/**
* Returns array of GroundItems with the first index to be the nearest
* Returns Array of GroundItems with the first index to be the nearest.
*
* @return GroundItems
* @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest.
*/
public static final GroundItem[] getNearest() {
return getNearest(ALL_FILTER);
}
/**
* Returns nearest ground items with given id
* Returns Array of GroundItems with the first index to be the nearest.
*
* @param ids
* @param ids GroundItem ID's to look for.
*
* @return GroundItems
* @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest.
*/
public static final GroundItem[] getNearest(final int... ids) {
return getNearest(new Filter<GroundItem>() {
@@ -1,20 +1,86 @@
package org.rev317.min.api.methods;
import org.parabot.environment.api.utils.Time;
import org.rev317.min.Loader;
import org.rev317.min.accessors.Interface;
/**
* @author JKetelaar, Empathy
* @author JKetelaar, Empathy, Fryslan
*/
public class Interfaces {
private static final int optionAction = 2494;
/**
* Get's the interfaces loaded in the interface Cache.
* @return Interfaces in the Interface Cache.
*/
public static Interface[] getInterfaces(){
return Loader.getClient().getInterfaceCache();
}
/**
* Get's the Interface from the Interface Cache using the given ID.
* @param id Interface ID.
* @return Interface from the cache by the given ID.
*/
public static Interface getInterface(int id){
return getInterfaces()[id];
}
/**
* Opens the Interface by the given ID.
* @param id ID of the Interface to Open.
*/
public static void openInterface(int id){
Loader.getClient().setInterface(id);
}
/**
* Get's the Open Interface ID.
* @return The ID of the Open Interface , will be -1 if all Interfaces are closed.
*/
public static int getOpenInterfaceId(){
return Loader.getClient().getOpenInterfaceId();
}
/**
* Get's the Open Back Dialog ID.
* @return The ID of the Open Back Dialog , will be -1 if all Back Dialogs are closed.
*/
public static int getBackDialogId(){
return Loader.getClient().getBackDialogId();
}
/**
* Checks if the Interface or Back Dialog by the given ID is Open.
* @param id ID of the Interface or Back Dialog to check for.
* @return True is the Interface or Back Dialog is Open else will return false.
*/
public static boolean isOpen(int id){
return getOpenInterfaceId() == id || getBackDialogId() == id;
}
/**
* Checks if the Interface by the given ID is Open.
* @param id ID of the Interface or Back Dialog to check for depending on the backDialog boolean.
* @param backDialog When tru it will check the Bank Dialog ID else it will check for the Interface ID.
* @return True is the Interface or Back Dialog is Open else will return false.
*/
public static boolean isOpen(int id, boolean backDialog){
if(backDialog){
return getBackDialogId() == id;
}else{
return getOpenInterfaceId() == id;
}
}
/**
* Clicks an option from the given back dialog
* @param index Index of the requested option whereas you start at 0
*/
private static void clickOption(int index) {
public static void clickBackDialogOption(int index) {
Menu.sendAction(315, 0, 0, optionAction + index, 0);
Time.sleep(1500);
Time.sleep(1000);
}
}