|
| 1 | +import org.osbot.rs07.api.ui.Message; |
| 2 | +import org.osbot.rs07.script.Script; |
| 3 | +import org.osbot.rs07.script.ScriptManifest; |
| 4 | +import util.MuleSettings; |
| 5 | +import util.customevents.DisableAudioEvent; |
| 6 | +import util.customevents.LoginEvent; |
| 7 | +import util.gamehandlers.TradeHandler; |
| 8 | +import util.timers.Time; |
| 9 | +import util.timers.Timer; |
| 10 | + |
| 11 | +import java.awt.*; |
| 12 | +import java.awt.event.KeyEvent; |
| 13 | +import java.util.ArrayList; |
| 14 | +import java.util.List; |
| 15 | + |
| 16 | +/** |
| 17 | + * Usage: |
| 18 | + * Local based mule handling |
| 19 | + * |
| 20 | + * Execute with parameters -allow norandoms |
| 21 | + * -script MuleScript:user_pass |
| 22 | + * |
| 23 | + * |
| 24 | + * |
| 25 | + * |
| 26 | + */ |
| 27 | +@ScriptManifest(name = "MuleScript", version = 1.0, author = "Chris", logo = "", info = "Mule until 30mins is up") |
| 28 | +public class Main extends Script { |
| 29 | + |
| 30 | + private MuleSettings muleSettings; |
| 31 | + private TradeHandler tradeHandler; |
| 32 | + private LoginEvent loginEvent; |
| 33 | + private DisableAudioEvent disableAudioEvent; |
| 34 | + private List<String> cacheRequests; |
| 35 | + private long startTime; |
| 36 | + private String status = "N/A", username, password, requestor; |
| 37 | + private Timer antiLogout, closeScriptTimer; |
| 38 | + private int tradesCompleted = 0, ticks = 0; |
| 39 | + |
| 40 | + @Override |
| 41 | + public void onStart() throws InterruptedException { |
| 42 | + // Idling sleep before starting |
| 43 | + sleep(7000); |
| 44 | + String parameters = getParameters(); |
| 45 | + |
| 46 | + if (parameters != null) { |
| 47 | + String[] param = parameters.split("_"); |
| 48 | + status = "Grabbing login info"; |
| 49 | + |
| 50 | + username = param[0]; |
| 51 | + password = param[1]; |
| 52 | + tradeHandler = new TradeHandler(getBot()); |
| 53 | + |
| 54 | + status = "Logging in to the game"; |
| 55 | + loginEvent = new LoginEvent(username, password); |
| 56 | + disableAudioEvent = new DisableAudioEvent(); |
| 57 | + |
| 58 | + getBot().addLoginListener(loginEvent); |
| 59 | + execute(loginEvent); |
| 60 | + status = "Logged in"; |
| 61 | + sleep(5000); |
| 62 | + |
| 63 | + // Save a mule file |
| 64 | + muleSettings = new MuleSettings(this, (myPlayer().getName() + ".txt")); |
| 65 | + muleSettings.saveSettings(myPlayer().getName(), getWorlds().getCurrentWorld(), myPosition()); |
| 66 | + |
| 67 | + // Set timer variables |
| 68 | + antiLogout = new Timer(270_000); |
| 69 | + closeScriptTimer = new Timer(30 * 60_000); |
| 70 | + startTime = System.currentTimeMillis(); |
| 71 | + getCamera().toTop(); |
| 72 | + execute(disableAudioEvent); |
| 73 | + |
| 74 | + // setup cache |
| 75 | + cacheRequests = new ArrayList<>(); |
| 76 | + cacheRequests.add(myPlayer().getName()); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public int onLoop() throws InterruptedException { |
| 82 | + if (!getClient().isLoggedIn()) { |
| 83 | + execute(loginEvent); |
| 84 | + return 200; |
| 85 | + } |
| 86 | + |
| 87 | + // If timer is done (30mins) close the client |
| 88 | + if (closeScriptTimer != null && !closeScriptTimer.isRunning()) { |
| 89 | + stop(true); |
| 90 | + return 600; |
| 91 | + } |
| 92 | + |
| 93 | + // Checks for last trade request & handles other logic |
| 94 | + requestor = getTrade().getLastRequestingPlayer() != null ? getTrade().getLastRequestingPlayer().getName() : null; |
| 95 | + if (tradeHandler.isTrading()) { |
| 96 | + requestor = null; |
| 97 | + status = "In trade"; |
| 98 | + if (ticks > 50){ |
| 99 | + if (tradeHandler.declineTrade()) |
| 100 | + sleep(2000); |
| 101 | + } else { |
| 102 | + tradeHandler.acceptFrom(null); |
| 103 | + } |
| 104 | + } else if (requestor != null && !cacheRequests.contains(requestor)) { |
| 105 | + status = "Trading " + requestor; |
| 106 | + if (tradeHandler.sentTradeRequest(requestor)) |
| 107 | + cacheRequests.add(requestor); |
| 108 | + } else { |
| 109 | + if (antiLogout != null && !antiLogout.isRunning()) { |
| 110 | + status = "Staying logged in..."; |
| 111 | + int id = random(0, 2) == 1 ? KeyEvent.VK_RIGHT : KeyEvent.VK_LEFT; |
| 112 | + getKeyboard().pressKey(id); |
| 113 | + sleep(random(50, 250)); |
| 114 | + getKeyboard().releaseKey(id); |
| 115 | + antiLogout.reset(); |
| 116 | + } |
| 117 | + status = "Waiting for new request..."; |
| 118 | + } |
| 119 | + return 1000; |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public void onExit() throws InterruptedException { |
| 124 | + // Reset the file then close the client. |
| 125 | + muleSettings.reset(); |
| 126 | + System.exit(0); |
| 127 | + } |
| 128 | + |
| 129 | + @Override |
| 130 | + public void onMessage(Message msg) throws InterruptedException { |
| 131 | + if (msg.getType() == Message.MessageType.GAME) { |
| 132 | + if (msg.getMessage().equals("Accepted trade.")) { |
| 133 | + log("Trade done."); |
| 134 | + sleep(3000); |
| 135 | + status = "Finished trade"; |
| 136 | + tradesCompleted++; |
| 137 | + ticks = 0; |
| 138 | + requestor = null; |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + public void onPaint(Graphics2D graphics) { |
| 145 | + graphics.setColor(Color.ORANGE); |
| 146 | + long realRunTime = System.currentTimeMillis() - this.startTime; |
| 147 | + graphics.drawString("Runtime: " + Time.format(realRunTime), 20, 50); |
| 148 | + graphics.drawString("Status: " + this.status, 20, 70); |
| 149 | + graphics.drawString("Trades Done: " + this.tradesCompleted, 20, 90); |
| 150 | + Point mP = getMouse().getPosition(); |
| 151 | + graphics.drawLine(mP.x - 3, mP.y + 3, mP.x + 3, mP.y - 3); |
| 152 | + graphics.drawLine(mP.x + 3, mP.y + 3, mP.x - 3, mP.y - 3); |
| 153 | + graphics.drawString("(" + mP.x + "," + mP.y + ")", mP.x, mP.y); |
| 154 | + } |
| 155 | +} |
0 commit comments