Skip to content

Commit

Permalink
Update to v1.5.5 (#3)
Browse files Browse the repository at this point in the history
- PaladiumModule: Fixed some common errors
- SentinelModule: It should now work better
- Defense Mode: You will now check the conditions for SAB
  • Loading branch information
dm94 authored Apr 5, 2022
1 parent de9ab82 commit d893d74
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 52 deletions.
104 changes: 73 additions & 31 deletions src/main/java/com/deeme/modules/PaladiumModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@
import com.deeme.types.VerifierChecker;
import com.deeme.types.backpage.HangarChanger;
import com.deeme.types.gui.ShipSupplier;

import com.github.manolo8.darkbot.Main;
import com.github.manolo8.darkbot.backpage.HangarManager;
import com.github.manolo8.darkbot.config.types.Editor;
import com.github.manolo8.darkbot.config.types.Option;
import com.github.manolo8.darkbot.config.types.Options;

import com.github.manolo8.darkbot.core.entities.BasePoint;
import com.github.manolo8.darkbot.core.itf.Configurable;
import com.github.manolo8.darkbot.core.itf.InstructionProvider;
import com.github.manolo8.darkbot.core.itf.Module;
import com.github.manolo8.darkbot.core.manager.HeroManager;
import com.github.manolo8.darkbot.core.manager.StatsManager;
import com.github.manolo8.darkbot.core.objects.Map;
import com.github.manolo8.darkbot.core.objects.OreTradeGui;
import com.github.manolo8.darkbot.core.utils.Drive;
import com.github.manolo8.darkbot.core.utils.Location;

import com.github.manolo8.darkbot.extensions.features.Feature;
import com.github.manolo8.darkbot.gui.tree.components.JListField;

import com.github.manolo8.darkbot.modules.LootNCollectorModule;
import com.github.manolo8.darkbot.modules.MapModule;

import eu.darkbot.api.managers.OreAPI.Ore;

import java.util.Arrays;
import java.util.List;

@Feature(name = "Palladium Hangar", description = "Collect palladium and change hangars to sell")
public class PaladiumModule extends LootNCollectorModule implements Module, Configurable<PaladiumModule.PalladiumConfig>, InstructionProvider {
public class PaladiumModule extends LootNCollectorModule implements Configurable<PaladiumModule.PalladiumConfig> {

private HeroManager hero;
private Drive drive;
Expand All @@ -51,15 +55,7 @@ public class PaladiumModule extends LootNCollectorModule implements Module, Conf
private HangarChanger hangarChanger;
private Integer hangarToChange = null;
private int cargos = 0;

@Override
public String instructions() {
return "Palladium Hangar Module: \n"+
"It is necessary that a portal allows refresh to change the hangar \n" +
"Use in 5-2 a ship with less cargo than 5-3 \n" +
"Select palladium hangar and 5-2 hangar \n" +
"If the hangar list does not appear, click on \"Update HangarList\", close the config windows and it will be updated within minutes.";
}
private boolean firstTick = true;

private enum State {
WAIT ("Waiting"),
Expand All @@ -74,7 +70,9 @@ private enum State {
NO_ACCEPT("You haven't opened the link"),
LOADING_HANGARS("Waiting - Loading hangars"),
SEARCHING_PORTALS("Looking for a portal to change hangar"),
DEFENSE_MODE("DEFENSE MODE");
DEFENSE_MODE("DEFENSE MODE"),
WAITING_HANGARS("Waiting - For change hangars"),
HANGAR_ERROR("Error when changing hangar");

private final String message;

Expand Down Expand Up @@ -109,27 +107,47 @@ public void setConfig(PalladiumConfig palladiumConfig) {

@Override
public boolean canRefresh() {
return hero.target == null;
return !hero.hasTarget();
}

@Override
public void tickStopped() {
if (main.repairManager.isDead()) {
main.guiManager.tryRevive();
}
tryUpdateHangarList();
if (currentStatus == State.SWITCHING_PALA_HANGAR || currentStatus == State.DEPOSIT_FULL_SWITCHING_HANGAR ||
currentStatus == State.DISCONNECTING || currentStatus == State.SWITCHING_HANGAR || currentStatus == State.RELOAD_GAME) {
currentStatus == State.DISCONNECTING || currentStatus == State.SWITCHING_HANGAR || currentStatus == State.RELOAD_GAME ||
currentStatus == State.WAITING_HANGARS || currentStatus == State.HANGAR_ERROR) {
if (hangarChanger.activeHangar != null) {
if (hangarChanger.disconectTime == 0 && !hangarChanger.isDisconnect()) {
currentStatus = State.DISCONNECTING;
hangarChanger.disconnect(true);
} else if (hangarChanger.isDisconnect() && currentStatus == State.DISCONNECTING && hangarChanger.disconectTime <= System.currentTimeMillis() - 30000) {
currentStatus = State.SWITCHING_HANGAR;
hangarChanger.changeHangar(hangarToChange, false);
if (!canBeDisconnected()) {
main.setRunning(true);
} else {
currentStatus = State.DISCONNECTING;
hangarChanger.disconnect(true);
hangarChanger.disconectTime = System.currentTimeMillis();
}
} else if (hangarChanger.isDisconnect() && (currentStatus == State.DISCONNECTING || currentStatus == State.HANGAR_ERROR) && hangarChanger.disconectTime <= System.currentTimeMillis() - 30000) {
if (hangarChanger.changeHangar(hangarToChange, false)) {
currentStatus = State.SWITCHING_HANGAR;
} else {
currentStatus = State.HANGAR_ERROR;
hangarChanger.disconectTime = System.currentTimeMillis();
}
} else if (hangarChanger.disconectTime <= System.currentTimeMillis() - 40000 && currentStatus == State.SWITCHING_HANGAR) {
currentStatus = State.WAITING_HANGARS;
} else if (hangarChanger.disconectTime <= System.currentTimeMillis() - 50000 && currentStatus == State.WAITING_HANGARS) {
currentStatus = State.RELOAD_GAME;
hangarChanger.reloadAfterDisconnect(true);
} else if (!hangarChanger.isDisconnect() && currentStatus == State.DISCONNECTING && hangarChanger.disconectTime <= System.currentTimeMillis() - 60000) {
hangarChanger.disconnect(true);
hangarChanger.disconectTime = System.currentTimeMillis();
}
}
}
if (!hangarChanger.isDisconnect() && currentStatus != State.DISCONNECTING && (hero.map == SELL_MAP || hero.map == ACTIVE_MAP)) {
currentStatus = State.WAIT;
this.firstTick = true;
main.setRunning(true);
hangarChanger.disconectTime = 0;
drive.stop(true);
Expand All @@ -139,13 +157,15 @@ public void tickStopped() {


public static class PalladiumConfig {

@Option(value = "Update HangarList", description = "Mark it to update the hangar list")
public transient boolean updateHangarList = true;

@Option(value = "Travel to portal before switch", description = "Go to the portal to change the hangar")
public boolean goPortalChange = true;

@Option(value = "Sell when it is on map 5-2", description = "If your collection ship passes 5-2 and has palladium it will go to sell and then go to 5-3")
public boolean sellOnDie = true;

@Option(value = "Collecting Hangar (5-3)", description = "Ship 5-3 Hangar ID")
@Editor(JListField.class)
@Options(ShipSupplier.class)
Expand All @@ -160,7 +180,7 @@ public static class PalladiumConfig {

@Override
public String status() {
return currentStatus.message + " | " + cargos + " | " + super.status();
return currentStatus.message + " | " + cargos + " | " + super.status();
}

@Override
Expand All @@ -172,36 +192,56 @@ public String stoppedStatus() {
public void tick() {
tryUpdateHangarList();

if (State.RELOAD_GAME == currentStatus) {
this.firstTick = true;
}

if (hangarChanger.activeHangar == null) {
currentStatus = State.LOADING_HANGARS;
hangarChanger.updateHangarActive();
return;
}

if (statsManager.deposit >= statsManager.depositTotal) {
if (this.firstTick) {
this.firstTick = false;
return;
}


if (statsManager.getCargo() >= statsManager.getMaxCargo() && this.main.guiManager.refinement.getAmount(Ore.PALLADIUM) > 15) {
if (hangarChanger.activeHangar.equals(configPa.sellHangar)) {
this.currentStatus = State.HANGAR_AND_MAP_BASE;
sell();
} else if (canBeDisconnected()) {
} else if (configPa.sellHangar != null && hangarChanger.activeHangar != null && configPa.sellHangar != hangarChanger.activeHangar && canBeDisconnected()) {
this.currentStatus = State.DEPOSIT_FULL_SWITCHING_HANGAR;
hangarToChange = configPa.sellHangar;
main.setRunning(false);
} else if (!main.guiManager.lostConnection.visible && !main.guiManager.logout.visible) {
super.tick();
currentStatus = State.SEARCHING_PORTALS;
}

} else if (hangarChanger.activeHangar.equals(configPa.collectHangar) &&
!main.guiManager.lostConnection.visible && !main.guiManager.logout.visible) {
if (hero.map.id == 93) {
if (hero.map.id == this.ACTIVE_MAP.id) {
this.currentStatus = State.LOOT_PALADIUM;
super.tick();
} else {
this.currentStatus = State.HANGAR_PALA_OTHER_MAP;
hero.roamMode();
this.main.setModule(new MapModule()).setTarget(this.main.starManager.byId(93));
if (configPa.sellOnDie && this.main.guiManager.refinement.getAmount(Ore.PALLADIUM) > 15) {
sell();
} else {
if (oreTrade.isVisible()) {
oreTrade.showTrade(false, (BasePoint) null);
if (oreTrade.isVisible()) {
hangarChanger.reloadAfterDisconnect(true);
}
} else {
this.main.setModule(new MapModule()).setTarget(this.ACTIVE_MAP);
}
}
}
} else if (configPa.collectHangar != null) {
} else if (configPa.collectHangar != null && hangarChanger.activeHangar != null && configPa.collectHangar != hangarChanger.activeHangar) {
this.currentStatus = State.SWITCHING_PALA_HANGAR;
hangarToChange = configPa.collectHangar;
main.setRunning(false);
Expand All @@ -210,7 +250,7 @@ public void tick() {

private boolean canBeDisconnected() {
if (configPa.goPortalChange) return super.canRefresh();
else return hero.health.hpPercent() >= 0.9 && SharedFunctions.getAttacker(hero, main, hero, null) == null;
return !hero.isAttacking() && SharedFunctions.getAttacker(hero, main, hero, null) == null;
}

private void sell() {
Expand All @@ -226,6 +266,7 @@ private void sell() {
oreTrade.sellOre(OreTradeGui.Ore.PALLADIUM);
sellClick = System.currentTimeMillis();
cargos++;
oreTrade.showTrade(false, base);
}
});
}
Expand All @@ -236,8 +277,9 @@ private void tryUpdateHangarList() {

try {
hangarManager.updateHangarList();
if (ShipSupplier.updateOwnedShips(hangarManager.getHangarList().getData().getRet().getShipInfos()))
if (ShipSupplier.updateOwnedShips(hangarManager.getHangarList().getData().getRet().getShipInfos())) {
configPa.updateHangarList = false;
}
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/deeme/modules/SentinelModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ public void tick() {
main.guiManager.pet.setEnabled(true);
if (main.guiManager.group.group != null && main.guiManager.group.group.isValid()) {
if (shipAround()) {
if (!isAttacking() && main.hero.target != sentinel) {
if (!isAttacking() && main.hero.getTarget() != sentinel) {
main.hero.roamMode();
drive.move(sentinel);
if (drive.getDistanceBetween(main.hero.locationInfo, sentinel.locationInfo) > 300) {
drive.move(sentinel);
}
} else {
drive.move(Location.of(attacker.target.locationInfo.now, rnd.nextInt(360), attacker.target.npcInfo.radius));
}
Expand All @@ -97,18 +99,21 @@ public void tick() {
}

private boolean isAttacking() {
if (this.npcs == null) { return false; }
if ((attacker.target = this.npcs.stream()
.filter(s -> sentinel.isAttacking(s))
.findAny().orElse(null)) == null) {
return false;
}

main.hero.attackMode(attacker.target);
attacker.doKillTargetTick();

return (attacker.target != null);
}

private boolean shipAround() {
if (this.ships == null) { return false; }
sentinel = this.ships.stream()
.filter(ship -> (sConfig.SENTINEL_TAG.has(main.config.PLAYER_INFOS.get(ship.id))))
.findAny().orElse(null);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/deeme/tasks/Skylab.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private int sendResources() {
if (this.config.sepromToSend == 0 && this.config.promeriumToSend == 0)
return 1;

int cargo = this.main.statsManager.depositTotal - this.main.statsManager.deposit + 50;
int cargo = this.main.statsManager.getMaxCargo() - this.main.statsManager.getCargo() + 50;
int seprom = 0;
int promerium = 0;

Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/deeme/types/ShipAttacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public ShipAttacker(Main main, Defense defense) {
this.defense = defense;
this.safety = new SafetyFinder(main);
this.rnd = new Random();

}

public void tick() {
Expand Down Expand Up @@ -113,7 +112,7 @@ private void setConfigToUse() {

void lockAndSetTarget() {
if (hero.locationInfo.distance(target) > 700 || System.currentTimeMillis() - clickDelay < 400) return;
hero.setTarget(target);
hero.setLocalTarget(target);
setRadiusAndClick(true);
clickDelay = System.currentTimeMillis();
fixTimes = 0;
Expand All @@ -136,8 +135,9 @@ protected void tryAttackOrFix() {
}

private boolean shouldSab() {
return defense.SAB.ENABLED && hero.health.shieldPercent() < defense.SAB.PERCENT
&& target.health.shield > defense.SAB.NPC_AMOUNT;
return defense.SAB.ENABLED && hero.getHealth().shieldPercent() <= defense.SAB.PERCENT
&& target.getHealth().getShield() > defense.SAB.NPC_AMOUNT
&& (defense.SAB.CONDITION == null || defense.SAB.CONDITION.get(this.main.pluginAPI).toBoolean());
}

private char getAttackKey() {
Expand Down Expand Up @@ -215,6 +215,11 @@ public boolean isUnderAttack() {
if (ships.isEmpty()) return false;

for (Ship ship : ships) {
if (defense.helpAttack && ship.isAttacking() && ship.getTarget() != null) {
target = (Ship) ship.getTarget();
return target != null;
}

target = SharedFunctions.getAttacker(ship,main,this.hero,target);
if (target != null) {
return target != null;
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/com/deeme/types/backpage/HangarChanger.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public HangarChanger(Main m, Map... maps) {
public void updateHangarActive() {
try {
hangarManager.updateHangarList();
hangarManager.updateCurrentHangar();
activeHangar = hangarManager.getHangarList().getData().getRet().getHangars().stream()
.filter(Hangar::isActive)
.map(Hangar::getHangarId)
Expand All @@ -49,16 +50,6 @@ public void updateHangarActive() {
}
}

public void changeHangar(Integer hangar, boolean inBase) {
if ((inBase || lostConnection.visible) && hangar != null) {
System.out.println("Hangar change to: " + hangar);
if (changeHangar(hangar)) {
activeHangar = null;
updateHangarActive();
}
}
}

public void disconnect(boolean stop) {
if (hero.map.id > 0 && (maps == null || maps.contains(hero.map))
&& !logout.visible && !main.hero.locationInfo.isMoving()) {
Expand Down Expand Up @@ -108,6 +99,18 @@ public void setDisconnectModule(String reason) {
}
}

public boolean changeHangar(Integer hangar, boolean inBase) {
if ((inBase || lostConnection.visible) && hangar != null) {
System.out.println("Hangar change to: " + hangar);
if (changeHangar(hangar)) {
activeHangar = null;
updateHangarActive();
return true;
}
}
return false;
}

private boolean changeHangar(Integer hangarId) {
String token = "";
try {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/deeme/types/config/Defense.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class Defense {
@Option(value = "Help everyone", description = "Help all those who are not enemies")
public boolean helpEveryone = true;

@Option(value = "Help to Attack", description = "Help to attack")
public boolean helpAttack = false;

@Option(value = "Movement Mode", description = "Choose how to move in defense mode")
@Editor(JListField.class)
@Options(MovementMode.class)
Expand Down
Loading

0 comments on commit d893d74

Please sign in to comment.