diff --git a/src/org/rev317/min/api/events/ActionEvent.java b/src/org/rev317/min/api/events/ActionEvent.java new file mode 100644 index 0000000..7b6e425 --- /dev/null +++ b/src/org/rev317/min/api/events/ActionEvent.java @@ -0,0 +1,35 @@ +package org.rev317.min.api.events; + +public final class ActionEvent{ + private int index,cmd1,cmd2,cmd3,action; + + public ActionEvent(int action,int cmd1,int cmd2, int cmd3,int index){ + this.action = action; + this.cmd1 = cmd1; + this.cmd2 = cmd2; + this.cmd3 = cmd3; + this.index = index; + } + + public int getCmd1(){ + return cmd1; + } + + public int getCmd2(){ + return cmd2; + } + + public int getCmd3(){ + return cmd3; + } + + public int getAction(){ + return action; + } + + public int getIndex(){ + return index; + } + + +} diff --git a/src/org/rev317/min/api/events/listeners/ActionListener.java b/src/org/rev317/min/api/events/listeners/ActionListener.java new file mode 100644 index 0000000..9a1940c --- /dev/null +++ b/src/org/rev317/min/api/events/listeners/ActionListener.java @@ -0,0 +1,9 @@ +package org.rev317.min.api.events.listeners; + +import org.rev317.min.api.events.ActionEvent; + +public interface ActionListener{ + + public void onGameAction(ActionEvent event); + +} diff --git a/src/org/rev317/min/api/methods/Menu.java b/src/org/rev317/min/api/methods/Menu.java index edd22cf..83d126f 100644 --- a/src/org/rev317/min/api/methods/Menu.java +++ b/src/org/rev317/min/api/methods/Menu.java @@ -170,23 +170,22 @@ public class Menu { * @param cmd3 */ public static void sendAction(int action, int cmd1, int cmd2, int cmd3) { - sendAction(action, cmd1, cmd2, cmd3, 0); + sendAction(action, cmd1, cmd2, cmd3, 1); } - + /** * Sends an action to the client * @param action * @param cmd1 * @param cmd2 * @param cmd3 - * @param cmd4 + * @param index */ - public static void sendAction(int action, int cmd1, int cmd2, int cmd3, int cmd4) { + public static void sendAction(int action, int cmd1, int cmd2, int cmd3, int index) { if (constants == null) { constants = Context.getInstance().getHookParser().getConstants(); } - int index = 0; Client client = Loader.getClient(); client.getMenuAction1()[index] = cmd1; diff --git a/src/org/rev317/min/api/methods/Skill.java b/src/org/rev317/min/api/methods/Skill.java index 333e327..35793ca 100644 --- a/src/org/rev317/min/api/methods/Skill.java +++ b/src/org/rev317/min/api/methods/Skill.java @@ -9,11 +9,11 @@ import org.rev317.min.Loader; */ public enum Skill { - ATTACK(0), DEFENSE(1), STRENGTH(2), HITPOINTS(3), CONSTITUTION(3), RANGE(4), PRAYER( - 5), MAGIC(6), COOKING(7), WOODCUTTING(8), FLETCHING(9), FISHING(10), FIREMAKING( - 11), CRAFTING(12), SMITHING(13), MINING(14), HERBLORE(15), HERBLAW( - 15), AGILITY(16), THIEVING(17), SLAYER(18), FARMING(19), RUNECRAFTING( - 20), HUNTER(21), CONSTRUCTION(22), SUMMONING(23), DUNGEONEERING(24); + ATTACK, DEFENSE, STRENGTH, HITPOINTS, CONSTITUTION, RANGE, PRAYER + , MAGIC, COOKING, WOODCUTTING, FLETCHING, FISHING, FIREMAKING + , CRAFTING, SMITHING, MINING, HERBLORE, HERBLAW + , AGILITY, THIEVING, SLAYER, FARMING, RUNECRAFTING + , HUNTER, CONSTRUCTION, SUMMONING, DUNGEONEERING; private static final int[] EXPERIENCE = { 0, 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, @@ -32,17 +32,12 @@ public enum Skill { 42769801, 47221641, 52136869, 57563718, 63555443, 70170840, 77474828, 85539082, 94442737, 104273167 }; - private int index; - - private Skill(int index) { - this.index = index; - } - /** + * @Deprecated use Skill.ordinal() instead * Returns the skill's index. */ public int getIndex() { - return this.index; + return ordinal(); } /** @@ -129,7 +124,8 @@ public enum Skill { * Done by Bears */ public static final int getCurrentLevel(int index) { - return Loader.getClient().getCurrentStats()[index]; + //return Loader.getClient().getCurrentStats()[index]; + return getRealLevel(index); //TODO fix this method, it invokes a method not in the client accessor. } /** diff --git a/src/org/rev317/min/callback/MenuAction.java b/src/org/rev317/min/callback/MenuAction.java index f61a46b..e9e14b7 100644 --- a/src/org/rev317/min/callback/MenuAction.java +++ b/src/org/rev317/min/callback/MenuAction.java @@ -4,22 +4,30 @@ import org.rev317.min.Loader; import org.rev317.min.accessors.Client; import org.rev317.min.debug.DActions; +import org.rev317.min.api.events.ActionEvent; + +import org.rev317.min.script.ScriptEngine; + /** * * @author Everel - * + * @author mat123337 + * */ public class MenuAction { public static void intercept(int index) { - if(DActions.debugActions()) { Client client = Loader.getClient(); int action1 = client.getMenuAction1()[index]; int action2 = client.getMenuAction2()[index]; int action3 = client.getMenuAction3()[index]; int actionId = client.getMenuActionId()[index]; + if(DActions.debugActions()) { System.out.println(String.format("[index: %d, action1: %d, action2: %d, action3: %d, id: %d]", index, action1, action2, action3, actionId)); } + + final ActionEvent actionEvent = new ActionEvent(actionId,action1,action2,action3,index); + ScriptEngine.getInstance().dispatch(actionEvent); } } diff --git a/src/org/rev317/min/script/ScriptEngine.java b/src/org/rev317/min/script/ScriptEngine.java index dd99929..9e0bf46 100644 --- a/src/org/rev317/min/script/ScriptEngine.java +++ b/src/org/rev317/min/script/ScriptEngine.java @@ -12,10 +12,13 @@ import org.parabot.environment.api.interfaces.Paintable; import org.parabot.environment.scripts.Script; import org.rev317.min.api.events.MessageEvent; import org.rev317.min.api.events.listeners.MessageListener; +import org.rev317.min.api.events.ActionEvent; +import org.rev317.min.api.events.listeners.ActionListener; /** * * @author Everel + * @author matt123337 * */ public class ScriptEngine { @@ -23,6 +26,7 @@ public class ScriptEngine { private ArrayList mouseListeners; private ArrayList mouseMotionListeners; private ArrayList messageListeners; + private ArrayList actionListeners; private Script script = null; @@ -30,6 +34,7 @@ public class ScriptEngine { this.mouseListeners = new ArrayList(); this.mouseMotionListeners = new ArrayList(); this.messageListeners = new ArrayList(); + this.actionListeners = new ArrayList(); instances.put(Context.getInstance(), this); } @@ -41,6 +46,18 @@ public class ScriptEngine { return new ScriptEngine(); } + public void addActionListener(ActionListener a){ + actionListeners.add(a); + } + + public void removeActionListener(ActionListener a){ + actionListeners.remove(a); + } + + public void clearActionListeners(){ + actionListeners.clear(); + } + public void addMouseListener(MouseListener mouseListener) { mouseListeners.add(mouseListener); } @@ -107,6 +124,9 @@ public class ScriptEngine { if(script instanceof Paintable) { Context.getInstance().addPaintable((Paintable)script); } + if(script instanceof ActionListener){ + addActionListener((ActionListener) script); + } } public void dispatch(AWTEvent event) { @@ -152,6 +172,12 @@ public class ScriptEngine { messageListener.messageReceived(event); } } + + public void dispatch(ActionEvent event) { + for(final ActionListener a : actionListeners) { + a.onGameAction(event); + } + } }