diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1680308..edc6e0e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,11 @@ - + + + + + @@ -50,21 +54,21 @@ + + + + + + + + + + - - - - - - - - - - diff --git a/src/main/java/ParaScript/Main.java b/src/main/java/ParaScript/Main.java index 9080692..cac1675 100644 --- a/src/main/java/ParaScript/Main.java +++ b/src/main/java/ParaScript/Main.java @@ -44,6 +44,9 @@ public class Main extends Script implements MessageListener, Paintable { if(Variables.skill_to_train == Skill.THIEVING) { strategies.add(new Thieving()); } + if(Variables.skill_to_train == Skill.ATTACK) { + strategies.add(new Fighting()); + } if(Variables.skill_to_train == null) { strategies.add(new Bank()); strategies.add(new Walk()); diff --git a/src/main/java/ParaScript/data/Variables.java b/src/main/java/ParaScript/data/Variables.java index 3e2d09c..4f275eb 100644 --- a/src/main/java/ParaScript/data/Variables.java +++ b/src/main/java/ParaScript/data/Variables.java @@ -1,16 +1,11 @@ package ParaScript.data; -import ParaScript.data.variables.Npcs; -import ParaScript.data.variables.Ores; -import ParaScript.data.variables.Trees; -import ParaScript.data.variables.Zone; +import ParaScript.data.variables.*; import org.parabot.environment.api.utils.Timer; import org.rev317.min.api.methods.Skill; import org.rev317.min.api.wrappers.Tile; import org.rev317.min.api.wrappers.TilePath; -import java.util.List; - public class Variables { public static final Timer SCRIPT_TIMER = new Timer(); @@ -35,9 +30,12 @@ public class Variables { public static Ores mining_ore_selected = Ores.COPPER_TIN; public static String mining_method = "Bank"; - //Thieving - public static Npcs thieving_npc_selected = Npcs.MAN_WOMAN; - public static String thieving_method = "None"; + // Thieving + public static ThievingNpcs thieving_npc_selected = ThievingNpcs.MAN_WOMAN; + //public static String thieving_method = "None"; + + // Fighting + public static FightingNpcs fighting_npc_selected = FightingNpcs.MAN_WOMAN; // Used for slave accounts diff --git a/src/main/java/ParaScript/data/variables/FightingNpcs.java b/src/main/java/ParaScript/data/variables/FightingNpcs.java new file mode 100644 index 0000000..15bc0d8 --- /dev/null +++ b/src/main/java/ParaScript/data/variables/FightingNpcs.java @@ -0,0 +1,46 @@ +package ParaScript.data.variables; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public enum FightingNpcs { + CHICKEN("Chicken", new int[]{41}, 3), + MAN_WOMAN("Man & Woman", new int[]{1, 2, 3, 4, 5, 6}, 0), + COW("Cow", new int[]{81, 397, 1766, 1767}, 0), + CUSTOM("Custom (specify IDs)", new int[]{-1}, 0); + + private String name; + private int[] ids; + private int hp; + + FightingNpcs(String name, int[] ids, int hp) { + this.name = name; + this.ids = ids; + this.hp = hp; + } + + public static String[] toStringArray() { + List enumList = Arrays.asList(FightingNpcs.values()); + List npcsArray = new ArrayList<>(); + for (FightingNpcs npc : enumList) { + npcsArray.add(npc.name); + } + + String[] simpleArray = new String[ npcsArray.size() ]; + npcsArray.toArray( simpleArray ); + return(simpleArray); + } + + public String getName() { return this.name; } + + public int[] getIDs() { return this.ids; } + + public void setIDs(int[] ids) { + if (this == CUSTOM){ + this.ids = ids; + } + } + + public double getHP() { return this.hp; } +} diff --git a/src/main/java/ParaScript/data/variables/Npcs.java b/src/main/java/ParaScript/data/variables/ThievingNpcs.java similarity index 82% rename from src/main/java/ParaScript/data/variables/Npcs.java rename to src/main/java/ParaScript/data/variables/ThievingNpcs.java index 2b4c6a9..489ba0f 100644 --- a/src/main/java/ParaScript/data/variables/Npcs.java +++ b/src/main/java/ParaScript/data/variables/ThievingNpcs.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public enum Npcs { +public enum ThievingNpcs { MAN_WOMAN("Man & Woman", new int[]{1, 2, 3, 4, 5, 6}, 8), CUSTOM("Custom (specify IDs)", new int[]{-1}, 0); @@ -12,16 +12,16 @@ public enum Npcs { private int[] ids; private double xp; - Npcs(String name, int[] ids, double xp) { + ThievingNpcs(String name, int[] ids, double xp) { this.name = name; this.ids = ids; this.xp = xp; } public static String[] toStringArray() { - List enumList = Arrays.asList(Npcs.values()); + List enumList = Arrays.asList(ThievingNpcs.values()); List npcsArray = new ArrayList<>(); - for (Npcs npc : enumList) { + for (ThievingNpcs npc : enumList) { npcsArray.add(npc.name); } diff --git a/src/main/java/ParaScript/strategies/Fighting.java b/src/main/java/ParaScript/strategies/Fighting.java new file mode 100644 index 0000000..61bda4a --- /dev/null +++ b/src/main/java/ParaScript/strategies/Fighting.java @@ -0,0 +1,48 @@ +package ParaScript.strategies; + +import ParaScript.data.Variables; +import org.parabot.environment.api.utils.Time; +import org.parabot.environment.scripts.framework.Strategy; +import org.rev317.min.api.methods.Inventory; +import org.rev317.min.api.methods.Npcs; +import org.rev317.min.api.methods.Players; +import org.rev317.min.api.wrappers.Npc; + +public class Fighting implements Strategy { + private Npc victim; + + @Override + public boolean activate() { + victim = victim(); // set the local Variable + if (Variables.running + && victim != null + && !Players.getMyPlayer().isInCombat() + && Players.getMyPlayer().getAnimation() == -1 + && !Inventory.isFull()) { + Variables.setStatus("fighting"); + return true; + } + Variables.setStatus("none"); + return false; + } + + @Override + public void execute() { + victim.interact(Npcs.Option.ATTACK); + Time.sleep(2000); + // Wait for the Player to finish attacking (max 5 seconds) + Time.sleep(() -> !Players.getMyPlayer().isInCombat(), 5000); + } + + private Npc victim(){ + try { + int[] npc_to_thieve = Variables.fighting_npc_selected.getIDs(); + for (Npc victim : Npcs.getNearest(npc_to_thieve)) { + if (victim != null) { + return victim; + } + } + } catch (Exception err){} + return null; + } +} \ No newline at end of file diff --git a/src/main/java/ParaScript/strategies/PickupItems.java b/src/main/java/ParaScript/strategies/PickupItems.java index d999212..87373fc 100644 --- a/src/main/java/ParaScript/strategies/PickupItems.java +++ b/src/main/java/ParaScript/strategies/PickupItems.java @@ -17,7 +17,6 @@ public class PickupItems implements Strategy { public boolean activate() { if (Variables.running && (Variables.getStatus() == "none" || Variables.getStatus() == "picking up items") - && Variables.VARROCK_EAST_MINE_ZONE.inTheZone() && !Players.getMyPlayer().isInCombat() && Players.getMyPlayer().getAnimation() == -1 && !Inventory.isFull()) { diff --git a/src/main/java/ParaScript/ui/UI.java b/src/main/java/ParaScript/ui/UI.java index 84a9f67..db3ad31 100644 --- a/src/main/java/ParaScript/ui/UI.java +++ b/src/main/java/ParaScript/ui/UI.java @@ -1,13 +1,13 @@ package ParaScript.ui; -import ParaScript.data.variables.Npcs; +import ParaScript.data.variables.FightingNpcs; +import ParaScript.data.variables.ThievingNpcs; import ParaScript.data.variables.Ores; import ParaScript.data.variables.Trees; import ParaScript.data.Variables; import org.rev317.min.api.methods.Game; import org.rev317.min.api.methods.Players; import org.rev317.min.api.methods.Skill; -import org.rev317.min.api.wrappers.Player; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -39,10 +39,15 @@ public class UI extends JFrame { private JComboBox oreSelect = new JComboBox(); private JComboBox miningMethod = new JComboBox(); - //Thieving - private JComboBox npcSelect = new JComboBox(); - private JLabel lblNpcThievingCustomID = new JLabel("Custom NPC IDs"); - private JTextField npcThievingCustomID = new JTextField(); + // Fighting + private JComboBox fightingNpcSelect = new JComboBox(); + private JLabel lblFightingNpcCustomID = new JLabel("Custom NPC IDs"); + private JTextField fightingNpcCustomID = new JTextField(); + + // Thieving + private JComboBox thievingNpcSelect = new JComboBox(); + private JLabel lblThievingNpcCustomID = new JLabel("Custom NPC IDs"); + private JTextField thievingNpcCustomID = new JTextField(); // Our colors private Color Color_MidnightBlue = new Color(44, 62, 80); @@ -121,6 +126,7 @@ public class UI extends JFrame { skillSelect.setModel(new DefaultComboBoxModel(new String[]{ Skill.WOODCUTTING.getName(), Skill.MINING.getName(), + Skill.ATTACK.getName(), Skill.THIEVING.getName(), "Bank Runner", })); @@ -264,6 +270,72 @@ public class UI extends JFrame { }); miningPanel.add(miningMethod); + /* + * Fighting Panel + */ + + JPanel fightingPanel = new JPanel(); + fightingPanel.setForeground(Color_WhiteSmoke); + fightingPanel.setBackground(Color_WetAsphalt); + tabbedPane.addTab("Fighting", null, fightingPanel, null); + fightingPanel.setLayout(null); + + // Select which npc should be our victim + JLabel lblFightingNpc = new JLabel("NPC"); + lblFightingNpc.setForeground(Color_WhiteSmoke); + lblFightingNpc.setBounds(20, 20, 73, 20); + fightingPanel.add(lblFightingNpc); + fightingNpcSelect.setModel(new DefaultComboBoxModel(FightingNpcs.toStringArray())); + fightingNpcSelect.setBounds(20, 40, 150, 20); + fightingNpcSelect.addActionListener (new ActionListener () { + public void actionPerformed(ActionEvent e) { + for (FightingNpcs npc : FightingNpcs.values()) { + if (npc.getName().equalsIgnoreCase(fightingNpcSelect.getSelectedItem().toString())) { + Variables.fighting_npc_selected = npc; + } + } + if (Variables.fighting_npc_selected == FightingNpcs.CUSTOM) { + lblThievingNpcCustomID.setVisible(true); + thievingNpcCustomID.setVisible(true); + } else { + lblThievingNpcCustomID.setVisible(false); + thievingNpcCustomID.setVisible(false); + } + UI.this.revalidate(); + UI.this.repaint(); + } + }); + fightingPanel.add(fightingNpcSelect); + + // Custom npc id to attack + lblFightingNpcCustomID.setForeground(Color_WhiteSmoke); + lblFightingNpcCustomID.setBounds(200, 20, 150, 20); + fightingPanel.add(lblFightingNpcCustomID); + fightingNpcCustomID.setBounds(200, 40, 150, 20); + fightingNpcCustomID.addFocusListener(new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + // we don't need to do anything here + } + + @Override + public void focusLost(FocusEvent e) { + try { + String[] sample = fightingNpcCustomID.getText().split("(,|;)\\s*"); + int[] customIDs = new int[sample.length]; + + for (int i = 0; i < sample.length; i++) + customIDs[i] = Integer.parseInt(sample[i]); + Variables.fighting_npc_selected.setIDs(customIDs); + } catch (Exception err) { + FightingNpcs.CUSTOM.setIDs(new int[]{0}); + } + } + }); + fightingPanel.add(fightingNpcCustomID); + lblFightingNpcCustomID.setVisible(false); + fightingNpcCustomID.setVisible(false); + /* * Thieving Panel */ @@ -275,38 +347,38 @@ public class UI extends JFrame { thievingPanel.setLayout(null); // Select which npc should be our victim - JLabel lblNpc = new JLabel("NPC"); - lblNpc.setForeground(Color_WhiteSmoke); - lblNpc.setBounds(20, 20, 73, 20); - thievingPanel.add(lblNpc); - npcSelect.setModel(new DefaultComboBoxModel(Npcs.toStringArray())); - npcSelect.setBounds(20, 40, 150, 20); - npcSelect.addActionListener (new ActionListener () { + JLabel lblThievingNpc = new JLabel("NPC"); + lblThievingNpc.setForeground(Color_WhiteSmoke); + lblThievingNpc.setBounds(20, 20, 73, 20); + thievingPanel.add(lblThievingNpc); + thievingNpcSelect.setModel(new DefaultComboBoxModel(ThievingNpcs.toStringArray())); + thievingNpcSelect.setBounds(20, 40, 150, 20); + thievingNpcSelect.addActionListener (new ActionListener () { public void actionPerformed(ActionEvent e) { - for (Npcs npc : Npcs.values()) { - if (npc.getName().equalsIgnoreCase(npcSelect.getSelectedItem().toString())) { + for (ThievingNpcs npc : ThievingNpcs.values()) { + if (npc.getName().equalsIgnoreCase(thievingNpcSelect.getSelectedItem().toString())) { Variables.thieving_npc_selected = npc; } } - if (Variables.thieving_npc_selected == Npcs.CUSTOM) { - lblNpcThievingCustomID.setVisible(true); - npcThievingCustomID.setVisible(true); + if (Variables.thieving_npc_selected == ThievingNpcs.CUSTOM) { + lblThievingNpcCustomID.setVisible(true); + thievingNpcCustomID.setVisible(true); } else { - lblNpcThievingCustomID.setVisible(false); - npcThievingCustomID.setVisible(false); + lblThievingNpcCustomID.setVisible(false); + thievingNpcCustomID.setVisible(false); } UI.this.revalidate(); UI.this.repaint(); } }); - thievingPanel.add(npcSelect); + thievingPanel.add(thievingNpcSelect); // Custom npc id to steal from - lblNpcThievingCustomID.setForeground(Color_WhiteSmoke); - lblNpcThievingCustomID.setBounds(200, 20, 150, 20); - thievingPanel.add(lblNpcThievingCustomID); - npcThievingCustomID.setBounds(200, 40, 150, 20); - npcThievingCustomID.addFocusListener(new FocusListener() { + lblThievingNpcCustomID.setForeground(Color_WhiteSmoke); + lblThievingNpcCustomID.setBounds(200, 20, 150, 20); + thievingPanel.add(lblThievingNpcCustomID); + thievingNpcCustomID.setBounds(200, 40, 150, 20); + thievingNpcCustomID.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { // we don't need to do anything here @@ -315,20 +387,20 @@ public class UI extends JFrame { @Override public void focusLost(FocusEvent e) { try { - String[] sample = npcThievingCustomID.getText().split("(,|;)\\s*"); + String[] sample = thievingNpcCustomID.getText().split("(,|;)\\s*"); int[] customIDs = new int[sample.length]; for (int i = 0; i < sample.length; i++) customIDs[i] = Integer.parseInt(sample[i]); Variables.thieving_npc_selected.setIDs(customIDs); } catch (Exception err) { - Npcs.CUSTOM.setIDs(new int[]{0}); + ThievingNpcs.CUSTOM.setIDs(new int[]{0}); } } }); - thievingPanel.add(npcThievingCustomID); - lblNpcThievingCustomID.setVisible(false); - npcThievingCustomID.setVisible(false); + thievingPanel.add(thievingNpcCustomID); + lblThievingNpcCustomID.setVisible(false); + thievingNpcCustomID.setVisible(false); /* * Slave Panel