Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions berti/behaviors/ConfigChanger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package dev.shared.berti.behaviors;

import eu.darkbot.api.PluginAPI;
import eu.darkbot.api.config.ConfigSetting;
import eu.darkbot.api.extensions.Behavior;
import eu.darkbot.api.extensions.Configurable;
import eu.darkbot.api.extensions.Feature;
import eu.darkbot.api.managers.AuthAPI;
import eu.darkbot.api.managers.ConfigAPI;
import eu.darkbot.api.managers.StatsAPI;
import dev.shared.berti.behaviors.configs.ConfigChangerConfig;
import java.util.Arrays;

@Feature(name="Config Changer (by @berti1027)", description="Changes config once the specified amount of booty keys has been collected")
public class ConfigChanger
implements Behavior,
Configurable<ConfigChangerConfig> {
private final StatsAPI statsAPI;
private final ConfigAPI configAPI;
private ConfigChangerConfig config;

public ConfigChanger(PluginAPI pluginAPI) {
this.statsAPI = (StatsAPI)pluginAPI.requireAPI(StatsAPI.class);
this.configAPI = (ConfigAPI)pluginAPI.requireAPI(ConfigAPI.class);
}

public void BootyKeys() {
if (this.config.BOOTY_KEY == null) {
return;
}
double booty_key = this.statsAPI.getStat((StatsAPI.Key)this.config.BOOTY_KEY).getCurrent();
if (booty_key <= this.config.STOP_AT_BOXES) {
this.configAPI.setConfigProfile(this.config.BOT_PROFILE);
}
}

public void setConfig(ConfigSetting<ConfigChangerConfig> config) {
this.config = (ConfigChangerConfig)config.getValue();
}

public void onTickBehavior() {
this.BootyKeys();
}
}
83 changes: 83 additions & 0 deletions berti/behaviors/CustomAbilities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package dev.shared.berti.behaviors;

import com.github.manolo8.darkbot.core.entities.Npc;
import eu.darkbot.api.PluginAPI;
import eu.darkbot.api.config.ConfigSetting;
import eu.darkbot.api.config.types.Condition;
import eu.darkbot.api.extensions.Behavior;
import eu.darkbot.api.extensions.Configurable;
import eu.darkbot.api.extensions.Feature;
import eu.darkbot.api.extensions.NpcFlags;
import eu.darkbot.api.game.group.GroupMember;
import eu.darkbot.api.game.items.ItemFlag;
import eu.darkbot.api.game.items.SelectableItem;
import eu.darkbot.api.managers.AuthAPI;
import eu.darkbot.api.managers.GroupAPI;
import eu.darkbot.api.managers.HeroAPI;
import eu.darkbot.api.managers.HeroItemsAPI;
import dev.shared.berti.behaviors.configs.CustomAbilitiesConfig;
import java.util.Arrays;

@Feature(name="Custom Abilities", description="Use abilities in an Optimal way")
public class CustomAbilities
implements Behavior,
Configurable<CustomAbilitiesConfig>,
NpcFlags<CustomAbilitiesConfig.AbilityFlags> {
private final PluginAPI pluginAPI;
private final HeroItemsAPI heroItemsAPI;
private final HeroAPI heroAPI;
private final GroupAPI groupAPI;
private CustomAbilitiesConfig config;

public CustomAbilities(PluginAPI pluginAPI) {
this.pluginAPI = pluginAPI;
this.groupAPI = (GroupAPI)pluginAPI.requireAPI(GroupAPI.class);
this.heroItemsAPI = (HeroItemsAPI)pluginAPI.requireAPI(HeroItemsAPI.class);
this.heroAPI = (HeroAPI)pluginAPI.requireAPI(HeroAPI.class);
}

public void setConfig(ConfigSetting<CustomAbilitiesConfig> config) {
this.config = (CustomAbilitiesConfig)config.getValue();
}

public void onTickBehavior() {
this.customAbility(this.config.ABILITY1, CustomAbilitiesConfig.AbilityFlags.ABILITY1);
this.customAbility(this.config.ABILITY2, CustomAbilitiesConfig.AbilityFlags.ABILITY2);
this.customAbility(this.config.ABILITY3, CustomAbilitiesConfig.AbilityFlags.ABILITY3);
this.customAbility(this.config.ABILITY4, CustomAbilitiesConfig.AbilityFlags.ABILITY4);
this.groupAbility(this.config.GROUP_ABILITY);
}

public void customAbility(CustomAbilitiesConfig.Ability config, CustomAbilitiesConfig.AbilityFlags abilityFlag) {
if (!config.ACTIVATED || config.CONDITION == null || config.ABILITIES == null) {
return;
}
if (config.CONDITION.get(this.pluginAPI) != Condition.Result.ALLOW) {
return;
}
if (config.NPC_FLAG) {
if (!this.heroAPI.isAttacking()) {
return;
}
Npc target = (Npc)this.heroAPI.getLocalTargetAs(Npc.class);
if (target != null && target.getInfo().hasExtraFlag((Enum)abilityFlag)) {
this.heroItemsAPI.useItem((SelectableItem)config.ABILITIES, new ItemFlag[0]);
}
} else {
this.heroItemsAPI.useItem((SelectableItem)config.ABILITIES, new ItemFlag[0]);
}
}

public void groupAbility(CustomAbilitiesConfig.GroupAbility config) {
Boolean plus;
String shipName = this.heroAPI.getShipType();
Boolean bl = plus = !shipName.contains("ship_solace") ? null : Boolean.valueOf(shipName.contains("-plus"));
if (!config.ACTIVATED) {
return;
}
for (GroupMember groupMember : this.groupAPI.getMembers()) {
if (!this.groupAPI.hasGroup() || groupMember.getMapId() != this.heroAPI.getMap().getId() || !(groupMember.getMemberInfo().hpPercent() <= config.GROUP_HEAL) || plus == null) continue;
this.heroItemsAPI.useItem((SelectableItem)(plus != false ? SelectableItem.Ability.SOLACE_PLUS_NANO_CLUSTER_REPAIRER_PLUS : SelectableItem.Ability.SOLACE), new ItemFlag[0]);
}
}
}
71 changes: 71 additions & 0 deletions berti/behaviors/CustomTechs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package dev.shared.berti.behaviors;

import eu.darkbot.api.PluginAPI;
import eu.darkbot.api.config.ConfigSetting;
import eu.darkbot.api.config.types.Condition;
import eu.darkbot.api.extensions.Behavior;
import eu.darkbot.api.extensions.Configurable;
import eu.darkbot.api.extensions.Feature;
import eu.darkbot.api.extensions.NpcFlags;
import eu.darkbot.api.game.entities.Npc;
import eu.darkbot.api.game.items.ItemFlag;
import eu.darkbot.api.game.items.SelectableItem;
import eu.darkbot.api.managers.AuthAPI;
import eu.darkbot.api.managers.HeroAPI;
import eu.darkbot.api.managers.HeroItemsAPI;
import dev.shared.berti.behaviors.configs.CustomTechsConfig;
import java.util.Arrays;

@Feature(name="Custom Techs", description="Use techs in an Optimal way")
public class CustomTechs
implements Behavior,
Configurable<CustomTechsConfig>,
NpcFlags<CustomTechsConfig.TechFlags> {
private final PluginAPI pluginAPI;
private final HeroItemsAPI heroItemsAPI;
private final HeroAPI heroAPI;
private CustomTechsConfig config;

public CustomTechs(PluginAPI pluginAPI) {
this.pluginAPI = pluginAPI;
this.heroItemsAPI = (HeroItemsAPI)this.pluginAPI.requireAPI(HeroItemsAPI.class);
this.heroAPI = (HeroAPI)this.pluginAPI.requireAPI(HeroAPI.class);
}

public void setConfig(ConfigSetting<CustomTechsConfig> config) {
this.config = (CustomTechsConfig)config.getValue();
}

public void onTickBehavior() {
this.customTech(this.config.TECH1, CustomTechsConfig.TechFlags.TECH1);
this.customTech(this.config.TECH2, CustomTechsConfig.TechFlags.TECH2);
this.customTech(this.config.TECH3, CustomTechsConfig.TechFlags.TECH3);
this.customTech(this.config.TECH4, CustomTechsConfig.TechFlags.TECH4);
this.customTech(this.config.TECH5, CustomTechsConfig.TechFlags.TECH5);
this.customTech(this.config.TECH6, CustomTechsConfig.TechFlags.TECH6);
this.customTech(this.config.TECH7, CustomTechsConfig.TechFlags.TECH7);
this.customTech(this.config.TECH8, CustomTechsConfig.TechFlags.TECH8);
this.customTech(this.config.TECH9, CustomTechsConfig.TechFlags.TECH9);
this.customTech(this.config.TECH10, CustomTechsConfig.TechFlags.TECH10);
}

public void customTech(CustomTechsConfig.Tech config, CustomTechsConfig.TechFlags techFlag) {
if (!config.ACTIVATED || config.CONDITION == null || config.TECHS == null) {
return;
}
if (config.CONDITION.get(this.pluginAPI) != Condition.Result.ALLOW) {
return;
}
if (config.NPC_FLAG) {
if (!this.heroAPI.isAttacking()) {
return;
}
Npc target = (Npc)this.heroAPI.getLocalTargetAs(Npc.class);
if (target != null && target.getInfo().hasExtraFlag((Enum)techFlag)) {
this.heroItemsAPI.useItem((SelectableItem)config.TECHS, new ItemFlag[0]);
}
} else {
this.heroItemsAPI.useItem((SelectableItem)config.TECHS, new ItemFlag[0]);
}
}
}
147 changes: 147 additions & 0 deletions berti/behaviors/EnemyTracker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package dev.shared.berti.behaviors;

import eu.darkbot.api.PluginAPI;
import eu.darkbot.api.config.ConfigSetting;
import eu.darkbot.api.extensions.Configurable;
import eu.darkbot.api.extensions.Feature;
import eu.darkbot.api.extensions.Task;
import eu.darkbot.api.game.entities.Entity;
import eu.darkbot.api.game.entities.Player;
import eu.darkbot.api.game.entities.Ship;
import eu.darkbot.api.managers.AttackAPI;
import eu.darkbot.api.managers.AuthAPI;
import eu.darkbot.api.managers.BackpageAPI;
import eu.darkbot.api.managers.EntitiesAPI;
import eu.darkbot.api.managers.HeroAPI;
import dev.shared.berti.behaviors.configs.EnemyTrackerConfig;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Feature(name="Enemy Tracker", description="This behavior helps you track enemies in a dedicated discord channel via webhook")
public class EnemyTracker
implements Task,
Configurable<EnemyTrackerConfig> {
protected long lastReportTime = 0L;
private long resetTime;
private EnemyTrackerConfig config;
private final HeroAPI hero;
private final AttackAPI attack;
private final Collection<? extends Player> allShips;
private final BackpageAPI backpageAPI;

public EnemyTracker(PluginAPI api) {
this.hero = (HeroAPI)api.requireAPI(HeroAPI.class);
this.attack = (AttackAPI)api.requireAPI(AttackAPI.class);
this.backpageAPI = (BackpageAPI)api.requireAPI(BackpageAPI.class);
this.allShips = ((EntitiesAPI)api.requireAPI(EntitiesAPI.class)).getPlayers();
}

private void reportToDiscord(String webhook, String message) {
if (this.resetTime != 0L && System.currentTimeMillis() / 1000L < this.resetTime) {
return;
}
String jsonBrut = "{\"content\": \"" + message + "\"}";
HttpURLConnection conn = null;
try {
conn = this.getHttpURLConnection(webhook);
OutputStream os = conn.getOutputStream();
os.write(jsonBrut.getBytes(StandardCharsets.UTF_8));
os.flush();
os.close();
conn.getInputStream().close();
conn.disconnect();
this.resetTime = 0L;
}
catch (Exception ex) {
try {
if (conn != null) {
System.out.println("-----START-----");
Map<String, List<String>> headers = conn.getHeaderFields();
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
String key = entry.getKey();
if (key == null || !key.contains("x-ratelimit") && !key.contains("Retry-After")) continue;
System.out.printf("DISCORD: %s : %s%n", key, entry.getValue());
}
System.out.println("-----END-----");
this.resetTime = Long.parseLong(headers.get("x-ratelimit-reset").get(0));
}
}
catch (Exception e) {
e.printStackTrace();
}
ex.printStackTrace();
}
}

private HttpURLConnection getHttpURLConnection(String webhook) throws IOException {
HttpURLConnection conn = (HttpURLConnection)new URL(webhook).openConnection();
conn.setConnectTimeout(5000);
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
return conn;
}

public void setConfig(ConfigSetting<EnemyTrackerConfig> configSetting) {
this.config = (EnemyTrackerConfig)configSetting.getValue();
}

public void onTickTask() {
if (this.config.surrounding && (this.lastReportTime == 0L || System.currentTimeMillis() >= this.lastReportTime + 10000L)) {
try {
List<Ship> enemies = this.allShips.stream().filter(Entity::isValid).filter(x -> x.getEntityInfo().isEnemy() && (x.hasEffect(341) || !this.backpageAPI.getInstanceURI().getRawPath().contains("gbl1"))).collect(Collectors.toList());
if (!enemies.isEmpty()) {
this.reportToDiscord(this.config.configdiscordwebhook, this.getEnemiesDiscordMessage(enemies));
}
this.lastReportTime = System.currentTimeMillis();
}
catch (Exception e) {
e.printStackTrace();
}
} else if (this.lastReportTime == 0L || System.currentTimeMillis() >= this.lastReportTime + 10000L) {
try {
StringBuilder messageBuilder = new StringBuilder();
if (this.attack.getTarget() instanceof Player) {
messageBuilder.append("Target: `[").append(this.attack.getTarget().getEntityInfo().getClanTag()).append("] ").append(this.attack.getTarget().getEntityInfo().getUsername()).append("` | Map: ").append(this.hero.getMap().getName());
} else {
messageBuilder.append("Map: ").append(this.hero.getMap().getName()).append(" | Target is not a player ship");
}
this.reportToDiscord(this.config.configdiscordwebhook, messageBuilder.toString());
this.lastReportTime = System.currentTimeMillis();
}
catch (Exception e) {
e.printStackTrace();
}
}
}

private String getEnemiesDiscordMessage(List<Ship> enemies) {
StringBuilder messageBuilder = new StringBuilder();
if (this.attack.getTarget() instanceof Player) {
messageBuilder.append("Map: ").append(this.hero.getMap().getName()).append(" | Target: `[").append(this.attack.getTarget().getEntityInfo().getClanTag()).append("]").append(this.attack.getTarget().getEntityInfo().getUsername()).append("`");
} else {
messageBuilder.append("Map: ").append(this.hero.getMap().getName()).append(" | Target is not a player ship ");
}
if (!enemies.isEmpty() && enemies.size() >= 2) {
messageBuilder.append(" | Other Enemies in sight:");
} else if (enemies.size() == 1) {
messageBuilder.append(" | Other Enemy in sight:");
}
for (Ship enemy : enemies) {
if (Objects.equals(enemy.getEntityInfo().getUsername(), this.attack.getTarget().getEntityInfo().getUsername())) continue;
messageBuilder.append(" | `[").append(enemy.getEntityInfo().getClanTag()).append("] ").append(enemy.getEntityInfo().getUsername()).append("`");
}
return messageBuilder.toString();
}
}
Loading