Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into astral-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dm94 committed Aug 18, 2023
2 parents df4d7cf + 1385cca commit b9d56d4
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 58 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/deeme/lang/strings_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ defense.help_list.everyone=Everyone
hitac_follower.go_pvp=Go to PVP Maps
hitac_follower.return_waiting_map=Return to waiting map
hitac_follower.waiting_map=Waiting map
hitac_follower.lowers=Go to Lower Maps
hitac_follower.lower_enemy=Go to Lower Enemy Maps
hitac_follower.uppers=Go to Upper Maps
hitac_follower.upper_enemy=Go to Upper Enemy Maps
hitac_follower.go_for_the_title=Going for the titles
hitac_follower.go_for_the_title.desc=The bot will go to the maps where it is announced that there is a title.
Expand Down
118 changes: 78 additions & 40 deletions src/main/java/com/deeme/tasks/HitacFollower.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -43,7 +45,8 @@ public class HitacFollower implements Task, Listener, Configurable<HitacFollower

private HitacFollowerConfig followerConfig;

private String lastHitacMap = "";
private final Deque<String> hitacAliensMaps = new LinkedList<>();

private long nextCheck = 0;
private boolean mapHasHitac = false;

Expand Down Expand Up @@ -90,81 +93,87 @@ public void onTickTask() {
if (mapHasHitac) {
mapHasHitac = false;
goToNextMap();
} else if (!lastHitacMap.isEmpty()) {
changeMap(lastHitacMap);
if (hero.getMap().getName().equals(lastHitacMap)) {
lastHitacMap = "";
}
} else if (!hitacAliensMaps.isEmpty()) {
changeMap(hitacAliensMaps.getFirst());
} else if (followerConfig.returnToWaitingMap) {
api.requireAPI(ConfigAPI.class).requireConfig("general.working_map")
.setValue(followerConfig.waitMap);
}
}

// remove if current map is the map next map visit
if (!hitacAliensMaps.isEmpty()
&& hitacAliensMaps.getFirst().equalsIgnoreCase(star.getCurrentMap().getShortName())) {
hitacAliensMaps.removeFirst();
}
}
}

@EventHandler
public void onLogMessage(GameLogAPI.LogMessageEvent message) {
if (followerConfig.enable && extensionsAPI.getFeatureInfo(this.getClass()).isEnabled()) {
String msg = message.getMessage();
if (!msg.isEmpty() && msg.contains("Hitac") && titleFilter(msg) && pvpFilter(msg)) {

if (msg.contains("Hitac") && titleFilter(msg) && pvpFilter(msg)) {
Matcher matcher = pattern.matcher(msg);
if (matcher.find()) {
lastHitacMap = matcher.group(0);
if (!hasHitac()) {
changeMap(matcher.group(0));
}
addSpawnHitac(matcher.group(0));
}

}
}
}

private boolean pvpFilter(String message) {
return (followerConfig.goToPVP && message.contains("PvP")) || !message.contains("PvP");
return followerConfig.goToPVP || !message.contains("PvP");
}

private boolean titleFilter(String message) {
return followerConfig.goForTheTitle || (!message.contains("Hitac-Underling")
&& !message.contains("Hitac-Underboss"));
return followerConfig.goForTheTitle || !(message.contains("Hitac-Underling")
&& message.contains("Hitac-Underboss"));
}

private void addSpawnHitac(String map) {
// add map if not in list
if (hitacAliensMaps.stream().noneMatch(alien -> alien.equalsIgnoreCase(this.star.getCurrentMap().getName()))) {
hitacAliensMaps.add(map);
}

// add next map it will jump to
String nextMap = getNextMap(map);
if (nextMap != null) {
hitacAliensMaps.add(nextMap);
}
}

private void goToNextMap() {
String currentMap = hero.getMap().getName();
String nextMap = null;
switch (currentMap) {
String nextMap = getNextMap(hero.getMap().getName());
if (nextMap != null) {
changeMap(nextMap);
}
}

private String getNextMap(String givenMap) {
switch (givenMap) {
case "1-3":
nextMap = "1-4";
break;
return "1-4";
case "1-4":
nextMap = "3-4";
break;
return "3-4";
case "3-4":
nextMap = "3-3";
break;
return "3-3";
case "3-3":
nextMap = "2-4";
break;
return "2-4";
case "2-4":
nextMap = "2-3";
break;
return "2-3";
case "2-3":
nextMap = "1-3";
break;
return "1-3";
case "4-1":
nextMap = "4-3";
break;
return "4-3";
case "4-2":
nextMap = "4-1";
break;
return "4-1";
case "4-3":
nextMap = "4-2";
break;
return "4-2";
default:
nextMap = null;
}
if (nextMap != null) {
changeMap(nextMap);
return null;
}
}

Expand All @@ -180,11 +189,40 @@ private boolean hasHitac() {
&& !s.getEntityInfo().getUsername().contains("Hitac-Underboss")));
}

private boolean isLowerMap(String mapName) {
return mapName.contains("-3") || mapName.contains("-4");
}

private boolean isUpperMap(String mapName) {
return mapName.contains("-5") || mapName.contains("-6") || mapName.contains("-7") || mapName.contains("-8");
}

private boolean isSameFaction(String mapName) {
return mapName.contains(this.hero.getEntityInfo().getFaction().ordinal() + "-");
}

private boolean lowerMapFilter(String mapName) {
return isLowerMap(mapName)
&& (!followerConfig.lowers || (!followerConfig.lowerEnemy && !isSameFaction(mapName)));
}

private boolean upperMapFilter(String mapName) {
return isUpperMap(mapName)
&& (!followerConfig.uppers || (!followerConfig.upperEnemy && !isSameFaction(mapName)));
}

private void changeMap(String mapName) {
if (!hitacAliensMaps.isEmpty() && hitacAliensMaps.getFirst().equalsIgnoreCase(mapName)
&& (lowerMapFilter(mapName) || upperMapFilter(mapName))) {
hitacAliensMaps.removeFirst();
return;
}

GameMap nextMap = star.findMap(mapName).orElse(null);
if (nextMap == null) {
return;
}

api.requireAPI(ConfigAPI.class).requireConfig("general.working_map").setValue(nextMap.getId());
}
}
27 changes: 10 additions & 17 deletions src/main/java/com/deeme/types/backpage/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public static synchronized void discordDonorCheck(FeatureInfo featureInfo, Strin
}

public static void showDiscordDialog() {
showDiscordDialog("To use this option you need to be on my discord");
}

public static void showDiscordDonorDialog() {
showDiscordDialog("Special features: Enter my discord to know more");
}

public static void showDiscordDialog(String text) {
JButton discordBtn = new JButton("Discord");
JButton closeBtn = new JButton("Close");
discordBtn.addActionListener(e -> {
Expand All @@ -46,7 +54,7 @@ public static void showDiscordDialog() {
closeBtn.addActionListener(e -> SwingUtilities.getWindowAncestor(closeBtn).setVisible(false));

Popups.of("DmPlugin",
new JOptionPane("To use this option you need to be on my discord", JOptionPane.INFORMATION_MESSAGE,
new JOptionPane(text, JOptionPane.INFORMATION_MESSAGE,
JOptionPane.DEFAULT_OPTION, null, new Object[] { discordBtn, closeBtn }))
.showAsync();
}
Expand All @@ -67,25 +75,10 @@ public static void showDonateDialog() {

Popups.of("DmPlugin donate",
new JOptionPane(
"You can help improve the plugin by donating. \n You get nothing extra if you donate.",
"You can help improve the plugin by donating.",
JOptionPane.INFORMATION_MESSAGE,
JOptionPane.DEFAULT_OPTION, null, new Object[] { donateBtn, closeBtn }))
.showAsync();
}
}

public static void showDiscordDonorDialog() {
JButton discordBtn = new JButton("Discord");
JButton closeBtn = new JButton("Close");
discordBtn.addActionListener(e -> {
SystemUtils.openUrl(DISCORD_URL);
SwingUtilities.getWindowAncestor(discordBtn).setVisible(false);
});
closeBtn.addActionListener(e -> SwingUtilities.getWindowAncestor(closeBtn).setVisible(false));

Popups.of("DmPlugin",
new JOptionPane("Special features: Enter my discord to know more", JOptionPane.INFORMATION_MESSAGE,
JOptionPane.DEFAULT_OPTION, null, new Object[] { discordBtn, closeBtn }))
.showAsync();
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/deeme/types/config/HitacFollowerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ public class HitacFollowerConfig {
@Option("general.enabled")
public boolean enable = false;

@Option("hitac_follower.lowers")
public boolean lowers = true;

@Option("hitac_follower.lower_enemy")
public boolean lowerEnemy = true;

@Option("hitac_follower.uppers")
public boolean uppers = false;

@Option("hitac_follower.upper_enemy")
public boolean upperEnemy = true;

@Option("hitac_follower.go_pvp")
public boolean goToPVP = true;

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "DmPlugin",
"author": "Dm94Dani",
"version": "2.0.3 beta 5",
"version": "2.1.0",
"minVersion": "1.127",
"supportedVersion": "1.127",
"basePackage": "com.deeme",
Expand Down

0 comments on commit b9d56d4

Please sign in to comment.