Skip to content

Commit

Permalink
Merge branch 'dm94:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dm94 authored Jun 13, 2023
2 parents 38a3a71 + 83f8a6b commit 0db1f2f
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/deeme/behaviours/Others.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ private void closeBotLogic() {
}

private boolean isDisconnect() {
return lostConnectionGUI != null && lostConnectionGUI.isVisible();
return heroapi.getMap() == null || heroapi.getMap().getId() == -1
|| (lostConnectionGUI != null && lostConnectionGUI.isVisible());
}

private void autoBuyLogic() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import java.util.Arrays;
import java.util.Collection;

import com.deeme.types.SharedFunctions;
import com.deeme.types.VerifierChecker;
import com.deeme.types.backpage.Utils;
import com.github.manolo8.darkbot.config.Config;
import com.github.manolo8.darkbot.config.NpcExtraFlag;
import com.github.manolo8.darkbot.core.itf.NpcExtraProvider;

Expand All @@ -19,11 +21,13 @@
import eu.darkbot.api.game.entities.Player;
import eu.darkbot.api.game.entities.Portal;
import eu.darkbot.api.game.items.ItemFlag;
import eu.darkbot.api.game.items.SelectableItem;
import eu.darkbot.api.game.items.SelectableItem.Formation;
import eu.darkbot.api.game.items.SelectableItem.Laser;
import eu.darkbot.api.game.other.Lockable;
import eu.darkbot.api.game.other.Movable;
import eu.darkbot.api.managers.AuthAPI;
import eu.darkbot.api.managers.ConfigAPI;
import eu.darkbot.api.managers.EntitiesAPI;
import eu.darkbot.api.managers.HeroAPI;
import eu.darkbot.api.managers.HeroItemsAPI;
Expand All @@ -43,6 +47,8 @@ public class AutoBestFormation implements Behavior, Configurable<BestFormationCo
private Collection<? extends Portal> allPortals;
private long nextCheck = 0;

protected final ConfigSetting<Config.ShipConfig> configOffensive;

private ArrayList<Formation> availableFormations = new ArrayList<>();

public AutoBestFormation(PluginAPI api) {
Expand All @@ -66,6 +72,9 @@ public AutoBestFormation(PluginAPI api, AuthAPI auth, HeroItemsAPI items) {
EntitiesAPI entities = api.getAPI(EntitiesAPI.class);
this.allNpcs = entities.getNpcs();
this.allPortals = entities.getPortals();

ConfigAPI configApi = api.getAPI(ConfigAPI.class);
this.configOffensive = configApi.requireConfig("general.offensive");
}

@Override
Expand Down Expand Up @@ -156,6 +165,11 @@ private Formation getBestFormation() {
return Formation.CHEVRON;
}

if (isAttacking()) {
SelectableItem formation = SharedFunctions.getItemById(config.defaultFormation);
return (Formation) formation;
}

return null;
}

Expand Down Expand Up @@ -234,8 +248,24 @@ private boolean shoulUseBat() {
}

private boolean useSelectableReadyWhenReady(Formation formation) {
return (formation != null && !heroapi.isInFormation(formation)
&& items.useItem(formation, 1000, ItemFlag.USABLE, ItemFlag.READY).isSuccessful());

if (formation != null && !heroapi.isInFormation(formation)
&& items.useItem(formation, 1000, ItemFlag.USABLE, ItemFlag.READY).isSuccessful()) {
changeOffensiveConfig(formation);
return true;
}
return false;
}

private void changeOffensiveConfig(Formation formation) {
try {
Character key = items.getKeyBind(formation);
if (key == null || configOffensive.getValue().getLegacyFormation() == null
|| configOffensive.getValue().getLegacyFormation().equals(key)) {
configOffensive.setValue(new Config.ShipConfig(configOffensive.getValue().CONFIG, key));
}
} catch (Exception e) {
}
}

private boolean hasTag(Enum<?> tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public class BestFormationConfig {
@Number(max = 300, step = 1)
public int timeToCheck = 5;

@Option("best_formation.default_formation")
@Dropdown(options = FormationSupplier.class)
public String defaultFormation = "";

@Option("best_formation.formations_to_use")
@Dropdown(multi = true)
public Set<SupportedFormations> formationsToUse = EnumSet.allOf(SupportedFormations.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.deeme.behaviours.bestformation;

import java.util.ArrayList;
import java.util.List;

import eu.darkbot.api.config.annotations.Dropdown;
import eu.darkbot.api.game.items.SelectableItem;
import eu.darkbot.api.game.items.SelectableItem.Formation;

public class FormationSupplier implements Dropdown.Options<String> {
private static ArrayList<String> allItemsIds = new ArrayList<>();

@Override
public List<String> options() {
if (allItemsIds.isEmpty()) {
Formation[] selectableItemList = SelectableItem.Formation.values();
for (Formation formation : selectableItemList) {
allItemsIds.add(formation.getId());
}
}
return allItemsIds;
}

@Override
public String getText(String id) {
Formation[] selectableItemList = SelectableItem.Formation.values();
for (Formation formation : selectableItemList) {
if (formation.getId().equals(id)) {
return formation.name();
}
}
return id;
}
}
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 @@ -51,6 +51,8 @@ best_ability.min_health_damage.desc=The bot will use the damage abilities if the

best_formation.formations_to_use=Formations to be used
best_formation.formations_to_use.desc=Mark the formations you want the bot to use
best_formation.default_formation=Default offensive formation
best_formation.default_formation.desc=Default offensive formation

best_rocket.npc_rocket=Rocket for NPCs
best_rocket.npc_rocket.desc=Other types of missiles will be used for players.
Expand Down Expand Up @@ -132,6 +134,8 @@ 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
ambulance.ship_type=Type of ship
ambulance.ship_type.desc=Also works with the plus versions
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/deeme/modules/astral/AstralConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ public class AstralConfig {

@Option("astral.choose_item")
public boolean autoChooseItem = false;

@Option("astral.display_warning")
public boolean displayWarning = false;
}
46 changes: 39 additions & 7 deletions src/main/java/com/deeme/modules/astral/AstralGate.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@
import eu.darkbot.api.utils.Inject;
import eu.darkbot.shared.modules.MapModule;
import eu.darkbot.shared.utils.SafetyFinder;
import eu.darkbot.util.Popups;

import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Random;

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

@Feature(name = "Astral Gate", description = "For the astral gate and another GGs")
public class AstralGate implements Module, InstructionProvider, Configurable<AstralConfig>, NpcExtraProvider {
protected final PluginAPI api;
Expand Down Expand Up @@ -92,6 +97,8 @@ public class AstralGate implements Module, InstructionProvider, Configurable<Ast
private int lastPortal = 0;
private State currentStatus;
private int guiOffset = 100;
private boolean showDialog = false;
private boolean warningDisplayed = false;

private double lastRadius = 0;

Expand Down Expand Up @@ -153,6 +160,8 @@ public AstralGate(PluginAPI api, AuthAPI auth, SafetyFinder safety) {
this.astralPortalSupplier = new AstralPortalSupplier(api, astralShip);

this.currentStatus = State.WAIT;
this.showDialog = false;
this.warningDisplayed = false;
}

@Override
Expand Down Expand Up @@ -194,11 +203,12 @@ public String instructions() {
@Override
public void onTickModule() {
pet.setEnabled(false);
showWarningDialog();
if (isAstral() || heroapi.getMap().isGG()) {
if (astralShip == null) {
astralShip = new AstralShip(heroapi.getShipType());
}
if (astralShip.isValid()) {
if (astralShip.isValid(heroapi.getShipType())) {
activeAutoRocketCPU();
repairShield = repairShield && heroapi.getHealth().shieldPercent() < 0.9
|| heroapi.getHealth().shieldPercent() < 0.2;
Expand All @@ -217,20 +227,20 @@ public void onTickModule() {
nextWaveCheck = System.currentTimeMillis() + 30000;
goToTheMiddle();

if (astralGui != null && (astralConfig.autoChoosePortal || astralConfig.autoChooseItem)) {
if (astralConfig.autoChoosePortal || astralConfig.autoChooseItem) {
autoChooseLogic();
} else if (!portals.isEmpty()) {
if (astralGui != null && astralGui.isVisible()) {
this.currentStatus = State.WAITING_HUMAN;
this.bot.setRunning(false);
}
} else if (!portals.isEmpty() || (astralGui != null && astralGui.isVisible())) {
this.currentStatus = State.WAITING_HUMAN;
this.showDialog = true;
this.bot.setRunning(false);
} else {
this.currentStatus = State.WAITING_WAVE;
}
}
waitingSign = true;
}
} else {
this.showDialog = true;
this.currentStatus = State.WAITING_SHIP;
this.astralShip = null;
this.bot.setRunning(false);
Expand All @@ -243,6 +253,7 @@ public void onTickModule() {
@Override
public void onTickStopped() {
if (isAstral()) {
showWarningDialog();
countItems();
}
}
Expand Down Expand Up @@ -631,6 +642,27 @@ private void countItems() {
}
}

private void showWarningDialog() {
if (!showDialog || warningDisplayed) {
return;
}

this.warningDisplayed = true;

JButton closeBtn = new JButton("Close");
closeBtn.addActionListener(e -> {
SwingUtilities.getWindowAncestor(closeBtn).setVisible(false);
warningDisplayed = false;
showDialog = false;
});
Popups.of("Astral Gate",
new JOptionPane(
"Manual action is needed",
JOptionPane.INFORMATION_MESSAGE,
JOptionPane.DEFAULT_OPTION, null, new Object[] { closeBtn }))
.showAsync();
}

enum CPUPLUS implements SelectableItem {
ASTRAL_CPU;

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/deeme/modules/astral/AstralShip.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public String getStatus() {
+ getMaxWeapons() + " | G: " + getGenerators() + "/" + getMaxGenerators();
}

public boolean isValid() {
return this.shipType != null;
public boolean isValid(String ship) {
return this.shipType != null
&& (ship.equals("ship_sentinel") || ship.equals("ship_diminisher") || ship.equals("ship_zephyr")
|| ship.equals("ship_pusat"));
}

public ShipType getShipType() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "DmPlugin",
"author": "Dm94Dani",
"version": "1.7.32",
"version": "1.7.33",
"minVersion": "1.120",
"supportedVersion": "1.121",
"basePackage": "com.deeme",
Expand Down Expand Up @@ -29,6 +29,6 @@
],
"donation": "https://www.paypal.com/donate/?business=JR2XWPSKLWN76&amount=5&no_recurring=0&currency_code=EUR",
"discord": "https://discord.gg/GPRTRRZJPw",
"download": "https://github.com/darkbot-reloaded/DmPlugin/releases/download/v1.7.32/DmPlugin.jar",
"download": "https://github.com/darkbot-reloaded/DmPlugin/releases/download/v1.7.33/DmPlugin.jar",
"update": "https://raw.githubusercontent.com/darkbot-reloaded/DmPlugin/master/src/main/resources/plugin.json"
}

0 comments on commit 0db1f2f

Please sign in to comment.