Add basic fighter

This commit is contained in:
RedSparr0w
2019-10-21 11:16:05 +13:00
parent ee0c396a24
commit fb64fbae18
8 changed files with 226 additions and 56 deletions
+15 -11
View File
@@ -3,7 +3,11 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3ab8e8a0-ccfd-4b0b-9547-98173085dc38" name="Default Changelist" comment=""> <list default="true" id="3ab8e8a0-ccfd-4b0b-9547-98173085dc38" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/ParaScript/strategies/Thieving.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ParaScript/strategies/Thieving.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/ParaScript/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ParaScript/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/ParaScript/data/Variables.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ParaScript/data/Variables.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/ParaScript/data/variables/Npcs.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ParaScript/data/variables/ThievingNpcs.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/ParaScript/strategies/PickupItems.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ParaScript/strategies/PickupItems.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/ParaScript/ui/UI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ParaScript/ui/UI.java" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@@ -50,21 +54,21 @@
<key name="ExtractSuperBase.RECENT_KEYS"> <key name="ExtractSuperBase.RECENT_KEYS">
<recent name="ParaScript" /> <recent name="ParaScript" />
</key> </key>
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\Dan-j\Documents\GitHub\ParaScript" />
</key>
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="ParaScript.data.variables" />
<recent name="ParaScript.strategies" />
<recent name="ParaScript" />
<recent name="ParaScript.ui" />
<recent name="ParaScript.data" />
</key>
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\Dan-j\Documents\GitHub\ParaScript\src\main" /> <recent name="C:\Users\Dan-j\Documents\GitHub\ParaScript\src\main" />
<recent name="C:\Users\Dan-j\Documents\GitHub\ParaScript\src" /> <recent name="C:\Users\Dan-j\Documents\GitHub\ParaScript\src" />
<recent name="C:\Users\Dan-j\Documents\GitHub\ParaScript\main\java" /> <recent name="C:\Users\Dan-j\Documents\GitHub\ParaScript\main\java" />
</key> </key>
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="ParaScript.strategies" />
<recent name="ParaScript" />
<recent name="ParaScript.data.variables" />
<recent name="ParaScript.ui" />
<recent name="ParaScript.data" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\Dan-j\Documents\GitHub\ParaScript" />
</key>
</component> </component>
<component name="RunDashboard"> <component name="RunDashboard">
<option name="ruleStates"> <option name="ruleStates">
+3
View File
@@ -44,6 +44,9 @@ public class Main extends Script implements MessageListener, Paintable {
if(Variables.skill_to_train == Skill.THIEVING) { if(Variables.skill_to_train == Skill.THIEVING) {
strategies.add(new Thieving()); strategies.add(new Thieving());
} }
if(Variables.skill_to_train == Skill.ATTACK) {
strategies.add(new Fighting());
}
if(Variables.skill_to_train == null) { if(Variables.skill_to_train == null) {
strategies.add(new Bank()); strategies.add(new Bank());
strategies.add(new Walk()); strategies.add(new Walk());
+7 -9
View File
@@ -1,16 +1,11 @@
package ParaScript.data; package ParaScript.data;
import ParaScript.data.variables.Npcs; import ParaScript.data.variables.*;
import ParaScript.data.variables.Ores;
import ParaScript.data.variables.Trees;
import ParaScript.data.variables.Zone;
import org.parabot.environment.api.utils.Timer; import org.parabot.environment.api.utils.Timer;
import org.rev317.min.api.methods.Skill; import org.rev317.min.api.methods.Skill;
import org.rev317.min.api.wrappers.Tile; import org.rev317.min.api.wrappers.Tile;
import org.rev317.min.api.wrappers.TilePath; import org.rev317.min.api.wrappers.TilePath;
import java.util.List;
public class Variables { public class Variables {
public static final Timer SCRIPT_TIMER = new Timer(); 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 Ores mining_ore_selected = Ores.COPPER_TIN;
public static String mining_method = "Bank"; public static String mining_method = "Bank";
//Thieving // Thieving
public static Npcs thieving_npc_selected = Npcs.MAN_WOMAN; public static ThievingNpcs thieving_npc_selected = ThievingNpcs.MAN_WOMAN;
public static String thieving_method = "None"; //public static String thieving_method = "None";
// Fighting
public static FightingNpcs fighting_npc_selected = FightingNpcs.MAN_WOMAN;
// Used for slave accounts // Used for slave accounts
@@ -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<FightingNpcs> enumList = Arrays.asList(FightingNpcs.values());
List<String> 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; }
}
@@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public enum Npcs { public enum ThievingNpcs {
MAN_WOMAN("Man & Woman", new int[]{1, 2, 3, 4, 5, 6}, 8), MAN_WOMAN("Man & Woman", new int[]{1, 2, 3, 4, 5, 6}, 8),
CUSTOM("Custom (specify IDs)", new int[]{-1}, 0); CUSTOM("Custom (specify IDs)", new int[]{-1}, 0);
@@ -12,16 +12,16 @@ public enum Npcs {
private int[] ids; private int[] ids;
private double xp; private double xp;
Npcs(String name, int[] ids, double xp) { ThievingNpcs(String name, int[] ids, double xp) {
this.name = name; this.name = name;
this.ids = ids; this.ids = ids;
this.xp = xp; this.xp = xp;
} }
public static String[] toStringArray() { public static String[] toStringArray() {
List<Npcs> enumList = Arrays.asList(Npcs.values()); List<ThievingNpcs> enumList = Arrays.asList(ThievingNpcs.values());
List<String> npcsArray = new ArrayList<>(); List<String> npcsArray = new ArrayList<>();
for (Npcs npc : enumList) { for (ThievingNpcs npc : enumList) {
npcsArray.add(npc.name); npcsArray.add(npc.name);
} }
@@ -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;
}
}
@@ -17,7 +17,6 @@ public class PickupItems implements Strategy {
public boolean activate() { public boolean activate() {
if (Variables.running if (Variables.running
&& (Variables.getStatus() == "none" || Variables.getStatus() == "picking up items") && (Variables.getStatus() == "none" || Variables.getStatus() == "picking up items")
&& Variables.VARROCK_EAST_MINE_ZONE.inTheZone()
&& !Players.getMyPlayer().isInCombat() && !Players.getMyPlayer().isInCombat()
&& Players.getMyPlayer().getAnimation() == -1 && Players.getMyPlayer().getAnimation() == -1
&& !Inventory.isFull()) { && !Inventory.isFull()) {
+103 -31
View File
@@ -1,13 +1,13 @@
package ParaScript.ui; 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.Ores;
import ParaScript.data.variables.Trees; import ParaScript.data.variables.Trees;
import ParaScript.data.Variables; import ParaScript.data.Variables;
import org.rev317.min.api.methods.Game; import org.rev317.min.api.methods.Game;
import org.rev317.min.api.methods.Players; import org.rev317.min.api.methods.Players;
import org.rev317.min.api.methods.Skill; import org.rev317.min.api.methods.Skill;
import org.rev317.min.api.wrappers.Player;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
@@ -39,10 +39,15 @@ public class UI extends JFrame {
private JComboBox oreSelect = new JComboBox(); private JComboBox oreSelect = new JComboBox();
private JComboBox miningMethod = new JComboBox(); private JComboBox miningMethod = new JComboBox();
//Thieving // Fighting
private JComboBox npcSelect = new JComboBox(); private JComboBox fightingNpcSelect = new JComboBox();
private JLabel lblNpcThievingCustomID = new JLabel("Custom NPC IDs"); private JLabel lblFightingNpcCustomID = new JLabel("Custom NPC IDs");
private JTextField npcThievingCustomID = new JTextField(); 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 // Our colors
private Color Color_MidnightBlue = new Color(44, 62, 80); private Color Color_MidnightBlue = new Color(44, 62, 80);
@@ -121,6 +126,7 @@ public class UI extends JFrame {
skillSelect.setModel(new DefaultComboBoxModel(new String[]{ skillSelect.setModel(new DefaultComboBoxModel(new String[]{
Skill.WOODCUTTING.getName(), Skill.WOODCUTTING.getName(),
Skill.MINING.getName(), Skill.MINING.getName(),
Skill.ATTACK.getName(),
Skill.THIEVING.getName(), Skill.THIEVING.getName(),
"Bank Runner", "Bank Runner",
})); }));
@@ -264,6 +270,72 @@ public class UI extends JFrame {
}); });
miningPanel.add(miningMethod); 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 * Thieving Panel
*/ */
@@ -275,38 +347,38 @@ public class UI extends JFrame {
thievingPanel.setLayout(null); thievingPanel.setLayout(null);
// Select which npc should be our victim // Select which npc should be our victim
JLabel lblNpc = new JLabel("NPC"); JLabel lblThievingNpc = new JLabel("NPC");
lblNpc.setForeground(Color_WhiteSmoke); lblThievingNpc.setForeground(Color_WhiteSmoke);
lblNpc.setBounds(20, 20, 73, 20); lblThievingNpc.setBounds(20, 20, 73, 20);
thievingPanel.add(lblNpc); thievingPanel.add(lblThievingNpc);
npcSelect.setModel(new DefaultComboBoxModel(Npcs.toStringArray())); thievingNpcSelect.setModel(new DefaultComboBoxModel(ThievingNpcs.toStringArray()));
npcSelect.setBounds(20, 40, 150, 20); thievingNpcSelect.setBounds(20, 40, 150, 20);
npcSelect.addActionListener (new ActionListener () { thievingNpcSelect.addActionListener (new ActionListener () {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
for (Npcs npc : Npcs.values()) { for (ThievingNpcs npc : ThievingNpcs.values()) {
if (npc.getName().equalsIgnoreCase(npcSelect.getSelectedItem().toString())) { if (npc.getName().equalsIgnoreCase(thievingNpcSelect.getSelectedItem().toString())) {
Variables.thieving_npc_selected = npc; Variables.thieving_npc_selected = npc;
} }
} }
if (Variables.thieving_npc_selected == Npcs.CUSTOM) { if (Variables.thieving_npc_selected == ThievingNpcs.CUSTOM) {
lblNpcThievingCustomID.setVisible(true); lblThievingNpcCustomID.setVisible(true);
npcThievingCustomID.setVisible(true); thievingNpcCustomID.setVisible(true);
} else { } else {
lblNpcThievingCustomID.setVisible(false); lblThievingNpcCustomID.setVisible(false);
npcThievingCustomID.setVisible(false); thievingNpcCustomID.setVisible(false);
} }
UI.this.revalidate(); UI.this.revalidate();
UI.this.repaint(); UI.this.repaint();
} }
}); });
thievingPanel.add(npcSelect); thievingPanel.add(thievingNpcSelect);
// Custom npc id to steal from // Custom npc id to steal from
lblNpcThievingCustomID.setForeground(Color_WhiteSmoke); lblThievingNpcCustomID.setForeground(Color_WhiteSmoke);
lblNpcThievingCustomID.setBounds(200, 20, 150, 20); lblThievingNpcCustomID.setBounds(200, 20, 150, 20);
thievingPanel.add(lblNpcThievingCustomID); thievingPanel.add(lblThievingNpcCustomID);
npcThievingCustomID.setBounds(200, 40, 150, 20); thievingNpcCustomID.setBounds(200, 40, 150, 20);
npcThievingCustomID.addFocusListener(new FocusListener() { thievingNpcCustomID.addFocusListener(new FocusListener() {
@Override @Override
public void focusGained(FocusEvent e) { public void focusGained(FocusEvent e) {
// we don't need to do anything here // we don't need to do anything here
@@ -315,20 +387,20 @@ public class UI extends JFrame {
@Override @Override
public void focusLost(FocusEvent e) { public void focusLost(FocusEvent e) {
try { try {
String[] sample = npcThievingCustomID.getText().split("(,|;)\\s*"); String[] sample = thievingNpcCustomID.getText().split("(,|;)\\s*");
int[] customIDs = new int[sample.length]; int[] customIDs = new int[sample.length];
for (int i = 0; i < sample.length; i++) for (int i = 0; i < sample.length; i++)
customIDs[i] = Integer.parseInt(sample[i]); customIDs[i] = Integer.parseInt(sample[i]);
Variables.thieving_npc_selected.setIDs(customIDs); Variables.thieving_npc_selected.setIDs(customIDs);
} catch (Exception err) { } catch (Exception err) {
Npcs.CUSTOM.setIDs(new int[]{0}); ThievingNpcs.CUSTOM.setIDs(new int[]{0});
} }
} }
}); });
thievingPanel.add(npcThievingCustomID); thievingPanel.add(thievingNpcCustomID);
lblNpcThievingCustomID.setVisible(false); lblThievingNpcCustomID.setVisible(false);
npcThievingCustomID.setVisible(false); thievingNpcCustomID.setVisible(false);
/* /*
* Slave Panel * Slave Panel