Created
September 17, 2022 10:30
-
-
Save Magnusrn/113e7ce08ddd03441d392cc5c0a4adc6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 net.unethicalite; | |
| import javax.inject.Inject; | |
| import javax.swing.*; | |
| import lombok.extern.slf4j.Slf4j; | |
| import lombok.val; | |
| import net.runelite.api.*; | |
| import net.runelite.api.coords.WorldArea; | |
| import net.runelite.api.coords.WorldPoint; | |
| import net.runelite.api.events.GameTick; | |
| import net.runelite.api.queries.GameObjectQuery; | |
| import net.runelite.api.widgets.Widget; | |
| import net.runelite.api.widgets.WidgetID; | |
| import net.runelite.api.widgets.WidgetInfo; | |
| import net.runelite.client.config.ConfigManager; | |
| import net.runelite.client.eventbus.Subscribe; | |
| import net.runelite.client.plugins.Plugin; | |
| import net.runelite.client.plugins.PluginDescriptor; | |
| import net.runelite.client.plugins.PluginManager; | |
| import net.unethicalite.api.entities.NPCs; | |
| import net.unethicalite.api.entities.Players; | |
| import net.unethicalite.api.entities.TileItems; | |
| import net.unethicalite.api.entities.TileObjects; | |
| import net.unethicalite.api.game.Worlds; | |
| import net.unethicalite.api.input.Keyboard; | |
| import net.unethicalite.api.items.Inventory; | |
| import net.unethicalite.api.movement.Movement; | |
| import java.awt.*; | |
| import java.awt.event.KeyEvent; | |
| import java.awt.event.KeyEvent.*; | |
| import net.unethicalite.api.plugins.Plugins; | |
| import org.pf4j.Extension; | |
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.Comparator; | |
| import java.util.List; | |
| import java.util.stream.Collectors; | |
| import static java.awt.event.KeyEvent.*; | |
| import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_INSTRUCTION_TEXT; | |
| @Extension | |
| @PluginDescriptor( | |
| name = "Cross Boosting Plugin", | |
| description = "wc/fm east varrock") | |
| @Slf4j | |
| public class CrossBoostingPlugin extends Plugin { | |
| @Inject | |
| private Client client; | |
| @Inject | |
| private PluginManager pluginManager; | |
| @Inject | |
| private ConfigManager configManager; | |
| private boolean firemaking = false; | |
| private int timeout = 0; | |
| @Override | |
| protected void startUp() { | |
| firemaking = false; | |
| configManager.setConfiguration("bank", "bankPinKeyboard", true); | |
| } | |
| @Subscribe | |
| private void onGameTick(GameTick gameTick) { | |
| if (shouldHop()) | |
| { | |
| print("Hopping as more than allowed fires exist"); | |
| hopWorld(); | |
| timeout = 5; | |
| return; | |
| } | |
| print("firemaking " + firemaking); | |
| if (timeout>0) | |
| { | |
| print("timeout : " + timeout); | |
| timeout--; | |
| return; | |
| } | |
| if (client.getRealSkillLevel(Skill.FIREMAKING) > 49) | |
| { | |
| print("firemaking completed(level 50): true"); | |
| fmCompletedHandler(); | |
| return; | |
| } | |
| if (client.getLocalPlayer().isMoving() || !Players.getLocal().isIdle()) | |
| { | |
| print("player is not idle or is busy"); | |
| return; | |
| } | |
| if (!(Inventory.contains("Logs") || Inventory.contains("Oak logs"))) | |
| { | |
| print("inventory empty so disabling firemaking"); | |
| firemaking = false; | |
| } | |
| if (shouldFiremake() && firemaking) | |
| { | |
| print("firemaking as in correct location and logs in invent"); | |
| firemakingHandler(); | |
| return; | |
| } | |
| if (Inventory.isFull()) | |
| { | |
| moveToFiremakingStartTile(); | |
| print("inventory full, moving to firemaking start tile"); | |
| return; | |
| } | |
| if (!firemaking) | |
| { | |
| print("woodcutting handler"); | |
| woodcuttingHandler(); | |
| } | |
| print("not firemaking, invent is not full and shouldn't firemake"); | |
| } | |
| private void print(String msg) { | |
| // return; | |
| client.addChatMessage(ChatMessageType.GAMEMESSAGE, "", msg, ""); | |
| } | |
| private void woodcuttingHandler() { | |
| //prevent accessing trees behind fence and ones tht would be botlike, not sure if unethical api has is reachable within getobjects | |
| WorldArea treeArea = new WorldArea(new WorldPoint(3270, 3408, 0), new WorldPoint(3286, 3457, 0)); | |
| String treeName = client.getRealSkillLevel(Skill.WOODCUTTING) > 14 ? "Oak" : "Tree"; | |
| GameObject tree = new GameObjectQuery() | |
| .nameEquals(treeName) | |
| .result(client) | |
| .stream().filter(t -> t.getWorldLocation().isInArea(treeArea)) | |
| .min(Comparator.comparing(t -> t.getWorldLocation().distanceTo(client.getLocalPlayer().getWorldLocation()))) | |
| .orElse(null); | |
| if (tree == null) return; | |
| tree.interact("Chop down"); | |
| } | |
| private void firemakingHandler() { | |
| //if fire exists in lane move to another | |
| List<TileObject> fires = TileObjects.getAll("Fire"); | |
| TileObject activeFire = fires.stream() | |
| .filter(fire-> fire.getWorldY()==client.getLocalPlayer().getWorldY()) | |
| .filter(fire-> fire.getWorldX()<client.getLocalPlayer().getWorldX()) | |
| .findAny() | |
| .orElse(null); | |
| print(String.valueOf(activeFire)); | |
| if (activeFire!=null) | |
| { | |
| client.addChatMessage(ChatMessageType.GAMEMESSAGE,"","fire already exists west of player, moving to new lane start",""); | |
| moveToFiremakingStartTile(); | |
| return; | |
| } | |
| Item log = Inventory.getFirst("Oak logs", "Logs"); | |
| if (log != null) { | |
| log.useOn(Inventory.getFirst("Tinderbox")); | |
| } | |
| } | |
| private boolean shouldFiremake() { | |
| if (Inventory.contains("Logs") || Inventory.contains("Oak logs")) | |
| { | |
| switch (client.getLocalPlayer().getWorldY()) { | |
| case 3249: | |
| case 3427: | |
| case 3428: | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| private boolean shouldHop() { | |
| print("Total amount of fires: " + TileObjects.getAll("Fire").size()); | |
| return TileObjects.getAll("Fire").size()>21; | |
| } | |
| private void moveToFiremakingStartTile() { | |
| firemaking = true; | |
| ArrayList<WorldPoint> startTiles = | |
| new ArrayList<>(Arrays.asList(new WorldPoint(3291, 3427, 0), new WorldPoint(3291, 3428, 0), new WorldPoint(3291, 3429, 0))); | |
| //pretty shitty but only runs once on initial full invent so doesn't really matter, cba doing difficult to read streams | |
| //boolean correlates to 3427,3428,3249 | |
| List<Boolean> emptyPath = new ArrayList<>(Arrays.asList(true, true, true)); | |
| List<TileObject> fires = TileObjects.getAll("Fire"); | |
| print("iterating over fires"); | |
| for (TileObject fire : fires) { | |
| switch (fire.getWorldY()) { | |
| case 3427: | |
| emptyPath.set(0, false); | |
| break; | |
| case 3428: | |
| emptyPath.set(1, false); | |
| break; | |
| case 3429: | |
| emptyPath.set(2, false); | |
| break; | |
| default: | |
| } | |
| } | |
| print(String.valueOf(emptyPath)); | |
| if (emptyPath.get(0)) Movement.walk(startTiles.get(0)); | |
| else if (emptyPath.get(1)) Movement.walk(startTiles.get(1)); | |
| else if (emptyPath.get(2)) Movement.walk(startTiles.get(2)); | |
| } | |
| private void fmCompletedHandler() { | |
| Widget pinWidget = client.getWidget(213,7); | |
| if (pinWidget != null) | |
| { | |
| print("entering pin"); | |
| pinHandler(); | |
| return; | |
| } | |
| WorldArea bank = new WorldArea(new WorldPoint(3249,3418,0), new WorldPoint(3259,3426,0)); | |
| if (!client.getLocalPlayer().getWorldLocation().isInArea(bank)) | |
| { | |
| print("walking to banker"); | |
| Movement.walkTo(new WorldPoint(3254,3420,0)); | |
| return; | |
| } | |
| Widget bankPinSettings = client.getWidget(14,22); | |
| Widget confirmDeletion = client.getWidget(14,33); | |
| Widget bankPinStatus = client.getWidget(14,6); | |
| if (bankPinStatus!=null && bankPinStatus.getText().equals("No PIN set")) | |
| { | |
| print("disabling plugin as pin has been removed"); | |
| disablePlugin(); | |
| return; | |
| } | |
| if (confirmDeletion!=null && confirmDeletion.isVisible()) { | |
| print("hidden" + confirmDeletion.isHidden()); | |
| print("pin deletion confirmation is open, selecting confirm"); | |
| client.invokeMenuAction("Continue", "", 0, MenuAction.WIDGET_CONTINUE.getId(), -1, 917537); | |
| return; | |
| } | |
| if (bankPinSettings!=null) | |
| { | |
| print("pin box is open, selecting remove pin"); | |
| client.invokeMenuAction("Continue", "", 0, MenuAction.WIDGET_CONTINUE.getId(), -1, 917527); | |
| return; | |
| } | |
| Widget bankerChat1 = client.getWidget(231,6); | |
| Widget bankerChat2 = client.getWidget(219,1); | |
| if (bankerChat2!=null && bankerChat2.getChild(0)!=null && bankerChat2.getChild(0).getText().equals("Select an Option")) | |
| { | |
| print("selecting pin settings dialog"); | |
| client.invokeMenuAction("Continue", "", 0, MenuAction.WIDGET_CONTINUE.getId(), 2, WidgetInfo.DIALOG_OPTION_OPTION1.getId()); | |
| return; | |
| } | |
| if (bankerChat1!=null) | |
| { | |
| print("continuing dialog"); | |
| client.invokeMenuAction("Continue", "", 0, MenuAction.WIDGET_CONTINUE.getId(), -1, 15138821); | |
| return; | |
| } | |
| print("interacting with banker"); | |
| NPC banker = NPCs.getNearest("Banker"); | |
| banker.interact("Talk-to"); | |
| } | |
| private void pinHandler() { | |
| Widget pinWidget = client.getWidget(BANK_PIN_INSTRUCTION_TEXT); | |
| if (pinWidget == null) return; | |
| switch (pinWidget.getText()) { | |
| case "First click the FIRST digit.": | |
| case "Time for the THIRD digit.": | |
| print("first or 3rd key"); | |
| Keyboard.type(2); | |
| return; | |
| case "Now click the SECOND digit.": | |
| case "Finally, the FOURTH digit.": | |
| print("2nd or 4th key"); | |
| Keyboard.type(0); | |
| } | |
| } | |
| private void disablePlugin() { | |
| for (Plugin plugin : pluginManager.getPlugins()) | |
| { | |
| if (plugin.getName().equals("Ammo")) | |
| { | |
| SwingUtilities.invokeLater(()-> | |
| { | |
| Plugins.startPlugin(plugin); | |
| Plugins.stopPlugin(this); | |
| }); | |
| } | |
| } | |
| } | |
| private void hopWorld() { | |
| Worlds.loadWorlds(); | |
| World world = Worlds.getRandom(w->!w.isMembers() && w.isNormal()); | |
| Worlds.hopTo(world); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment