diff --git a/src/main/java/com/deeme/lang/strings_en.properties b/src/main/java/com/deeme/lang/strings_en.properties index 89e93af0..e99ee390 100644 --- a/src/main/java/com/deeme/lang/strings_en.properties +++ b/src/main/java/com/deeme/lang/strings_en.properties @@ -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. diff --git a/src/main/java/com/deeme/tasks/HitacFollower.java b/src/main/java/com/deeme/tasks/HitacFollower.java index 1b6f4391..b32366a6 100644 --- a/src/main/java/com/deeme/tasks/HitacFollower.java +++ b/src/main/java/com/deeme/tasks/HitacFollower.java @@ -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; @@ -43,7 +45,8 @@ public class HitacFollower implements Task, Listener, Configurable hitacAliensMaps = new LinkedList<>(); + private long nextCheck = 0; private boolean mapHasHitac = false; @@ -90,16 +93,19 @@ 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(); + } } } @@ -107,64 +113,67 @@ public void onTickTask() { 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; } } @@ -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()); } } \ No newline at end of file diff --git a/src/main/java/com/deeme/types/backpage/Utils.java b/src/main/java/com/deeme/types/backpage/Utils.java index 2e3fbd08..f3db630d 100644 --- a/src/main/java/com/deeme/types/backpage/Utils.java +++ b/src/main/java/com/deeme/types/backpage/Utils.java @@ -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 -> { @@ -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(); } @@ -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(); - } } \ No newline at end of file diff --git a/src/main/java/com/deeme/types/config/HitacFollowerConfig.java b/src/main/java/com/deeme/types/config/HitacFollowerConfig.java index a8c35109..db65a92e 100644 --- a/src/main/java/com/deeme/types/config/HitacFollowerConfig.java +++ b/src/main/java/com/deeme/types/config/HitacFollowerConfig.java @@ -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; diff --git a/src/main/resources/plugin.json b/src/main/resources/plugin.json index 702506d1..4aaa8361 100644 --- a/src/main/resources/plugin.json +++ b/src/main/resources/plugin.json @@ -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",