diff --git a/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.SwapTest.cs b/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.SwapTest.cs index 7ae87d9..0461dc3 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.SwapTest.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.SwapTest.cs @@ -86,5 +86,6 @@ public partial class BuffManager _swapTestAt = Now; LastWandSwapTrail = ""; _host.Log($"[SwapTest] start: '{name}' (mode {CurrentCombatMode})"); + _host.WriteToChat($"[RynthAi] Swap test: {name}; the result follows.", 1); // /ra swaptest's answer } } diff --git a/Plugins/RynthCore.Plugin.RynthAi/CommandReply.cs b/Plugins/RynthCore.Plugin.RynthAi/CommandReply.cs new file mode 100644 index 0000000..ae79c22 --- /dev/null +++ b/Plugins/RynthCore.Plugin.RynthAi/CommandReply.cs @@ -0,0 +1,175 @@ +using System; +using System.Collections.Generic; + +namespace RynthCore.Plugin.RynthAi; + +/// +/// What a chat command (/ra, /ub, /mt, /vt) says back: the one place the rule lives (2026-10-28). +/// +/// A command the player typed answers in chat, in one line (more only for lists, status and help): +/// says what changed and the value now, why it didn't work and the +/// usage. A typed command that said nothing at all still gets a line (). +/// A command a meta, a nav route or a script sent is quiet when it works (the log has the line), +/// so metas don't flood chat. Its errors still show in chat, each distinct one at most once a minute. +/// is output the command was asked for (a list, a status, help): shown either way. +/// +/// Who sent the line is per thread: a command is handled start to finish on the thread it came in on. +/// +internal sealed class CommandReply +{ + /// AC chat types: RynthAi's usual lines, and its error lines (AutoVendor, salvage, pack full). + public const int OkColor = 1, FailColor = 2; + + /// A meta repeating the same error says it in chat at most this often (the log has every one). + public const long FailRepeatMs = 60_000; + + /// The line a typed command that answered nothing gets (the log says which command). + public const string RanPrefix = "[RynthAi] Ran: "; + + private readonly Action _chat; + private readonly Action _log; + private readonly Func _metaActive; + private readonly Dictionary _failSaidAt = new(StringComparer.Ordinal); + + /// Milliseconds, for the once-a-minute error repeat (tests set it). + internal Func Clock { get; set; } = () => Environment.TickCount64; + + [ThreadStatic] private static int t_scriptDepth; // AsScript on the stack: a script's or a route's line + [ThreadStatic] private static int t_queued; // RunQueued: 0 none, 1 sent by a script, 2 typed + [ThreadStatic] private static int t_runDepth; // Run on the stack + [ThreadStatic] private static bool t_answered; // the command being run has said something + + /// Writes a chat line in a colour. + /// Writes a log line. + /// True while a meta's action or chat command is being run. + public CommandReply(Action chat, Action log, Func metaActive) + { + _chat = chat; + _log = log; + _metaActive = metaActive; + } + + /// True when a meta, a route or a script sent the line being handled, not the player. + public bool FromScript => t_queued switch + { + 1 => true, + 2 => false, + _ => t_scriptDepth > 0 || _metaActive(), + }; + + /// It worked: what changed and the value now. Chat when typed; the log only for a meta or script. + public void Ok(string text) + { + t_answered = true; + if (FromScript) _log(text); + else _chat(text, OkColor); + } + + /// It didn't work: why, and the usage. Always logged; in chat when typed, and for a meta or + /// script the first time in a minute that this exact line comes up. + public void Fail(string text) + { + t_answered = true; + _log(text); + if (FromScript && !FirstInAMinute(text)) return; + _chat(text, FailColor); + } + + /// + /// Accepted and ignored on purpose (a VTank or UtilityBelt verb with no RynthAi equivalent): said + /// as a failure when typed, so the player knows nothing happened; only logged for a meta, which + /// sends it on every pass and is meant to keep running. + /// + public void Ignored(string text) + { + if (FromScript) { t_answered = true; _log(text); } + else Fail(text); + } + + /// Output the command was asked for (a list, a status, help, a lookup): chat either way. + public void Info(string text) + { + t_answered = true; + _chat(text, OkColor); + } + + /// The command's answer comes another way: a later line (a queued action that says what + /// it did), the server, the engine, or the plugin the command was handed to. + public void Answered() => t_answered = true; + + /// + /// Handles one command line. A typed command that said nothing gets one line anyway (and the + /// log names it, so it can get a proper answer); one that threw says so instead of nothing. + /// A meta's or a script's line runs as it is. + /// + public void Run(string line, Action handle) + { + bool outer = t_runDepth == 0; + bool savedAnswered = t_answered; + if (outer) t_answered = false; + bool typed = !FromScript; + t_runDepth++; + try + { + handle(); + } + catch (Exception ex) when (outer && typed) + { + _log($"[CmdReply] '{line}' threw: {ex}"); + Fail($"[RynthAi] {line}: failed ({ex.GetType().Name}: {ex.Message})."); + } + finally + { + t_runDepth--; + if (outer) + { + if (typed && !t_answered) + { + _log($"[CmdReply] '{line}' gave no reply of its own; said \"{RanPrefix}{line}\" for it."); + _chat(RanPrefix + line, OkColor); + } + t_answered = savedAnswered; + } + } + } + + /// Runs as a line a script or a nav route sent (quiet when it works). + public T AsScript(Func action) + { + t_scriptDepth++; + try { return action(); } + finally { t_scriptDepth--; } + } + + /// + /// A queued command (run later on the tick) answers as the line that queued it would have: + /// is when it was queued. + /// + public void RunQueued(bool fromScript, Action action) + { + int saved = t_queued; + t_queued = fromScript ? 1 : 2; + try { action(); } + finally { t_queued = saved; } + } + + /// True when this error line wasn't said in the last minute (a meta repeating it says it once). + private bool FirstInAMinute(string text) + { + long now = Clock(); + lock (_failSaidAt) + { + if (_failSaidAt.TryGetValue(text, out long at) && now - at < FailRepeatMs) return false; + if (_failSaidAt.Count >= 256) + { + var old = new List(); + foreach (var kv in _failSaidAt) + if (now - kv.Value >= FailRepeatMs) old.Add(kv.Key); + foreach (string k in old) _failSaidAt.Remove(k); + if (_failSaidAt.Count >= 256) _failSaidAt.Clear(); + } + _failSaidAt[text] = now; + return true; + } + } +} diff --git a/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs b/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs index a05f2c8..503368b 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs @@ -3849,7 +3849,7 @@ public sealed partial class RynthAiPlugin var settings = _dashboard?.Settings; if (settings == null || _objectCache == null || _playerId == 0) { - ChatLine("[RynthAi] Corpse info not ready yet."); + ReplyFail("[RynthAi] Corpse info not ready yet."); return; } @@ -3874,14 +3874,14 @@ public sealed partial class RynthAiPlugin var settings = _dashboard?.Settings; if (settings == null || _objectCache == null || _playerId == 0) { - ChatLine("[RynthAi] Corpse ownership diagnostics are not ready yet."); + ReplyFail("[RynthAi] Corpse ownership diagnostics are not ready yet."); return; } string selector = parts.Length >= 3 ? parts[2].Trim().ToLowerInvariant() : string.Empty; if (!TryResolveCorpseForDiagnostics(selector, out WorldObject? corpse, out string source)) { - ChatLine("[RynthAi] No corpse found for diagnostics. Use /ra corpsecheck [target|open|nearest]."); + ReplyFail("[RynthAi] No corpse found for diagnostics. Use /ra corpsecheck [target|open|nearest]."); return; } @@ -3911,14 +3911,14 @@ public sealed partial class RynthAiPlugin { if (_fellowshipTracker == null) { - ChatLine("[RynthAi] Fellowship tracker is not ready yet."); + ReplyFail("[RynthAi] Fellowship tracker is not ready yet."); return; } string fellowSub = parts.Length >= 3 ? parts[2].Trim().ToLowerInvariant() : "status"; if (!_fellowshipTracker.IsInFellowship && fellowSub != "help") { - ChatLine("[RynthAi] Not in a fellowship."); + ReplyFail("[RynthAi] Not in a fellowship."); return; } @@ -3972,7 +3972,7 @@ public sealed partial class RynthAiPlugin } else { - ChatLine("[RynthAi] Usage: /ra fellow ismember "); + ReplyFail("[RynthAi] Usage: /ra fellow ismember "); } break; @@ -3981,7 +3981,7 @@ public sealed partial class RynthAiPlugin break; default: - ChatLine($"[RynthAi] Unknown fellow subcommand: {fellowSub}. Try /ra fellow help"); + ReplyFail($"[RynthAi] Unknown fellow subcommand: {fellowSub}. Try /ra fellow help"); break; } } @@ -4099,27 +4099,27 @@ public sealed partial class RynthAiPlugin var settings = _dashboard?.Settings; if (settings == null || _objectCache == null || _playerId == 0) { - ChatLine("[RynthAi] Corpse opening is not ready yet."); + ReplyFail("[RynthAi] Corpse opening is not ready yet."); return; } if (_openedContainerId != 0) { - ChatLine($"[RynthAi] A container is already open: 0x{(uint)_openedContainerId:X8}"); + ReplyFail($"[RynthAi] A container is already open: 0x{(uint)_openedContainerId:X8}"); return; } double maxMeters = GetCorpseApproachRangeMaxMeters(settings); if (!TryFindNearestCorpse(maxMeters, out WorldObject? corpse, out double distanceMeters)) { - ChatLine("[RynthAi] No unopened corpse is within corpse max range."); + ReplyFail("[RynthAi] No unopened corpse is within corpse max range."); return; } _targetCorpseId = corpse!.Id; _corpseTargetSince = CorpseNowMs; _lastCorpseOpenAttemptAt = 0; - ChatLine($"[RynthAi] Corpse target set to {corpse.Name} at {ConvertMetersToYards(distanceMeters):F1} yd."); + ReplyOk($"[RynthAi] Corpse target set to {corpse.Name} at {ConvertMetersToYards(distanceMeters):F1} yd."); TickCorpseOpening(); } } diff --git a/Plugins/RynthCore.Plugin.RynthAi/Dashboard/InstrumentDashboard.cs b/Plugins/RynthCore.Plugin.RynthAi/Dashboard/InstrumentDashboard.cs index 56ece8e..e75eecf 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Dashboard/InstrumentDashboard.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Dashboard/InstrumentDashboard.cs @@ -17,16 +17,17 @@ // activity an inset line: what the bot is doing (coloured, with its icon) and // the meta's state. // controls RUN / STOP, the five subsystem keys (lit LED = on; right-click: -// their settings), Force rebuff. +// their settings), then RynthSort's auto-sort key (when it's loaded; +// right-click: its window) and Force rebuff. // launchers a tray of window buttons (lit while open), labels when wide. // footer FPS (coloured by rate), RynthAi's version, bot and client uptime. // bars the vitals and the target (15 segments, coloured by health). // Minimized keeps the header, the activity line, the controls and the bars. -// Drawers on the edges (docked only): Ranges, Loaded files, Patrol and the Mini +// Drawers on the edges, docked or popped out: Ranges, Loaded files, Patrol and the Mini // Remote on the left, My settings on the right; a tab's right-click moves its // drawer to the other edge. Ranges, Patrol and My settings show the Settings // panel's rows, which RynthCore draws into them (RenderSettingsDrawer, v90). -// Popped out the pickers are in the options. +// Popped out the pickers are in the options as well. // // Colours: the player's theme (GetUiColor v90: Background, KeyFace, Hairline, // Inset, Text, Muted, Faint, Accent, Highlight); health, stamina, mana and the @@ -68,6 +69,11 @@ internal interface IDashboardHost void AdjustOpacity(float delta); void ToggleLock(); void SelectProfile(int kind, int index); + /// RynthSort's auto-sort: -1 RynthSort not loaded (or not logged in, or too old to say), 0 off, 1 on. + int AutoSort { get; } + void SetAutoSort(bool on); + /// RynthSort's own window, shown or hidden. + void ToggleSortWindow(); void StartPatrol(); void ToggleSpells(); /// The Classic (retail) look: RynthCore's own face comes back for it. @@ -195,7 +201,10 @@ internal sealed unsafe class InstrumentDashboard OptionsMenu(prefs); CharMenu(); - if (!popped) Drawers(prefs, origin, new Vector2(width, height)); + // Popped out too (Tom 2026-10-24: "many of the settings are built into the drawers"): the + // pop-out's picture grows past the panel to hold them, and RynthCore's pop-outs take clicks + // on a window drawn there, not only on a menu. + Drawers(prefs, origin, new Vector2(width, height)); return new Vector2(width, height); } @@ -428,18 +437,31 @@ internal sealed unsafe class InstrumentDashboard Tracked(dl, bf, bf.FontSize, new Vector2(gx + glyph + Px(6), MathF.Round(rp.Y + (h - bf.FontSize) * 0.5f)), fg, word, track); } - // The subsystem keys. + // The subsystem keys. With RynthSort loaded its auto-sort key sits at the right beside Force + // rebuff, and at the narrowest window every key gives up a pixel for it. + int sort = _d.AutoSort; + float kw = Px(KeyW); + if (sort >= 0) + kw = MathF.Min(kw, MathF.Floor((w - Px(RunW) - 2 * Px(Gap) - Subsystems.Length * Px(KeyGap) - Px(FrW)) / (Subsystems.Length + 1))); float kx = x0 + Px(RunW) + Px(Gap); bool[] on = { _r.Combat, _r.Buffing, _r.Navigation, _r.Looting, _r.Meta }; for (int i = 0; i < Subsystems.Length; i++) { - Key(dl, i, on[i], new Vector2(kx, y), new Vector2(Px(KeyW), h)); - kx += Px(KeyW) + Px(KeyGap); + Key(dl, i, on[i], new Vector2(kx, y), new Vector2(kw, h)); + kx += kw + Px(KeyGap); } + float keysEnd = kx - Px(KeyGap); - // Force rebuff, set apart at the right. + // Auto-sort, then Force rebuff, set apart at the right. Vector2 fp = new(x0 + w - Px(FrW), y), fs = new(Px(FrW), h); - dl.AddLine(new Vector2(fp.X - Px(Gap) - 0.5f, y + (h - Px(18)) * 0.5f), new Vector2(fp.X - Px(Gap) - 0.5f, y + (h + Px(18)) * 0.5f), _line); + float group = fp.X; + if (sort >= 0) + { + group = fp.X - Px(KeyGap) - kw; + SortKey(dl, sort == 1, new Vector2(group, y), new Vector2(kw, h)); + } + float lx = MathF.Round(MathF.Max(group - Px(Gap), keysEnd + (group - keysEnd) * 0.5f)) - 0.5f; + dl.AddLine(new Vector2(lx, y + (h - Px(18)) * 0.5f), new Vector2(lx, y + (h + Px(18)) * 0.5f), _line); ImGui.SetCursorScreenPos(fp); if (ImGui.InvisibleButton("##fr", fs, ImGuiButtonFlags.MouseButtonLeft | ImGuiButtonFlags.MouseButtonRight) && ImGui.IsMouseReleased(ImGuiMouseButton.Left)) @@ -467,6 +489,29 @@ internal sealed unsafe class InstrumentDashboard bool right = ImGui.IsItemClicked(ImGuiMouseButton.Right); bool hot = ImGui.IsItemHovered(); SafeImGui.SetItemTooltip((on ? s.Name + " on. Click to turn it off." : s.Name + " off. Click to turn it on.") + "\nRight-click: " + s.Right + "."); + KeyFace(dl, s.Icon, on, hot, pos, size); + if (clicked) _d.SetSubsystem(i, !on); + if (right) SubsystemSettings(i); + } + + /// RynthSort's auto-sort, a key like the subsystems'. Click: on/off; right-click: RynthSort's window. + private void SortKey(ImDrawListPtr dl, bool on, Vector2 pos, Vector2 size) + { + ImGui.SetCursorScreenPos(pos); + bool clicked = ImGui.InvisibleButton("##key_sort", size, ImGuiButtonFlags.MouseButtonLeft | ImGuiButtonFlags.MouseButtonRight) + && ImGui.IsMouseReleased(ImGuiMouseButton.Left); + bool right = ImGui.IsItemClicked(ImGuiMouseButton.Right); + bool hot = ImGui.IsItemHovered(); + SafeImGui.SetItemTooltip(on ? "Auto-sort (RynthSort) on. Click to turn it off.\nRight-click: RynthSort's window." + : "Auto-sort (RynthSort) off. Click to turn it on.\nRight-click: RynthSort's window."); + KeyFace(dl, RynthIcons.SortAscending, on, hot, pos, size); + if (clicked) _d.SetAutoSort(!on); + if (right) _d.ToggleSortWindow(); + } + + /// A key's face: raised with its LED lit when on, flat and dim when off. + private void KeyFace(ImDrawListPtr dl, string icon, bool on, bool hot, Vector2 pos, Vector2 size) + { float r = Px(3); if (on) { @@ -478,7 +523,7 @@ internal sealed unsafe class InstrumentDashboard { dl.AddRect(pos, pos + size, Mix(_bg, _line, 0.55f), r); } - DrawIcon(dl, s.Icon, pos, size, Px(15), on || hot ? _text : _faint); + DrawIcon(dl, icon, pos, size, Px(15), on || hot ? _text : _faint); // The LED, top right: lit in the accent with a glow, or dark. Vector2 led = new(pos.X + size.X - Px(6), pos.Y + Px(6)); if (on) @@ -491,8 +536,6 @@ internal sealed unsafe class InstrumentDashboard dl.AddCircleFilled(led, Px(2), _inset, 12); dl.AddCircle(led, Px(2), _line, 12, 1f); } - if (clicked) _d.SetSubsystem(i, !on); - if (right) SubsystemSettings(i); } /// A key's right-click: its settings. @@ -543,7 +586,7 @@ internal sealed unsafe class InstrumentDashboard Vector2 p = new(bx, y), s = new(ex - bx, h); bool lit = l.Label switch { - "Patrol" => !_popped && prefs.IsOpen(DashboardPrefs.PatrolDrawer), + "Patrol" => prefs.IsOpen(DashboardPrefs.PatrolDrawer), "Char" => host.SetPanelOpen(OracleKey, RynthPanelOpen.Ask) == 1 || host.SetPanelOpen("Mini Remote", RynthPanelOpen.Ask) == 1, _ => host.SetPanelOpen(l.Key, RynthPanelOpen.Ask) == 1, }; @@ -598,7 +641,7 @@ internal sealed unsafe class InstrumentDashboard { if (label == "Patrol") { - if (!_popped) prefs.ToggleDrawer(DashboardPrefs.PatrolDrawer); + prefs.ToggleDrawer(DashboardPrefs.PatrolDrawer); } else if (label == "Char") { @@ -887,7 +930,8 @@ internal sealed unsafe class InstrumentDashboard } if (_popped) { - // No drawers popped out: the pickers are here. + // Popped out the pickers are here as well (an older RynthCore's pop-out lets clicks + // beside the panel through, so its drawers can't be used). p.Y += Px(4); dl.AddLine(new Vector2(p.X, p.Y + 0.5f), new Vector2(p.X + w, p.Y + 0.5f), _line); p.Y += Px(5); @@ -1059,7 +1103,7 @@ internal sealed unsafe class InstrumentDashboard if (ImGui.MenuItem(key, command, state == 1)) host.SetPanelOpen(key, RynthPanelOpen.Toggle); } - // ── Drawers (docked): tabs on both edges, one panel open per side ─── + // ── Drawers: tabs on both edges, one panel open per side ──────────── // // Ranges, Loaded files, Patrol and the Mini Remote start on the left edge, My settings on the // right; a tab's right-click moves its drawer to the other edge (DashboardPrefs keeps the sides, @@ -1214,7 +1258,7 @@ internal sealed unsafe class InstrumentDashboard ImGui.End(); } - if (si >= 0 && shown >= 1f) DrawerPanel(prefs, DrawerDefs[si], si, panelW, shown, winX, panelX, dashPos.Y, right); + if (si >= 0 && shown >= 1f) DrawerPanel(prefs, DrawerDefs[si], si, panelW, shown, winX, panelX, dashPos.Y, dashSize.Y, right); } private int TabsOn(DashboardPrefs prefs, bool right) @@ -1225,6 +1269,7 @@ internal sealed unsafe class InstrumentDashboard } private const float SlideSeconds = 0.16f; + private const float PopOutReach = 600f; private readonly float[] _slideT = new float[2]; // left, right: 0 closed .. 1 open private readonly string[] _slideKey = { string.Empty, string.Empty }; // the drawer whose panel draws @@ -1272,12 +1317,15 @@ internal sealed unsafe class InstrumentDashboard /// pixels of , from ), the panel drawn whole at /// and clipped to it. /// - private void DrawerPanel(DashboardPrefs prefs, DrawerDef def, int di, float panelW, float shown, float winX, float x, float top, bool right) + private void DrawerPanel(DashboardPrefs prefs, DrawerDef def, int di, float panelW, float shown, float winX, float x, float top, float dashH, bool right) { Vector2 display = ImGui.GetIO().DisplaySize; // The frame around the body: padding, the title row, the gap under it. float chrome = Px(7) + Px(20) + Px(5) + Px(8); float maxBody = display.Y > 1 ? Math.Max(Px(60), display.Y - top - chrome - Px(8)) : Px(600); + // Popped out, the picture reaches at most PopOutReach pixels past the panel (RynthCore's + // ImGuiPopOuts.MaxMargin is 640): a longer drawer scrolls. + if (_popped) maxBody = Math.Max(Px(60), Math.Min(maxBody, dashH + PopOutReach - chrome)); float body = def.Key switch { DashboardPrefs.FilesDrawer => FilesHeight(), diff --git a/Plugins/RynthCore.Plugin.RynthAi/GroundLootController.cs b/Plugins/RynthCore.Plugin.RynthAi/GroundLootController.cs index 2017b85..01e5990 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/GroundLootController.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/GroundLootController.cs @@ -323,7 +323,7 @@ public sealed partial class RynthAiPlugin private void HandleGroundLootCommand(string[] parts) { var settings = _dashboard?.Settings; - if (settings == null) { ChatLine("[RynthAi] Not logged in."); return; } + if (settings == null) { ReplyFail("[RynthAi] Not logged in."); return; } string verb = parts.Length >= 3 ? parts[2].Trim().ToLowerInvariant() : "status"; switch (verb) @@ -331,17 +331,17 @@ public sealed partial class RynthAiPlugin case "on": settings.EnableGroundLoot = true; _dashboard?.SaveSettings(); - ChatLine("[RynthAi] Ground loot ON (uses the loot profile and the corpse max range)."); + ReplyOk("[RynthAi] Ground loot ON (uses the loot profile and the corpse max range)."); break; case "off": settings.EnableGroundLoot = false; ResetGroundLoot(clearCaches: true); _dashboard?.SaveSettings(); - ChatLine("[RynthAi] Ground loot OFF."); + ReplyOk("[RynthAi] Ground loot OFF."); break; case "scan": ResetGroundLoot(clearCaches: true); - ChatLine("[RynthAi] Ground loot: cleared skip list; rescanning."); + ReplyOk("[RynthAi] Ground loot: cleared skip list; rescanning."); break; default: double yards = settings.CorpseApproachRangeMax; diff --git a/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.Extra.cs b/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.Extra.cs index df9b475..8284526 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.Extra.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.Extra.cs @@ -55,12 +55,10 @@ public sealed partial class RynthAiPlugin private bool KeystrokesAllowed(string verb) { if (_dashboard?.Settings.AllowMetaKeystrokes == true) return true; - if (_keystrokeRefusalSaid.Add(verb)) - { - string msg = $"[RynthAi] {verb} ignored: it sends keys or clicks to the game window, and 'Allow metas to send keystrokes (/mt send)' is off (Settings, Advanced). Said once."; - Log(msg); - ChatLine(msg); - } + string why = $"[RynthAi] {verb} ignored: it sends keys or clicks to the game window, and 'Allow metas to send keystrokes (/mt send)' is off (Settings, Advanced)."; + // Typed: said every time (a typed command always answers). A meta: said once per verb. + if (!Reply.FromScript) ReplyFail(why); + else if (_keystrokeRefusalSaid.Add(verb)) ReplyFail(why + " Said once."); return false; } @@ -72,9 +70,7 @@ public sealed partial class RynthAiPlugin private bool RequireRunningMeta(string verb) { if (MetaCommandActive) return true; - string msg = $"[RynthAi] {verb} only runs from a meta that is running (macro and Meta on); refused."; - Log(msg); - ChatLine(msg); + ReplyFail($"[RynthAi] {verb} only runs from a meta that is running (macro and Meta on); refused."); return false; } @@ -95,13 +91,13 @@ public sealed partial class RynthAiPlugin case "autopack": // Mag-Tools packs by its own rules; RynthAi's equivalent is a cram + stack pass. _inventoryManager?.RunManual(cram: true, stack: true); - ChatLine("[RynthAi] Autopack: cramming items into side packs and stacking them."); + ReplyOk("[RynthAi] Autopack: cramming items into side packs and stacking them."); return true; case "dumpspells": return HandleMtDumpSpells(); case "click": return HandleMtClick(parts); case "get": if (parts.Length >= 3 && parts[2].Equals("xy", StringComparison.OrdinalIgnoreCase)) return HandleMtCursor(); - ChatLine("[RynthAi] Usage: /mt get xy"); + ReplyFail("[RynthAi] Usage: /mt get xy"); return true; case "cursor": return HandleMtCursor(); case "movement": return HandleMtMovement(parts); @@ -124,36 +120,43 @@ public sealed partial class RynthAiPlugin /// private bool HandleMtSend(string[] parts, string fullCommand) { - if (parts.Length < 3) { ChatLine("[RynthAi] Usage: /mt send enter|pause|del|space|f4|f12|cntrl+|msg "); return true; } + const string usage = "[RynthAi] Usage: /mt send enter|pause|del|space|f4|f12|cntrl+|msg "; + if (parts.Length < 3) { ReplyFail(usage); return true; } string arg = parts[2].ToLowerInvariant(); if (parts[2].StartsWith('/')) { - if (Host.HasInvokeChatParser) Host.InvokeChatParser(string.Join(" ", parts, 2, parts.Length - 2)); + // The command answers for itself. + if (Host.HasInvokeChatParser) { Host.InvokeChatParser(string.Join(" ", parts, 2, parts.Length - 2)); Reply.Answered(); } + else ReplyFail("[RynthAi] /mt send: the chat parser isn't available."); return true; } if (!KeystrokesAllowed("/mt send")) return true; - if (!GameInput.Available) { ChatLine("[RynthAi] /mt send: the game window wasn't found."); return true; } - Log($"[RynthAi] /mt send {string.Join(" ", parts, 2, Math.Min(parts.Length - 2, 2))}: keys posted to the game window"); + if (!GameInput.Available) { ReplyFail("[RynthAi] /mt send: the game window wasn't found."); return true; } + string what = string.Join(" ", parts, 2, Math.Min(parts.Length - 2, 2)); + Log($"[RynthAi] /mt send {what}: keys posted to the game window"); + string sent = $"[RynthAi] /mt send {what}: sent to the game window."; switch (arg) { - case "enter": GameInput.SendEnter(); return true; - case "pause": GameInput.SendPause(); return true; - case "del": GameInput.SendDel(); return true; - case "space": GameInput.SendSpace(); return true; - case "f4": GameInput.SendF4(); return true; - case "f12": GameInput.SendF12(); return true; + case "enter": GameInput.SendEnter(); ReplyOk(sent); return true; + case "pause": GameInput.SendPause(); ReplyOk(sent); return true; + case "del": GameInput.SendDel(); ReplyOk(sent); return true; + case "space": GameInput.SendSpace(); ReplyOk(sent); return true; + case "f4": GameInput.SendF4(); ReplyOk(sent); return true; + case "f12": GameInput.SendF12(); ReplyOk(sent); return true; case "msg": int at = fullCommand.IndexOf(" msg ", StringComparison.OrdinalIgnoreCase); - if (at < 0 || at + 5 >= fullCommand.Length) { ChatLine("[RynthAi] Usage: /mt send msg "); return true; } + if (at < 0 || at + 5 >= fullCommand.Length) { ReplyFail("[RynthAi] Usage: /mt send msg "); return true; } GameInput.SendMsg(fullCommand[(at + 5)..]); + ReplyOk("[RynthAi] /mt send msg: typed into the game window."); return true; } if (arg.StartsWith("cntrl+", StringComparison.Ordinal) && arg.Length >= 7) { GameInput.SendCntrl(arg[6]); + ReplyOk(sent); return true; } - ChatLine("[RynthAi] Usage: /mt send enter|pause|del|space|f4|f12|cntrl+|msg "); + ReplyFail(usage); return true; } @@ -171,11 +174,12 @@ public sealed partial class RynthAiPlugin ms = Math.Clamp(ms, 0, 1000); string letters = (w ? "w" : "") + (x ? "x" : "") + (z ? "z" : "") + (c ? "c" : "") + (shift ? "s" : ""); - if (_jumper != null && _jumper.Start(letters, null, ms)) return true; + if (_jumper != null && _jumper.Start(letters, null, ms)) { ReplyOk(JumpLine(letters, null, ms)); return true; } if (_jumper?.IsBusy == true) return true; // it said so in chat if (!KeystrokesAllowed("/mt jump (keys)")) return true; - if (!GameInput.Available) { ChatLine("[RynthAi] /mt jump: no jump hook and no game window."); return true; } + if (!GameInput.Available) { ReplyFail("[RynthAi] /mt jump: no jump hook and no game window."); return true; } GameInput.SendSpace(ms, shift, w, z, x, c); + ReplyOk(JumpLine(letters, null, ms) + " (the space key)"); return true; } @@ -184,37 +188,44 @@ public sealed partial class RynthAiPlugin /// /mt trade add|addp <item> | accept | decline | reset | end. private bool HandleMtTrade(string[] parts) { - if (parts.Length < 3) { ChatLine("[RynthAi] Usage: /mt trade add|addp | accept | decline | reset | end"); return true; } + if (parts.Length < 3) { ReplyFail("[RynthAi] Usage: /mt trade add|addp | accept | decline | reset | end"); return true; } string sub = parts[2].ToLowerInvariant(); // Completing a trade is only ever a running meta's doing (checked before anything else). if (sub == "accept" && !RequireRunningMeta("/mt trade accept")) return true; - if (!Host.HasTrade) { ChatLine("[RynthAi] Trading needs a newer RynthCore engine."); return true; } + if (!Host.HasTrade) { ReplyFail("[RynthAi] Trading needs a newer RynthCore engine."); return true; } switch (sub) { case "add": case "addp": { - if (parts.Length < 4) { ChatLine($"[RynthAi] Usage: /mt trade {sub} "); return true; } + if (parts.Length < 4) { ReplyFail($"[RynthAi] Usage: /mt trade {sub} "); return true; } string name = string.Join(" ", parts, 3, parts.Length - 3); var item = FindObject(name, inv: true, land: false, partial: sub == "addp"); - if (item == null) { ChatLine($"[RynthAi] Item not found: '{name}'"); return true; } - ChatLine(Host.TradeAdd(unchecked((uint)item.Id)) - ? $"[RynthAi] Added {item.Name} to the trade." : "[RynthAi] Could not add it to the trade."); + if (item == null) { ReplyFail($"[RynthAi] Item not found: '{name}'"); return true; } + if (Host.TradeAdd(unchecked((uint)item.Id))) ReplyOk($"[RynthAi] Added {item.Name} to the trade."); + else ReplyFail("[RynthAi] Could not add it to the trade."); return true; } case "accept": Log("[RynthAi] /mt trade accept (from the running meta)"); - Host.TradeAccept(); + TradeSaid(Host.TradeAccept(), "Accepting the trade.", "accept"); return true; - case "decline": Host.TradeDecline(); return true; - case "reset": Host.TradeReset(); return true; - case "end": Host.TradeClose(); return true; + case "decline": TradeSaid(Host.TradeDecline(), "Declining the trade.", "decline"); return true; + case "reset": TradeSaid(Host.TradeReset(), "Clearing the trade window.", "reset"); return true; + case "end": TradeSaid(Host.TradeClose(), "Closing the trade.", "close"); return true; default: - ChatLine("[RynthAi] Usage: /mt trade add|addp | accept | decline | reset | end"); + ReplyFail("[RynthAi] Usage: /mt trade add|addp | accept | decline | reset | end"); return true; } } + /// A trade action's answer: what it does, or that it couldn't be sent. + private void TradeSaid(bool sent, string ok, string what) + { + if (sent) ReplyOk("[RynthAi] " + ok); + else ReplyFail($"[RynthAi] Could not send the trade {what}."); + } + // ── vendor ─────────────────────────────────────────────────────────────────── /// @@ -224,15 +235,15 @@ public sealed partial class RynthAiPlugin private bool HandleMtVendor(string[] parts) { const string usage = "[RynthAi] Usage: /mt vendor addbuy|addbuyp [count] | addsell|addsellp | buy | clearbuy | sell | clearsell"; - if (parts.Length < 3) { ChatLine(usage); return true; } + if (parts.Length < 3) { ReplyFail(usage); return true; } // Spending or selling is only ever a running meta's doing (checked before anything else). string verb = parts[2].ToLowerInvariant(); if (verb == "buy" && !RequireRunningMeta("/mt vendor buy")) return true; if (verb == "sell" && !RequireRunningMeta("/mt vendor sell")) return true; - if (!Host.HasVendorTrade) { ChatLine("[RynthAi] Vendor trading needs a newer RynthCore engine."); return true; } + if (!Host.HasVendorTrade) { ReplyFail("[RynthAi] Vendor trading needs a newer RynthCore engine."); return true; } if (!Host.TryGetVendorInfo(out VendorInfo info) || info.VendorId == 0) { - ChatLine("[RynthAi] No vendor is open."); + ReplyFail("[RynthAi] No vendor is open."); return true; } string sub = parts[2].ToLowerInvariant(); @@ -241,7 +252,7 @@ public sealed partial class RynthAiPlugin case "addbuy": case "addbuyp": { - if (parts.Length < 4) { ChatLine($"[RynthAi] Usage: /mt vendor {sub} [count]"); return true; } + if (parts.Length < 4) { ReplyFail($"[RynthAi] Usage: /mt vendor {sub} [count]"); return true; } var words = parts.Skip(3).ToList(); int count = 1; if (words.Count > 1 && int.TryParse(words[^1], out int n) && n > 0) { count = n; words.RemoveAt(words.Count - 1); } @@ -250,42 +261,42 @@ public sealed partial class RynthAiPlugin VendorItem? item = Host.GetVendorItems().FirstOrDefault(v => partial ? v.Name.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0 : string.Equals(v.Name, name, StringComparison.OrdinalIgnoreCase)); - if (item == null) { ChatLine($"[RynthAi] {info.Name} doesn't sell '{name}'."); return true; } + if (item == null) { ReplyFail($"[RynthAi] {info.Name} doesn't sell '{name}'."); return true; } _mtBuyList.Add((item.ObjectId, item.Name, count)); - ChatLine($"[RynthAi] Buy list: {count} x {item.Name} ({_mtBuyList.Count} entr{(_mtBuyList.Count == 1 ? "y" : "ies")})."); + ReplyOk($"[RynthAi] Buy list: {count} x {item.Name} ({_mtBuyList.Count} entr{(_mtBuyList.Count == 1 ? "y" : "ies")})."); return true; } case "addsell": case "addsellp": { - if (parts.Length < 4) { ChatLine($"[RynthAi] Usage: /mt vendor {sub} "); return true; } + if (parts.Length < 4) { ReplyFail($"[RynthAi] Usage: /mt vendor {sub} "); return true; } string name = string.Join(" ", parts, 3, parts.Length - 3); var item = FindObject(name, inv: true, land: false, partial: sub == "addsellp"); - if (item == null) { ChatLine($"[RynthAi] Item not found: '{name}'"); return true; } + if (item == null) { ReplyFail($"[RynthAi] Item not found: '{name}'"); return true; } uint id = unchecked((uint)item.Id); if (!_mtSellList.Any(s => s.Id == id)) _mtSellList.Add((id, item.Name)); - ChatLine($"[RynthAi] Sell list: {item.Name} ({_mtSellList.Count} item(s))."); + ReplyOk($"[RynthAi] Sell list: {item.Name} ({_mtSellList.Count} item(s))."); return true; } case "buy": { - if (_mtBuyList.Count == 0) { ChatLine("[RynthAi] The buy list is empty (/mt vendor addbuy [count])."); return true; } + if (_mtBuyList.Count == 0) { ReplyFail("[RynthAi] The buy list is empty (/mt vendor addbuy [count])."); return true; } var entries = _mtBuyList.Select(b => new VendorTradeEntryNative(b.Id, b.Amount)).ToList(); Log($"[RynthAi] /mt vendor buy (from the running meta): {_mtBuyList.Count} entr{(_mtBuyList.Count == 1 ? "y" : "ies")} from {info.Name} 0x{info.VendorId:X8}: " + string.Join(", ", _mtBuyList.Select(b => $"{b.Amount} x {b.Name}"))); uint sent = Host.VendorBuy(info.VendorId, entries); - ChatLine(sent != 0 ? $"[RynthAi] Buying {_mtBuyList.Count} entr{(_mtBuyList.Count == 1 ? "y" : "ies")} from {info.Name}." - : "[RynthAi] The buy could not be sent."); + if (sent != 0) ReplyOk($"[RynthAi] Buying {_mtBuyList.Count} entr{(_mtBuyList.Count == 1 ? "y" : "ies")} from {info.Name}."); + else ReplyFail("[RynthAi] The buy could not be sent."); if (sent != 0) _mtBuyList.Clear(); return true; } case "clearbuy": _mtBuyList.Clear(); - ChatLine("[RynthAi] Buy list cleared."); + ReplyOk("[RynthAi] Buy list cleared."); return true; case "sell": { - if (_mtSellList.Count == 0) { ChatLine("[RynthAi] The sell list is empty (/mt vendor addsell )."); return true; } + if (_mtSellList.Count == 0) { ReplyFail("[RynthAi] The sell list is empty (/mt vendor addsell )."); return true; } // Checked again now, not only when the item was listed: it may have been worn since, // and RynthAi's own gear and consumables are never sold by a meta. var toSell = new List<(uint Id, string Name)>(); @@ -299,22 +310,23 @@ public sealed partial class RynthAiPlugin if (toSell.Count == 0) { _mtSellList.Clear(); - ChatLine("[RynthAi] Nothing left to sell: every listed item is protected."); + ReplyFail("[RynthAi] Nothing left to sell: every listed item is protected."); return true; } Log($"[RynthAi] /mt vendor sell (from the running meta): {toSell.Count} item(s) to {info.Name} 0x{info.VendorId:X8}: " + string.Join(", ", toSell.Select(s => s.Name))); uint sent = Host.VendorSell(info.VendorId, toSell.Select(s => s.Id).ToList()); - ChatLine(sent != 0 ? $"[RynthAi] Selling {toSell.Count} item(s) to {info.Name}." : "[RynthAi] The sell could not be sent."); + if (sent != 0) ReplyOk($"[RynthAi] Selling {toSell.Count} item(s) to {info.Name}."); + else ReplyFail("[RynthAi] The sell could not be sent."); if (sent != 0) _mtSellList.Clear(); return true; } case "clearsell": _mtSellList.Clear(); - ChatLine("[RynthAi] Sell list cleared."); + ReplyOk("[RynthAi] Sell list cleared."); return true; default: - ChatLine(usage); + ReplyFail(usage); return true; } } @@ -374,9 +386,9 @@ public sealed partial class RynthAiPlugin w.WriteLine($"{id}\t{name}\t{family}\t{difficulty}"); } } - ChatLine($"[RynthAi] {rows.Count} spells written to {path}"); + ReplyOk($"[RynthAi] {rows.Count} spells written to {path}"); } - catch (Exception ex) { ChatLine($"[RynthAi] /mt dumpspells failed: {ex.Message}"); } + catch (Exception ex) { ReplyFail($"[RynthAi] /mt dumpspells failed: {ex.Message}"); } return true; } @@ -390,9 +402,9 @@ public sealed partial class RynthAiPlugin /// private void HandleEquipForCommand(string[] parts) { - if (parts.Length < 3) { ChatLine("[RynthAi] Usage: /ra equipfor "); return; } + if (parts.Length < 3) { ReplyFail("[RynthAi] Usage: /ra equipfor "); return; } var rules = _dashboard?.Settings?.MonsterRules; - if (rules == null || rules.Count == 0) { ChatLine("[RynthAi] No monster rules loaded."); return; } + if (rules == null || rules.Count == 0) { ReplyFail("[RynthAi] No monster rules loaded."); return; } string monster = string.Join(" ", parts, 2, parts.Length - 2).Trim(); var rule = rules.FirstOrDefault(r => string.Equals(r.Name, monster, StringComparison.OrdinalIgnoreCase)) @@ -400,28 +412,28 @@ public sealed partial class RynthAiPlugin && r.Name.Length > 0 && monster.IndexOf(r.Name, StringComparison.OrdinalIgnoreCase) >= 0) .OrderByDescending(r => r.Name.Length).FirstOrDefault() ?? rules.FirstOrDefault(r => string.Equals(r.Name, "Default", StringComparison.OrdinalIgnoreCase)); - if (rule == null) { ChatLine($"[RynthAi] No monster rule for '{monster}'."); return; } + if (rule == null) { ReplyFail($"[RynthAi] No monster rule for '{monster}'."); return; } var ids = new List(); if (rule.WeaponId != 0) ids.Add(rule.WeaponId); if (rule.OffhandId != 0) ids.Add(rule.OffhandId); if (ids.Count == 0) { - ChatLine($"[RynthAi] '{rule.Name}' has no set weapon (combat picks one when it fights '{monster}')."); + ReplyOk($"[RynthAi] '{rule.Name}' has no set weapon (combat picks one when it fights '{monster}')."); return; } - if (!Host.HasUseObject) { ChatLine("[RynthAi] UseObject not available."); return; } + if (!Host.HasUseObject) { ReplyFail("[RynthAi] UseObject not available."); return; } int sent = 0; foreach (int id in ids) { var wo = _objectCache?[id]; - if (wo == null) { ChatLine($"[RynthAi] '{rule.Name}': item 0x{(uint)id:X8} isn't carried."); continue; } + if (wo == null) { ReplyFail($"[RynthAi] '{rule.Name}': item 0x{(uint)id:X8} isn't carried."); continue; } if (wo.Values(LongValueKey.CurrentWieldedLocation, 0) > 0) continue; // already wielded Host.UseFor(unchecked((uint)id), "Command", "/ra equipfor", UseKind.Asked); sent++; } - ChatLine(sent > 0 ? $"[RynthAi] Equipping for '{monster}' ({rule.Name}): {sent} item(s)." + ReplyOk(sent > 0 ? $"[RynthAi] Equipping for '{monster}' ({rule.Name}): {sent} item(s)." : $"[RynthAi] '{rule.Name}' gear for '{monster}' is already wielded."); } @@ -430,21 +442,22 @@ public sealed partial class RynthAiPlugin /// /mt click ok|yes|no|<x> <y>: a click in the game window (window coordinates). private bool HandleMtClick(string[] parts) { - if (parts.Length < 3) { ChatLine("[RynthAi] Usage: /mt click ok|yes|no| "); return true; } + if (parts.Length < 3) { ReplyFail("[RynthAi] Usage: /mt click ok|yes|no| "); return true; } if (!KeystrokesAllowed("/mt click")) return true; - if (!GameInput.Available) { ChatLine("[RynthAi] /mt click: the game window wasn't found."); return true; } + if (!GameInput.Available) { ReplyFail("[RynthAi] /mt click: the game window wasn't found."); return true; } switch (parts[2].ToLowerInvariant()) { - case "ok": GameInput.ClickOK(); return true; - case "yes": GameInput.ClickYes(); return true; - case "no": GameInput.ClickNo(); return true; + case "ok": GameInput.ClickOK(); ReplyOk("[RynthAi] Clicked OK."); return true; + case "yes": GameInput.ClickYes(); ReplyOk("[RynthAi] Clicked Yes."); return true; + case "no": GameInput.ClickNo(); ReplyOk("[RynthAi] Clicked No."); return true; } if (parts.Length >= 4 && int.TryParse(parts[2], out int x) && int.TryParse(parts[3], out int y)) { GameInput.SendMouseClick(x, y); + ReplyOk($"[RynthAi] Clicked at {x},{y} in the game window."); return true; } - ChatLine("[RynthAi] Usage: /mt click ok|yes|no| "); + ReplyFail("[RynthAi] Usage: /mt click ok|yes|no| "); return true; } @@ -462,12 +475,13 @@ public sealed partial class RynthAiPlugin { if (parts.Length != 4 || parts[2].Length != 1 || !int.TryParse(parts[3], out int ms) || ms < 0) { - ChatLine("[RynthAi] Usage: /mt movement (e.g. /mt movement w 1500)"); + ReplyFail("[RynthAi] Usage: /mt movement (e.g. /mt movement w 1500)"); return true; } if (!KeystrokesAllowed("/mt movement")) return true; - if (!GameInput.Available) { ChatLine("[RynthAi] /mt movement: the game window wasn't found."); return true; } + if (!GameInput.Available) { ReplyFail("[RynthAi] /mt movement: the game window wasn't found."); return true; } GameInput.SendMovement(parts[2][0], ms); + ReplyOk($"[RynthAi] Holding '{parts[2][0]}' for {ms} ms."); return true; } @@ -476,14 +490,15 @@ public sealed partial class RynthAiPlugin { if (parts.Length != 4 || !int.TryParse(parts[3], out int ms) || ms < 0) { - ChatLine("[RynthAi] Usage: /mt strafe left|l|right|r "); + ReplyFail("[RynthAi] Usage: /mt strafe left|l|right|r "); return true; } char key = parts[2].ToLowerInvariant() switch { "left" or "l" => 'z', "right" or "r" => 'c', _ => '\0' }; - if (key == '\0') { ChatLine("[RynthAi] /mt strafe: left, l, right or r."); return true; } + if (key == '\0') { ReplyFail("[RynthAi] Usage: /mt strafe left|l|right|r "); return true; } if (!KeystrokesAllowed("/mt strafe")) return true; - if (!GameInput.Available) { ChatLine("[RynthAi] /mt strafe: the game window wasn't found."); return true; } + if (!GameInput.Available) { ReplyFail("[RynthAi] /mt strafe: the game window wasn't found."); return true; } GameInput.SendMovement(key, ms); + ReplyOk($"[RynthAi] Strafing {(key == 'z' ? "left" : "right")} for {ms} ms."); return true; } @@ -493,13 +508,13 @@ public sealed partial class RynthAiPlugin string sub = parts.Length >= 3 ? parts[2].ToLowerInvariant() : ""; switch (sub) { - case "minimize": if (KeystrokesAllowed("/mt client")) GameInput.Minimize(); return true; - case "restore": if (KeystrokesAllowed("/mt client")) GameInput.Restore(); return true; + case "minimize": if (KeystrokesAllowed("/mt client")) { GameInput.Minimize(); ReplyOk("[RynthAi] Game window minimized."); } return true; + case "restore": if (KeystrokesAllowed("/mt client")) { GameInput.Restore(); ReplyOk("[RynthAi] Game window restored."); } return true; case "frame": - ChatLine("[RynthAi] The window frame is RynthCore's: Settings > Display (Borderless Windowed, Reset Window Borders) or /rc window reset."); + ChatLine("[RynthAi] The window frame is RynthCore's: Settings > Display, Borderless Windowed (there is no chat command for it)."); return true; default: - ChatLine("[RynthAi] Usage: /mt client minimize | restore"); + ReplyFail("[RynthAi] Usage: /mt client minimize | restore"); return true; } } diff --git a/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.cs b/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.cs index 719bf26..ff23ac0 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.cs @@ -82,14 +82,16 @@ public sealed partial class RynthAiPlugin // ── Session ────────────────────────────────────────────────────── case "logoff": case "logout": - if (Host.HasInvokeChatParser) Host.InvokeChatParser("/logout"); + if (Host.HasInvokeChatParser) { Host.InvokeChatParser("/logout"); Reply.Answered(); } // the client logs out + else ReplyFail("[RynthAi] Can't log out: the chat parser isn't available."); return true; case "quit": case "exit": // Close the client (also /ub quit|exit, which land here). "/quit" is not an AC // client command and did nothing; the engine's /rc quit closes the client the way // its close button does, logging the character off. - if (Host.HasInvokeChatParser) Host.InvokeChatParser("/rc quit"); + if (Host.HasInvokeChatParser) { Host.InvokeChatParser("/rc quit"); Reply.Answered(); } // the client closes + else ReplyFail("[RynthAi] Can't close the client: the chat parser isn't available."); return true; // ── Keys in the game window (Mag-Tools /mt send); a "/" line is still sent as a command ── @@ -119,7 +121,7 @@ public sealed partial class RynthAiPlugin if (sub == "list") { var map = _metaManager?.Expressions?.BuildSettingsMapPublic(); - if (map == null) { ChatLine("[RynthAi] Settings not ready."); return true; } + if (map == null) { ReplyFail("[RynthAi] Settings not ready."); return true; } ChatLine("[RynthAi] === Options ==="); foreach (var kvp in map) ChatLine($"[RynthAi] {kvp.Key} = {kvp.Value.Get()}"); @@ -130,9 +132,8 @@ public sealed partial class RynthAiPlugin { string optName = parts[3]; string? val = GetOptionValue(optName); - ChatLine(val != null - ? $"[RynthAi] {optName} = {val}" - : $"[RynthAi] Unknown option: {optName}"); + if (val != null && OptionKnown(optName)) ChatLine($"[RynthAi] {optName} = {val}"); + else ReplyFail($"[RynthAi] Unknown option: {optName} (/mt opt list shows them)."); return true; } @@ -140,7 +141,9 @@ public sealed partial class RynthAiPlugin { string optName = parts[3]; string optVal = parts[4]; + if (_metaManager?.Expressions == null) { ReplyFail("[RynthAi] Settings not ready (log in first)."); return true; } SetOptionValue(optName, optVal); + ReplyOptionValue(optName, optVal); return true; } @@ -152,8 +155,10 @@ public sealed partial class RynthAiPlugin if (val != null) { _rememberedOptions[optName.ToLower()] = val; - Host.Log($"[RynthAi] Remembered {optName} = {val}"); + ReplyOk($"[RynthAi] Remembered {optName} = {val}" + + (OptionKnown(optName) ? "" : " (not an option RynthAi maps or a meta has set)")); } + else ReplyFail($"[RynthAi] Unknown option: {optName} (nothing to remember)."); return true; } @@ -163,14 +168,68 @@ public sealed partial class RynthAiPlugin if (_rememberedOptions.TryGetValue(optName.ToLower(), out string? saved)) { SetOptionValue(optName, saved); - Host.Log($"[RynthAi] Restored {optName} = {saved}"); + ReplyOk($"[RynthAi] Restored {optName} = {saved}"); } + else ReplyFail($"[RynthAi] Nothing remembered for {optName} (/mt opt remember {optName} first)."); return true; } return false; } + /// A Mag-Tools / VTank option RynthAi maps, or one a meta has stored (an unknown name reads as 0). + private bool OptionKnown(string optName) + => MtOptionMap.ContainsKey(optName) || _metaManager?.Expressions?.Options.ContainsKey(optName) == true; + + /// + /// After /mt opt set (and /ub opt set): the option's value now. Bools read back as 1/0; asked as + /// true/false/on/off they show as True/False. An option RynthAi doesn't map is only kept for metas. + /// + private void ReplyOptionValue(string optName, string asked) + { + string now = GetOptionValue(optName) ?? "(not set)"; + bool askedBool = asked.ToLowerInvariant() is "true" or "false" or "on" or "off"; + if (askedBool && now is "1" or "0") now = now == "1" ? "True" : "False"; + ReplyOk($"[RynthAi] {optName} = {now}" + + (MtOptionMap.ContainsKey(optName) ? "" : " (not an option RynthAi maps: kept only for metas to read)")); + } + + /// The /mt verbs RynthAi takes, for the usage line. + private const string MtVerbList = "opt, combatstate, face, cast[p], use[i|l][p], select[p], give[p], loot[p], drop[p], " + + "equip[p], dequip[p], fellow, logout, quit, send, jump, trade, vendor, autopack, dumpspells, click, get xy, " + + "cursor, movement, strafe, client, config, test"; + + /// How to use a /mt (or, with "/ub", a translated /ub) verb; null when it isn't one. + private static string? MtVerbUsage(string verb, string prefix) => verb switch + { + "opt" or "config" => $"{prefix} opt list | get