-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 58894a1
Showing
15 changed files
with
508 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import nodes.*; | ||
import org.rspeer.runetek.api.ClientSupplier; | ||
import org.rspeer.runetek.api.movement.position.Area; | ||
import org.rspeer.runetek.api.movement.position.Position; | ||
import res.Settings; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.util.HashMap; | ||
|
||
public class GUI extends JFrame { | ||
|
||
public GUI(){ | ||
super("Fighter"); | ||
|
||
//TODO: add these to an enum maybe idk | ||
String[] bankNames = new String[]{"Falador East"}; | ||
HashMap<String, Position> banks = new HashMap<>(); | ||
banks.put("Falador East", new Position(3012, 3355)); | ||
|
||
String[] areaNames = new String[]{"Falador South Cows", "Lumbridge East Chickens"}; | ||
HashMap<String, Area> areas = new HashMap<>(); | ||
areas.put("Falador South Cows", Area.rectangular(3043, 3313, 3021, 3299)); | ||
areas.put("Lumbridge East Chickens", Area.rectangular(3186, 3303, 3169, 3288)); | ||
|
||
JPanel panel = new JPanel(); | ||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); | ||
|
||
JLabel targetTitle = new JLabel("NPC Names, one per line:"); | ||
JTextArea targetList = new JTextArea(""); | ||
targetList.setColumns(10); | ||
targetList.setRows(5); | ||
|
||
JLabel lootTitle = new JLabel("Loot names, one per line:"); | ||
JTextArea lootList = new JTextArea(""); | ||
lootList.setColumns(10); | ||
lootList.setRows(5); | ||
|
||
JCheckBox buryCheck = new JCheckBox("Bury bones?"); | ||
|
||
JLabel bankTitle = new JLabel("Bank:"); | ||
JComboBox bankName = new JComboBox(bankNames); | ||
JLabel areaTitle = new JLabel("Area:"); | ||
JComboBox areaName = new JComboBox(areaNames); | ||
JButton start = new JButton("Start"); | ||
|
||
setLocationRelativeTo(ClientSupplier.get().getCanvas()); | ||
setSize(new Dimension(450, 95)); | ||
|
||
panel.add(targetTitle); | ||
panel.add(targetList); | ||
panel.add(lootTitle); | ||
panel.add(lootList); | ||
panel.add(buryCheck); | ||
panel.add(bankTitle); | ||
panel.add(bankName); | ||
panel.add(areaTitle); | ||
panel.add(areaName); | ||
panel.add(start); | ||
add(panel); | ||
|
||
pack(); | ||
|
||
setDefaultCloseOperation(HIDE_ON_CLOSE); | ||
|
||
//Add action listener to start script when button is pressed | ||
start.addActionListener(event -> { | ||
if (lootList.getText() != null && lootList.getText().length() > 0) { | ||
Settings.loot = lootList.getText().toLowerCase().split("\n"); | ||
} | ||
if (buryCheck.isSelected()) { | ||
Settings.bury = true; | ||
} | ||
Settings.bank = banks.get(bankName.getSelectedItem()); | ||
Settings.area = areas.get(areaName.getSelectedItem()); | ||
|
||
Settings.nodes.add(new DismissRandoms()); | ||
Settings.nodes.add(new EnableRun()); | ||
Settings.nodes.add(new CloseLevelDialog()); | ||
Settings.nodes.add(new WalkToCombatArea()); | ||
if (Settings.loot.length > 0) { | ||
Settings.nodes.add(new PickupLoot()); | ||
if (Settings.bury) { | ||
Settings.nodes.add(new BuryBones()); | ||
} | ||
Settings.nodes.add(new TravelToBank()); | ||
Settings.nodes.add(new OpenBank()); | ||
Settings.nodes.add(new DepositBank()); | ||
} | ||
if (targetList.getText() != null && targetList.getText().length() > 0) { | ||
Settings.targets = targetList.getText().toLowerCase().split("\n"); | ||
Settings.nodes.add(new Combat()); | ||
} | ||
|
||
Settings.start = true; | ||
setVisible(false); | ||
}); | ||
} | ||
|
||
} |
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,71 @@ | ||
import nodes.*; | ||
import org.rspeer.runetek.adapter.scene.PathingEntity; | ||
import org.rspeer.runetek.api.Game; | ||
import org.rspeer.runetek.api.movement.Movement; | ||
import org.rspeer.runetek.api.movement.position.Position; | ||
import org.rspeer.runetek.api.scene.Players; | ||
import org.rspeer.runetek.event.listeners.RenderListener; | ||
import org.rspeer.runetek.event.types.RenderEvent; | ||
import org.rspeer.script.Script; | ||
import org.rspeer.script.ScriptMeta; | ||
|
||
import res.Settings; | ||
|
||
import java.awt.*; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
@ScriptMeta(developer = "fatchan", desc = "fight, loot, bury bones, bank", name = "fighter") | ||
public class Main extends Script implements RenderListener { | ||
|
||
private long startTime; | ||
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss"); | ||
|
||
@Override | ||
public void onStart() { | ||
startTime = System.currentTimeMillis(); | ||
new GUI().setVisible(true); | ||
} | ||
|
||
public int loop () { | ||
if (!Settings.start) { | ||
return 1000; | ||
} | ||
for (Node n : Settings.nodes) { | ||
if (n.isValid()) { | ||
n.execute(); | ||
} | ||
} | ||
return 1000; | ||
} | ||
|
||
@Override | ||
public void notify(RenderEvent renderEvent) { | ||
if (!Settings.start) { | ||
return; | ||
} | ||
Graphics g = renderEvent.getSource(); | ||
long runtime = System.currentTimeMillis() - startTime; | ||
String dateString = simpleDateFormat.format(new Date(runtime)); | ||
g.setColor(Color.BLACK); | ||
g.fillRect(7, 459, 506, 15); | ||
g.setColor(Color.GREEN); | ||
g.drawString("Runtime: " + dateString, 8, 471); | ||
g.drawString("Status: " + Settings.state, 150, 471); | ||
if (Game.isLoggedIn()) { | ||
PathingEntity target = Players.getLocal().getTarget(); | ||
if(target != null) { | ||
g.setColor(Color.RED); | ||
target.getPosition().outline(g); | ||
} | ||
Position destination = Movement.getDestination(); | ||
if (destination != null) { | ||
g.setColor(Color.BLUE); | ||
destination.outline(g); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
} |
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,33 @@ | ||
package nodes; | ||
|
||
import org.rspeer.runetek.adapter.component.Item; | ||
import org.rspeer.runetek.api.commons.Time; | ||
import org.rspeer.runetek.api.commons.math.Random; | ||
import org.rspeer.runetek.api.component.tab.Inventory; | ||
import org.rspeer.ui.Log; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public class BuryBones extends Node { | ||
|
||
private static final Predicate<Item> BONES_ITEM = item -> item.getName().toLowerCase().contains("bone") && item.containsAction("Bury"); | ||
|
||
@Override | ||
public boolean isValid() { | ||
return Inventory.contains(BONES_ITEM) && Checker.notInCombat(); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
Log.info("Burying bones"); | ||
Item bone = Inventory.getFirst(BONES_ITEM); | ||
int inventoryAmount = Inventory.getCount(); | ||
while (bone != null) { | ||
bone.interact("Bury"); | ||
Time.sleepUntil(()-> Inventory.getCount() < inventoryAmount, Random.low(3000,5000)); | ||
Time.sleep(Random.low(750, 1500)); //oof | ||
bone = Inventory.getFirst(BONES_ITEM); | ||
} | ||
} | ||
|
||
} |
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,14 @@ | ||
package nodes; | ||
|
||
import org.rspeer.runetek.api.scene.Players; | ||
|
||
public final class Checker { | ||
|
||
private Checker() { } | ||
|
||
//TODO: add more of these here | ||
public static boolean notInCombat() { | ||
return Players.getLocal().getTargetIndex() == -1 || (Players.getLocal().getTarget() != null && Players.getLocal().getTarget().getHealthPercent() == 0); | ||
} | ||
|
||
} |
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,22 @@ | ||
package nodes; | ||
|
||
import org.rspeer.runetek.api.commons.Time; | ||
import org.rspeer.runetek.api.commons.math.Random; | ||
import org.rspeer.runetek.api.component.Dialog; | ||
import res.Settings; | ||
|
||
public class CloseLevelDialog extends Node { | ||
|
||
@Override | ||
public boolean isValid() { | ||
return Dialog.isOpen() && Dialog.canContinue(); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
Settings.state = "skipping dialog"; | ||
Dialog.processContinue(); | ||
Time.sleepUntil(()-> !isValid(), Random.low(2000,3000)); | ||
} | ||
|
||
} |
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,54 @@ | ||
package nodes; | ||
|
||
import org.rspeer.runetek.adapter.scene.Npc; | ||
import org.rspeer.runetek.api.commons.Time; | ||
import org.rspeer.runetek.api.commons.math.Random; | ||
import org.rspeer.runetek.api.component.tab.Inventory; | ||
import org.rspeer.runetek.api.movement.Movement; | ||
import org.rspeer.runetek.api.scene.Npcs; | ||
import org.rspeer.runetek.api.scene.Players; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.Predicate; | ||
|
||
import res.Settings; | ||
|
||
public class Combat extends Node { | ||
|
||
private Predicate<Npc> NOT_IN_COMBAT_TARGET = npc -> Settings.area.contains(npc.getPosition()) | ||
&& Arrays.stream(Settings.targets).anyMatch(npc.getName().toLowerCase()::startsWith) | ||
&& npc.getTargetIndex() == -1 | ||
&& npc.getHealthBar() == null | ||
&& npc.getHealthPercent() > 0 | ||
&& Movement.isInteractable(npc.getPosition()); | ||
|
||
private Predicate<Npc> IN_COMBAT_TARGET = npc -> Settings.area.contains(npc.getPosition()) | ||
&& Arrays.stream(Settings.targets).anyMatch(npc.getName().toLowerCase()::startsWith) | ||
&& npc.getTargetIndex() != -1 | ||
&& npc.getTarget() == Players.getLocal() | ||
&& npc.getHealthPercent() > 0 | ||
&& Movement.isInteractable(npc.getPosition()); | ||
|
||
@Override | ||
public boolean isValid() { | ||
return Settings.area.contains(Players.getLocal().getPosition()) && Checker.notInCombat() && !Inventory.isFull(); | ||
} | ||
|
||
|
||
@Override | ||
public void execute() { | ||
Npc npc = Npcs.getNearest(IN_COMBAT_TARGET) != null ? Npcs.getNearest(IN_COMBAT_TARGET) : Npcs.getNearest(NOT_IN_COMBAT_TARGET); | ||
if (npc != null) { | ||
Settings.state = "found target"; | ||
npc.interact("Attack"); | ||
Settings.state = "attacking"; | ||
Time.sleepUntil(()-> npc.getHealthBar() != null, Random.low(5000,10000)); | ||
if (npc.getTarget() != null && !npc.getTarget().equals(Players.getLocal())) { | ||
Settings.state = "target lost/stolen"; | ||
return; | ||
} | ||
Settings.state = "in combat"; | ||
} | ||
} | ||
|
||
} |
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,23 @@ | ||
package nodes; | ||
|
||
import org.rspeer.runetek.api.commons.Time; | ||
import org.rspeer.runetek.api.component.Bank; | ||
import org.rspeer.runetek.api.component.tab.Inventory; | ||
|
||
import res.Settings; | ||
|
||
public class DepositBank extends Node { | ||
|
||
@Override | ||
public boolean isValid() { | ||
return Bank.isOpen(); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
Settings.state = "depositing"; | ||
Bank.depositInventory(); | ||
Time.sleepUntil(() -> Inventory.isEmpty(), 2000); | ||
} | ||
|
||
} |
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,28 @@ | ||
package nodes; | ||
|
||
import org.rspeer.runetek.adapter.scene.Npc; | ||
import org.rspeer.runetek.api.commons.Time; | ||
import org.rspeer.runetek.api.commons.math.Random; | ||
import org.rspeer.runetek.api.scene.Npcs; | ||
import org.rspeer.runetek.api.scene.Players; | ||
import res.Settings; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public class DismissRandoms extends Node { | ||
|
||
private static final Predicate<Npc> RANDOM_EVENT = npc -> npc.containsAction("Dismiss") && npc.getTarget() != null && npc.getTarget().equals(Players.getLocal()); | ||
|
||
@Override | ||
public boolean isValid() { | ||
return Npcs.getNearest(RANDOM_EVENT) != null; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
Settings.state = "dismissing random"; | ||
Npcs.getNearest(RANDOM_EVENT).interact("Dismiss"); | ||
Time.sleepUntil(()-> !isValid(), Random.low(2000,3000)); | ||
} | ||
|
||
} |
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,21 @@ | ||
package nodes; | ||
|
||
import org.rspeer.runetek.api.commons.math.Random; | ||
import org.rspeer.runetek.api.movement.Movement; | ||
import org.rspeer.ui.Log; | ||
import res.Settings; | ||
|
||
public class EnableRun extends Node { | ||
|
||
@Override | ||
public boolean isValid() { | ||
return !Movement.isRunEnabled() && Movement.getRunEnergy() > Random.high(0,100); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
Settings.state = "enabling run"; | ||
Movement.toggleRun(true); | ||
} | ||
|
||
} |
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,9 @@ | ||
package nodes; | ||
|
||
public abstract class Node { | ||
|
||
public abstract boolean isValid(); | ||
|
||
public abstract void execute(); | ||
|
||
} |
Oops, something went wrong.