Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.runelite.client.plugins.wildyHelper;
- import javax.inject.Inject;
- import javax.inject.Singleton;
- import lombok.extern.slf4j.Slf4j;
- import net.runelite.api.*;
- import net.runelite.api.events.ChatMessage;
- import net.runelite.api.events.GameObjectSpawned;
- import net.runelite.api.events.GameTick;
- import net.runelite.api.events.ProjectileSpawned;
- import net.runelite.api.widgets.Widget;
- import net.runelite.api.widgets.WidgetInfo;
- import net.runelite.client.chat.ChatMessageManager;
- import net.runelite.client.eventbus.EventBus;
- import net.runelite.client.eventbus.Subscribe;
- import net.runelite.client.plugins.Plugin;
- import net.runelite.client.plugins.PluginDescriptor;
- import net.runelite.client.game.WorldService;
- import net.runelite.client.util.WorldUtil;
- import net.runelite.http.api.worlds.World;
- import net.runelite.http.api.worlds.WorldResult;
- import net.runelite.http.api.worlds.WorldType;
- import java.util.EnumSet;
- import java.util.List;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- @PluginDescriptor(
- loadWhenOutdated = true, // prevent users from disabling
- hidden = false, // prevent users from disabling
- name = "Wildy Helper by Sehyo"
- )
- @Singleton
- @Slf4j
- public class WildyHelperPlugin extends Plugin
- {
- private net.runelite.api.World quickHopTargetWorld = null;
- private Integer maxWildyLevel = -1;
- private Integer minWildyLevel = -1;
- @Inject
- private Client client;
- @Inject
- private EventBus eventBus;
- @Inject
- private WorldService worldService;
- @Inject
- private ChatMessageManager chatMessageManager;
- @Subscribe
- private void onChatMessage(ChatMessage event)
- {
- // Event handling for chat messages.
- // Maybe check if they contain our username or smth and nudge client.
- }
- @Subscribe
- private void onGameTick(GameTick event)
- {
- if(quickHopTargetWorld != null)
- {
- client.openWorldHopper();
- log.info("Hopping to world " + quickHopTargetWorld.getId());
- client.hopToWorld(quickHopTargetWorld);
- quickHopTargetWorld = null;
- }
- if(setWildyLevels() == 1) // See if we are in wildy.
- {
- if (client.getPlayers().size() > 1)
- {
- log.info("Other player detected.\nChecking if they are within attackable levels.");
- boolean attackablePlayerExists = false;
- for(Player player : client.getPlayers())
- {
- if(player.isClanMember() || player.isFriend()) continue;
- if(player == client.getLocalPlayer()) continue;
- if(player.getCombatLevel() >= minWildyLevel && player.getCombatLevel() <= maxWildyLevel)
- {
- attackablePlayerExists = true;
- break;
- }
- }
- if(attackablePlayerExists)
- {
- hop(false);
- }
- }
- }
- }
- @Subscribe
- private void onGameObjectSpawned(GameObjectSpawned event)
- {
- //
- }
- @Subscribe
- private void onProjectileSpawned(ProjectileSpawned event)
- {
- //
- }
- // Sets minWildyLevel and maxWildyLevel vars.
- // Also returns 0 if we are not in wildy, or 1 if we are.
- private int setWildyLevels()
- {
- final Widget wildernessLevelWidget = client.getWidget(WidgetInfo.PVP_WILDERNESS_LEVEL);
- if(wildernessLevelWidget == null) return 0; // Level 0 means not in wildy.
- int lowerLevel, higherLevel;
- final String wildernessLevelText = wildernessLevelWidget.getText();
- log.info("Wildy text:\n" + wildernessLevelText);
- String regex = "<br>(.*?)(.*)";
- Pattern pattern = Pattern.compile(regex);
- final Matcher matcher = pattern.matcher(wildernessLevelText);
- if(!matcher.find()) return 0;
- log.info("group is: " + matcher.group(2));
- String[] levels = matcher.group(2).split("-");
- minWildyLevel = Integer.parseInt(levels[0]);
- maxWildyLevel = Integer.parseInt(levels[1]);
- return 1;
- }
- // Mostly copy pasted from the WorldHopper plugin, thx.
- private void hop(int worldId)
- {
- WorldResult worldResult = worldService.getWorlds();
- // Don't try to hop if the world doesn't exist
- World world = worldResult.findWorld(worldId);
- if (world == null)
- {
- return;
- }
- final net.runelite.api.World rsWorld = client.createWorld();
- rsWorld.setActivity(world.getActivity());
- rsWorld.setAddress(world.getAddress());
- rsWorld.setId(world.getId());
- rsWorld.setPlayerCount(world.getPlayers());
- rsWorld.setLocation(world.getLocation());
- rsWorld.setTypes(WorldUtil.toWorldTypes(world.getTypes()));
- if (client.getGameState() == GameState.LOGIN_SCREEN)
- {
- // on the login screen we can just change the world by ourselves
- client.changeWorld(rsWorld);
- return;
- }
- log.info("Hopping to world " + world.getId());
- quickHopTargetWorld = rsWorld;
- }
- // Mostly copy pasted from the WorldHopper plugin, thx.
- private void hop(boolean previous)
- {
- WorldResult worldResult = worldService.getWorlds();
- if(worldResult == null || client.getGameState() != GameState.LOGGED_IN)
- return;
- World currentWorld = worldResult.findWorld(client.getWorld());
- if(currentWorld == null) return;
- EnumSet<WorldType> currentWorldTypes = currentWorld.getTypes().clone();
- currentWorldTypes.remove(WorldType.PVP);
- currentWorldTypes.remove(WorldType.HIGH_RISK);
- currentWorldTypes.remove(WorldType.BOUNTY);
- currentWorldTypes.remove(WorldType.SKILL_TOTAL);
- currentWorldTypes.remove(WorldType.LAST_MAN_STANDING);
- List<World> worlds = worldResult.getWorlds();
- int worldIdx = worlds.indexOf(currentWorld);
- int totalLevel = client.getTotalLevel();
- World world;
- int iters = 0;
- do
- {
- if(previous)
- {
- worldIdx--;
- if (worldIdx < 0) worldIdx = worlds.size() - 1;
- }
- else
- {
- worldIdx++;
- if (worldIdx >= worlds.size())
- worldIdx = 0;
- }
- log.info("Did " + iters + " iterations searching for world.");
- log.info("Worlds size is: " + worlds.size());
- world = worlds.get(worldIdx);
- EnumSet<WorldType> types = world.getTypes().clone();
- types.remove(WorldType.BOUNTY);
- types.remove(WorldType.LAST_MAN_STANDING);
- if(types.contains(WorldType.SKILL_TOTAL))
- {
- try {
- int totalRequirement = Integer.parseInt(world.getActivity().substring(0, world.getActivity().indexOf(" ")));
- if (totalLevel >= totalRequirement) {
- types.remove(WorldType.SKILL_TOTAL);
- }
- } catch (NumberFormatException ex) {
- log.warn("Failed to parse total level requirement for target world", ex);
- }
- }
- // Break out if we've found a good world to hop to
- if (currentWorldTypes.equals(types))
- {
- log.info("Breaking out because world types are equals.");
- log.info("Found world id: " + world.getId());
- log.info("Current world id: " + currentWorld.getId());
- break;
- }
- if(world == currentWorld)
- {
- log.info("Breaking out because worlds match.");
- }
- } while(world != currentWorld);
- if (world == currentWorld)
- log.info("Couldn't find world to hop to!");
- else
- hop(world.getId());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement