mirror of
https://github.com/2006-Scape/Script-Factory.git
synced 2026-07-02 16:49:10 +00:00
Attempt 2
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
package scriptfactory.Actions;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static scriptfactory.VarsMethods.log;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/9/2018.
|
||||
*/
|
||||
public class Action {
|
||||
|
||||
private final String action;
|
||||
private final ArrayList<String> params = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Gets the full action, i.e. type and method name
|
||||
*/
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets only the method name
|
||||
*/
|
||||
public String getMethod() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public String getParamAsString(int paramIndex) {
|
||||
try {
|
||||
return params.get(paramIndex);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
log("Error parsing parameter in the following action - did you fill them all out properly?");
|
||||
log("Action: " + this.toString());
|
||||
return "1";
|
||||
}
|
||||
}
|
||||
|
||||
public int getParamCount()
|
||||
{
|
||||
return params.size();
|
||||
}
|
||||
|
||||
public int getParam(int paramIndex) {
|
||||
return Integer.parseInt(getParamAsString(paramIndex));
|
||||
}
|
||||
|
||||
public int[] getParamArray()
|
||||
{
|
||||
return params.stream().mapToInt(Integer::parseInt).toArray();
|
||||
}
|
||||
|
||||
public Action(String action, ArrayList<JTextArea> inputs) {
|
||||
if (action.equals("Comment"))
|
||||
{
|
||||
this.action = "//";
|
||||
params.add(inputs.get(0).getText());
|
||||
return;
|
||||
}
|
||||
this.action = action;
|
||||
for (JTextArea input : inputs) {
|
||||
for (String p : input.getText().split(","))
|
||||
{
|
||||
if (!p.equals(""))
|
||||
{
|
||||
params.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Action() {
|
||||
this.action = "";
|
||||
}
|
||||
|
||||
public Action(String fromString) {
|
||||
if (fromString.startsWith("//"))
|
||||
{
|
||||
this.action = "Comment";
|
||||
params.add(fromString.replaceFirst("//", ""));
|
||||
return;
|
||||
}
|
||||
this.action = readAction(fromString);
|
||||
int index = 0;
|
||||
while (!readParam(fromString, index).equals(""))
|
||||
{
|
||||
this.params.add(readParam(fromString, index++));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (action.equals("//"))
|
||||
return "//" + params.get(0);
|
||||
return action.replace(" ", "-") + "(" + getCommaSeperatedParameters() + ")";
|
||||
}
|
||||
|
||||
private String getCommaSeperatedParameters() {
|
||||
StringBuilder paramsString = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (String p : params)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
paramsString.append(",");
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
paramsString.append(p);
|
||||
}
|
||||
|
||||
return paramsString.toString();
|
||||
}
|
||||
|
||||
private String readAction(String str)
|
||||
{
|
||||
if (str.equals("Endif"))
|
||||
return "Endif";
|
||||
|
||||
String pattern = "(If(Not)? )?(.*)\\(.*";
|
||||
return getRegex(pattern, str, 3);
|
||||
}
|
||||
|
||||
private String readParam(String str, int i) {
|
||||
if (str.equals("Endif"))
|
||||
return "";
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
return getRegex("[^\\(]*\\(([^,)]*).*", str, 1);
|
||||
}
|
||||
String pattern = "";
|
||||
String basePattern = "[^,]*,";
|
||||
for (int j = 0; j < i; j++) {
|
||||
pattern += basePattern;
|
||||
}
|
||||
pattern += "([^,)]*).*";
|
||||
return getRegex(pattern, str, 1);
|
||||
}
|
||||
|
||||
private String getRegex(String pattern, String str, int match) {
|
||||
Matcher m = Pattern.compile(pattern).matcher(str);
|
||||
return m.matches() ? m.group(match) : "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package scriptfactory.Actions;
|
||||
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
import org.parabot.environment.input.Keyboard;
|
||||
import org.parabot.environment.input.Mouse;
|
||||
import org.rev317.min.api.methods.*;
|
||||
import org.rev317.min.api.wrappers.*;
|
||||
import scriptfactory.VarsMethods;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static scriptfactory.VarsMethods.*;
|
||||
|
||||
|
||||
public class ActionHandler {
|
||||
|
||||
private static String debugString = "";
|
||||
|
||||
public void handleInteractWith(Action a)
|
||||
{
|
||||
int[] ids = new int[a.getParamCount() -1];
|
||||
for (int i = 0; i < a.getParamCount() - 1; i++) {
|
||||
ids[i] = a.getParam(i);
|
||||
}
|
||||
interactWithEntity(ids, a.getParamAsString(a.getParamCount() - 1));
|
||||
}
|
||||
|
||||
public void handleInteractWithByLoc(Action a) {
|
||||
interactWithEntityByTile(new Tile(a.getParam(0), a.getParam(1)), a.getParamAsString(2));
|
||||
}
|
||||
|
||||
public void inventoryItemInteract(Action a)
|
||||
{
|
||||
try {
|
||||
Item tea = Inventory.getItem(a.getParam(0));
|
||||
tea.interact(VarsMethods.getItemOption(a.getParamAsString(1)));
|
||||
} catch (NullPointerException e) {
|
||||
log("Warning: Couldn't find inventory item with id " + a.getParam(0));
|
||||
if (Inventory.getCount(a.getParam(0) + 1) > 0)
|
||||
{
|
||||
log("But, you seem to have " + Inventory.getCount(a.getParam(0) + 1) + " items with id " + (a.getParam(0) + 1));
|
||||
log("Try the new ID out. It might work for what you want.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void useItemOn(Action a)
|
||||
{
|
||||
Item toUse = Inventory.getItem(parsePint(a.getParamAsString(0)));
|
||||
Menu.interact(toUse, VarsMethods.getItemOption(a.getParamAsString(1)));
|
||||
|
||||
interactWithEntity(new int[]{a.getParam(1)}, "1");
|
||||
}
|
||||
|
||||
public void type(Action a)
|
||||
{
|
||||
if (a.getParamAsString(0).toLowerCase().equals("{esc}"))
|
||||
{
|
||||
Keyboard.getInstance().clickKey(KeyEvent.VK_ESCAPE);
|
||||
}
|
||||
else
|
||||
{
|
||||
Keyboard.getInstance().sendKeys(a.getParamAsString(0), a.getParamAsString(1).equals("1"));
|
||||
}
|
||||
}
|
||||
|
||||
public void clickxy(Action a)
|
||||
{
|
||||
Mouse.getInstance().click(a.getParam(0), a.getParam(1), a.getParamAsString(2).equals("0"));
|
||||
}
|
||||
|
||||
public void sleep(Action a) {
|
||||
int totalSleep = 0;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
VarsMethods.currentAction = "Sleep " + totalSleep + "/" + a.getParam(0);
|
||||
totalSleep += a.getParam(0)/10;
|
||||
Time.sleep(a.getParam(0)/10);
|
||||
}
|
||||
VarsMethods.currentAction = "Sleep " + totalSleep + "/" + a.getParam(0);
|
||||
}
|
||||
|
||||
public void sendRawAction(Action a)
|
||||
{
|
||||
String[] actionIds = a.getParamAsString(1).replaceAll("[^0-9;]", "").split(";");
|
||||
if (actionIds.length == 4)
|
||||
{
|
||||
Menu.sendAction(a.getParam(0), parsePint(actionIds[0]), parsePint(actionIds[1]), parsePint(actionIds[2]), parsePint(actionIds[3]), 0);
|
||||
} else {
|
||||
Menu.sendAction(a.getParam(0), parsePint(actionIds[0]), parsePint(actionIds[1]), parsePint(actionIds[2]), 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void walkTo(Action a) {
|
||||
Walking.walkTo(new Tile(a.getParam(0), a.getParam(1)));
|
||||
Time.sleep(a.getParam(2));
|
||||
}
|
||||
|
||||
public void handleGroundItemInteract(Action a) {
|
||||
try {
|
||||
GroundItem item = GroundItems.getNearest(o -> o.getId() == a.getParam(0))[0];
|
||||
if (item == null)
|
||||
{
|
||||
log("Could not find item with id" + a.getParam(0));
|
||||
} else {
|
||||
item.take();
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException e)
|
||||
{
|
||||
log("Warning: Grounditem not found in the following action:");
|
||||
log(a.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void bankAllExcept(Action a) {
|
||||
if (!Bank.isOpen())
|
||||
{
|
||||
log("Warning: Bank isn't open!");
|
||||
}
|
||||
Bank.depositAllExcept(a.getParamArray());
|
||||
}
|
||||
|
||||
private void interactWithEntity(int[] id, String option)
|
||||
{
|
||||
SceneObject candidateObject = SceneObjects.getClosest(id);
|
||||
Npc candidateNpc = Npcs.getClosest(o -> !o.isInCombat() && Arrays.stream(id).anyMatch(i -> i == o.getDef().getId()));
|
||||
debugString = "id: " + Arrays.toString(id);
|
||||
tryToInteract(candidateObject, candidateNpc, option);
|
||||
}
|
||||
|
||||
private void interactWithEntityByTile(Tile tile, String option) {
|
||||
SceneObject[] sos = SceneObjects.getNearest(o -> o.getLocation().equals(tile));
|
||||
SceneObject candidateObject = null;
|
||||
if (sos.length > 0)
|
||||
candidateObject = sos[0];
|
||||
Npc[] npca = Npcs.getNearest(o -> o.getLocation().equals(tile));
|
||||
Npc candidateNpc = null;
|
||||
if (npca.length > 0)
|
||||
candidateNpc = npca[0];
|
||||
|
||||
debugString = "tile: " + tile;
|
||||
tryToInteract(candidateObject, candidateNpc, option);
|
||||
}
|
||||
|
||||
private void tryToInteract(SceneObject candidateObject, Npc candidateNpc, String option)
|
||||
{
|
||||
if (candidateObject != null)
|
||||
{
|
||||
candidateObject.interact(VarsMethods.getSceneOption(option));
|
||||
} else {
|
||||
if (candidateNpc != null)
|
||||
{
|
||||
candidateNpc.interact(VarsMethods.getNpcOption(option));
|
||||
} else {
|
||||
log("Couldn't find entity on action " + VarsMethods.currentAction + ", " + debugString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package scriptfactory.Actions.Logic;
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/15/2018.
|
||||
*/
|
||||
public class Endif extends Action {
|
||||
public Endif() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Endif(String fromString)
|
||||
{
|
||||
super(fromString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Endif";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package scriptfactory.Actions.Logic;
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/9/2018.
|
||||
*/
|
||||
public class If extends Action {
|
||||
@Override
|
||||
public String getAction()
|
||||
{
|
||||
return "If " + super.getAction();
|
||||
}
|
||||
|
||||
public If(String action, ArrayList<JTextArea> inputs) {
|
||||
super(action, inputs);
|
||||
}
|
||||
|
||||
public If(String fromString)
|
||||
{
|
||||
super(fromString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "If " + super.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package scriptfactory.Actions.Logic;
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class IfNot extends Action {
|
||||
@Override
|
||||
public String getAction()
|
||||
{
|
||||
return "IfNot " + super.getAction();
|
||||
}
|
||||
|
||||
public IfNot(String action, ArrayList<JTextArea> inputs) {
|
||||
super(action, inputs);
|
||||
}
|
||||
|
||||
public IfNot(String fromString)
|
||||
{
|
||||
super(fromString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IfNot " + super.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package scriptfactory.Actions.Logic;
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
import org.rev317.min.api.methods.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static scriptfactory.VarsMethods.log;
|
||||
import static scriptfactory.VarsMethods.toPintArray;
|
||||
|
||||
public class LogicHandler {
|
||||
public boolean determineIf(Action a) {
|
||||
switch (a.getMethod().replaceAll("-", " "))
|
||||
{
|
||||
case "Item is in Inventory":
|
||||
return Inventory.getCount(a.getParam(0)) >= (a.getParamAsString(1).equals("") ? 0 : a.getParam(1));
|
||||
case "Inventory slots used":
|
||||
return Inventory.getCount() >= a.getParam(0);
|
||||
case "Item is on Ground":
|
||||
return GroundItems.getGroundItems(o-> o.getId() == a.getParam(0)).length > 0;
|
||||
case "Entity is around":
|
||||
ArrayList<Integer> ids = new ArrayList<>();
|
||||
for (int i = 0; i < a.getParamCount(); i++)
|
||||
ids.add(a.getParam(i));
|
||||
return Npcs.getClosest(toPintArray(ids)) != null ||
|
||||
SceneObjects.getClosest(toPintArray(ids)) != null;
|
||||
case "Hitpoints is below":
|
||||
return Players.getMyPlayer().getHealth() < a.getParam(0);
|
||||
case "In Combat":
|
||||
return Players.getMyPlayer().isInCombat();
|
||||
default:
|
||||
log("Error: Unimplemented conditional: " + a.getAction());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String determineIfAsBoolString(Action a)
|
||||
{
|
||||
return determineIf(a) ? "True" : "False";
|
||||
}
|
||||
|
||||
public String determineIfNotAsBoolString(Action a) {
|
||||
return determineIfAsBoolString(a).equals("True") ? "False" : "True";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package scriptfactory.Actions;
|
||||
|
||||
import scriptfactory.Strategies.ActionExecutor;
|
||||
import scriptfactory.VarsMethods;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static scriptfactory.VarsMethods.*;
|
||||
|
||||
public class SubscriptHandler {
|
||||
public static void runSubscript(String path)
|
||||
{
|
||||
ArrayList<Action> actions = new ArrayList<>();
|
||||
File subscriptFile = new File(DEFAULT_DIR + FSEP + path);
|
||||
if (subscriptFile.exists())
|
||||
loadscript(actions, subscriptFile);
|
||||
else
|
||||
loadscript(actions, new File(DEFAULT_DIR + FSEP + "dependencies" + FSEP + path));
|
||||
ActionExecutor executor = new ActionExecutor(actions);
|
||||
|
||||
VarsMethods.currentSubscript = path;
|
||||
|
||||
for (int i = 0; i < actions.size(); i++) {
|
||||
executor.execute();
|
||||
}
|
||||
|
||||
VarsMethods.currentSubscript = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package scriptfactory.AdvancedGui;
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
import scriptfactory.AdvancedGui.ScriptFactorySDN.ScriptFactorySDNGui;
|
||||
import scriptfactory.GUI.EnterJButton;
|
||||
import scriptfactory.NewGuis.UncommonActionGuiInfo;
|
||||
import scriptfactory.VarsMethods;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static scriptfactory.NewGuis.NewStatementGUI.addEscapeHotkey;
|
||||
import static scriptfactory.VarsMethods.log;
|
||||
|
||||
public class AdvancedOptionsGUI extends JFrame {
|
||||
private JPanel tickSpeedPanel = new JPanel();
|
||||
private TipsAndTricksGUI tipsFrame = new TipsAndTricksGUI();
|
||||
private EnterJButton tipsAndTricksButton = new EnterJButton("Tips and tricks");
|
||||
private EnterJButton moveLineButton = new EnterJButton("Move line");
|
||||
private EnterJButton recoverPreviousScript = new EnterJButton("Recover previous script");
|
||||
private EnterJButton uncommonActionButton = new EnterJButton("Add uncommon actions");
|
||||
private EnterJButton premadeScriptsButton = new EnterJButton("Premade scripts");
|
||||
|
||||
private ArrayList<Action> actions;
|
||||
private Consumer<Integer> updateTextfield;
|
||||
|
||||
private JFrame moveLineFrame = new JFrame();
|
||||
private UncommonActionGuiInfo uncommonActionGui;
|
||||
private ScriptFactorySDNGui sdnGui;
|
||||
|
||||
public AdvancedOptionsGUI(ArrayList<Action> actions, Consumer<Integer> updateTextfield, JTextField tickSpeedField) {
|
||||
this.actions = actions;
|
||||
this.updateTextfield = updateTextfield;
|
||||
|
||||
setLayout(new GridLayout(2, 4, 15, 15));
|
||||
setTitle("Parabot.org Script Factory - Advanced Options");
|
||||
initButtons();
|
||||
|
||||
generateTickSpeedPanel(tickSpeedField);
|
||||
add(tickSpeedPanel);
|
||||
|
||||
add(tipsAndTricksButton);
|
||||
|
||||
generateMoveLineFrame();
|
||||
add(moveLineButton);
|
||||
|
||||
add(recoverPreviousScript);
|
||||
|
||||
uncommonActionGui = new UncommonActionGuiInfo(actions, updateTextfield);
|
||||
add(uncommonActionButton);
|
||||
|
||||
sdnGui = new ScriptFactorySDNGui();
|
||||
add(premadeScriptsButton);
|
||||
|
||||
addEscapeHotkey(this);
|
||||
addEscapeHotkey(moveLineFrame);
|
||||
setMinimumSize(new Dimension(400, 250));
|
||||
revalidate();
|
||||
pack();
|
||||
}
|
||||
|
||||
private void generateTickSpeedPanel(JTextField tickSpeedField) {
|
||||
tickSpeedPanel.setLayout(new GridLayout(2, 1));
|
||||
tickSpeedPanel.add(new JLabel("Change tick speed (ms):"));
|
||||
tickSpeedField.setColumns(8);
|
||||
tickSpeedField.setText("1200");
|
||||
tickSpeedPanel.add(tickSpeedField);
|
||||
}
|
||||
|
||||
private void generateMoveLineFrame() {
|
||||
JTextField lineToMove = new JTextField(6);
|
||||
JTextField lineToInsertAbove = new JTextField(6);
|
||||
EnterJButton submitMove = new EnterJButton("Submit");
|
||||
|
||||
moveLineFrame.setLayout(new GridLayout(5, 1, 5, 15));
|
||||
moveLineFrame.setMinimumSize(new Dimension(250, 400));
|
||||
moveLineFrame.setTitle("Move a script line");
|
||||
|
||||
moveLineFrame.add(new JLabel("Enter the line # you wish to move: "));
|
||||
moveLineFrame.add(lineToMove);
|
||||
moveLineFrame.add(new JLabel("Enter the line # you wish to move it above:"));
|
||||
moveLineFrame.add(lineToInsertAbove);
|
||||
moveLineFrame.add(submitMove);
|
||||
|
||||
moveLineFrame.pack();
|
||||
|
||||
submitMove.addActionListener(b ->
|
||||
{
|
||||
int lineToMoveAsPint = VarsMethods.parsePint(lineToMove.getText());
|
||||
int lineToPlaceAboveAsPint = VarsMethods.parsePint(lineToInsertAbove.getText());
|
||||
|
||||
Action removed = actions.remove(lineToMoveAsPint);
|
||||
if (lineToPlaceAboveAsPint <= lineToMoveAsPint)
|
||||
actions.add(lineToPlaceAboveAsPint, removed);
|
||||
else
|
||||
if (lineToPlaceAboveAsPint > actions.size())
|
||||
actions.add(removed);
|
||||
else
|
||||
actions.add(lineToPlaceAboveAsPint - 1, removed);
|
||||
updateTextfield.accept(5);
|
||||
moveLineFrame.setVisible(false);
|
||||
log("Successfully moved line " + lineToMove.getText() + ".");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void initButtons()
|
||||
{
|
||||
tipsAndTricksButton.addActionListener(o -> {
|
||||
tipsFrame.setVisible(true);
|
||||
this.setVisible(false);
|
||||
});
|
||||
moveLineButton.addActionListener(o -> {
|
||||
moveLineFrame.setVisible(true);
|
||||
this.setVisible(false);
|
||||
});
|
||||
recoverPreviousScript.addActionListener(o ->
|
||||
{
|
||||
VarsMethods.loadscript(actions, new File(VarsMethods.CACHED_LOC));
|
||||
updateTextfield.accept(5);
|
||||
this.setVisible(false);
|
||||
});
|
||||
uncommonActionButton.addActionListener(o -> {
|
||||
uncommonActionGui.setVisible(true);
|
||||
this.setVisible(false);
|
||||
});
|
||||
premadeScriptsButton.addActionListener(o -> {
|
||||
sdnGui.setVisible(true);
|
||||
this.setVisible(false);
|
||||
});
|
||||
}
|
||||
|
||||
public void killAllGuis() {
|
||||
moveLineFrame.setVisible(false);
|
||||
tipsFrame.setVisible(false);
|
||||
uncommonActionGui.setVisible(false);
|
||||
sdnGui.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
package scriptfactory.AdvancedGui.ScriptFactorySDN;
|
||||
|
||||
import org.parabot.environment.scripts.Category;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeCellRenderer;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static scriptfactory.VarsMethods.*;
|
||||
|
||||
/**
|
||||
* Script Factory SDN scriptfactory.GUI, shows all scripts
|
||||
*
|
||||
* @author Everel, stolen by Before
|
||||
*/
|
||||
public class ScriptFactorySDNGui extends JFrame {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final int WIDTH;
|
||||
private final int HEIGHT;
|
||||
private HashMap<String, DefaultMutableTreeNode> categories;
|
||||
private HashMap<String, ScriptFactoryScript> format;
|
||||
private DefaultMutableTreeNode root;
|
||||
private DefaultTreeModel model;
|
||||
private Font fontCategory = new Font("Arial", Font.BOLD, 12);
|
||||
private Font fontScript = new Font("Arial", Font.PLAIN, 12);
|
||||
private JTree tree;
|
||||
private JEditorPane scriptInfo;
|
||||
|
||||
public ScriptFactorySDNGui() {
|
||||
this.categories = new HashMap<>();
|
||||
this.format = new HashMap<>();
|
||||
this.root = new DefaultMutableTreeNode("Scripts");
|
||||
this.WIDTH = 640;
|
||||
this.HEIGHT = 256 + 128;
|
||||
this.model = new DefaultTreeModel(root);
|
||||
putScripts();
|
||||
createUI();
|
||||
}
|
||||
|
||||
private void downloadScript(ScriptFactoryScript desc) {
|
||||
log("Downloading script " + desc.scriptName + "...");
|
||||
createScriptFile(desc);
|
||||
log("Downloading dependencies...");
|
||||
for (String i : desc.dependencies)
|
||||
{
|
||||
downloadScript(ScriptFactoryScript.getScriptByName(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void createScriptFile(ScriptFactoryScript desc) {
|
||||
String filePath = DEFAULT_DIR + FSEP + (desc.category.equals("Dependency") ? "dependencies" + FSEP : "") + desc.scriptName;
|
||||
PrintWriter writer = null;
|
||||
try {
|
||||
writer = new PrintWriter(new File(filePath));
|
||||
writer.write(desc.code);
|
||||
writer.close();
|
||||
} catch (FileNotFoundException ignored) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void putScripts() {
|
||||
final ScriptFactoryScript[] descs = ScriptFactoryScript.getDescriptions();
|
||||
if (descs == null) {
|
||||
return;
|
||||
}
|
||||
for (final ScriptFactoryScript scriptDesc : descs) {
|
||||
if (categories.get(scriptDesc.category) == null) {
|
||||
DefaultMutableTreeNode cat = null;
|
||||
if (scriptDesc.category.equals("Dependency"))
|
||||
cat = new DefaultMutableTreeNode("Dependencies");
|
||||
else
|
||||
cat = new DefaultMutableTreeNode(Category.valueOf(scriptDesc.category.toUpperCase()));
|
||||
cat.add(new DefaultMutableTreeNode(scriptDesc.scriptName));
|
||||
root.add(cat);
|
||||
categories.put(scriptDesc.category, cat);
|
||||
} else {
|
||||
categories.get(scriptDesc.category).add(
|
||||
new DefaultMutableTreeNode(scriptDesc.scriptName));
|
||||
}
|
||||
|
||||
format.put(scriptDesc.scriptName, scriptDesc);
|
||||
}
|
||||
}
|
||||
|
||||
private String getScriptName(String path) {
|
||||
return path.split(", ")[2].replaceAll("\\]", "");
|
||||
}
|
||||
|
||||
private String getServerDesc(final String[] servers) {
|
||||
if (servers == null) {
|
||||
return "Unknown";
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < servers.length; i++) {
|
||||
builder.append(servers[i]);
|
||||
if ((i + 1) < servers.length) {
|
||||
builder.append(", ");
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private void createUI() {
|
||||
|
||||
this.setTitle("Script Selector");
|
||||
this.setLayout(new BorderLayout());
|
||||
this.setResizable(false);
|
||||
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
|
||||
JPanel panel = new JPanel(null);
|
||||
panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
|
||||
|
||||
tree = new JTree();
|
||||
tree.setCellRenderer(new ScriptTreeCellRenderer());
|
||||
tree.setRootVisible(false);
|
||||
tree.setShowsRootHandles(true);
|
||||
tree.setModel(model);
|
||||
tree.addTreeSelectionListener(new TreeSelectionListener() {
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
String path = e.getPath().toString();
|
||||
if (path.split(",").length == 3) {
|
||||
|
||||
// local scripts
|
||||
ScriptFactoryScript def = format.get(getScriptName(e
|
||||
.getPath().toString()));
|
||||
if (def != null) {
|
||||
StringBuilder html = new StringBuilder("<html>");
|
||||
html.append("<h1><font color=\"black\">")
|
||||
.append(def.scriptName)
|
||||
.append("</font></h1><br/>");
|
||||
html.append("<font color=\"black\"><b>Author: </b>")
|
||||
.append(def.author).append("</font><br/>");
|
||||
html.append("<font color=\"black\"><b>Servers: </b>")
|
||||
.append(getServerDesc(def.servers))
|
||||
.append("</font><br/>");
|
||||
html.append("<font color=\"black\"><b>Version: </b>")
|
||||
.append(def.version).append("</font><br/>");
|
||||
html.append(
|
||||
"<font color=\"black\"><b>Description: </b>")
|
||||
.append(def.description).append("</font><br/>");
|
||||
html.append("</html>");
|
||||
scriptInfo.setText(new String(html));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
scriptInfo = new JEditorPane();
|
||||
scriptInfo.setContentType("text/html");
|
||||
scriptInfo.setEditable(false);
|
||||
|
||||
JScrollPane scrlScriptTree = new JScrollPane(tree);
|
||||
scrlScriptTree.setBounds(4, 4, WIDTH / 2 - 4 - 64, HEIGHT - 4 - 28);
|
||||
|
||||
JScrollPane scrlScriptInfo = new JScrollPane(scriptInfo);
|
||||
scrlScriptInfo.setBounds(WIDTH / 2 + 4 - 64, 4, WIDTH / 2 - 8 + 64,
|
||||
HEIGHT - 4 - 28);
|
||||
|
||||
JButton cmdStart = new JButton("Download");
|
||||
cmdStart.setBounds(WIDTH - 156 - 4, HEIGHT - 24 - 4, 156, 24);
|
||||
cmdStart.addActionListener(e -> {
|
||||
String s = getScriptName(tree.getSelectionPath().toString());
|
||||
downloadScript(format.get(s));
|
||||
JOptionPane.showMessageDialog(null, "Script downloaded successfully. You can now run it by clicking \"Load\" in the main menu.");
|
||||
});
|
||||
|
||||
JButton cmdHome = new JButton("Open home");
|
||||
cmdHome.setBounds(WIDTH - (96 * 2 + 60) - 4 - 32, HEIGHT - 24 - 4, 96 + 32,
|
||||
24);
|
||||
cmdHome.addActionListener(e -> {
|
||||
try {
|
||||
Desktop.getDesktop().open(new File(DEFAULT_DIR));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
panel.add(scrlScriptTree);
|
||||
panel.add(scrlScriptInfo);
|
||||
panel.add(cmdStart);
|
||||
panel.add(cmdHome);
|
||||
|
||||
this.add(panel);
|
||||
this.pack();
|
||||
this.setLocationRelativeTo(getOwner());
|
||||
|
||||
}
|
||||
|
||||
private class ScriptTreeCellRenderer implements TreeCellRenderer {
|
||||
private JLabel label;
|
||||
|
||||
ScriptTreeCellRenderer() {
|
||||
label = new JLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTreeCellRendererComponent(JTree list, Object value,
|
||||
boolean selected, boolean expanded, boolean leaf, int row,
|
||||
boolean focused) {
|
||||
Object o = ((DefaultMutableTreeNode) value).getUserObject();
|
||||
BufferedImage icon = (o instanceof Category ? ((Category) o)
|
||||
.getIcon() : Category.getIcon("script"));
|
||||
label.setIcon(icon != null ? new ImageIcon(icon) : null);
|
||||
label.setFont(o instanceof Category ? fontCategory : fontScript);
|
||||
label.setForeground(selected ? Color.DARK_GRAY : Color.BLACK);
|
||||
label.setText(String.valueOf(value));
|
||||
return label;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package scriptfactory.AdvancedGui.ScriptFactorySDN;
|
||||
|
||||
import scriptfactory.AdvancedGui.ScriptFactorySDN.Scripts.Cowkiller;
|
||||
import org.parabot.core.desc.ScriptDescription;
|
||||
import org.parabot.environment.scripts.Category;
|
||||
|
||||
public class ScriptFactoryScript extends ScriptDescription {
|
||||
|
||||
String code;
|
||||
String[] dependencies;
|
||||
|
||||
public ScriptFactoryScript(String scriptName, String author, Category category, double version, String description, String code, String[] dependencies) {
|
||||
super(scriptName, author, String.valueOf(category), version, description, new String[]{"Any"});
|
||||
this.code = code;
|
||||
this.dependencies = dependencies;
|
||||
}
|
||||
|
||||
public ScriptFactoryScript(String scriptName, String author, String category, double version, String description, String code, String[] dependencies) {
|
||||
super(scriptName, author, category, version, description, new String[]{"Any"});
|
||||
this.code = code;
|
||||
this.dependencies = dependencies;
|
||||
}
|
||||
|
||||
public static ScriptFactoryScript[] getDescriptions() {
|
||||
return new ScriptFactoryScript[]{
|
||||
new Cowkiller(),
|
||||
new Cowkiller.Walktocows(),
|
||||
new Cowkiller.Openlummybank(),
|
||||
};
|
||||
}
|
||||
|
||||
public static ScriptFactoryScript getScriptByName(String name)
|
||||
{
|
||||
for (ScriptFactoryScript s : getDescriptions())
|
||||
if (s.scriptName.equals(name))
|
||||
return s;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package scriptfactory.AdvancedGui.ScriptFactorySDN.Scripts;
|
||||
|
||||
import scriptfactory.AdvancedGui.ScriptFactorySDN.ScriptFactoryScript;
|
||||
import org.parabot.environment.scripts.Category;
|
||||
|
||||
public class Cowkiller extends ScriptFactoryScript {
|
||||
public Cowkiller() {
|
||||
super(
|
||||
"Cow killer (with banking)",
|
||||
"Before",
|
||||
Category.COMBAT,
|
||||
1.0,
|
||||
"Kills cows in lumbridge and banks in the castle",
|
||||
"If Inventory-slots-used(28)\n" +
|
||||
"Run-subscript(Openlummybank)\n" +
|
||||
"Bank-all-except-IDs()\n" +
|
||||
"Run-subscript(Walktocows)\n" +
|
||||
"Endif\n" +
|
||||
"IfNot In-Combat()\n" +
|
||||
"If Entity-is-around(81,397,1767,1768)\n" +
|
||||
"Take-Ground-item(2132)\n" +
|
||||
"Take-Ground-item(526)\n" +
|
||||
"Take-Ground-item(1739)\n" +
|
||||
"Interact-with-entity-by-ID(81,397,1767,1768,1)\n" +
|
||||
"Endif\n" +
|
||||
"IfNot Entity-is-around(81,397,1767,1768)\n" +
|
||||
"Run-subscript(Walktocows)\n" +
|
||||
"Endif\n" +
|
||||
"Endif\n",
|
||||
new String[]{"Walktocows", "Openlummybank"}
|
||||
);
|
||||
}
|
||||
|
||||
public static class Walktocows extends ScriptFactoryScript
|
||||
{
|
||||
|
||||
public Walktocows() {
|
||||
super(
|
||||
"Walktocows",
|
||||
"Before",
|
||||
"Dependency",
|
||||
1.0,
|
||||
"Walks to the cows in lumbridge from anywhere",
|
||||
"IfNot Entity-is-around(81,397,1767,1768)\n" +
|
||||
"Type(::stuck,1)\n" +
|
||||
"Sleep(1500)\n" +
|
||||
"Walk-to(3241,3226,14000)\n" +
|
||||
"Walk-to(3259,3233,14000)\n" +
|
||||
"Walk-to(3256,3250,14000)\n" +
|
||||
"Walk-to(3252,3266,14000)\n" +
|
||||
"Interact-with-entity-by-location(3253,3266,1)\n" +
|
||||
"Walk-to(3258,3268,5000)\n" +
|
||||
"Endif\n",
|
||||
new String[]{}
|
||||
);
|
||||
}
|
||||
}
|
||||
public static class Openlummybank extends ScriptFactoryScript
|
||||
{
|
||||
|
||||
public Openlummybank() {
|
||||
super(
|
||||
"Openlummybank",
|
||||
"Before",
|
||||
"Dependency",
|
||||
1.0,
|
||||
"Opens the bank in lumbridge castle from anywhere",
|
||||
"Type(::stuck,1)\n" +
|
||||
"Sleep(1500)\n" +
|
||||
"Interact-with-entity-by-location(3217,3218,1)\n" +
|
||||
"Interact-with-entity-by-location(3215,3211,1)\n" +
|
||||
"Interact-with-entity-by-location(3204,3207,1)\n" +
|
||||
"Sleep(15000)\n" +
|
||||
"Interact-with-entity-by-location(3204,3207,1)\n" +
|
||||
"Interact-with-entity-by-location(3204,3207,2)\n" +
|
||||
"Interact-with-entity-by-ID(494,3)\n" +
|
||||
"Sleep(6000)\n",
|
||||
new String[]{}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package scriptfactory.AdvancedGui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
import static scriptfactory.NewGuis.NewStatementGUI.addEscapeHotkey;
|
||||
import static scriptfactory.VarsMethods.centralizeComponent;
|
||||
|
||||
class TipsAndTricksGUI extends JFrame
|
||||
{
|
||||
private JLabel tipsAndTricksLabel = new JLabel("Welcome to the Tips and Tricks!");
|
||||
private JTextArea textAreaTips = new JTextArea(12, 30);
|
||||
private String[] tipsAndTipsStrings;
|
||||
|
||||
public TipsAndTricksGUI()
|
||||
{
|
||||
setLayout(new GridLayout(1, 2));
|
||||
setTitle("Parabot.org Script Factory - Tips!");
|
||||
setMaximumSize(new Dimension(300, 120));
|
||||
|
||||
tipsAndTipsStrings = new String[]{
|
||||
"Don't know what to do? Read this guide! https://parabot.slack.com",
|
||||
"Click File > Logger for debugging help",
|
||||
"You can edit the scripts you save manually in Notepad",
|
||||
"The Type function can accept {ESC} if you want it to hit the \"Escape\" key",
|
||||
"scriptfactory.GUI navigation has hotkeys;",
|
||||
"\tTab brings you to the next input field",
|
||||
"\tShift Tab brings you to the previous field",
|
||||
"\tYou can hit Enter when highlighting over a button to click it",
|
||||
"\tYou can hit Escape to close sub-interfaces quickly",
|
||||
"Share your scripts! It helps everyone learn faster :)",
|
||||
"Interact-with-entity will only look for entities that are not in combat",
|
||||
};
|
||||
|
||||
textAreaTips.setEditable(false);
|
||||
|
||||
for (String i : tipsAndTipsStrings)
|
||||
{
|
||||
textAreaTips.append("- " + i + "\n");
|
||||
}
|
||||
|
||||
JScrollPane textAreaScroll = new JScrollPane(textAreaTips);
|
||||
textAreaScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
textAreaScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
|
||||
add(centralizeComponent(tipsAndTricksLabel));
|
||||
add(textAreaScroll);
|
||||
addEscapeHotkey(this);
|
||||
pack();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package scriptfactory;
|
||||
|
||||
import scriptfactory.GUI.GUI;
|
||||
import scriptfactory.Strategies.RunLoop;
|
||||
import scriptfactory.Actions.Action;
|
||||
import org.parabot.environment.api.interfaces.Paintable;
|
||||
import org.parabot.environment.scripts.Category;
|
||||
import org.parabot.environment.scripts.Script;
|
||||
import org.parabot.environment.scripts.ScriptManifest;
|
||||
import org.parabot.environment.scripts.framework.Strategy;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static scriptfactory.VarsMethods.log;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/9/2018.
|
||||
* Welcome to AIO AIO - ScriptFactory. Make your own scripts!
|
||||
*/
|
||||
|
||||
@ScriptManifest(author = "Before", name = "Script Factory 1.5", category = Category.OTHER, version = 1.5, description = "Create your own scripts!", servers = "All")
|
||||
public class Core extends Script implements Paintable {
|
||||
|
||||
private ArrayList<Action> actions = new ArrayList<>();
|
||||
private ArrayList<Strategy> strategies = new ArrayList<>();
|
||||
|
||||
private GUI gui;
|
||||
|
||||
@Override
|
||||
public boolean onExecute() {
|
||||
File directory = new File(VarsMethods.DEFAULT_DIR + VarsMethods.FSEP + "dependencies");
|
||||
if (!directory.exists())
|
||||
directory.mkdirs();
|
||||
|
||||
gui = new GUI(actions);
|
||||
|
||||
while (gui.isShowing())
|
||||
{
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (!gui.scriptStarted)
|
||||
{
|
||||
gui.killAllGuis();
|
||||
VarsMethods.savescript(actions, new File(VarsMethods.CACHED_LOC));
|
||||
return false;
|
||||
}
|
||||
|
||||
strategies.add(new RunLoop(actions));
|
||||
provide(strategies);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
try { g.setColor(Color.BLUE);
|
||||
g.fillRect(560, 310, 170, 70);
|
||||
|
||||
g.setColor(Color.YELLOW);
|
||||
g.setFont(new Font("Cordia New", Font.PLAIN, 16));
|
||||
g.drawString("Script Factory", 580, 330);
|
||||
g.setFont(new Font("Cordia New", Font.PLAIN, 12));
|
||||
g.drawString("Currently executing: ", 580, 347);
|
||||
g.drawString(VarsMethods.currentAction, 580, 360);
|
||||
g.drawString(VarsMethods.currentSubscript.equals("") ? "" : "Subscript " + VarsMethods.currentSubscript, 580, 373);}
|
||||
catch (Exception e)
|
||||
{
|
||||
log("Found it");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package scriptfactory.GUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class EnterJButton extends JButton {
|
||||
public EnterJButton(String text)
|
||||
{
|
||||
super(text);
|
||||
EnterJButton me = this;
|
||||
this.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent keyEvent) {
|
||||
if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER)
|
||||
me.doClick();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
package scriptfactory.GUI;
|
||||
|
||||
import scriptfactory.Actions.Logic.If;
|
||||
import scriptfactory.Actions.Logic.Endif;
|
||||
import scriptfactory.Actions.Action;
|
||||
import scriptfactory.Actions.Logic.IfNot;
|
||||
import scriptfactory.GUI.MainPanels.ActionPanel;
|
||||
import scriptfactory.AdvancedGui.AdvancedOptionsGUI;
|
||||
import scriptfactory.NewGuis.ActionGuiInfo;
|
||||
import scriptfactory.NewGuis.ConditionGuiInfo;
|
||||
import scriptfactory.VarsMethods;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static scriptfactory.VarsMethods.log;
|
||||
|
||||
/**
|
||||
* Created by Cyn on 1/9/2018.
|
||||
*/
|
||||
public class GUI extends JFrame {
|
||||
public boolean scriptStarted = false;
|
||||
private EnterJButton saveButton = new EnterJButton("Save"), loadButton = new EnterJButton("Load");
|
||||
private EnterJButton addSleepButton = new EnterJButton("Add sleep");
|
||||
private JTextArea sleepAmountField = new JTextArea();
|
||||
private JTextField mostRecentLog = new JTextField("", 15);
|
||||
private File selectedFile = null;
|
||||
private EnterJButton startButton = new EnterJButton("Start");
|
||||
|
||||
private JTextPane actionList = new JTextPane();
|
||||
|
||||
private JTextField tickSpeedField = new JTextField(0);
|
||||
|
||||
private ConditionGuiInfo newCondition;
|
||||
private ActionGuiInfo newAction;
|
||||
private AdvancedOptionsGUI advancedOptions;
|
||||
private ArrayList<Action> actions;
|
||||
|
||||
public GUI(ArrayList<Action> actions)
|
||||
{
|
||||
this.actions = actions;
|
||||
|
||||
//These are like little functions we pass around
|
||||
Consumer<Integer> updateTextfield = (Integer i) -> {
|
||||
updateActionList();
|
||||
};
|
||||
Consumer<Integer> removeAction = (Integer toRemove) -> {
|
||||
log("Trying to remove " + toRemove);
|
||||
int pint = toRemove;
|
||||
actions.remove(pint);
|
||||
updateActionList();
|
||||
};
|
||||
Consumer<Boolean> endIf = (Boolean remove) -> {
|
||||
actions.add(new Endif());
|
||||
updateTextfield.accept(1);
|
||||
};
|
||||
|
||||
newAction = new ActionGuiInfo(actions, updateTextfield);
|
||||
newCondition = new ConditionGuiInfo(actions, updateTextfield);
|
||||
advancedOptions = new AdvancedOptionsGUI(actions, updateTextfield, tickSpeedField);
|
||||
|
||||
|
||||
setTitle("Parabot.org Script Factory");
|
||||
setLayout(new BorderLayout(12, 20));
|
||||
|
||||
add(new ActionPanel(actionList, newAction, newCondition, advancedOptions, removeAction, endIf), BorderLayout.WEST);
|
||||
add(rightPanel(), BorderLayout.EAST);
|
||||
add(startPanel(), BorderLayout.PAGE_END);
|
||||
|
||||
this.revalidate();
|
||||
pack();
|
||||
|
||||
addActionListeners();
|
||||
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void addActionListeners() {
|
||||
startButton.addActionListener(o -> {
|
||||
this.setVisible(false);
|
||||
log("Executing the following script:");
|
||||
for (Action a : actions)
|
||||
{
|
||||
log(a.toString());
|
||||
}
|
||||
VarsMethods.tickSpeed = VarsMethods.parsePint(tickSpeedField.getText());
|
||||
selectedFile = new File(VarsMethods.CACHED_LOC);
|
||||
saveContents();
|
||||
scriptStarted = true;
|
||||
});
|
||||
|
||||
saveButton.addActionListener(o -> {
|
||||
if (updateFile())
|
||||
saveContents();
|
||||
});
|
||||
|
||||
loadButton.addActionListener(o -> {
|
||||
if (updateFile())
|
||||
loadContents();
|
||||
});
|
||||
|
||||
addSleepButton.addActionListener(o -> {
|
||||
ArrayList<JTextArea> sleepAmountFieldAsAL = new ArrayList<>();
|
||||
sleepAmountFieldAsAL.add(sleepAmountField);
|
||||
actions.add(new Action("Sleep", sleepAmountFieldAsAL));
|
||||
updateActionList();
|
||||
});
|
||||
}
|
||||
|
||||
private void loadContents() {
|
||||
VarsMethods.loadscript(actions, selectedFile);
|
||||
updateActionList();
|
||||
}
|
||||
|
||||
private void saveContents() {
|
||||
VarsMethods.savescript(actions, selectedFile);
|
||||
}
|
||||
|
||||
private void updateActionList()
|
||||
{
|
||||
actionList.setText("");
|
||||
int tabsInFront = 0;
|
||||
String prepend;
|
||||
for (int i = 0; i < actions.size(); i++)
|
||||
{
|
||||
if (actions.get(i) instanceof Endif)
|
||||
{
|
||||
tabsInFront --;
|
||||
}
|
||||
|
||||
prepend = (i < 10 ? " " : "") + i + ": ";
|
||||
for (int j = 0; j < tabsInFront; j++)
|
||||
{
|
||||
prepend = prepend + " ";
|
||||
}
|
||||
try {
|
||||
actionList.getStyledDocument().insertString(actionList.getStyledDocument().getLength(), prepend, actionList.getStyle("red"));
|
||||
actionList.getStyledDocument().insertString(actionList.getStyledDocument().getLength(), actions.get(i).toString() + "\n", actionList.getStyle("black"));
|
||||
} catch (BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//actionList.append(prepend + actions.get(i).toString() + "\n");
|
||||
|
||||
if (actions.get(i) instanceof If || actions.get(i) instanceof IfNot)
|
||||
{
|
||||
tabsInFront ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean updateFile() {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setCurrentDirectory(new File(VarsMethods.DEFAULT_DIR));
|
||||
|
||||
int option = fileChooser.showOpenDialog(GUI.this);
|
||||
|
||||
if (option == JFileChooser.APPROVE_OPTION) {
|
||||
mostRecentLog.setText("File used: " + fileChooser.getSelectedFile().getPath());
|
||||
selectedFile = fileChooser.getSelectedFile();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private JPanel startPanel() {
|
||||
JPanel start = new JPanel();
|
||||
|
||||
start.add(startButton);
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
private JPanel rightPanel() {
|
||||
JPanel save = new JPanel();
|
||||
save.setLayout(new GridLayout(3, 1, 20, 5));
|
||||
|
||||
//Adds the save and load buttons
|
||||
JPanel buttons = new JPanel();
|
||||
buttons.setLayout(new GridLayout(2, 1, 20, 5));
|
||||
buttons.add(saveButton);
|
||||
buttons.add(loadButton);
|
||||
|
||||
|
||||
save.add(buttons);
|
||||
|
||||
//Adds the info about last saved file
|
||||
JPanel chosen = new JPanel();
|
||||
chosen.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||
chosen.add(new JLabel("Info: "));
|
||||
mostRecentLog.setEditable(false);
|
||||
chosen.add(mostRecentLog);
|
||||
|
||||
save.add(chosen);
|
||||
|
||||
//Adds the Sleep button
|
||||
JPanel addSleepPanel = new JPanel();
|
||||
addSleepPanel.setLayout(new GridLayout(2, 1));
|
||||
addSleepPanel.add(addSleepButton);
|
||||
JPanel sleepTextAndLabel = new JPanel();
|
||||
sleepTextAndLabel.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||
sleepTextAndLabel.add(new JLabel("Sleep time (ms): "));
|
||||
sleepAmountField.setColumns(8);
|
||||
sleepAmountField.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
|
||||
sleepTextAndLabel.add(sleepAmountField);
|
||||
addSleepPanel.add(sleepTextAndLabel);
|
||||
save.add(addSleepPanel);
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
public void killAllGuis()
|
||||
{
|
||||
newAction.setVisible(false);
|
||||
newCondition.setVisible(false);
|
||||
advancedOptions.killAllGuis();
|
||||
advancedOptions.setVisible(false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package scriptfactory.GUI.MainPanels;
|
||||
|
||||
import scriptfactory.GUI.EnterJButton;
|
||||
import scriptfactory.AdvancedGui.AdvancedOptionsGUI;
|
||||
import scriptfactory.NewGuis.ActionGuiInfo;
|
||||
import scriptfactory.NewGuis.ConditionGuiInfo;
|
||||
import scriptfactory.VarsMethods;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.Style;
|
||||
import javax.swing.text.StyleConstants;
|
||||
import java.awt.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/10/2018.
|
||||
*/
|
||||
public class ActionPanel extends JPanel {
|
||||
private EnterJButton actionButton = new EnterJButton("Add Action"), startIfButton = new EnterJButton("Begin If-Action"), endIfButton = new EnterJButton("End If-Block"), removeButton = new EnterJButton ("Remove Line"), advancedButton = new EnterJButton("Advanced");
|
||||
private JTextPane actionList;
|
||||
|
||||
private ActionGuiInfo newAction;
|
||||
private ConditionGuiInfo newCondition;
|
||||
private Consumer<Integer> removeAction;
|
||||
private Consumer<Boolean> endIf;
|
||||
private AdvancedOptionsGUI advancedOptions;
|
||||
|
||||
public ActionPanel(JTextPane actionList, ActionGuiInfo newAction, ConditionGuiInfo newCondition, AdvancedOptionsGUI advancedOptions, Consumer<Integer> removeAction, Consumer<Boolean> endIf)
|
||||
{
|
||||
this.actionList = actionList;
|
||||
this.newAction = newAction;
|
||||
this.newCondition = newCondition;
|
||||
this.removeAction = removeAction;
|
||||
this.endIf = endIf;
|
||||
this.advancedOptions = advancedOptions;
|
||||
|
||||
setLayout(new BorderLayout(20, 0));
|
||||
|
||||
this.actionList.setEditable(false);
|
||||
this.actionList.setText(" ");
|
||||
Style redStyle = this.actionList.addStyle("red", null);
|
||||
StyleConstants.setForeground(redStyle, Color.red);
|
||||
Style blackStyle = this.actionList.addStyle("black", null);
|
||||
StyleConstants.setForeground(blackStyle, Color.black);
|
||||
this.actionList.setBorder(BorderFactory.createEtchedBorder(Color.BLUE, Color.BLACK));
|
||||
|
||||
JPanel noWrapPanel = new JPanel(new GridLayout(1, 1, 0, 0));
|
||||
noWrapPanel.add(this.actionList);
|
||||
actionList.setMinimumSize(new Dimension(350, 200));
|
||||
JScrollPane scroll = new JScrollPane(noWrapPanel);
|
||||
scroll.getVerticalScrollBar().setUnitIncrement(5);
|
||||
|
||||
JPanel actionListButtons = new JPanel();
|
||||
actionListButtons.setLayout(new GridLayout(5, 1, 0, 20));
|
||||
actionListButtons.add(actionButton);
|
||||
actionListButtons.add(startIfButton);
|
||||
actionListButtons.add(endIfButton);
|
||||
actionListButtons.add(removeButton);
|
||||
actionListButtons.add(advancedButton);
|
||||
|
||||
add(actionListButtons, BorderLayout.EAST);
|
||||
add(scroll, BorderLayout.WEST);
|
||||
|
||||
initButtons();
|
||||
}
|
||||
|
||||
private void initButtons() {
|
||||
actionButton.addActionListener(o -> {
|
||||
newAction.setVisible(true);
|
||||
});
|
||||
|
||||
startIfButton.addActionListener(o -> {
|
||||
newCondition.setVisible(true);
|
||||
});
|
||||
|
||||
endIfButton.addActionListener(o -> {
|
||||
endIf.accept(true);
|
||||
});
|
||||
|
||||
removeButton.addActionListener(o -> {
|
||||
String path = JOptionPane.showInputDialog("Enter the line# you wish to delete:");
|
||||
|
||||
removeAction.accept(VarsMethods.parsePint(path));
|
||||
});
|
||||
|
||||
advancedButton.addActionListener(o -> {
|
||||
advancedOptions.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package scriptfactory.NewGuis;
|
||||
|
||||
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/9/2018.
|
||||
*/
|
||||
public class ActionGuiInfo extends NewStatementGUI {
|
||||
public ActionGuiInfo(ArrayList<Action> actionList, Consumer<Integer> updateTextField) {
|
||||
String[] actionTypes = new String[]{"Interact with entity by ID", "Interact with entity by location", "Walk to", "Take Ground item", "Inventory item interact", "Use item on", "Type", "Click xy", "Sleep", "Send raw Action"};
|
||||
NewStatementGUI.Descriptions[] setDescs = {
|
||||
new Descriptions("Entity to interact with (eg. \"1767,1768\" selects cows)", "Option to select (eg. \"1\") (Required)"),
|
||||
new Descriptions("Entity x coordinate", "Entity y coordinate", "Option to select (eg. \"1\") (Required)"),
|
||||
new Descriptions("X-tile coordinate", "Y-tile coordinate", "Time (ms) to wait after walking"),
|
||||
new Descriptions("Item to take (eg. 526 picks up bones)"),
|
||||
new Descriptions("Item in your inventory to use (eg. 951 = \"Silk\")", "Option to select (eg. 1 might be \"eat\")"),
|
||||
new Descriptions("Item in your inventory to use (eg. 999 = \"Bones\")", "Entity to use it on (eg. 999 = altar)<999 isn't actually altar>", "Item option to select (i.e. \"Use\") (cAsE sEnSiTiVe)"),
|
||||
new Descriptions("Text to type in (eg. 28)", "Hit enter? (0 for no, 1 for yes)"),
|
||||
new Descriptions("X coordinate to click (eg. 0)", "Y coordinate to click (eg. 600)", "Click type? (0 for left, 1 for right)"),
|
||||
new Descriptions("Amount of time to sleep (ms)"),
|
||||
new Descriptions("Action id", "scriptfactory.Actions in format: \"action1; action2; action3; action4\""),
|
||||
};
|
||||
|
||||
initGui("Add new action", actionList, updateTextField, actionTypes, setDescs);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package scriptfactory.NewGuis;
|
||||
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/9/2018.
|
||||
*/
|
||||
public class ConditionGuiInfo extends NewStatementGUI {
|
||||
public ConditionGuiInfo(ArrayList<Action> actionList, Consumer<Integer> updateTextfield) {
|
||||
String[] actionTypes = new String[]{"Item is in Inventory", "Inventory slots used", "Item is on Ground", "Entity is around", "Hitpoints is below", "In Combat"};
|
||||
Descriptions[] setDescs = {
|
||||
new Descriptions("Item to detect (eg. 4296 = bones)", "Number of them to detect (blank = 1)"),
|
||||
new Descriptions("Inventory slots greater than or equal to (eg. \"28\" detects a full inventory)"),
|
||||
new Descriptions("Item to detect (eg. 314 = feathers)"),
|
||||
new Descriptions("Entity to detect (eg. \"81,397,1767,1768\" detects cows)"),
|
||||
new Descriptions("Below health # (eg. 10)"),
|
||||
new Descriptions(),
|
||||
};
|
||||
|
||||
initGui("Add new condition", actionList, updateTextfield, actionTypes, setDescs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
package scriptfactory.NewGuis;
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
import scriptfactory.Actions.Logic.If;
|
||||
import scriptfactory.Actions.Logic.IfNot;
|
||||
import scriptfactory.GUI.EnterJButton;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static scriptfactory.VarsMethods.MAX_PARAMS;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/10/2018.
|
||||
* Creates the scriptfactory.scriptfactory.GUI that is extended by actions and if statements
|
||||
* Allows user to generate new actions/if statements
|
||||
*/
|
||||
public class NewStatementGUI extends JFrame {
|
||||
private ArrayList<JTextArea> inputs = new ArrayList<>();
|
||||
private ArrayList<JLabel> descLabels = new ArrayList<>();
|
||||
|
||||
private EnterJButton add = new EnterJButton("Add");
|
||||
private EnterJButton addInverse = new EnterJButton("Add inverse");
|
||||
private JPanel addPanel = new JPanel();
|
||||
private String selectedAction;
|
||||
|
||||
/**
|
||||
* Creates whole scriptfactory.GUI
|
||||
* @param title: Title for JFrame
|
||||
* @param actionList: List of steps (actions) in script
|
||||
* @param updateTextfield: Function to refresh the action list UI
|
||||
* @param actionTypes: List of possible actions the user can select
|
||||
* @param descStrings: Descriptions to display for the actions
|
||||
*/
|
||||
void initGui(String title, ArrayList<Action> actionList, Consumer<Integer> updateTextfield, String[] actionTypes, Descriptions[] descStrings) {
|
||||
setTitle(title);
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
for (int i = 0; i < MAX_PARAMS; i++) {
|
||||
inputs.add(new JTextArea());
|
||||
descLabels.add(new JLabel());
|
||||
}
|
||||
|
||||
JPanel dropDownAndDesc = new JPanel(new GridLayout(2, 1));
|
||||
dropDownAndDesc.add(actionTypeCombo(actionTypes, descStrings));
|
||||
dropDownAndDesc.add(new JLabel("To IDs, click the \"Debug\" dropdown on the top right corner of the client."));
|
||||
add(dropDownAndDesc, BorderLayout.PAGE_START);
|
||||
|
||||
add(fillInfo());
|
||||
|
||||
add(generateAddButton(title), BorderLayout.PAGE_END);
|
||||
|
||||
setSize(650, 300);
|
||||
|
||||
addEscapeHotkey(this);
|
||||
|
||||
add.addActionListener(o -> {
|
||||
if (this.getTitle().contains("action"))
|
||||
actionList.add(new Action(selectedAction, inputs));
|
||||
else
|
||||
actionList.add(new If(selectedAction, inputs));
|
||||
updateTextfield.accept(5);
|
||||
this.setVisible(false);
|
||||
clearInputs();
|
||||
});
|
||||
addInverse.addActionListener(o -> {
|
||||
actionList.add(new IfNot(selectedAction, inputs));
|
||||
updateTextfield.accept(5);
|
||||
this.setVisible(false);
|
||||
clearInputs();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UI to include descriptions for newly selected action
|
||||
*
|
||||
* @param actionTypes: scriptfactory.Actions user can select
|
||||
* @param descs: Field descriptions for that action
|
||||
*/
|
||||
private JComboBox actionTypeCombo(String[] actionTypes, Descriptions[] descs) {
|
||||
JComboBox actionType = new JComboBox(actionTypes);
|
||||
selectedAction = actionTypes[0]; //prevents null
|
||||
setupInputFields(descs[0]);
|
||||
|
||||
actionType.addActionListener(o -> {
|
||||
selectedAction = actionType.getSelectedItem().toString();
|
||||
|
||||
setupInputFields(descs[actionType.getSelectedIndex()]);
|
||||
});
|
||||
|
||||
return actionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the "Add" button
|
||||
* Figures out if "Add Inverse" is needed
|
||||
* Adds their hotkeys
|
||||
*/
|
||||
private JPanel generateAddButton(String title) {
|
||||
addPanel.add(add);
|
||||
|
||||
if (title.equals("Add new condition"))
|
||||
{
|
||||
addPanel.add(addInverse);
|
||||
}
|
||||
|
||||
return addPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return: Panel holding the 3 descriptions and fields for user input in the UI
|
||||
*/
|
||||
private JPanel fillInfo() {
|
||||
JPanel fillInfo = new JPanel();
|
||||
fillInfo.setLayout(new GridLayout(3, 1, 20, 20));
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
fillInfo.add(detailGrabber(inputs.get(i), descLabels.get(i)));
|
||||
setHKNavigation(inputs.get(i));
|
||||
}
|
||||
|
||||
fillInfo.updateUI();
|
||||
fillInfo.repaint();
|
||||
return fillInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible)
|
||||
{
|
||||
super.setVisible(visible);
|
||||
for (int i = 0; i < inputs.size(); i++) {
|
||||
inputs.get(i).setText("");
|
||||
inputs.get(i).repaint();
|
||||
//i.updateUI() ?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the textareas respond to hotkeys
|
||||
* Currently supports Tab, Shift Tab
|
||||
* @param textArea current TextArea to operate on
|
||||
*/
|
||||
private void setHKNavigation(JTextArea textArea) {
|
||||
textArea.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent keyEvent) {
|
||||
if (keyEvent.getKeyCode() == KeyEvent.VK_TAB) {
|
||||
if (keyEvent.getModifiers() > 0)
|
||||
textArea.transferFocusBackward();
|
||||
else
|
||||
textArea.transferFocus();
|
||||
keyEvent.consume();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void addEscapeHotkey(JFrame temp) {
|
||||
ActionListener escListener = e -> temp.setVisible(false);
|
||||
temp.getRootPane().registerKeyboardAction(escListener,
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
|
||||
JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param input: Where the user types in the value
|
||||
* @param desc: Description of the input field
|
||||
* @return: Panel holding input field and description
|
||||
*/
|
||||
private JPanel detailGrabber(JTextArea input, JLabel desc) {
|
||||
JPanel forum = new JPanel();
|
||||
forum.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||
forum.add(input);
|
||||
forum.add(desc);
|
||||
input.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
input.setColumns(8);
|
||||
|
||||
return forum;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void setupInputFields(Descriptions desc)
|
||||
{
|
||||
for (int i = 0; i < MAX_PARAMS; i++) {
|
||||
if (desc.getLabelText(i) == null)
|
||||
inputs.get(i).setVisible(false);
|
||||
else
|
||||
inputs.get(i).setVisible(true);
|
||||
|
||||
descLabels.get(i).setText(desc.getLabelText(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void clearInputs() {
|
||||
for (int i = 0; i < MAX_PARAMS; i++)
|
||||
inputs.get(i).setText("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple class holding three strings that will be the descriptions on the UI
|
||||
*/
|
||||
class Descriptions {
|
||||
private String[] labelText;
|
||||
|
||||
Descriptions(String... descriptions)
|
||||
{
|
||||
this.labelText = descriptions;
|
||||
}
|
||||
|
||||
String getLabelText(int index) {
|
||||
if (index < labelText.length)
|
||||
return labelText[index];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package scriptfactory.NewGuis;
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class UncommonActionGuiInfo extends NewStatementGUI {
|
||||
public UncommonActionGuiInfo(ArrayList<Action> actionList, Consumer<Integer> updateTextField)
|
||||
{
|
||||
String[] actionTypes = new String[]{"Comment", "Run subscript", "Bank all except IDs"};
|
||||
NewStatementGUI.Descriptions[] setDescs = {
|
||||
new Descriptions("Enter any text to be your comment."),
|
||||
new Descriptions("Enter the file name of the subscript (cAsE sEnSiTiVe)"),
|
||||
new Descriptions("Enter the IDs to keep (comma separated) (i.e. \"995,150,356\") (can be blank)"),
|
||||
};
|
||||
initGui("Add new uncommon action", actionList, updateTextField, actionTypes, setDescs);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package scriptfactory.Strategies;
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
import scriptfactory.Actions.ActionHandler;
|
||||
import scriptfactory.Actions.Logic.Endif;
|
||||
import scriptfactory.Actions.Logic.If;
|
||||
import scriptfactory.Actions.Logic.IfNot;
|
||||
import scriptfactory.Actions.Logic.LogicHandler;
|
||||
import scriptfactory.Actions.SubscriptHandler;
|
||||
import scriptfactory.VarsMethods;
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Stack;
|
||||
|
||||
import static scriptfactory.VarsMethods.log;
|
||||
|
||||
public class ActionExecutor {
|
||||
private ArrayList<Action> actions;
|
||||
private ActionHandler actionHandler;
|
||||
private LogicHandler logicHandler;
|
||||
private Stack ifStack;
|
||||
|
||||
private int lineIndex;
|
||||
|
||||
public ActionExecutor(ArrayList<Action> actions) {
|
||||
this.actions = actions;
|
||||
|
||||
actionHandler = new ActionHandler();
|
||||
logicHandler = new LogicHandler();
|
||||
ifStack = new Stack();
|
||||
ifStack.push("True");
|
||||
|
||||
lineIndex = 0;
|
||||
}
|
||||
|
||||
public void execute()
|
||||
{
|
||||
Action line = actions.get(lineIndex);
|
||||
lineIndex = ++lineIndex == actions.size() ? 0 : lineIndex;
|
||||
|
||||
if (line instanceof Endif)
|
||||
{
|
||||
ifStack.pop();
|
||||
return;
|
||||
} else if ((line instanceof If || line instanceof IfNot) && ifStack.peek().equals("False")) {
|
||||
ifStack.push("False");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ifStack.peek().equals("True"))
|
||||
{
|
||||
VarsMethods.currentAction = line.getAction();
|
||||
|
||||
try {
|
||||
executeLine(line);
|
||||
} catch (NumberFormatException notFilledIn) {
|
||||
log("Error on line " + line);
|
||||
log("Make sure you fill in all numeric values properly! Numbers only!");
|
||||
}
|
||||
|
||||
Time.sleep(VarsMethods.tickSpeed);
|
||||
}
|
||||
|
||||
Time.sleep(50);
|
||||
}
|
||||
|
||||
private void executeLine(Action action) {
|
||||
if (action instanceof If)
|
||||
{
|
||||
ifStack.push(logicHandler.determineIfAsBoolString(action));
|
||||
}
|
||||
else if (action instanceof IfNot)
|
||||
{
|
||||
ifStack.push(logicHandler.determineIfNotAsBoolString(action));
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (action.getMethod().replace("-", " "))
|
||||
{
|
||||
case "Interact with entity by ID":
|
||||
actionHandler.handleInteractWith(action);
|
||||
break;
|
||||
case "Interact with entity by location":
|
||||
actionHandler.handleInteractWithByLoc(action);
|
||||
break;
|
||||
case "Take Ground item":
|
||||
actionHandler.handleGroundItemInteract(action);
|
||||
break;
|
||||
case "Inventory item interact":
|
||||
actionHandler.inventoryItemInteract(action);
|
||||
break;
|
||||
case "Use item on":
|
||||
actionHandler.useItemOn(action);
|
||||
break;
|
||||
case "Type":
|
||||
actionHandler.type(action);
|
||||
break;
|
||||
case "Click xy":
|
||||
actionHandler.clickxy(action);
|
||||
break;
|
||||
case "Sleep":
|
||||
actionHandler.sleep(action);
|
||||
break;
|
||||
case "Send raw Action":
|
||||
actionHandler.sendRawAction(action);
|
||||
break;
|
||||
case "Walk to":
|
||||
actionHandler.walkTo(action);
|
||||
break;
|
||||
case "Run subscript":
|
||||
SubscriptHandler.runSubscript(action.getParamAsString(0));
|
||||
break;
|
||||
case "Bank all except IDs":
|
||||
actionHandler.bankAllExcept(action);
|
||||
break;
|
||||
default:
|
||||
log("Error: Unimplemented action: " + action.getAction());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package scriptfactory.Strategies;
|
||||
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
import org.parabot.environment.scripts.framework.Strategy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/15/2018.
|
||||
*/
|
||||
public class RunLoop implements Strategy {
|
||||
|
||||
private ActionExecutor actionExecutor;
|
||||
|
||||
public RunLoop(ArrayList<Action> actions)
|
||||
{
|
||||
actionExecutor = new ActionExecutor(actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
actionExecutor.execute();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
package scriptfactory;
|
||||
|
||||
import org.parabot.core.ui.Logger;
|
||||
import org.rev317.min.api.methods.GroundItems;
|
||||
import org.rev317.min.api.methods.Items;
|
||||
import org.rev317.min.api.methods.Npcs;
|
||||
import org.rev317.min.api.methods.SceneObjects;
|
||||
import scriptfactory.Actions.Action;
|
||||
import scriptfactory.Actions.Logic.Endif;
|
||||
import scriptfactory.Actions.Logic.If;
|
||||
import scriptfactory.Actions.Logic.IfNot;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class VarsMethods {
|
||||
public static int tickSpeed = 1200;
|
||||
public static String currentAction = "";
|
||||
public static String currentSubscript = "";
|
||||
|
||||
public final static String DEFAULT_DIR = System.getProperty("user.home") + System.getProperty("file.separator") + "Parabot" + System.getProperty("file.separator") + "Script Factory";
|
||||
public final static String CACHED_LOC = DEFAULT_DIR + System.getProperty("file.separator") + "ScriptFactory cache.txt";
|
||||
public final static String FSEP = System.getProperty("file.separator");
|
||||
public final static int MAX_PARAMS = 3;
|
||||
|
||||
public static void log(String str)
|
||||
{
|
||||
Logger.addMessage(str, false);
|
||||
System.out.println(str);
|
||||
}
|
||||
|
||||
public static void loadscript(ArrayList<Action> actions, File selectedFile) {
|
||||
actions.clear();
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(selectedFile))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
switch (line.split(" ")[0])
|
||||
{
|
||||
case "If":
|
||||
actions.add(new If(line));
|
||||
break;
|
||||
case "IfNot":
|
||||
actions.add(new IfNot(line));
|
||||
break;
|
||||
case "Endif":
|
||||
actions.add(new Endif(line));
|
||||
break;
|
||||
default:
|
||||
actions.add(new Action(line));
|
||||
}
|
||||
}
|
||||
log("File loaded successfully");
|
||||
} catch (FileNotFoundException e) {
|
||||
log("Warning: Could not find file " + selectedFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void savescript(ArrayList<Action> actions, File selectedFile) {
|
||||
PrintWriter writer = null;
|
||||
try {
|
||||
writer = new PrintWriter(selectedFile);
|
||||
|
||||
for (Action a : actions)
|
||||
{
|
||||
writer.println(a.toString());
|
||||
}
|
||||
writer.close();
|
||||
} catch (FileNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static JPanel centralizeComponent(Component component)
|
||||
{
|
||||
JPanel centralizer = new JPanel();
|
||||
centralizer.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
centralizer.add(component);
|
||||
|
||||
return centralizer;
|
||||
}
|
||||
|
||||
public static int parsePint(String toParse)
|
||||
{
|
||||
return Integer.parseInt(toParse.replaceAll("[^0-9]", ""));
|
||||
}
|
||||
|
||||
public static int[] toPintArray(ArrayList<Integer> ids) {
|
||||
int[] array = new int[ids.size()];
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
array[i] = ids.get(i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static SceneObjects.Option getSceneOption(String option) {
|
||||
switch (option)
|
||||
{
|
||||
case "1":
|
||||
return SceneObjects.Option.FIRST;
|
||||
case "2":
|
||||
return SceneObjects.Option.SECOND;
|
||||
case "3":
|
||||
return SceneObjects.Option.THIRD;
|
||||
case "4":
|
||||
return SceneObjects.Option.FOURTH;
|
||||
case "5":
|
||||
return SceneObjects.Option.FIFTH;
|
||||
default:
|
||||
VarsMethods.log("Invalid Object option: " + option);
|
||||
return SceneObjects.Option.valueOf(option);
|
||||
}
|
||||
}
|
||||
|
||||
public static Npcs.Option getNpcOption(String option) {
|
||||
switch (option)
|
||||
{
|
||||
case "1":
|
||||
return Npcs.Option.FIRST;
|
||||
case "2":
|
||||
return Npcs.Option.SECOND;
|
||||
case "3":
|
||||
return Npcs.Option.THIRD;
|
||||
case "4":
|
||||
return Npcs.Option.FOURTH;
|
||||
case "5":
|
||||
return Npcs.Option.FIFTH;
|
||||
default:
|
||||
VarsMethods.log("Invalid Object option: " + option);
|
||||
return Npcs.Option.valueOf(option);
|
||||
}
|
||||
}
|
||||
|
||||
public static Items.Option getItemOption(String option) {
|
||||
switch (option)
|
||||
{
|
||||
case "1":
|
||||
return Items.Option.FIRST;
|
||||
case "2":
|
||||
return Items.Option.SECOND;
|
||||
case "3":
|
||||
return Items.Option.THIRD;
|
||||
case "4":
|
||||
return Items.Option.FOURTH;
|
||||
case "5":
|
||||
return Items.Option.FIFTH;
|
||||
default:
|
||||
VarsMethods.log("Invalid Object option: " + option);
|
||||
return Items.Option.valueOf(option);
|
||||
}
|
||||
}
|
||||
|
||||
public static GroundItems.Option getGroundItemOption(String option) {
|
||||
switch (option)
|
||||
{
|
||||
case "1":
|
||||
return GroundItems.Option.FIRST;
|
||||
case "2":
|
||||
return GroundItems.Option.SECOND;
|
||||
case "3":
|
||||
return GroundItems.Option.THIRD;
|
||||
case "4":
|
||||
return GroundItems.Option.FOURTH;
|
||||
case "5":
|
||||
return GroundItems.Option.FIFTH;
|
||||
default:
|
||||
VarsMethods.log("Invalid Object option: " + option);
|
||||
return GroundItems.Option.valueOf(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<config>
|
||||
<jars basedir="${project.basedir}/target/">
|
||||
<jar in="${project.build.finalName}.jar" out="/home/ci/jars/${project.build.finalName}.jar"/>
|
||||
</jars>
|
||||
|
||||
<classpath basedir="/home/ci/allatori/libs">
|
||||
<jar name="./*.jar"/>
|
||||
</classpath>
|
||||
|
||||
<!-- String encryption -->
|
||||
<property name="string-encryption" value="enable"/>
|
||||
<property name="string-encryption-type" value="fast"/>
|
||||
<property name="string-encryption-version" value="v4"/>
|
||||
|
||||
<!-- Control flow obfuscation -->
|
||||
<property name="control-flow-obfuscation" value="enable"/>
|
||||
<property name="extensive-flow-obfuscation" value="normal"/>
|
||||
|
||||
<!-- Renaming -->
|
||||
<property name="default-package" value=""/>
|
||||
<property name="force-default-package" value="disable"/>
|
||||
|
||||
<property name="classes-naming" value="unique"/>
|
||||
<property name="methods-naming" value="iii"/>
|
||||
<property name="fields-naming" value="iii"/>
|
||||
<property name="local-variables-naming" value="abc"/>
|
||||
|
||||
<!-- Other -->
|
||||
<property name="line-numbers" value="keep"/>
|
||||
<property name="generics" value="keep"/>
|
||||
<property name="member-reorder" value="enable"/>
|
||||
<property name="finalize" value="disable"/>
|
||||
<property name="synthetize-methods" value="private"/>
|
||||
<property name="synthetize-fields" value="private"/>
|
||||
<property name="remove-toString" value="disable"/>
|
||||
</config>
|
||||
Reference in New Issue
Block a user