Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
84436b5
Added an option for the "DisconnectModule" module to be able to close…
dm94 Jul 2, 2023
e087897
Added the console log of why the bot closes.
dm94 Jul 2, 2023
2b86884
The bot will now show a pop-up warning the user that the bot will be …
dm94 Jul 2, 2023
45eb232
Now it will show the pop-up only when the bot is to be closed.
dm94 Jul 3, 2023
d583a85
Merge branch 'master' into master
dm94 Jul 5, 2023
044764e
Merge branch 'darkbot-reloaded:master' into master
dm94 Jul 20, 2023
1a59564
Merge branch 'darkbot-reloaded:master' into master
dm94 Jul 22, 2023
fd9d85e
Merge branch 'darkbot-reloaded:master' into master
dm94 Jul 25, 2023
6eb94eb
fix: Now it will not open the popup when creating DisconnectModule
dm94 Jul 26, 2023
45fe474
Merge branch 'darkbot-reloaded:master' into master
dm94 Jul 28, 2023
d0300bc
Merge branch 'master' into master
dm94 Jul 30, 2023
3548d02
Merge branch 'darkbot-reloaded:master' into master
dm94 Aug 14, 2023
f0fbd0d
Merge branch 'master' of https://github.com/dm94/DarkBot
dm94 Jan 4, 2024
73f05bc
Merge branch 'master' of https://github.com/dm94/DarkBot
dm94 Jan 12, 2024
11dcb6d
Merge branch 'master' of https://github.com/dm94/DarkBot
dm94 Jan 15, 2024
1328a1f
Merge branch 'darkbot-reloaded:master' into master
dm94 Jan 29, 2024
aa46f74
Merge branch 'darkbot-reloaded:master' into master
dm94 Sep 3, 2024
9035e8a
feat(StarBuilder): add weight support for portals in star graph
dm94 Sep 18, 2025
22fb755
Merge branch 'master' into feat/portals-weight
dm94 Sep 18, 2025
93f18e5
Merge branch 'master' into feat/portals-weight
dm94 Dec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/main/java/com/github/manolo8/darkbot/core/entities/Portal.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,35 @@ public class Portal extends Entity implements eu.darkbot.api.game.entities.Porta

public final Map target;
public final int factionId;
public final double weight;
private final PortalMatcher matcher;
public boolean isJumping;
public int type;

public Portal(int id, int type, int x, int y) {
this(id, type, x, y, null, -1);
this(id, type, x, y, null, -1, 1.0);
}

public Portal(int searchType, int searchX, int searchY, Map target, int factionId) {
this(-1, searchType, searchX, searchY, target, factionId);
this(searchType, searchX, searchY, target, factionId, 1.0);
}

public Portal(int searchType, int searchX, int searchY, Map target, int factionId, double weight) {
this(-1, searchType, searchX, searchY, target, factionId, weight);
}

public Portal(int id, int searchType, int searchX, int searchY, Map target, int factionId) {
this(id, searchType, searchX, searchY, target, factionId, 1.0);
}

public Portal(int id, int searchType, int searchX, int searchY, Map target, int factionId, double weight) {
super(id);
this.matcher = new PortalMatcher(searchType, searchX, searchY, target != null && target.id == 71);

super.removed = true;
this.target = target;
super.removed = true;
this.target = target;
this.factionId = factionId;
this.weight = weight;
}

public boolean matches(int x, int y, int type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ private static class TempMap {
private static class TempPort {
private final int x, y, type, factionId;
private final String targetMap;
private final double weight;

TempPort(int x, int y, int type, int factionId, String targetMap) {
this(x, y, type, factionId, targetMap, 1.0);
}

TempPort(int x, int y, int type, int factionId, String targetMap, double weight) {
this.x = x;
this.y = y;
this.type = type;
this.factionId = factionId;
this.targetMap = targetMap;
this.weight = weight;
}
}

Expand Down Expand Up @@ -98,6 +104,11 @@ protected StarBuilder addPortal(int x, int y, String targetMap) {
return this;
}

protected StarBuilder addPortal(int x, int y, String targetMap, double weight) {
current.ports.add(new TempPort(x, y, -1, -1, targetMap, weight));
return this;
}

@SuppressWarnings("SameParameterValue")
protected StarBuilder addPortal(int x, int y, String targetMap, int factionId) {
current.ports.add(new TempPort(x, y, -1, factionId, targetMap));
Expand Down Expand Up @@ -155,16 +166,24 @@ public Graph<Map, Portal> build() {
for (TempMap map : maps) {
for (TempPort port : map.ports) {
Map target = mapsByName.get(port.targetMap);
graph.addEdge(mapsByName.get(map.name), target, new Portal(port.type, port.x, port.y, target, port.factionId));
Portal portal = new Portal(port.type, port.x, port.y, target, port.factionId, port.weight);
graph.addEdge(mapsByName.get(map.name), target, portal);
graph.setEdgeWeight(portal, portal.weight);
}
}

for (GGPort ggPort : ggPorts) {
Map gg = mapsByName.get(ggPort.targetMap);
if (ggPort.looped) graph.addEdge(gg, gg, new Portal(ggPort.type, -1, -1, gg, -1));
if (ggPort.looped) {
Portal portal = new Portal(ggPort.type, -1, -1, gg, -1);
graph.addEdge(gg, gg, portal);
graph.setEdgeWeight(portal, portal.weight);
}
for (String mapName : ggPort.maps) {
Map from = mapsByName.get(mapName);
graph.addEdge(from, gg, new Portal(ggPort.type, ggPort.x, ggPort.y, gg, -1));
Portal portal = new Portal(ggPort.type, ggPort.x, ggPort.y, gg, -1);
graph.addEdge(from, gg, portal);
graph.setEdgeWeight(portal, portal.weight);
}
}
return graph;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private StarManager() {
.addMap(17, "1-5").addPortal(19000, 6000, "4-4").addPortal(10000, 12000, "4-5").addPortal(2000, 2000, "1-6").addPortal(2000, 11500, "1-7").addPortal(10500, 6750, "Experiment Zone 2-1")
.addMap(18, "1-6").addPortal(18500, 11500, "1-5").addPortal(2000, 11500, "1-8")
.addMap(19, "1-7").addPortal(2000, 2000, "1-8").addPortal(18500, 2000, "1-5")
.addMap(20, "1-8").addPortal(18500, 2000, "1-6").addPortal(18500, 11500, "1-7").addPortal(11084, 11084, "1BL");
.addMap(20, "1-8").addPortal(18500, 2000, "1-6").addPortal(18500, 11500, "1-7").addPortal(10500, 1000, "1BL", 10.0);
// EIC
mapBuild.addMap(5, "2-1").addPortal(2000, 11500, "2-2").addPortal(10500, 6750, "Experiment Zone 1")
.addMap(6, "2-2").addPortal(2000, 11500, "2-3").addPortal(18500, 11500, "2-4").addPortal(18500, 2000, "2-1")
Expand All @@ -57,7 +57,7 @@ private StarManager() {
.addMap(21, "2-5").addPortal(2000, 11500, "4-4").addPortal(18500, 11500, "4-5").addPortal(2000, 2000, "2-6").addPortal(18500, 2000, "2-7").addPortal(10500, 6750, "Experiment Zone 2-2")
.addMap(22, "2-6").addPortal(2000, 11500, "2-5").addPortal(18500, 2000, "2-8")
.addMap(23, "2-7").addPortal(2000, 11500, "2-5").addPortal(18500, 2000, "2-8")
.addMap(24, "2-8").addPortal(2000, 11500, "2-6").addPortal(18500, 11500, "2-7").addPortal(11084, 11084, "2BL");
.addMap(24, "2-8").addPortal(2000, 11500, "2-6").addPortal(18500, 11500, "2-7").addPortal(10500, 12500, "2BL", 10.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just makes it so the void will avoid using BL portals even if they may be significantly shorter paths.
I don't understand the rationale behind this, unless its intended to be for accounts of a level lower than minimum requirement, but if that's the aim then it shouldn't be just 10 more weight, it should be straight up disabled until you have the minimum level, and should change based on your level.

// VRU
mapBuild.addMap(9, "3-1").addPortal(2000, 2000, "3-2").addPortal(10500, 6750, "Experiment Zone 1")
.addMap(10, "3-2").addPortal(18500, 2000, "3-3").addPortal(2000, 2000, "3-4").addPortal(18500, 11500, "3-1")
Expand All @@ -66,7 +66,7 @@ private StarManager() {
.addMap(25, "3-5").addPortal(2000, 2000, "4-4").addPortal(16500, 1500, "4-5").addPortal(2000, 11500, "3-6").addPortal(18500, 11500, "3-7").addPortal(10500, 6750, "Experiment Zone 2-3")
.addMap(26, "3-6").addPortal(2000, 2000, "3-5").addPortal(18500, 11500, "3-8")
.addMap(27, "3-7").addPortal(2000, 11500, "3-5").addPortal(18500, 11500, "3-8")
.addMap(28, "3-8").addPortal(2000, 2000, "3-7").addPortal(2000, 11500, "3-6").addPortal(11084, 11084, "3BL");
.addMap(28, "3-8").addPortal(2000, 2000, "3-7").addPortal(2000, 11500, "3-6").addPortal(10500, 1000, "3BL", 10.0);
// B-MAPS
mapBuild.addMap(13, "4-1").addPortal(1500, 6000, "1-4").addPortal(18500, 2000, "4-2").addPortal(18500, 11500, "4-3").addPortal(10500, 6750, "4-4")
.addMap(14, "4-2").addPortal(10000, 1500, "2-4").addPortal(2000, 11500, "4-1").addPortal(18500, 11500, "4-3").addPortal(10500, 6750, "4-4")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import com.github.manolo8.darkbot.utils.I18n;
import com.github.manolo8.darkbot.utils.Time;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import eu.darkbot.util.Popups;

@SuppressWarnings("removal")
public class DisconnectModule extends TemporalModule {

Expand All @@ -23,15 +29,27 @@ public class DisconnectModule extends TemporalModule {

private Long pauseUntil = null;
private boolean refreshing = false;
private boolean closeBot = false;
private boolean popupOpened = false;

/**
* @param pauseTime null for infinite pause, otherwise pause for that amount of MS.
* @param pauseTime null for infinite pause, otherwise pause for that amount of
* MS.
*/
public DisconnectModule(Long pauseTime, String reason) {
this.reason = reason;
this.pauseTime = pauseTime;
}

/**
* @param pauseTime null for infinite pause, otherwise pause for that amount of
* MS.
*/
public DisconnectModule(Long pauseTime, String reason, boolean closeBot) {
this(pauseTime, reason);
this.closeBot = closeBot;
}

@Override
public void install(Main main) {
super.install(main);
Expand All @@ -55,6 +73,7 @@ public boolean canRefresh() {

@Override
public void tick() {
showClosePopup();
// Just in case refresh was super quick, don't go back to normal tick.
if (refreshing) {
tickStopped();
Expand All @@ -63,8 +82,10 @@ public void tick() {
main.guiManager.pet.setEnabled(false);
safety.setRefreshing(true);
safety.tick();
if (hero.locationInfo.isMoving() || safety.state() != SafetyFinder.Escaping.WAITING) return;
if (!logout.visible) logoutStart = System.currentTimeMillis();
if (hero.locationInfo.isMoving() || safety.state() != SafetyFinder.Escaping.WAITING)
return;
if (!logout.visible)
logoutStart = System.currentTimeMillis();
logout.show(true);
// Prevent bug where logout gets to 0 and doesn't log out, just force a reload
if (System.currentTimeMillis() - logoutStart > 25_000) {
Expand All @@ -76,14 +97,23 @@ public void tick() {

@Override
public void tickStopped() {
showClosePopup();
if (main.isRunning()) {
if (!lostConnection.visible) return;
if (!lostConnection.visible)
return;
// Bot done. Pause "forever" (unless a behaviour restarts it).
if (pauseTime == null) main.setRunning(false);
else if (pauseTime == 0) goBack();
if (pauseTime == null)
main.setRunning(false);
else if (pauseTime == 0)
goBack();
else {
pauseUntil = System.currentTimeMillis() + pauseTime;
main.setRunning(false);

if (closeBot) {
System.out.println("Exit by the Disconnect module, exiting");
System.exit(0);
}
}
} else if (pauseUntil != null && System.currentTimeMillis() > pauseUntil - 10_000) {
if (!refreshing) {
Expand All @@ -104,7 +134,32 @@ public String status() {

@Override
public String stoppedStatus() {
if (pauseUntil == null) return I18n.get("module.disconnect.status_stopped", reason);
else return I18n.get("module.disconnect.status_paused", reason, Time.toString(Math.max(0, pauseUntil - System.currentTimeMillis())));
if (pauseUntil == null)
return I18n.get("module.disconnect.status_stopped", reason);
else
return I18n.get("module.disconnect.status_paused", reason,
Time.toString(Math.max(0, pauseUntil - System.currentTimeMillis())));
}

private void showClosePopup() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disconnect module changes look good, but them being in the same PR as the other changes is not
please open them separately if you want these merged

if (!closeBot || popupOpened) {
return;
}

this.popupOpened = true;
JButton okBtn = new JButton(I18n.get("module.disconnect.popup.ok_btn"));
JButton cancelBtn = new JButton(I18n.get("module.disconnect.popup.cancel_btn"));
okBtn.addActionListener(e -> {
SwingUtilities.getWindowAncestor(okBtn).setVisible(false);
});
cancelBtn.addActionListener(e -> {
closeBot = false;
SwingUtilities.getWindowAncestor(cancelBtn).setVisible(false);
});

Popups.of(I18n.get("module.disconnect.popup.title"),
new JOptionPane(I18n.get("module.disconnect.popup.message"), JOptionPane.INFORMATION_MESSAGE,
JOptionPane.DEFAULT_OPTION, null, new Object[] { okBtn, cancelBtn }))
.showAsync();
}
}
4 changes: 4 additions & 0 deletions src/main/resources/lang/strings_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,10 @@ module.disconnect.reason.break=taking a break
module.disconnect.reason.death_pause=Killed by {0} {1} times
module.disconnect.reason.honor=lost honor
module.disconnect.reason.draw_fire=Enemy used draw fire
module.disconnect.popup.cancel_btn=Cancel
module.disconnect.popup.ok_btn=Ok
module.disconnect.popup.title=The bot will be closed
module.disconnect.popup.message=The bot will close completely when it disconnects, you can cancel it.

module.portal_jumper.status=Jumping to {0}

Expand Down
Loading