import java.util.Objects; /** * Represents a single right-click or left-click menu entry in the game. */ public class MenuEntry { private String rawText; private int actionId; private int cmd1; private int cmd2; private int cmd3; public MenuEntry() { } public MenuEntry(String rawText, int actionId, int cmd1, int cmd2, int cmd3) { this.rawText = rawText; this.actionId = actionId; this.cmd1 = cmd1; this.cmd2 = cmd2; this.cmd3 = cmd3; } public String getRawText() { return rawText != null ? rawText : ""; } public void setRawText(String rawText) { this.rawText = rawText; } public int getActionId() { return actionId; } public void setActionId(int actionId) { this.actionId = actionId; } public int getCmd1() { return cmd1; } public void setCmd1(int cmd1) { this.cmd1 = cmd1; } public int getCmd2() { return cmd2; } public void setCmd2(int cmd2) { this.cmd2 = cmd2; } public int getCmd3() { return cmd3; } public void setCmd3(int cmd3) { this.cmd3 = cmd3; } /** * Strips RS color tags like @yel@, @whi@, @gre@, etc. */ public static String stripColorTags(String text) { if (text == null) { return ""; } StringBuilder sb = new StringBuilder(text.length()); boolean inTag = false; for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (c == '@' && !inTag) { // Check if closing '@' exists within next 5 chars int closingIndex = text.indexOf('@', i + 1); if (closingIndex > i && closingIndex - i <= 5) { i = closingIndex; continue; } } sb.append(c); } return sb.toString().trim(); } /** * Returns the verb / action prefix (e.g. "Talk-to", "Attack", "Take", "Bank", "Examine"). */ public String getAction() { String clean = stripColorTags(rawText); int spaceIndex = clean.indexOf(' '); if (spaceIndex != -1) { return clean.substring(0, spaceIndex).trim(); } return clean.trim(); } /** * Returns the target name without action or color tags (e.g. "Man", "Chicken", "Feather"). */ public String getTarget() { String clean = stripColorTags(rawText); int spaceIndex = clean.indexOf(' '); if (spaceIndex != -1) { String target = clean.substring(spaceIndex + 1).trim(); // If combat level is attached: e.g. "Chicken (level-1)", strip combat level if desired or keep return target; } return ""; } /** * Case-insensitive match check for action and target patterns. * Empty or null pattern acts as wildcard "*". */ public boolean matches(String actionPattern, String targetPattern) { String act = getAction(); String tgt = getTarget(); if (actionPattern != null && !actionPattern.isEmpty() && !actionPattern.equals("*")) { if (!act.equalsIgnoreCase(actionPattern)) { return false; } } if (targetPattern != null && !targetPattern.isEmpty() && !targetPattern.equals("*")) { if (!tgt.toLowerCase().contains(targetPattern.toLowerCase())) { return false; } } return true; } @Override public String toString() { return "MenuEntry{" + "action='" + getAction() + '\'' + ", target='" + getTarget() + '\'' + ", raw='" + rawText + '\'' + ", id=" + actionId + ", cmd1=" + cmd1 + ", cmd2=" + cmd2 + ", cmd3=" + cmd3 + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof MenuEntry)) return false; MenuEntry menuEntry = (MenuEntry) o; return actionId == menuEntry.actionId && cmd1 == menuEntry.cmd1 && cmd2 == menuEntry.cmd2 && cmd3 == menuEntry.cmd3 && Objects.equals(rawText, menuEntry.rawText); } @Override public int hashCode() { return Objects.hash(rawText, actionId, cmd1, cmd2, cmd3); } }