-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apologies for issues with last commit. Still learning.
- Loading branch information
1 parent
b0282db
commit 59a3edd
Showing
25 changed files
with
1,512 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
513 changes: 513 additions & 0 deletions
513
...src/main/java/net/runelite/client/plugins/microbot/bradleycombat/BradleyCombatConfig.java
Large diffs are not rendered by default.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
...rc/main/java/net/runelite/client/plugins/microbot/bradleycombat/BradleyCombatOverlay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package net.runelite.client.plugins.microbot.bradleycombat; | ||
|
||
import com.google.common.base.Strings; | ||
import net.runelite.api.Actor; | ||
import net.runelite.api.Perspective; | ||
import net.runelite.api.Point; | ||
import net.runelite.api.coords.LocalPoint; | ||
import net.runelite.api.coords.WorldPoint; | ||
import net.runelite.api.events.ActorDeath; | ||
import net.runelite.client.eventbus.Subscribe; | ||
import net.runelite.client.plugins.microbot.Microbot; | ||
import net.runelite.client.plugins.microbot.util.player.Rs2Player; | ||
import net.runelite.client.plugins.microbot.util.target.Rs2Target; | ||
import net.runelite.client.ui.overlay.Overlay; | ||
import net.runelite.client.ui.overlay.OverlayLayer; | ||
import net.runelite.client.ui.overlay.OverlayPosition; | ||
import net.runelite.client.ui.overlay.OverlayUtil; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.inject.Inject; | ||
import java.awt.*; | ||
|
||
public class BradleyCombatOverlay extends Overlay { | ||
private final BradleyCombatConfig config; | ||
|
||
@Inject | ||
BradleyCombatOverlay(BradleyCombatPlugin plugin, BradleyCombatConfig config) { | ||
super(plugin); | ||
this.config = config; | ||
setPosition(OverlayPosition.DYNAMIC); | ||
setNaughty(); | ||
setLayer(OverlayLayer.ABOVE_SCENE); | ||
} | ||
|
||
@Override | ||
public Dimension render(Graphics2D graphics) { | ||
try { | ||
if (Rs2Target.getTarget() != null && !Rs2Target.getTarget().isDead()) { | ||
WorldPoint targetLoc = Rs2Target.getTarget().getWorldLocation(); | ||
if (targetLoc != null) { | ||
Color highlightColor = config.targetTileColor(); | ||
drawTile(graphics, targetLoc, highlightColor, "", new BasicStroke(2)); | ||
} | ||
} | ||
} catch (Exception ex) { | ||
System.out.println(ex.getMessage()); | ||
} | ||
return null; | ||
} | ||
|
||
private void drawTile(Graphics2D graphics, WorldPoint point, Color color, @Nullable String label, Stroke borderStroke) { | ||
if (point == null) { | ||
return; | ||
} | ||
WorldPoint playerLocation = Rs2Player.getWorldLocation(); | ||
if (playerLocation == null || point.distanceTo(playerLocation) >= 32) { | ||
return; | ||
} | ||
LocalPoint lp = LocalPoint.fromWorld(Microbot.getClient(), point); | ||
if (lp == null) { | ||
return; | ||
} | ||
Polygon poly = Perspective.getCanvasTilePoly(Microbot.getClient(), lp); | ||
if (poly != null) { | ||
OverlayUtil.renderPolygon(graphics, poly, color, new Color(0, 0, 0, 50), borderStroke); | ||
} | ||
if (!Strings.isNullOrEmpty(label)) { | ||
Point canvasTextLocation = Perspective.getCanvasTextLocation(Microbot.getClient(), graphics, lp, label, 0); | ||
if (canvasTextLocation != null) { | ||
OverlayUtil.renderTextLocation(graphics, canvasTextLocation, label, color); | ||
} | ||
} | ||
} | ||
|
||
@Subscribe | ||
public void onActorDeath(ActorDeath event) { | ||
Actor deadActor = event.getActor(); | ||
if (deadActor != null && deadActor == Rs2Target.getTarget()) { | ||
Rs2Target.setTarget(null); | ||
} | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
149
...src/main/java/net/runelite/client/plugins/microbot/bradleycombat/BradleyCombatPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package net.runelite.client.plugins.microbot.bradleycombat; | ||
|
||
import com.google.inject.Provides; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.runelite.client.callback.ClientThread; | ||
import net.runelite.client.config.ConfigManager; | ||
import net.runelite.client.config.Keybind; | ||
import net.runelite.client.eventbus.EventBus; | ||
import net.runelite.client.input.KeyListener; | ||
import net.runelite.client.input.KeyManager; | ||
import net.runelite.client.plugins.Plugin; | ||
import net.runelite.client.plugins.PluginDescriptor; | ||
import net.runelite.client.plugins.microbot.Microbot; | ||
import net.runelite.client.plugins.microbot.bradleycombat.actions.*; | ||
import net.runelite.client.plugins.microbot.bradleycombat.handlers.MenuHandler; | ||
import net.runelite.client.plugins.microbot.bradleycombat.handlers.PostActionHandler; | ||
import net.runelite.client.plugins.microbot.bradleycombat.handlers.RelayHandler; | ||
import net.runelite.client.plugins.microbot.bradleycombat.handlers.TankHandler; | ||
import net.runelite.client.plugins.microbot.util.prayer.Rs2PrayerEnum; | ||
import net.runelite.client.ui.overlay.OverlayManager; | ||
|
||
import javax.inject.Inject; | ||
import java.awt.*; | ||
import java.awt.event.KeyEvent; | ||
|
||
import static net.runelite.client.plugins.microbot.Microbot.isLoggedIn; | ||
|
||
@Slf4j | ||
@PluginDescriptor(name = PluginDescriptor.Bradley + "Bradley Combat", description = "A plugin for managing combat swaps, special attacks, prayer toggles, and food/potion actions via hotkeys.", tags = {"combat", "hotkeys", "microbot"}, enabledByDefault = false) | ||
public class BradleyCombatPlugin extends Plugin implements KeyListener { | ||
@Inject | ||
private BradleyCombatConfig config; | ||
@Inject | ||
private KeyManager keyManager; | ||
@Inject | ||
private OverlayManager overlayManager; | ||
@Inject | ||
private BradleyCombatOverlay overlay; | ||
@Inject | ||
private BradleyCombatScript script; | ||
@Inject | ||
private MenuHandler menuHandler; | ||
@Inject | ||
private PostActionHandler postActionHandler; | ||
@Inject | ||
private TankHandler tankHandler; | ||
@Inject | ||
private EventBus eventBus; | ||
@Inject | ||
private ClientThread clientThread; | ||
@Inject | ||
private RelayHandler relayHandler; | ||
private boolean hotkeyConsumed = false; | ||
|
||
@Provides | ||
BradleyCombatConfig provideConfig(ConfigManager m) { | ||
return m.getConfig(BradleyCombatConfig.class); | ||
} | ||
|
||
@Override | ||
protected void startUp() throws Exception { | ||
keyManager.registerKeyListener(this); | ||
overlayManager.add(overlay); | ||
eventBus.register(menuHandler); | ||
eventBus.register(tankHandler); | ||
eventBus.register(postActionHandler); | ||
eventBus.register(overlayManager); | ||
script.run(config); | ||
} | ||
|
||
@Override | ||
protected void shutDown() { | ||
script.shutdown(); | ||
Microbot.enableAutoRunOn = false; | ||
keyManager.unregisterKeyListener(this); | ||
overlayManager.remove(overlay); | ||
eventBus.unregister(menuHandler); | ||
eventBus.unregister(postActionHandler); | ||
eventBus.unregister(tankHandler); | ||
eventBus.unregister(overlayManager); | ||
} | ||
|
||
@Override | ||
public void keyTyped(KeyEvent e) { | ||
if (hotkeyConsumed) { | ||
e.consume(); | ||
hotkeyConsumed = false; | ||
} | ||
} | ||
|
||
@Override | ||
public void keyPressed(KeyEvent e) { | ||
if (!isLoggedIn()) return; | ||
if (!Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK)) return; | ||
hotkeyConsumed = false; | ||
if (processKey(e, config.protectFromMagic(), () -> relayHandler.action(config.protectFromMagic(), new DefensivePrayerAction(Rs2PrayerEnum.PROTECT_MAGIC)))) | ||
return; | ||
if (processKey(e, config.protectFromMissles(), () -> relayHandler.action(config.protectFromMissles(), new DefensivePrayerAction(Rs2PrayerEnum.PROTECT_RANGE)))) | ||
return; | ||
if (processKey(e, config.protectFromMelee(), () -> relayHandler.action(config.protectFromMelee(), new DefensivePrayerAction(Rs2PrayerEnum.PROTECT_MELEE)))) | ||
return; | ||
if (processKey(e, config.hotkeyMeleePrimary(), () -> relayHandler.action(config.hotkeyMeleePrimary(), new MeleeAction(config, 1)))) | ||
return; | ||
if (processKey(e, config.hotkeyMeleeSecondary(), () -> relayHandler.action(config.hotkeyMeleeSecondary(), new MeleeAction(config, 2)))) | ||
return; | ||
if (processKey(e, config.hotkeyMeleeTertiary(), () -> relayHandler.action(config.hotkeyMeleeTertiary(), new MeleeAction(config, 3)))) | ||
return; | ||
if (processKey(e, config.hotkeyRangePrimary(), () -> relayHandler.action(config.hotkeyRangePrimary(), new RangeAction(config, 1)))) | ||
return; | ||
if (processKey(e, config.hotkeyRangeSecondary(), () -> relayHandler.action(config.hotkeyRangeSecondary(), new RangeAction(config, 2)))) | ||
return; | ||
if (processKey(e, config.hotkeyRangeTertiary(), () -> relayHandler.action(config.hotkeyRangeTertiary(), new RangeAction(config, 3)))) | ||
return; | ||
if (processKey(e, config.hotkeyMagePrimary(), () -> relayHandler.action(config.hotkeyMagePrimary(), new MageAction(config, 1)))) | ||
return; | ||
if (processKey(e, config.hotkeyMageSecondary(), () -> relayHandler.action(config.hotkeyMageSecondary(), new MageAction(config, 2)))) | ||
return; | ||
if (processKey(e, config.hotkeyMageTertiary(), () -> relayHandler.action(config.hotkeyMageTertiary(), new MageAction(config, 3)))) | ||
return; | ||
if (processKey(e, config.hotkeySpecialAttackPrimary(), () -> relayHandler.action(config.hotkeySpecialAttackPrimary(), new SpecAction(config, 1)))) | ||
return; | ||
if (processKey(e, config.hotkeySpecialAttackSecondary(), () -> relayHandler.action(config.hotkeySpecialAttackSecondary(), new SpecAction(config, 2)))) | ||
return; | ||
if (processKey(e, config.hotkeySpecialAttackTertiary(), () -> relayHandler.action(config.hotkeySpecialAttackTertiary(), new SpecAction(config, 3)))) | ||
return; | ||
if (processKey(e, config.hotkeyTank(), () -> relayHandler.action(config.hotkeyTank(), new TankAction(config)))) | ||
return; | ||
if (processKey(e, config.walkUnderHotkey(), () -> relayHandler.action(config.walkUnderHotkey(), new WalkUnderAction()))) | ||
; | ||
} | ||
|
||
@Override | ||
public void keyReleased(KeyEvent e) { | ||
} | ||
|
||
private boolean processKey(KeyEvent e, Keybind key, Runnable action) { | ||
if (key.matches(e)) { | ||
e.consume(); | ||
hotkeyConsumed = true; | ||
Microbot.getClientThread().runOnSeperateThread(() -> { | ||
if (isLoggedIn()) | ||
action.run(); | ||
return null; | ||
}); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...src/main/java/net/runelite/client/plugins/microbot/bradleycombat/BradleyCombatScript.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.runelite.client.plugins.microbot.bradleycombat; | ||
|
||
import net.runelite.client.plugins.microbot.Microbot; | ||
import net.runelite.client.plugins.microbot.Script; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class BradleyCombatScript extends Script { | ||
|
||
public boolean run(BradleyCombatConfig config) { | ||
|
||
Microbot.enableAutoRunOn = true; | ||
mainScheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(() -> | ||
{ | ||
try { | ||
if (!Microbot.isLoggedIn()) return; | ||
if (!super.run()) return; | ||
// TODO: Logic for potions and food coming soon. | ||
} catch (Exception ex) { | ||
System.out.println(ex.getMessage()); | ||
} | ||
}, 0, 100, TimeUnit.MILLISECONDS); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
super.shutdown(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...rc/main/java/net/runelite/client/plugins/microbot/bradleycombat/actions/AttackAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package net.runelite.client.plugins.microbot.bradleycombat.actions; | ||
|
||
import net.runelite.api.Player; | ||
import net.runelite.client.plugins.microbot.bradleycombat.interfaces.CombatAction; | ||
import net.runelite.client.plugins.microbot.util.player.Rs2Player; | ||
import net.runelite.client.plugins.microbot.util.target.Rs2Target; | ||
|
||
public class AttackAction implements CombatAction { | ||
private final boolean shouldAttack; | ||
|
||
public AttackAction(boolean shouldAttack) { | ||
this.shouldAttack = shouldAttack; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
if (!shouldAttack) return; | ||
if (Rs2Target.validTarget()) Rs2Player.attack((Player) Rs2Target.getTarget()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ava/net/runelite/client/plugins/microbot/bradleycombat/actions/DefensivePrayerAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package net.runelite.client.plugins.microbot.bradleycombat.actions; | ||
|
||
import net.runelite.client.plugins.microbot.bradleycombat.interfaces.CombatAction; | ||
import net.runelite.client.plugins.microbot.util.prayer.Rs2Prayer; | ||
import net.runelite.client.plugins.microbot.util.prayer.Rs2PrayerEnum; | ||
|
||
public class DefensivePrayerAction implements CombatAction { | ||
private final Rs2PrayerEnum prayer; | ||
|
||
public DefensivePrayerAction(Rs2PrayerEnum prayer) { | ||
this.prayer = prayer; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
Rs2Prayer.toggle(prayer, true); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...ain/java/net/runelite/client/plugins/microbot/bradleycombat/actions/EnableSpecAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.runelite.client.plugins.microbot.bradleycombat.actions; | ||
|
||
import net.runelite.client.plugins.microbot.bradleycombat.BradleyCombatConfig; | ||
import net.runelite.client.plugins.microbot.bradleycombat.enums.SpecType; | ||
import net.runelite.client.plugins.microbot.bradleycombat.interfaces.CombatAction; | ||
import net.runelite.client.plugins.microbot.util.combat.Rs2Combat; | ||
|
||
import static net.runelite.client.plugins.microbot.util.Global.sleep; | ||
|
||
public class EnableSpecAction implements CombatAction { | ||
private final BradleyCombatConfig config; | ||
private final int variant; | ||
|
||
public EnableSpecAction(BradleyCombatConfig config, int variant) { | ||
this.config = config; | ||
this.variant = variant; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
int energy; | ||
SpecType specType; | ||
switch (variant) { | ||
case 1: | ||
energy = config.specEnergyPrimary(); | ||
specType = config.specTypePrimary(); | ||
break; | ||
case 2: | ||
energy = config.specEnergySecondary(); | ||
specType = config.specTypeSecondary(); | ||
break; | ||
case 3: | ||
energy = config.specEnergyTertiary(); | ||
specType = config.specTypeTertiary(); | ||
break; | ||
default: | ||
energy = 0; | ||
specType = SpecType.SINGLE; | ||
} | ||
if (specType == SpecType.DOUBLE) { | ||
energy *= 2; | ||
} | ||
if (!Rs2Combat.getSpecState() && Rs2Combat.getSpecEnergy() >= energy) { | ||
if (specType == SpecType.SINGLE) { | ||
Rs2Combat.setSpecState(true, energy); | ||
} else { | ||
Rs2Combat.setSpecState(true, energy); | ||
sleep(20); | ||
Rs2Combat.setSpecState(true, energy); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.