Skip to content
Draft
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
1 change: 1 addition & 0 deletions curr.pid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
79177 1741993455247
34 changes: 26 additions & 8 deletions src/main/java/com/github/manolo8/darkbot/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.manolo8.darkbot.config.types.suppliers.BrowserApi;
import com.github.manolo8.darkbot.config.types.suppliers.DisplayFlag;
import com.github.manolo8.darkbot.config.types.suppliers.LanguageSupplier;
import com.github.manolo8.darkbot.config.types.suppliers.LaserSupplier;
import com.github.manolo8.darkbot.config.types.suppliers.ModuleSupplier;
import com.github.manolo8.darkbot.config.types.suppliers.PetGears;
import com.github.manolo8.darkbot.config.types.suppliers.ReviveLocation;
Expand All @@ -25,6 +26,7 @@
import eu.darkbot.api.config.annotations.Tag;
import eu.darkbot.api.config.annotations.Visibility;
import eu.darkbot.api.config.annotations.Visibility.Level;
import eu.darkbot.api.config.types.ShipMode;
import eu.darkbot.api.game.enums.PetGear;
import eu.darkbot.api.game.items.ItemCategory;
import eu.darkbot.api.game.items.SelectableItem;
Expand Down Expand Up @@ -152,7 +154,9 @@ public static class Rsb {
public @Option Character KEY = '3';
public @Deprecated int AMMO_REFRESH = 3500;
}
public @Option Character AMMO_KEY = '1';

public @Option.Ignore Character AMMO_KEY = '1';
public @Option @Dropdown(options = LaserSupplier.class) SelectableItem.Laser LASER = SelectableItem.Laser.LCB_10;
public @Option @Visibility(Level.INTERMEDIATE) Character SHIP_ABILITY;
public @Option @Visibility(Level.INTERMEDIATE) @Number(min = 50_000, max = 5_000_000, step = 50_000) int SHIP_ABILITY_MIN = 150_000;
public @Option @Visibility(Level.ADVANCED) @Number(max = 10, step = 1) int MAX_CIRCLE_ITERATIONS = 5;
Expand All @@ -176,10 +180,13 @@ public static class PetSettings {
}

public @Option GroupSettings GROUP = new GroupSettings();

public static class GroupSettings {
public @Option boolean ACCEPT_INVITES = false;
public @Option @Tag(Tag.Default.ALL) PlayerTag WHITELIST_TAG = null;
public @Option @Tag(Tag.Default.NONE) PlayerTag INVITE_TAG = null;
public @Option
@Tag(Tag.Default.ALL) PlayerTag WHITELIST_TAG = null;
public @Option
@Tag(Tag.Default.NONE) PlayerTag INVITE_TAG = null;
public @Option boolean OPEN_INVITES = false;
public @Option boolean BLOCK_INVITES = false;
public @Option boolean LEAVE_NO_WHITELISTED = false;
Expand Down Expand Up @@ -207,15 +214,26 @@ public static class Miscellaneous {
}

public @Option BotSettings BOT_SETTINGS = new BotSettings();

public static class BotSettings {
public @Option BotGui BOT_GUI = new BotGui();

public static class BotGui {
@Option @Dropdown(options = LanguageSupplier.class)
@Option
@Dropdown(options = LanguageSupplier.class)
public Locale LOCALE = new Locale(Locale.getDefault().getLanguage());

public @Option @Visibility(Level.INTERMEDIATE) boolean CONFIRM_EXIT = true;
public @Option @Visibility(Level.INTERMEDIATE) boolean SAVE_GUI_POS = false;
public @Option @Visibility(Level.ADVANCED) @Number(min = 1, max = 20, step = 1) int BUTTON_SIZE = 4;
@Option
@Dropdown(multi = true)
public Set<SelectableItem.Laser> LASER = EnumSet.of(SelectableItem.Laser.LCB_10, SelectableItem.Laser.MCB_25,
SelectableItem.Laser.MCB_50, SelectableItem.Laser.UCB_100,
SelectableItem.Laser.RSB_75, SelectableItem.Laser.A_BL, SelectableItem.Laser.JOB_100);
public @Option
@Visibility(Level.INTERMEDIATE) boolean CONFIRM_EXIT = true;
public @Option
@Visibility(Level.INTERMEDIATE) boolean SAVE_GUI_POS = false;
public @Option
@Visibility(Level.ADVANCED)
@Number(min = 1, max = 20, step = 1) int BUTTON_SIZE = 4;

public boolean ALWAYS_ON_TOP = true; // No @Option. Edited via button
public WindowPosition MAIN_GUI_WINDOW = new WindowPosition();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/github/manolo8/darkbot/config/NpcInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class NpcInfo implements eu.darkbot.api.config.types.NpcInfo {
public boolean kill;
@Option("config.loot.npc_table.attack_key")
public Character attackKey;
@Option("config.loot.npc_table.attack_laser")
public SelectableItem.Laser attackLaser;
@Option("config.loot.npc_table.attack_formation")
public Character attackFormation;
public ExtraNpcInfo extra = new ExtraNpcInfo();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.manolo8.darkbot.config.types.suppliers;

import com.github.manolo8.darkbot.core.manager.HeroManager;
import eu.darkbot.api.config.annotations.Dropdown;
import eu.darkbot.api.game.items.SelectableItem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

public class LaserSupplier implements Dropdown.Options<SelectableItem.Laser>{
@Override
public Collection<SelectableItem.Laser> options() {
return HeroManager.instance.main.config.BOT_SETTINGS.BOT_GUI.LASER;
}

@Override
public @NotNull String getText(SelectableItem.@Nullable Laser option) {
return Dropdown.Options.super.getText(option);
}

@Override
public @Nullable String getTooltip(SelectableItem.@Nullable Laser option) {
return Dropdown.Options.super.getTooltip(option);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ private enum LoadStatus {
CLICKING_ONE(gm -> {
if (gm.loggedInTimer.getRemainingFuse() > 13000) return false;
Character keyBind = gm.main.facadeManager.slotBars.getKeyBind(gm.main.hero.getFormation());
API.keyboardClick(keyBind == null ? gm.main.config.LOOT.AMMO_KEY : keyBind, false);
// API.keyboardClick(keyBind == null ? gm.main.config.LOOT.AMMO_KEY : keyBind, false);
return true;
}),
CLICKING_TWO(gm -> {
if (gm.loggedInTimer.getRemainingFuse() > 12000) return false;
Character keyBind = gm.main.facadeManager.slotBars.getKeyBind(gm.main.hero.getFormation());
API.keyboardClick(keyBind == null ? gm.main.config.LOOT.AMMO_KEY : keyBind, false);
// API.keyboardClick(keyBind == null ? gm.main.config.LOOT.AMMO_KEY : keyBind, false);
return true;
}),
CLICKING_THREE(gm -> {
if (gm.loggedInTimer.getRemainingFuse() > 11000) return false;
Character keyBind = gm.main.facadeManager.slotBars.getKeyBind(gm.main.hero.getFormation());
API.keyboardClick(keyBind == null ? gm.main.config.LOOT.AMMO_KEY : keyBind, false);
// API.keyboardClick(keyBind == null ? gm.main.config.LOOT.AMMO_KEY : keyBind, false);
return true;
}),
DONE(q -> false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.github.manolo8.darkbot.config.NpcInfo;
import com.github.manolo8.darkbot.gui.utils.MultiTableRowSorter;
import com.github.manolo8.darkbot.gui.utils.table.ExtraNpcInfoEditor;
import com.github.manolo8.darkbot.gui.utils.table.LaserNpcInfoEditor;
import eu.darkbot.api.config.ConfigSetting;
import eu.darkbot.api.config.annotations.Table;
import eu.darkbot.api.game.items.SelectableItem;
import eu.darkbot.api.managers.ConfigAPI;
import eu.darkbot.api.managers.StarSystemAPI;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -76,6 +78,7 @@ public void handle(JTable jTable, JScrollPane jScrollPane,
new RowSorter.SortKey(2, SortOrder.ASCENDING),
new RowSorter.SortKey(0, SortOrder.DESCENDING)));

jTable.setDefaultEditor(SelectableItem.Laser.class, new LaserNpcInfoEditor());
jTable.setDefaultEditor(NpcInfo.ExtraNpcInfo.class, new ExtraNpcInfoEditor());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.github.manolo8.darkbot.gui.utils.table;

import com.github.manolo8.darkbot.core.manager.HeroManager;
import com.github.manolo8.darkbot.gui.utils.PopupMenuListenerAdapter;
import eu.darkbot.api.game.items.SelectableItem;

import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LaserNpcInfoEditor extends TableDelegateEditor<JLabel> {

private static final ToolTipManager TOOLTIPS = ToolTipManager.sharedInstance();
private final JPopupMenu popupMenu = new JPopupMenu();
private SelectableItem.Laser selectedLaser;
private int tooltipDelay = -1;

public LaserNpcInfoEditor() {
super(new JLabel());

popupMenu.addPopupMenuListener(new PopupMenuListenerAdapter() {
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
if (tooltipDelay != -1) {
TOOLTIPS.setInitialDelay(tooltipDelay); // Restore original delay
}
}
});
}

@Override
protected void setValue(Object val) {
if (val instanceof SelectableItem.Laser) {
selectedLaser = (SelectableItem.Laser) val;
delegate.setText(selectedLaser.toString());
} else {
selectedLaser = null;
delegate.setText("None");
}
}

@Override
protected Object getValue() {
return selectedLaser;
}

public void startEditing(JTable table, Object value, boolean isSelected, int row, int column) {
SwingUtilities.invokeLater(() -> {
if (!table.isShowing()) return;

// Rebuild the menu every time it's opened
rebuildPopupMenu();

Rectangle cellRect = table.getCellRect(row, column, false);
int x = cellRect.x;
int y = cellRect.y + cellRect.height;

popupMenu.show(table, x, y);
});
}

private void rebuildPopupMenu() {
popupMenu.removeAll(); // Clear old items

// "None" option to clear selection
JMenuItem noneItem = new JMenuItem("None");
noneItem.addActionListener(e -> {
selectedLaser = null;
delegate.setText("None");
stopCellEditing();
});
popupMenu.add(noneItem);
popupMenu.addSeparator();

// Dynamically add all available lasers
for (SelectableItem.Laser laser : HeroManager.instance.main.config.BOT_SETTINGS.BOT_GUI.LASER) {
JMenuItem menuItem = new JMenuItem(laser.toString());
menuItem.setToolTipText("Select laser: " + laser);
menuItem.addActionListener(new AmmoSelectionHandler(laser));
popupMenu.add(menuItem);
}
}


private class AmmoSelectionHandler implements ActionListener {
private final SelectableItem.Laser laser;

public AmmoSelectionHandler(SelectableItem.Laser laser) {
this.laser = laser;
}

@Override
public void actionPerformed(ActionEvent e) {
selectedLaser = laser;
delegate.setText(laser.toString());
stopCellEditing();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public static class DefaultLaserSupplier implements LaserSelector, PrioritizedSu

private final HeroAPI hero;
private final HeroItemsAPI items;
private final ConfigSetting<Character> ammoKey;
private final ConfigSetting<SelectableItem.Laser> ammoLaser;

public DefaultLaserSupplier(HeroAPI hero, HeroItemsAPI items, ConfigAPI config) {
this.hero = hero;
this.items = items;
this.ammoKey = config.requireConfig("loot.ammo_key");
this.ammoLaser = config.requireConfig("loot.laser");
}

@Override
Expand All @@ -48,8 +48,7 @@ public SelectableItem.Laser get() {
if (ammo.isPresent()) return ammo.get();
}

Item i = items.getItem(ammoKey.getValue());
return i != null ? i.getAs(SelectableItem.Laser.class) : null;
return ammoLaser.getValue();
}
}

Expand Down Expand Up @@ -135,17 +134,14 @@ private boolean shouldSab() {
Npc target = hero.getLocalTargetAs(Npc.class);

Config.Loot.Sab SAB = sabSettings.getValue();
if (target == null || !SAB.ENABLED || SAB.KEY == null
if (target == null || !SAB.ENABLED
|| target.getInfo().hasExtraFlag(NpcExtra.NO_SAB)
|| hero.getHealth().shieldPercent() > SAB.PERCENT
|| target.getHealth().getShield() <= SAB.NPC_AMOUNT
|| (SAB.CONDITION != null && !SAB.CONDITION.get(main).toBoolean()))
return false;

Item i = heroItems.getItem(SAB.KEY);
laser = i != null ? i.getAs(SelectableItem.Laser.class) : null;

return laser != null && heroItems.getItem(i, ItemFlag.USABLE, ItemFlag.READY)
return heroItems.getItem(SelectableItem.Laser.SAB_50, ItemFlag.USABLE, ItemFlag.READY)
.filter(item -> item.getQuantity() > 50)
.isPresent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class NpcAttacker implements AttackAPI {

protected boolean firstAttack; // If the initial attack was cast

protected Character lastShot;
protected SelectableItem.Laser lastShot;

// This is now always unset, kept for plugin backwards compat
protected @Deprecated boolean sab, rsb;
Expand Down Expand Up @@ -138,7 +138,7 @@ protected void tryAttackOrFix() {
if (!firstAttack) {
firstAttack = true;
sendAttack(1500, 5000, true);
} else if (getPreviousAttackKey() != getAttackKey()) {
} else if (getPreviousAttackLaser() != getAttackLaser()) {
sendAttack(250, 5000, true);
} else if (!hero.isAttacking(target) || !hero.isAiming(target)) {
sendAttack(1500, 5000, false);
Expand All @@ -153,7 +153,7 @@ protected void tryAttackOrFix() {
private void sendAttack(long minWait, long bugTime, boolean normal) {
laserTime = System.currentTimeMillis() + minWait;
isAttacking = Math.max(isAttacking, laserTime + bugTime);
if (normal) API.keyboardClick(lastShot = getAttackKey());
if (normal) items.useItem(lastShot = getAttackLaser());
else if (API.hasCapability(Capability.ALL_KEYBINDS_SUPPORT))
keybinds.pressKeybind(ATTACK_LASER);
else target.trySelect(true);
Expand All @@ -167,21 +167,20 @@ public double modifyRadius(double radius) {
return radius + bar.findItemById("ability_zephyr_mmt").map(i -> i.quantity).orElse(0d) * 5;
}

private Character getAttackKey() {
private SelectableItem.Laser getAttackLaser() {
caller = this;
SelectableItem.Laser laser = laserHandler.getBest();
caller = null;

if (laser != null) {
Character key = items.getKeyBind(laser);
if (key != null) return key;
return laser;
}

return this.target == null || this.target.npcInfo.attackKey == null ?
main.config.LOOT.AMMO_KEY : this.target.npcInfo.attackKey;
return this.target == null || this.target.npcInfo.attackLaser == null ?
main.config.LOOT.LASER : this.target.npcInfo.attackLaser;
}

private Character getPreviousAttackKey() {
private SelectableItem.Laser getPreviousAttackLaser() {
return lastShot;
}

Expand Down Expand Up @@ -224,7 +223,7 @@ public void stopAttack() {
laserTime = System.currentTimeMillis() + 1500;
if (API.hasCapability(Capability.ALL_KEYBINDS_SUPPORT))
API.keyboardClick(keybinds.getCharCode(ATTACK_LASER));
else API.keyboardClick(getPreviousAttackKey());
else items.useItem(getPreviousAttackLaser());
}
}

Expand Down Expand Up @@ -310,8 +309,7 @@ public SabSupplier(Main main, HeroAPI hero, AttackAPI attacker, HeroItemsAPI ite
@Override
public SelectableItem.Laser get() {
if (!shouldSab()) return null;
Item sab = items.getItem(main.config.LOOT.SAB.KEY);
return sab != null ? sab.getAs(SelectableItem.Laser.class) : null;
return SelectableItem.Laser.SAB_50;
}

private boolean shouldSab() {
Expand Down
Loading