Skip to content

Commit

Permalink
v2.0.4 (#73)
Browse files Browse the repository at this point in the history
* Ambulance Mode: Removed useless options
* Replaced getByName for findMap
* ProfileChanger: Added refresh option
* HitacFollower: Updated for the new event

Co-authored-by: Anjesh Shrestha <[email protected]>
Co-authored-by: Anjesh Shrestha <[email protected]>
  • Loading branch information
3 people authored Aug 18, 2023
1 parent 3347aed commit 1cb46d5
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 101 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/deeme/behaviours/ProfileChanger.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ private void changeAction() {
}
} else {
resetCounters();
if (config.reloadBot) {
Main.API.handleRefresh();
}
main.setConfig(config.BOT_PROFILE);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.deeme.behaviours.ambulance;

import eu.darkbot.api.config.annotations.Configuration;
import eu.darkbot.api.config.annotations.Dropdown;
import eu.darkbot.api.config.annotations.Number;
import eu.darkbot.api.config.annotations.Option;
import eu.darkbot.api.config.annotations.Percentage;
Expand All @@ -11,10 +10,6 @@ public class AmbulanceConfig {
@Option("general.enabled")
public boolean enable = false;

@Option("ambulance.ship_type")
@Dropdown
public AvailableShips shipType = AvailableShips.AEGIS;

@Option("general.next_check_time")
@Number(min = 1, max = 300, step = 1)
public int timeToCheck = 20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class ProfileChangerConfig {
@Option("profile_changer.close_bot")
public boolean closeBot = false;

@Option("profile_changer.reload_bot")
public boolean reloadBot = false;

@Option("profile_changer.only_one_condition")
public boolean orConditional = false;

Expand Down
24 changes: 18 additions & 6 deletions src/main/java/com/deeme/lang/strings_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,18 @@ astral.best_ammo=Auto choose the best ammo
astral.best_ammo.list.always=Always
astral.best_ammo.list.special_logic=Special Logic
astral.best_ammo.list.only_marked=Only marked NPCs
astral.choose_portal=Auto choose the portal (TEST)
astral.choose_portal.desc=It will choose the map that he thinks is the most appropriate.
astral.choose_item=Auto choose the item (TEST)
astral.choose_item.desc=It will choose the items randomly. DON´T USE FOR NOW
astral.display_warning=Display a warning when necessary
astral.display_warning.desc=Displays a warning when manual action is required
astral.auto_choose=Auto choose the best option [PLUS]
astral.auto_choose.desc=PLUS options only work for some users
astral.ship_to_choose=Ship to choose [PLUS]
astral.ship_to_choose.desc=PLUS options only work for some users
astral.choose_portal.desc=It will choose the portal and item that he thinks is the most appropriate.
astral.min_cpus=Minimum number of CPUs
astral.min_cpus.desc=It will not open any more astrals if it is below this number.
astral.portal_table=Portal Types
astral.portal_table.priority=Priority
astral.portal_table.priority.desc=Lower value = higher priority
astral.portal_table.ignore_limit=Ignore Limit
astral.portal_table.ignore_limit.desc=It will enter the portal even if you have the maximum of those items.
ambulance.ship_type=Type of ship
ambulance.ship_type.desc=Also works with the plus versions
Expand Down Expand Up @@ -195,6 +199,12 @@ 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.
profile_changer.only_one_condition=Only one condition is necessary
profile_changer.only_one_condition.desc=Only one condition in true will be necessary for the change to be made.
Expand All @@ -216,6 +226,8 @@ profile_changer.deaths_condition=Deaths condition
profile_changer.deaths_condition.max_deaths=Max deaths
profile_changer.close_bot=Close bot
profile_changer.close_bot.desc=Will close the bot instead of changing profile
profile_changer.reload_bot=Reload Bot
profile_changer.reload_bot.desc=It will Reload the bot when changing profile.
palladium_hangar.go_portal_change=Travel to portal before switch
palladium_hangar.go_portal_change.desc=Go to the portal to change the hangar
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/com/deeme/modules/PalladiumHangar.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,8 @@ public PalladiumHangar(Main main, PluginAPI api, AuthAPI auth, SafetyFinder safe
this.bases = entities.getStations();

StarSystemAPI starSystem = api.getAPI(StarSystemAPI.class);
try {
this.sellMap = starSystem.getByName("5-2");
} catch (Exception e) {
this.sellMap = main.starManager.byName("5-2");
}
try {
this.activeMap = starSystem.getByName("5-3");
} catch (Exception e) {
this.activeMap = main.starManager.byName("5-3");
}
this.sellMap = starSystem.findMap("5-2").orElse(starSystem.findMap(92).orElse(null));
this.activeMap = starSystem.findMap("5-3").orElse(starSystem.findMap(93).orElse(null));

this.currentStatus = State.WAIT;
this.lastStatus = State.WAIT;
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/com/deeme/tasks/AutoChangeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,12 @@ private void selectMap(Map.Entry<String, MapData> chosseMap) {
}

private void updateWorkingMap(String mapName) {
try {
GameMap map = star.getByName(mapName);
if (map == null) {
return;
}

int mapId = map.getId();

api.requireAPI(ConfigAPI.class).requireConfig("general.working_map").setValue(mapId);
mapsAlreadyUsed.add(mapName);
} catch (Exception e) {
/* Nothing here */
GameMap map = star.findMap(mapName).orElse(null);
if (map == null) {
return;
}

api.requireAPI(ConfigAPI.class).requireConfig("general.working_map").setValue(map.getId());
mapsAlreadyUsed.add(mapName);
}
}
139 changes: 93 additions & 46 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 All @@ -17,6 +19,7 @@
import eu.darkbot.api.extensions.Feature;
import eu.darkbot.api.extensions.Task;
import eu.darkbot.api.game.entities.Npc;
import eu.darkbot.api.game.other.GameMap;
import eu.darkbot.api.managers.AuthAPI;
import eu.darkbot.api.managers.BotAPI;
import eu.darkbot.api.managers.ConfigAPI;
Expand All @@ -42,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 @@ -89,73 +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")
&& ((followerConfig.goToPVP && msg.contains("PvP")) || !msg.contains("PvP")))) {

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");
}

private boolean titleFilter(String message) {
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 @@ -164,18 +182,47 @@ private boolean hasHitac() {
return false;
}
return npcs.stream()
.filter(s -> (s.getInfo() != null && s.getEntityInfo() != null
.anyMatch(s -> (s.getEntityInfo() != null
&& s.getEntityInfo().getUsername() != null
&& s.getEntityInfo().getUsername().contains("Hitac")))
.findAny().orElse(null) != null;
&& s.getEntityInfo().getUsername().contains("Hitac")
&& !s.getEntityInfo().getUsername().contains("Hitac-Underling")
&& !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) {
try {
int map = star.getByName(mapName).getId();
api.requireAPI(ConfigAPI.class).requireConfig("general.working_map").setValue(map);
} catch (Exception e) {
System.out.println("Map not found" + e.getMessage());
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());
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/deeme/tasks/discord/Discord.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private String getAuthorPart() {
String help = "";
help += "\"author\": {";
help += "\"name\": \"Dm94Dani's Projects Discord\",";
help += "\"url\": \"https://discord.gg/GPRTRRZJPw\",";
help += "\"url\": \"" + Utils.DISCORD_URL + "\",";
help += "\"icon_url\": \"https://raw.githubusercontent.com/dm94/dm94/master/FENIX-dm94dani.png\"";
help += "}";

Expand Down
Loading

0 comments on commit 1cb46d5

Please sign in to comment.