Skip to content

Commit 8c5fb29

Browse files
Update
- Added MulingScript
1 parent 256bb9e commit 8c5fb29

File tree

9 files changed

+926
-0
lines changed

9 files changed

+926
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package util;
2+
3+
import org.osbot.rs07.api.map.Position;
4+
import org.osbot.rs07.script.Script;
5+
6+
import java.io.File;
7+
import java.io.FileInputStream;
8+
import java.io.FileOutputStream;
9+
import java.io.IOException;
10+
import java.util.Properties;
11+
12+
/**
13+
* Created by Chris on 03/06/2018.
14+
*/
15+
public class MuleSettings {
16+
17+
private final Properties prop;
18+
private File file;
19+
private String name, filePath;
20+
private int world;
21+
private Position tile;
22+
23+
public MuleSettings(final Script bot, final String fileName) {
24+
this.prop = new Properties();
25+
this.filePath = bot.getDirectoryData() + fileName;
26+
this.file = new File(filePath);
27+
try {
28+
if (!file.exists()) {
29+
if (file.createNewFile()) {
30+
bot.log("Creating new file. file did not exist. params: null, 0, (0,0,0)");
31+
saveSettings("null", 0, new Position(0, 0, 0));
32+
}
33+
} else bot.log("Mule File: " + fileName + " exists.");
34+
} catch (Exception e1) {
35+
e1.printStackTrace();
36+
}
37+
}
38+
39+
/**
40+
* @param name - RSPlayer.getName();
41+
* @param world - Worlds.getCurrentWorld();
42+
* @param tile - Position.getPosition();
43+
* @Description -
44+
* 1) Clears the prop cache
45+
* 2) Saves parameter data to file
46+
*/
47+
public void saveSettings(final String name, final int world, final Position tile) {
48+
if (!prop.isEmpty())
49+
prop.clear();
50+
51+
String coords = "" + tile.getX() + "," + tile.getY() + "," + tile.getZ();
52+
prop.put("name", name);
53+
prop.put("world", Integer.toString(world));
54+
prop.put("tile", coords);
55+
56+
try {
57+
prop.store(new FileOutputStream(file), "Mule Settings");
58+
} catch (IOException e) {
59+
e.printStackTrace();
60+
}
61+
}
62+
63+
64+
/**
65+
* @Description -
66+
* 1) Clears the prop cache
67+
* 2) Reads and loads the file from C/Users/You/OSBot/Data
68+
* 3) Sets MuleSettings instance variables
69+
*/
70+
public void loadSettings() {
71+
this.file = new File(filePath);
72+
73+
if (!prop.isEmpty())
74+
prop.clear();
75+
76+
try {
77+
prop.load(new FileInputStream(file));
78+
} catch (IOException e) {
79+
e.printStackTrace();
80+
}
81+
82+
String[] coords = prop.getProperty("tile").split(",");
83+
setName(prop.getProperty("name"));
84+
setWorld(Integer.parseInt(prop.getProperty("world")));
85+
setTile(new Position(Integer.parseInt(coords[0]), Integer.parseInt(coords[1]), Integer.parseInt(coords[2])));
86+
}
87+
88+
@Override
89+
public String toString() {
90+
return "[MULE INITIATED]\nname="+this.name+",world="+this.world+",position="+this.tile;
91+
}
92+
93+
/**
94+
* @Description -
95+
* 1) Call #loadSettings() *See method doc*
96+
* 2) Checks if instance variables meet the condition
97+
*/
98+
public boolean canMule(){
99+
return this.name != null && !this.name.equals("null") && this.world != 0;
100+
}
101+
102+
/**
103+
* @Description -
104+
* 1) Resets file to default parameters
105+
*/
106+
public void reset() {
107+
saveSettings("null", 0, new Position(0, 0, 0));
108+
}
109+
110+
111+
public String getName() {
112+
return name;
113+
}
114+
115+
private void setName(String name) {
116+
this.name = name;
117+
}
118+
119+
public int getWorld() {
120+
return world;
121+
}
122+
123+
private void setWorld(int world) {
124+
this.world = world;
125+
}
126+
127+
public Position getTile() {
128+
return tile;
129+
}
130+
131+
private void setTile(Position tile) {
132+
this.tile = tile;
133+
}
134+
135+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package util.customevents;
2+
3+
import org.osbot.rs07.api.ui.Tab;
4+
import org.osbot.rs07.event.Event;
5+
import util.wrappers.CachedWidget;
6+
import util.wrappers.WidgetActionFilter;
7+
8+
public final class DisableAudioEvent extends Event {
9+
10+
private final CachedWidget soundSettingsWidget = new CachedWidget(new WidgetActionFilter("Audio"));
11+
private final CachedWidget musicVolumeWidget = new CachedWidget(new WidgetActionFilter("Adjust Music Volume"));
12+
private final CachedWidget soundEffectVolumeWidget = new CachedWidget(new WidgetActionFilter("Adjust Sound Effect Volume"));
13+
private final CachedWidget areaSoundEffectVolumeWidget = new CachedWidget(new WidgetActionFilter("Adjust Area Sound Effect Volume"));
14+
15+
private static final int musicVolumeConfig = 168;
16+
private static final int soundEffectVolumeConfig = 169;
17+
private static final int areaSoundEffectVolumeConfig = 872;
18+
19+
@Override
20+
public final int execute() throws InterruptedException {
21+
if (Tab.SETTINGS.isDisabled(getBot())) {
22+
setFailed();
23+
} else if (getTabs().getOpen() != Tab.SETTINGS) {
24+
getTabs().open(Tab.SETTINGS);
25+
} else if (!musicVolumeWidget.get(getWidgets()).isPresent()) {
26+
soundSettingsWidget.get(getWidgets()).ifPresent(widget -> widget.interact());
27+
} else if (!isVolumeDisabled(musicVolumeConfig)) {
28+
musicVolumeWidget.get(getWidgets()).ifPresent(widget -> widget.interact());
29+
} else if (!isVolumeDisabled(soundEffectVolumeConfig)) {
30+
soundEffectVolumeWidget.get(getWidgets()).ifPresent(widget -> widget.interact());
31+
} else if (!isVolumeDisabled(areaSoundEffectVolumeConfig)) {
32+
areaSoundEffectVolumeWidget.get(getWidgets()).ifPresent(widget -> widget.interact());
33+
} else {
34+
setFinished();
35+
}
36+
return 200;
37+
}
38+
39+
public boolean isVolumeDisabled(final int config) {
40+
return getConfigs().get(config) == 4;
41+
}
42+
}

0 commit comments

Comments
 (0)