Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import org.rsbot.script.methods.Game;
- import org.rsbot.script.methods.Interfaces;
- import org.rsbot.script.util.Filter;
- import org.rsbot.script.wrappers.RSComponent;
- import org.rsbot.script.wrappers.RSInterface;
- /**
- * Used for lobby interaction
- *
- * @author Equinox_
- *
- */
- public class Lobby {
- public final static int HIGH_RISK_WILDY = 93;
- public final static int CURRENT_WORLD = 11;
- public final static int WORLD_ACTIVITY = 72;
- public final static int WORLD_FAVE_1 = 21;
- public final static int WORLD_FAVE_2 = 22;
- public final static int WORLD_FAVES = 68;
- public final static int WORLD_FLAG = 73;
- public final static int WORLD_INTERFACE = 910;
- public final static int WORLD_LINES = 77;
- public final static int WORLD_LOOT_SHARE = 75;
- public final static int WORLD_NUMBERS = 69;
- public final static int WORLD_PING = 76;
- public final static int WORLD_PLAYERS = 71;
- public final static int WORLD_SCROLL = 86;
- public final static int WORLD_TYPE_STAR = 70;
- public final static int WORLD_TYPE_TEXT = 74;
- public final static int WORLDS_REFRESH = 6;
- private final static int MEMBERS_YES = 1531;
- private final static int LOOTSHARE_YES = 699;
- // private final static int FAVORITE_YES = 1541;
- // Player Info
- public final static int PLAYER_INFO_INTERFACE = 907;
- public final static int MEMBERSHIP_CHECK = 48;
- // private final static int PLAYER_INFO_CHECK_YES = 2669;
- public final static int EMAIL_REGISTERED = 34;
- public final static int RECOVERY_QUESTIONS_SET = 22;
- public final static int MESSAGES_CHECK = 10;
- public final static int MEMBERSHIP_EXPIRES = 53;
- public final static int PLAYER_LAST_LOGIN = 1;
- // Message of the week
- public final static int MESSAGE_OF_THE_WEEK_INTERFACE = 908;
- public final static int MESSAGE_OF_THE_WEEK = 19;
- // Friends
- public final static int FRIENDS_INTERFACE = 0;
- public final static int FRIEND_NAMES = 45;
- public final static int FRIEND_WORLDS = 46;
- public final static int FRIENDS_SCROLL = 47;
- public final static int IGNORE_NAMES = 87;
- public final static int IGNORE_SCROLL = 79;
- // Friends Chat
- public final static int FRIENDS_CHAT_INTERFACE = 0;
- // Clan Chat
- public final static int CLAN_CHAT_INTERFACE = 0;
- // Options
- public final static int OPTIONS_INTERFACE = 0;
- // Main Interface
- public final static int MAIN_INTERFACE = 906;
- public final static int[] FAVE_BUTTON = { 165, 166 };
- public final static int[] FAVE_TEXT = { 167, 168 };
- public final static int PLAY_BUTTON = 160;
- public final static int TAB_INFO = 0;
- public final static int TAB_WORLDS = 1;
- public final static int TAB_FRIENDS = 2;
- public final static int TAB_FRIENDS_CHAT = 3;
- public final static int TAB_CLAN_CHAT = 4;
- public final static int TAB_OPTIONS = 5;
- public final static String[] TAB_NAMES = { "Player<br>Info",
- "World<br>Select", "Friends", "Friends<br>Chat", "Clan<br>Chat",
- "Options" };
- public final static int[] TAB_INTERFACES = { PLAYER_INFO_INTERFACE,
- WORLD_INTERFACE, FRIENDS_INTERFACE, FRIENDS_CHAT_INTERFACE,
- CLAN_CHAT_INTERFACE, OPTIONS_INTERFACE };
- public final Interfaces interfaces;
- public final Game game;
- public Lobby(Interfaces inter, Game game) {
- this.interfaces = inter;
- this.game = game;
- }
- public boolean openTab(int tabID) {
- if (game.isLoginScreen())
- game.login();
- if (game.isLoggedIn())
- game.logout(true);
- RSInterface inter;
- if (tabID >= 0 && tabID < TAB_NAMES.length
- && (inter = interfaces.get(MAIN_INTERFACE)) != null
- && inter.isValid()) {
- for (RSComponent c : inter.getComponents())
- if (c != null
- && c.isValid()
- && c.getText() != null
- && c.getText().trim()
- .equalsIgnoreCase(TAB_NAMES[tabID].trim())) {
- for (byte b = 0; b < 5 && getCurrentTab() != tabID; b++) {
- if (c.doClick())
- return true;
- interfaces.sleep(500);
- }
- return false;
- }
- }
- return false;
- }
- public int getCurrentTab() {
- for (int i = 0; i < TAB_INTERFACES.length; i++)
- if (interfaces.get(TAB_INTERFACES[i]) != null
- && interfaces.get(TAB_INTERFACES[i]).isValid())
- return i;
- return -1;
- }
- public boolean logout() {
- RSInterface inter;
- if ((inter = interfaces.get(MAIN_INTERFACE)) != null && inter.isValid()) {
- for (RSComponent c : inter.getComponents())
- if (c != null && c.isValid() && c.getActions() != null)
- for (String s : c.getActions())
- if (s != null && s.trim().equalsIgnoreCase("logout"))
- return c.doClick();
- }
- return false;
- }
- public World[] getAvaliableFavorites(final boolean members,
- final int ttlLevel) {
- return getFavorites(new Filter<World>() {
- @Override
- public boolean accept(World t) {
- return ttlLevel >= t.getMinimumTotalLevel()
- && (members ? true : !t.members);
- }
- });
- }
- public World[] getAvaliableWorlds(final boolean members) {
- return getWorlds(new Filter<World>() {
- @Override
- public boolean accept(World t) {
- return (members == t.members);
- }
- });
- }
- public World[] getAvaliableWorlds(final boolean members, final int ttlLevel) {
- return getWorlds(new Filter<World>() {
- @Override
- public boolean accept(World t) {
- return ttlLevel >= t.getMinimumTotalLevel()
- && (members ? true : !t.members);
- }
- });
- }
- public World[] getFavorites() {
- RSComponent fave1 = interfaces.getComponent(WORLD_INTERFACE,
- WORLD_FAVE_1);
- RSComponent fave2 = interfaces.getComponent(WORLD_INTERFACE,
- WORLD_FAVE_2);
- World fave1W = null;
- World fave2W = null;
- if (fave1 != null && fave1.getComponents() != null
- && fave1.getComponents().length >= 13) {
- int ping = -1;
- try {
- ping = Integer.valueOf(fave1.getComponent(12).getText().trim());
- } catch (Exception e) {
- }
- int players = 2000;
- try {
- players = Integer.valueOf(fave1.getComponent(7).getText()
- .trim());
- } catch (Exception e) {
- }
- World_Flag flag = World_Flag.RIS;
- int tex = fave1.getComponent(8).getBackgroundColor();
- for (World_Flag f : World_Flag.values())
- if (tex == f.texID)
- flag = f;
- fave1W = new World(
- Integer.valueOf(fave1.getComponent(6).getText().trim()),
- fave1.getComponent(5).getBackgroundColor() == MEMBERS_YES,
- flag,
- true,
- fave1.getComponent(9).getText().trim(),
- fave1.getComponent(11).getBackgroundColor() == LOOTSHARE_YES,
- ping, players);
- }
- if (fave2 != null && fave2.getComponents() != null
- && fave2.getComponents().length >= 13) {
- int ping = -1;
- try {
- ping = Integer.valueOf(fave2.getComponent(12).getText().trim());
- } catch (Exception e) {
- }
- int players = 2000;
- try {
- players = Integer.valueOf(fave2.getComponent(7).getText()
- .trim());
- } catch (Exception e) {
- }
- World_Flag flag = World_Flag.RIS;
- int tex = fave2.getComponent(8).getBackgroundColor();
- for (World_Flag f : World_Flag.values())
- if (tex == f.texID)
- flag = f;
- fave2W = new World(
- Integer.valueOf(fave2.getComponent(6).getText().trim()),
- fave2.getComponent(5).getBackgroundColor() == MEMBERS_YES,
- flag,
- true,
- fave2.getComponent(9).getText().trim(),
- fave2.getComponent(11).getBackgroundColor() == LOOTSHARE_YES,
- ping, players);
- }
- if (fave1W == null && fave2W != null)
- return new World[] { fave2W };
- else if (fave1W != null && fave2W != null)
- return new World[] { fave1W, fave2W };
- else
- return new World[] {};
- }
- public int[] getBasicFavorites() {
- RSComponent fave1 = interfaces.getComponent(MAIN_INTERFACE,
- FAVE_TEXT[0]);
- RSComponent fave2 = interfaces.getComponent(MAIN_INTERFACE,
- FAVE_TEXT[1]);
- int f1 = -1, f2 = -1;
- if (fave1 != null && fave1.isValid() && fave1.getText() != null) {
- try {
- f1 = Integer.valueOf(fave1.getText().trim());
- } catch (NumberFormatException e) {
- f1 = -1;
- }
- }
- if (fave2 != null && fave2.isValid() && fave2.getText() != null) {
- try {
- f2 = Integer.valueOf(fave2.getText().trim());
- } catch (NumberFormatException e) {
- f2 = -1;
- }
- }
- if (f1 > 0 && f2 > 0)
- return new int[] { f1, f2 };
- else if (f1 > 0)
- return new int[] { f1 };
- else if (f2 > 0)
- return new int[] { f2 };
- else
- return new int[] {};
- }
- public World[] getFavorites(Filter<World> filter) {
- World[] wrls = getFavorites();
- List<World> result = new ArrayList<World>();
- for (World w : wrls)
- if (filter.accept(w))
- result.add(w);
- return result.toArray(new World[result.size()]);
- }
- /**
- * Gets the selected world
- *
- * @return Gets the selected world
- * @link{org.rsbot.script.methods.Lobby#getSelectedWorldID()
- */
- public World getSelectedWorld() {
- return getWorld(getSelectedWorldID());
- }
- /**
- * Gets the ID of the selected world
- *
- * @return The id of the selected world, or 1 if none are selected
- */
- public int getSelectedWorldID() {
- String s = interfaces.getComponent(WORLD_INTERFACE, CURRENT_WORLD)
- .getText().split(" ")[1];
- try {
- return Integer.valueOf(s);
- } catch (Exception e) {
- return 1;
- }
- }
- /**
- * Gets the world with the specified id
- *
- * @param world
- * the world id
- * @return The world
- */
- public World getWorld(int world) {
- int cpIdx = getWorldIndex(world);
- return cpIdx >= 0 ? new World(world, isMembers(cpIdx), getFlag(cpIdx),
- isFavorite(cpIdx), getActivity(cpIdx), isLootShare(cpIdx),
- getPing(cpIdx), getPlayers(cpIdx)) : null;
- }
- private int getWorldIndex(int world) {
- openTab(TAB_WORLDS);
- for (RSComponent c : interfaces.getComponent(WORLD_INTERFACE,
- WORLD_NUMBERS).getComponents()) {
- try {
- if (Integer.valueOf(c.getText().trim()) == world)
- return c.getIndex();
- } catch (Exception e) {
- }
- }
- return -1;
- }
- /**
- * Gets all worlds
- *
- * @return All the worlds
- */
- public World[] getWorlds() {
- World[] wrls = new World[interfaces.getComponent(WORLD_INTERFACE,
- WORLD_NUMBERS).getComponents().length];
- for (int i = 0; i < interfaces.getComponent(WORLD_INTERFACE,
- WORLD_NUMBERS).getComponents().length; i++)
- wrls[i] = getWorld(i);
- return wrls;
- }
- /**
- * Gets all worlds that the filter accepts
- *
- * @param filter
- * The Filter to use
- * @return All the valid worlds
- */
- public World[] getWorlds(Filter<World> filter) {
- World[] wrls = getWorlds();
- List<World> result = new ArrayList<World>();
- for (World w : wrls)
- if (filter.accept(w))
- result.add(w);
- return result.toArray(new World[result.size()]);
- }
- private RSComponent getWorldSwitchComponent(int world) {
- if (isFavorite(world)) {
- for (int i = 0; i < FAVE_TEXT.length; i++)
- if (interfaces.getComponent(MAIN_INTERFACE, FAVE_TEXT[i])
- .getText().trim()
- .equalsIgnoreCase(String.valueOf(world)))
- return interfaces.getComponent(MAIN_INTERFACE,
- FAVE_BUTTON[i]);
- }
- return interfaces.getComponent(WORLD_INTERFACE, WORLD_LINES)
- .getComponent(getWorldIndex(world));
- }
- /**
- * Logs into the provided world
- *
- * @param w
- * the World
- * @return did we login
- */
- public boolean login(World w) {
- return login(w.number);
- }
- /**
- * Logs into the world with the given id
- *
- * @param world
- * the world id
- * @return did we login
- */
- public boolean login(int world) {
- if (game.isLoginScreen())
- game.login();
- if (game.isLoggedIn())
- game.logout(true);
- RSComponent wrl = getWorldSwitchComponent(world);
- if (isFavorite(world)) {
- if (wrl.doClick()) {
- for (byte b = 0; b < 60
- && interfaces.getComponent(MAIN_INTERFACE, PLAY_BUTTON)
- .isValid(); b++) {
- if (interfaces
- .getComponent(MAIN_INTERFACE, HIGH_RISK_WILDY)
- .isValid())
- interfaces
- .getComponent(MAIN_INTERFACE, HIGH_RISK_WILDY)
- .doClick();
- interfaces.sleep(550);
- }
- return true;
- }
- return false;
- } else {
- if (interfaces.scrollTo(wrl,
- interfaces.getComponent(WORLD_INTERFACE, WORLD_SCROLL)))
- if (wrl.doClick())
- if (interfaces.getComponent(MAIN_INTERFACE, PLAY_BUTTON)
- .doClick()) {
- for (byte b = 0; b < 60
- && interfaces.getComponent(MAIN_INTERFACE,
- PLAY_BUTTON).isValid(); b++) {
- if (interfaces.getComponent(MAIN_INTERFACE,
- HIGH_RISK_WILDY).isValid())
- interfaces.getComponent(MAIN_INTERFACE,
- HIGH_RISK_WILDY).doClick();
- interfaces.sleep(550);
- }
- return true;
- }
- return false;
- }
- }
- private String getActivity(int cpIdx) {
- return interfaces.getComponent(WORLD_INTERFACE, WORLD_ACTIVITY)
- .getComponent(cpIdx).getText().trim();
- }
- private World_Flag getFlag(int cpIdx) {
- int tex = interfaces.getComponent(WORLD_INTERFACE, WORLD_FLAG)
- .getComponent(cpIdx).getBackgroundColor();
- for (World_Flag f : World_Flag.values())
- if (tex == f.texID)
- return f;
- return World_Flag.RIS;
- }
- private int getPing(int cpIdx) {
- String s = interfaces.getComponent(WORLD_INTERFACE, WORLD_PING)
- .getComponent(cpIdx).getText().trim();
- if (s.equalsIgnoreCase("N/A"))
- return -1;
- else
- try {
- return Integer.valueOf(s);
- } catch (Exception e) {
- return -1;
- }
- }
- private int getPlayers(int cpIdx) {
- String s = interfaces.getComponent(WORLD_INTERFACE, WORLD_PLAYERS)
- .getComponent(cpIdx).getText().trim();
- if (s.equalsIgnoreCase("Full"))
- return 2000;
- else
- try {
- return Integer.valueOf(s);
- } catch (Exception e) {
- return 2000;
- }
- }
- /**
- * Checks if the given world is a favorite
- *
- * @param world
- * the world id
- * @return is the world a favorite
- */
- public boolean isFavorite(int world) {
- int[] faveWorlds = getBasicFavorites();
- for (int i : faveWorlds)
- if (i == world)
- return true;
- return false;
- }
- private boolean isLootShare(int cpIdx) {
- return interfaces.getComponent(WORLD_INTERFACE, WORLD_LOOT_SHARE)
- .getComponent(cpIdx).getBackgroundColor() == LOOTSHARE_YES;
- }
- private boolean isMembers(int cpIdx) {
- return interfaces.getComponent(WORLD_INTERFACE, WORLD_TYPE_STAR)
- .getComponent(cpIdx).getBackgroundColor() == MEMBERS_YES;
- }
- /**
- * Class representing a world
- *
- * @author Equinox_
- *
- */
- public static class World {
- public final String activity;
- public final boolean favorite;
- public final World_Flag flag;
- public final boolean lootShare;
- public final boolean members;
- public final int number;
- public final int ping;
- public final int playerCount;
- /**
- * Contructs a world with the given paramters
- *
- * @param number
- * The world number
- * @param members
- * Is members only
- * @param flag
- * The world's flag
- * @param favorite
- * Is a favorite world
- * @param activity
- * The activity
- * @param lootShare
- * Is lootshare enabled
- * @param ping
- * The ping
- * @param playerCount
- * The number of players
- */
- public World(int number, boolean members, World_Flag flag,
- boolean favorite, String activity, boolean lootShare, int ping,
- int playerCount) {
- this.number = number;
- this.members = members;
- this.flag = flag;
- this.favorite = favorite;
- this.activity = activity;
- this.lootShare = lootShare;
- this.ping = ping;
- this.playerCount = playerCount;
- }
- /**
- * Gets the minimum skill total
- *
- * @return The minimum skill total to login to this world
- */
- public int getMinimumTotalLevel() {
- if (activity.toLowerCase().contains("skill total"))
- return Integer.valueOf(activity.substring(
- activity.indexOf("(") + 1, activity.indexOf(")")));
- return -1;
- }
- }
- /**
- * Refreshes the list of worlds
- *
- * @return did refresh
- */
- public boolean refreshWorlds() {
- openTab(TAB_WORLDS);
- RSComponent refresh = interfaces.getComponent(WORLD_INTERFACE,
- WORLDS_REFRESH);
- return refresh != null && refresh.isValid() && refresh.doClick();
- }
- /**
- * World Flags
- *
- * @author Equinox_
- */
- public enum World_Flag {
- Australia(1513), Belgium(1518), Canada(1512), Denmark(1521), Finland(
- 1516), Lithuania(3806), Mexico(1526), Netherlands(1514), NewZeland(
- 1520), Norway(1519), Poland(3805), RIS(2173), Spain(3807), Sweden(
- 1515), UnitedKingdom(1511), UnitedStates(1510);
- final int texID;
- private World_Flag(int texID) {
- this.texID = texID;
- }
- }
- /**
- * Gets all of your friends
- *
- * @return All your friends
- */
- public Friend[] getFriends() {
- if (openTab(TAB_FRIENDS)) {
- List<Friend> list = new ArrayList<Friend>();
- RSComponent fList = interfaces.getComponent(FRIENDS_INTERFACE,
- FRIEND_NAMES);
- RSComponent wList = interfaces.getComponent(FRIENDS_INTERFACE,
- FRIEND_WORLDS);
- if (fList != null && wList != null && fList.isValid()
- && wList.isValid()) {
- RSComponent[] names = fList.getComponents();
- RSComponent[] worlds = wList.getComponents();
- if (names != null && worlds != null)
- for (int i = 0; i < Math.min(names.length, worlds.length); i++) {
- RSComponent nCp = fList.getComponent(i);
- RSComponent wCp = wList.getComponent(i);
- String name = null, world = null;
- if (nCp != null && nCp.getText() != null)
- name = nCp.getText();
- if (wCp != null && wCp.getText() != null)
- world = wCp.getText().toLowerCase();
- if (name != null && world != null) {
- String wID = world.contains(" ") ? world
- .substring(world.lastIndexOf(" ") + 1)
- : "offline";
- int worldNumber = -1;
- try {
- worldNumber = Integer.valueOf(wID);
- } catch (NumberFormatException e) {
- worldNumber = -1;
- }
- FriendsWorldType type = FriendsWorldType.FunOrb;
- if (world.contains("runescape"))
- type = FriendsWorldType.Runescape;
- else if (world.contains("lobby"))
- type = FriendsWorldType.Lobby;
- else if (world.contains("offline"))
- type = FriendsWorldType.None;
- list.add(new Friend(name.trim(), worldNumber, type));
- }
- }
- }
- return list.toArray(new Friend[list.size()]);
- }
- return null;
- }
- public static class Friend {
- final int world;
- final FriendsWorldType type;
- final String name;
- public Friend(String name, int world, FriendsWorldType type) {
- this.world = world;
- this.name = name;
- this.type = type;
- }
- }
- public enum FriendsWorldType {
- Runescape, FunOrb, None, Lobby
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment