diff --git a/curr.pid b/curr.pid new file mode 100644 index 000000000..f0a472788 --- /dev/null +++ b/curr.pid @@ -0,0 +1 @@ +79177 1741993455247 \ No newline at end of file diff --git a/src/main/java/com/github/manolo8/darkbot/config/Config.java b/src/main/java/com/github/manolo8/darkbot/config/Config.java index ae05ee051..e109c93dd 100644 --- a/src/main/java/com/github/manolo8/darkbot/config/Config.java +++ b/src/main/java/com/github/manolo8/darkbot/config/Config.java @@ -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; @@ -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; @@ -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; @@ -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; @@ -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 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(); diff --git a/src/main/java/com/github/manolo8/darkbot/config/NpcInfo.java b/src/main/java/com/github/manolo8/darkbot/config/NpcInfo.java index 990c8be64..e4fe8129d 100644 --- a/src/main/java/com/github/manolo8/darkbot/config/NpcInfo.java +++ b/src/main/java/com/github/manolo8/darkbot/config/NpcInfo.java @@ -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(); diff --git a/src/main/java/com/github/manolo8/darkbot/config/types/suppliers/LaserSupplier.java b/src/main/java/com/github/manolo8/darkbot/config/types/suppliers/LaserSupplier.java new file mode 100644 index 000000000..aad042d8a --- /dev/null +++ b/src/main/java/com/github/manolo8/darkbot/config/types/suppliers/LaserSupplier.java @@ -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{ + @Override + public Collection 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); + } +} diff --git a/src/main/java/com/github/manolo8/darkbot/core/manager/GuiManager.java b/src/main/java/com/github/manolo8/darkbot/core/manager/GuiManager.java index fb9b16808..9d83aec0e 100644 --- a/src/main/java/com/github/manolo8/darkbot/core/manager/GuiManager.java +++ b/src/main/java/com/github/manolo8/darkbot/core/manager/GuiManager.java @@ -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); diff --git a/src/main/java/com/github/manolo8/darkbot/gui/tree/utils/TableHelpers.java b/src/main/java/com/github/manolo8/darkbot/gui/tree/utils/TableHelpers.java index 9718ccd54..9d1f9b6c1 100644 --- a/src/main/java/com/github/manolo8/darkbot/gui/tree/utils/TableHelpers.java +++ b/src/main/java/com/github/manolo8/darkbot/gui/tree/utils/TableHelpers.java @@ -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; @@ -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()); } } diff --git a/src/main/java/com/github/manolo8/darkbot/gui/utils/table/LaserNpcInfoEditor.java b/src/main/java/com/github/manolo8/darkbot/gui/utils/table/LaserNpcInfoEditor.java new file mode 100644 index 000000000..c40065f8d --- /dev/null +++ b/src/main/java/com/github/manolo8/darkbot/gui/utils/table/LaserNpcInfoEditor.java @@ -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 { + + 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(); + } + } +} + diff --git a/src/main/java/com/github/manolo8/darkbot/modules/utils/LegacyLaserSuppliers.java b/src/main/java/com/github/manolo8/darkbot/modules/utils/LegacyLaserSuppliers.java index 758c446d0..361cb4533 100644 --- a/src/main/java/com/github/manolo8/darkbot/modules/utils/LegacyLaserSuppliers.java +++ b/src/main/java/com/github/manolo8/darkbot/modules/utils/LegacyLaserSuppliers.java @@ -26,12 +26,12 @@ public static class DefaultLaserSupplier implements LaserSelector, PrioritizedSu private final HeroAPI hero; private final HeroItemsAPI items; - private final ConfigSetting ammoKey; + private final ConfigSetting 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 @@ -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(); } } @@ -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(); } diff --git a/src/main/java/com/github/manolo8/darkbot/modules/utils/NpcAttacker.java b/src/main/java/com/github/manolo8/darkbot/modules/utils/NpcAttacker.java index 0b61e42d8..505ad5598 100644 --- a/src/main/java/com/github/manolo8/darkbot/modules/utils/NpcAttacker.java +++ b/src/main/java/com/github/manolo8/darkbot/modules/utils/NpcAttacker.java @@ -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; @@ -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); @@ -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); @@ -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; } @@ -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()); } } @@ -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() { diff --git a/src/main/resources/lang/strings_en.properties b/src/main/resources/lang/strings_en.properties index 0397e597c..09a18481e 100644 --- a/src/main/resources/lang/strings_en.properties +++ b/src/main/resources/lang/strings_en.properties @@ -106,7 +106,7 @@ config.loot.rsb=RSB config.loot.rsb.desc=Uses RSB ammo on aliens with UR flag config.loot.rsb.enabled=Enabled config.loot.rsb.key=Key -config.loot.ammo_key=Ammo key +config.loot.laser=Ammo config.loot.ship_ability=Offensive ability key config.loot.ship_ability_min=Offensive ability min health config.loot.ship_ability_min.desc=Min NPC health to use ability @@ -128,6 +128,8 @@ config.loot.npc_table.kill=Kill config.loot.npc_table.kill.desc=If this NPC should be killed config.loot.npc_table.attack_key=Ammo key config.loot.npc_table.attack_key.desc=Special ammo for this NPC, if unset, default is used +config.loot.npc_table.attack_laser=Ammo +config.loot.npc_table.attack_laser.desc=Special ammo for this NPC, if unset, default is used config.loot.npc_table.attack_formation=Formation config.loot.npc_table.attack_formation.desc=Special formation for this NPC, if unset, formation from attack config is used config.loot.npc_table.extra=Extra @@ -228,6 +230,7 @@ config.bot_settings=Bot settings config.bot_settings.bot_gui=Bot Interface config.bot_settings.bot_gui.locale=Language +config.bot_settings.bot_gui.laser=Ammo Selection List config.bot_settings.bot_gui.confirm_exit=Confirm exiting config.bot_settings.bot_gui.confirm_exit.desc=Confirm before exiting the bot config.bot_settings.bot_gui.save_gui_pos=Save gui position and size