diff --git a/src/RynthCore.Engine/D3D9/GameMatrixCapture.cs b/src/RynthCore.Engine/D3D9/GameMatrixCapture.cs index 4e2ea30..c2dd011 100644 --- a/src/RynthCore.Engine/D3D9/GameMatrixCapture.cs +++ b/src/RynthCore.Engine/D3D9/GameMatrixCapture.cs @@ -177,6 +177,19 @@ internal static unsafe class GameMatrixCapture } } + /// + /// Rebuilds the view matrix from AC's camera as it is right now. CaptureFrame runs at + /// EndScene, after the frame's 3D scene and AC's UI pass are done, so a draw at the UI pass + /// (the Nav3D markers, the world overlays) would otherwise project with the PREVIOUS frame's + /// camera: one frame of camera travel off the depth buffer it is tested against, which makes + /// unclimbable-slope triangles blink while the player moves. AC's render thread. + /// + public static void RefreshView() + { + if (_hasProj) + BuildViewProjFromCamera(); + } + private static void BuildViewProjFromCamera() { if (!SmartBoxLocator.TryGetSmartBox(out IntPtr smartBox, out _, out _)) diff --git a/src/RynthCore.Engine/D3D9/Nav3DRenderInjector.cs b/src/RynthCore.Engine/D3D9/Nav3DRenderInjector.cs index f44632a..36f32f5 100644 --- a/src/RynthCore.Engine/D3D9/Nav3DRenderInjector.cs +++ b/src/RynthCore.Engine/D3D9/Nav3DRenderInjector.cs @@ -189,6 +189,9 @@ internal static class Nav3DRenderInjector _markersRenderedThisFrame = true; _inRender = true; + // This frame's camera, not the one EndScene captured last frame (see RefreshView). + try { GameMatrixCapture.RefreshView(); } + catch { } try { // At the UI pass AC has set a full-screen viewport; the markers project diff --git a/src/RynthCore.Engine/Hotkeys/HotkeyModel.cs b/src/RynthCore.Engine/Hotkeys/HotkeyModel.cs index 841d66a..b2c6edb 100644 --- a/src/RynthCore.Engine/Hotkeys/HotkeyModel.cs +++ b/src/RynthCore.Engine/Hotkeys/HotkeyModel.cs @@ -183,6 +183,8 @@ internal static class HotkeyActions public const string PanelPrefix = "panel:"; public const string VTankPrefix = "vt:"; public const string VTankGroup = "VTank-style"; + /// The one-touch heal / stamina / mana actions (RynthAi's /ra heal, /ra stam, /ra mana). + public const string HealId = "heal", StaminaId = "stamina", ManaId = "mana"; /// The parameterized "Meta: set state" action (its binding's Command is the state name). public const string MetaStateId = VTankPrefix + "metastate"; @@ -222,6 +224,14 @@ internal static class HotkeyActions new("looting", "Toggle Looting"), new("meta", "Toggle Meta"), new("forcerebuff", "Force rebuff"), + // One-touch heal (RynthAi /ra heal | stam | mana): the best kit, spell or potion for that vital now. + // HotkeyDefaults binds them once to F6 / F7 / F8. + new(HealId, "Heal now (one touch)", Chat: "/ra heal", Tip: "Uses the best healing option you have right now: a healing kit, " + + "Heal Self or a health potion, whatever your Heal At lines say, even with the macro stopped (/ra heal)."), + new(StaminaId, "Restore stamina now (one touch)", Chat: "/ra stam", Tip: "A stamina kit, a stamina potion or Revitalize Self, " + + "now, even with the macro stopped (/ra stam)."), + new(ManaId, "Restore mana now (one touch)", Chat: "/ra mana", Tip: "Stamina to Mana Self or a mana potion, now, " + + "even with the macro stopped (/ra mana)."), new("patrol", "Start dungeon patrol"), new("autosort", "Toggle auto-sort (RynthSort)"), new("reload", "Reload the engine"), @@ -572,8 +582,45 @@ internal static class HotkeyCommandParser private static HotkeyCommand Fail(string error) => new(HotkeyVerb.Error, Error: error); } -/// The bindings and the master switch, as saved. -internal sealed record HotkeyFile(bool Enabled, List Bindings); +/// The bindings and the master switch, as saved. : the +/// version already offered to this file (0 = never). +internal sealed record HotkeyFile(bool Enabled, List Bindings, int DefaultsApplied = 0); + +/// +/// Bindings a file gets once, when it has never been offered this version of them (a new PC, or an +/// engine that brought new default keys): the one-touch heal keys. Added only where they cannot take +/// anything from the player: an action already bound to any key is left alone, and so is a key already +/// bound to anything. The version is saved with the file, so a default the player removes or changes +/// stays gone. Raise with new entries; entries already offered are not offered again. +/// +internal static class HotkeyDefaults +{ + public const int Version = 1; + + private const int VK_F6 = 0x75, VK_F7 = 0x76, VK_F8 = 0x77; + + /// The default key for each action, in the order they are added. Tell the player where: Settings > Hotkeys. + public static readonly (KeyCombo Combo, string Action)[] All = + { + (new KeyCombo(VK_F6, HotkeyMods.None), HotkeyActions.HealId), + (new KeyCombo(VK_F7, HotkeyMods.None), HotkeyActions.StaminaId), + (new KeyCombo(VK_F8, HotkeyMods.None), HotkeyActions.ManaId), + }; + + /// The file with the defaults it has not been offered yet (the same file when it has been). + public static HotkeyFile Apply(HotkeyFile file) + { + if (file.DefaultsApplied >= Version) return file; + var list = new List(file.Bindings); + foreach (var (combo, action) in All) + { + bool actionBound = list.Exists(b => string.Equals(b.Action, action, StringComparison.OrdinalIgnoreCase)); + bool keyBound = list.Exists(b => b.Combo == combo); + if (!actionBound && !keyBound) list.Add(new HotkeyBinding(combo, action)); + } + return file with { Bindings = list, DefaultsApplied = Version }; + } +} /// /// %LOCALAPPDATA%\RynthCore\hotkeys.txt, for every client on this PC. Text, one binding a line: @@ -599,6 +646,7 @@ internal static class HotkeyStore sb.Append("# RynthCore hotkeys (Settings > Hotkeys, /rc hotkey). Shared by every client on this PC.\n"); sb.Append("# One per line: on|off combo action chat command (action \"command\").\n"); sb.Append("enabled=").Append(file.Enabled ? '1' : '0').Append('\n'); + if (file.DefaultsApplied > 0) sb.Append("defaults=").Append(file.DefaultsApplied).Append('\n'); foreach (HotkeyBinding b in file.Bindings) { if (b.Combo.IsEmpty) continue; @@ -615,6 +663,7 @@ internal static class HotkeyStore { var file = new HotkeyFile(true, new List()); bool enabled = true; + int defaults = 0; if (string.IsNullOrEmpty(text)) return file; foreach (string raw in text.Split('\n')) { @@ -625,6 +674,11 @@ internal static class HotkeyStore enabled = line.Substring(8).Trim() != "0"; continue; } + if (line.StartsWith("defaults=", StringComparison.OrdinalIgnoreCase)) + { + int.TryParse(line.Substring(9).Trim(), out defaults); + continue; + } string[] f = line.Split('\t', 4); if (f.Length < 3) continue; if (!HotkeyKeys.TryParse(f[1], out KeyCombo combo, out _)) continue; @@ -634,7 +688,7 @@ internal static class HotkeyStore bool on = !f[0].Trim().Equals("off", StringComparison.OrdinalIgnoreCase); file.Bindings.Add(new HotkeyBinding(combo, action, cmd, on)); } - return file with { Enabled = enabled }; + return file with { Enabled = enabled, DefaultsApplied = Math.Max(0, defaults) }; } public static HotkeyFile Load() diff --git a/src/RynthCore.Engine/Hotkeys/HotkeyService.cs b/src/RynthCore.Engine/Hotkeys/HotkeyService.cs index d728a4e..f8c1a00 100644 --- a/src/RynthCore.Engine/Hotkeys/HotkeyService.cs +++ b/src/RynthCore.Engine/Hotkeys/HotkeyService.cs @@ -32,6 +32,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; using System.Threading; using RynthCore.Engine.Compatibility; @@ -95,13 +96,22 @@ internal static class HotkeyService if (Volatile.Read(ref _pendingSaves) > 0) return; // our own write is on its way; don't read a half-old file DateTime w = HotkeyStore.LastWriteUtc(); if (_loaded && w == _seenWriteUtc) return; - HotkeyFile loaded = HotkeyStore.Load(); + HotkeyFile read = HotkeyStore.Load(); + // A file that was never offered the default keys (HotkeyDefaults: the one-touch heal keys) gets them + // once and is written back, so they show in Settings > Hotkeys and a removed one stays removed. + HotkeyFile loaded = HotkeyDefaults.Apply(read); + bool seeded = !ReferenceEquals(loaded, read); bool first = !_loaded; _loaded = true; _seenWriteUtc = w; Volatile.Write(ref _file, loaded); if (first || loaded.Bindings.Count > 0) RynthLog.UI($"Hotkeys: {(first ? "loaded" : "reloaded")} {loaded.Bindings.Count} binding(s) from {HotkeyStore.FilePath} (hotkeys {(loaded.Enabled ? "on" : "off")})."); + if (seeded) + { + RynthLog.UI($"Hotkeys: added the default keys ({string.Join(", ", HotkeyDefaults.All.Select(d => d.Combo + " " + d.Action))}) where free."); + Commit(loaded); + } } } diff --git a/src/RynthCore.Engine/ImGui/Panels/DamageDetailFace.cs b/src/RynthCore.Engine/ImGui/Panels/DamageDetailFace.cs index 2a13715..ffd80ef 100644 --- a/src/RynthCore.Engine/ImGui/Panels/DamageDetailFace.cs +++ b/src/RynthCore.Engine/ImGui/Panels/DamageDetailFace.cs @@ -409,6 +409,15 @@ internal sealed class DamageDetailFace : IImGuiPanel pick => DamageCommands.EditRule(name, r => r.ExVuln = pick), "A vulnerability of another element, on top of Vuln (which follows the attack's element)."); + // The DEFAULT line's own choice is the Prefer chip in the Damage panel's top bar. + if (!isDefault) + Combo("Prefer", "##prefer", DamageCommands.PreferredDamages, string.IsNullOrEmpty(view.PreferredDamage) ? "Auto" : view.PreferredDamage, + pick => DamageCommands.EditRule(name, r => r.PreferredDamage = pick), + "The kind of damage to fight this monster with, for a character who uses more than one kind.\n" + + "Auto = the Prefer chip's choice in the Damage panel's top bar.\n" + + "Melee / Missile / War Magic / Void Magic = only weapons of that kind are wielded; with none\n" + + "listed it falls back to Auto. A weapon you set for the monster in the Damage panel still wins."); + // Match expression (Default never matches by name, so it has none) if (!isDefault) { diff --git a/src/RynthCore.Engine/ImGui/Panels/DamageFace.cs b/src/RynthCore.Engine/ImGui/Panels/DamageFace.cs index 2772a57..86e2f68 100644 --- a/src/RynthCore.Engine/ImGui/Panels/DamageFace.cs +++ b/src/RynthCore.Engine/ImGui/Panels/DamageFace.cs @@ -60,11 +60,11 @@ internal sealed class DamageFace : IImGuiPanel // Column widths (the Avalonia grid's) and their left edges. // Widths are the user's (dragged in the header, saved per PC), else these defaults. - private static readonly float[] DefaultColW = { 210, 72, 84, 92, 150, 130, 120, 56, 70, 96, 26 }; + private static readonly float[] DefaultColW = { 210, 72, 84, 92, 150, 130, 120, 84, 56, 70, 96, 26 }; // Saved width keys: the columns keep the keys they had before Priority was added (2026-10-03), // so a saved layout still fits them; Priority has its own. private static readonly string[] ColKeys = - { "col0", "colPrio", "col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8", "col9" }; + { "col0", "colPrio", "col1", "col2", "col3", "col4", "col5", "colPrefer", "col6", "col7", "col8", "col9" }; private static readonly float[] ColW = LoadColW(); private static float[] ColX = BuildColX(); @@ -76,9 +76,9 @@ internal sealed class DamageFace : IImGuiPanel return w; } private static readonly string[] Headers = - { "Monster", "Priority", "HP", "Weak to", "Weapon", "Offhand", "Pet", "Kills", "Sec/Kill", "Debuffs", "" }; - private const int ColMonster = 0, ColPrio = 1, ColHp = 2, ColWeak = 3, ColWeapon = 4, ColOffhand = 5, ColPet = 6, ColKills = 7, - ColSec = 8, ColDebuffs = 9, ColDel = 10; + { "Monster", "Priority", "HP", "Weak to", "Weapon", "Offhand", "Pet", "Prefer", "Kills", "Sec/Kill", "Debuffs", "" }; + private const int ColMonster = 0, ColPrio = 1, ColHp = 2, ColWeak = 3, ColWeapon = 4, ColOffhand = 5, ColPet = 6, ColPrefer = 7, ColKills = 8, + ColSec = 9, ColDebuffs = 10, ColDel = 11; private const float RowH = 22; private static float TableW => ColX[^1] + ColW[^1]; @@ -96,7 +96,8 @@ internal sealed class DamageFace : IImGuiPanel /// The name as shown: "Rampager (2 kinds)" for a row of several wcids. public string NameShown = "", NameTip = ""; public string Weapon = "", Offhand = "", Pet = "", WeakTop = "", Sec = "", SecTip = ""; - public bool CritSet, NonCritSet, WeaponGold, OffhandGold, PetGold; + public string Prefer = "Auto"; + public bool CritSet, NonCritSet, WeaponGold, OffhandGold, PetGold, PreferGold; public string[] TierLines = Array.Empty(); /// Priority shown (int.MinValue = rules not loaded), whether it's the monster's own /// (gold), the rule an edit copies when it has none (a name rule covering it), and the tip. @@ -280,6 +281,7 @@ internal sealed class DamageFace : IImGuiPanel ColWeapon => (a, b) => string.Compare(_text[a].Weapon, _text[b].Weapon, StringComparison.OrdinalIgnoreCase), ColOffhand => (a, b) => string.Compare(_text[a].Offhand, _text[b].Offhand, StringComparison.OrdinalIgnoreCase), ColPet => (a, b) => string.Compare(_text[a].Pet, _text[b].Pet, StringComparison.OrdinalIgnoreCase), + ColPrefer => (a, b) => string.Compare(_text[a].Prefer, _text[b].Prefer, StringComparison.OrdinalIgnoreCase), ColKills => (a, b) => a.Kills.CompareTo(b.Kills), ColSec => (a, b) => (a.SecKill > 0 ? a.SecKill : double.MaxValue).CompareTo(b.SecKill > 0 ? b.SecKill : double.MaxValue), _ => (a, b) => string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase), @@ -347,6 +349,9 @@ internal sealed class DamageFace : IImGuiPanel : ruleOff is >= 1 and <= 4 ? DamageCommands.OffhandModeNames[ruleOff] : ruleOff != 0 ? Trunc(WeaponName(unchecked((uint)ruleOff)), 16) : "Auto"; + string pref = RuleFor(r.IsDefault ? "Default" : r.Name, out _)?.PreferredDamage ?? ""; + t.PreferGold = pref.Length > 0 && !pref.Equals("Auto", StringComparison.OrdinalIgnoreCase); + t.Prefer = t.PreferGold ? pref : "Auto"; t.PetGold = r.Pet.Length > 0; t.Pet = Trunc(t.PetGold ? r.PetLabel : "Auto", 16); int comma = r.Weak.IndexOf(','); @@ -426,6 +431,8 @@ internal sealed class DamageFace : IImGuiPanel ImGuiNET.ImGui.SetItemTooltip("Keep the monster you're fighting (teal) and the ones on this landblock (green) at the top."); x += nw + 6; + x = PreferChip(x, p.Y); + if (Button("##reset", ResetLabel, new Vector2(x, p.Y), new Vector2(84, 22), White, ResetBg, ResetBorder)) _resetOpen = true; ImGuiNET.ImGui.SetItemTooltip("Clear all learned damage statistics (keeps monster names + your manual settings)."); @@ -438,6 +445,35 @@ internal sealed class DamageFace : IImGuiPanel ImGuiNET.ImGui.Dummy(new Vector2(0, 0)); } + // ── Preferred damage (2026-10-16) ──────────────────────────────────── + // The Default rule's PreferredDamage: the kind of damage RynthAi fights with when the character + // uses more than one (Auto = the first listed weapon's kind). A monster's own rule can differ + // (Rule section of its detail drawer); one left on Auto follows this. + + /// The "Prefer" chip at ; returns the x after it. + private float PreferChip(float x, float y) + { + string current = _rules?.DefaultRule()?.PreferredDamage ?? "Auto"; + int cur = Math.Max(0, Array.FindIndex(DamageCommands.PreferredDamages, v => v.Equals(current, StringComparison.OrdinalIgnoreCase))); + string label = "Prefer: " + DamageCommands.PreferredDamages[cur] + " " + PhosphorIcons.CaretDown; + float w = ImGuiNET.ImGui.CalcTextSize(label).X + 16; + if (Button("##prefer", label, new Vector2(x, y), new Vector2(w, 22), cur > 0 ? Gold : White, FilterBg, cur > 0 ? Gold : EntryBorder)) + { + _pickItems.Clear(); + for (int i = 0; i < DamageCommands.PreferredDamages.Length; i++) + _pickItems.Add(((uint)i, DamageCommands.PreferredDamages[i])); + OpenPicker(new Vector2(x, y + 22), (uint)cur, + id => DamageCommands.EditRule("Default", r => r.PreferredDamage = DamageCommands.PreferredDamages[Math.Min((int)id, DamageCommands.PreferredDamages.Length - 1)])); + } + SafeImGui.SetItemTooltip( + "The kind of damage to fight with, for a character who uses more than one kind.\n" + + "Auto = the kind of the first weapon in the Items list.\n" + + "Melee / Missile / War Magic / Void Magic = only weapons of that kind are wielded;\n" + + "with none listed (or usable) it falls back to Auto.\n" + + "A monster with its own Prefer setting (its drawer) keeps it; a weapon you set for it still wins."); + return x + w + 6; + } + // ── Aelrynth difficulty tier (2026-10-03) ──────────────────────────── // Awakened worlds and scaled dungeons hold the same monsters, +5% health, skills and damage a // tier, and RynthAi keeps each tier's numbers apart. The chip says which tier the table shows @@ -764,6 +800,7 @@ internal sealed class DamageFace : IImGuiPanel } ImGuiNET.ImGui.SetItemTooltip("Default weapon: used by every monster that has no weapon of its own."); DefaultOffhandAndPet(p); + PreferCell("Default", true, t, p); DebuffCell("Default", p, ty); ImGuiNET.ImGui.PopID(); ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(p.X, p.Y + RowH)); @@ -837,6 +874,8 @@ internal sealed class DamageFace : IImGuiPanel } ImGuiNET.ImGui.SetItemTooltip("Summon for this monster. Auto = an essence of the element it takes most damage from (Weak to); or pick an element or a specific essence."); + PreferCell(r.Name, false, t, p); + dl.AddText(new Vector2(p.X + ColX[ColKills] + 4, ty), White, t.Kills); dl.AddText(new Vector2(p.X + ColX[ColSec] + 4, ty), r.SecKill > 0 ? White : Dim, t.Sec); ImGuiNET.ImGui.SetCursorScreenPos(new Vector2(p.X + ColX[ColSec], p.Y)); @@ -864,6 +903,29 @@ internal sealed class DamageFace : IImGuiPanel { (1, "Auto"), (2, "Shield"), (3, "Dual wield"), (4, "None") }; private static readonly string[] PetElements = { "Fire", "Cold", "Lightning", "Acid", "Nether", "Slash", "Pierce", "Bludgeon" }; + /// The Prefer cell: Auto, Melee, Missile, War Magic or Void Magic for a monster's rule (or the DEFAULT line's). + private void PreferCell(string name, bool isDefault, RowText t, Vector2 p) + { + if (CellPicker("##pref", t.Prefer, t.PreferGold, p, ColPrefer)) + { + string[] choices = DamageCommands.PreferredDamages; + _pickItems.Clear(); + for (int i = 0; i < choices.Length; i++) _pickItems.Add(((uint)i, choices[i])); + int cur = Math.Max(0, Array.FindIndex(choices, v => v.Equals(t.Prefer, StringComparison.OrdinalIgnoreCase))); + bool hasOwn = isDefault || (_rules?.FindRule(name) != null); + OpenPicker(new Vector2(p.X + ColX[ColPrefer], p.Y + RowH), (uint)cur, id => + { + string pick = choices[Math.Min((int)id, choices.Length - 1)]; + // Auto on a monster with no rule of its own is already what it does: don't make one. + if (!hasOwn && pick == "Auto") return; + DamageCommands.EditRule(name, r => r.PreferredDamage = pick); + }); + } + ImGuiNET.ImGui.SetItemTooltip(isDefault + ? "Default preferred damage: the kind of damage used against every monster without its own.\nAuto = the kind of the first weapon in the Items list. Same as the Prefer chip above." + : "The kind of damage to fight this monster with (Melee, Missile, War Magic, Void Magic).\nAuto = the DEFAULT line's. A weapon picked in the Weapon column still wins."); + } + private void DefaultOffhandAndPet(Vector2 p) { Rule? def = _rules?.DefaultRule(); diff --git a/src/RynthCore.Engine/ImGui/Panels/ItemsFace.cs b/src/RynthCore.Engine/ImGui/Panels/ItemsFace.cs index d67b5fa..680043c 100644 --- a/src/RynthCore.Engine/ImGui/Panels/ItemsFace.cs +++ b/src/RynthCore.Engine/ImGui/Panels/ItemsFace.cs @@ -67,27 +67,45 @@ internal sealed class ItemsFace : IImGuiPanel else { TableHeader("Element", bw); - for (int i = 0; i < _data.Weapons.Count; i++) + // Grouped by kind (the order only matters inside a group); with a single group the + // sub-headings would say nothing, so they are left out. + var groups = new List<(string Name, List Idx)>(); + foreach (string kind in KindOrder) { - ItemsPanel.WeaponEntry wpn = _data.Weapons[i]; - ImGuiNET.ImGui.PushID("w" + i); - int r = Row(wpn.Name, wpn.Element, i, bw, _data.MissingIds.Contains(wpn.Id)); - ImGuiNET.ImGui.PopID(); - if (r == 1) + var idx = new List(); + for (int i = 0; i < _data.Weapons.Count; i++) + if (KindGroup(_data.Weapons[i].Kind) == kind) idx.Add(i); + if (idx.Count > 0) groups.Add((kind, idx)); + } + bool removed = false; + int shown = 0; + foreach (var (groupName, idx) in groups) + { + if (groups.Count > 1) KindHeading(groupName, idx.Count, bw); + foreach (int i in idx) { - Vector2 at = ImGuiNET.ImGui.GetIO().MousePos; - _picker.Open(at, ItemsCommands.Elements, Array.IndexOf(ItemsCommands.Elements, wpn.Element), e => + ItemsPanel.WeaponEntry wpn = _data.Weapons[i]; + ImGuiNET.ImGui.PushID("w" + i); + int r = Row(wpn.Name, wpn.Element, shown++, bw, _data.MissingIds.Contains(wpn.Id)); + ImGuiNET.ImGui.PopID(); + if (r == 1) { - wpn.Element = ItemsCommands.Elements[e]; + Vector2 at = ImGuiNET.ImGui.GetIO().MousePos; + _picker.Open(at, ItemsCommands.Elements, Array.IndexOf(ItemsCommands.Elements, wpn.Element), e => + { + wpn.Element = ItemsCommands.Elements[e]; + Save(); + }, 160); + } + else if (r == 2) + { + _data.Weapons.RemoveAt(i); Save(); - }, 160); - } - else if (r == 2) - { - _data.Weapons.RemoveAt(i); - Save(); - break; + removed = true; + break; + } } + if (removed) break; } } AddSelected("##add_weapon", PhosphorIcons.Plus + " Add Selected Weapon", "(select a weapon in inventory first)", ItemsCommands.AddSelectedWeapon); @@ -189,6 +207,26 @@ internal sealed class ItemsFace : IImGuiPanel ImGuiNET.ImGui.Dummy(new Vector2(w, h)); } + // The weapon groups, in the order shown. "Other" holds items RynthAi doesn't know right now (not carried). + private static readonly string[] KindOrder = { "Melee", "Missile", "War Magic", "Void Magic", "Shield", "Ammo", "Other" }; + + private static string KindGroup(string kind) + { + foreach (string k in KindOrder) + if (k.Equals(kind, StringComparison.OrdinalIgnoreCase)) return k; + return "Other"; + } + + private static void KindHeading(string title, int count, float w) + { + Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos(); + ImFontPtr f = ImGuiFonts.Get(UiFont.UiBold11); + var dl = ImGuiNET.ImGui.GetWindowDrawList(); + dl.AddRectFilled(p, p + new Vector2(w, 20), PanelBg); + dl.AddText(f, f.FontSize, p + new Vector2(8, (20 - f.FontSize) * 0.5f), Teal, title + " (" + count + ")"); + ImGuiNET.ImGui.Dummy(new Vector2(w, 20)); + } + private static void TableHeader(string column, float w) { Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos(); diff --git a/src/RynthCore.Engine/UI/Data/DamageData.cs b/src/RynthCore.Engine/UI/Data/DamageData.cs index de9a9c4..0c4b849 100644 --- a/src/RynthCore.Engine/UI/Data/DamageData.cs +++ b/src/RynthCore.Engine/UI/Data/DamageData.cs @@ -676,22 +676,22 @@ internal static unsafe class DamageCommands MonstersPanel.Rule? from = string.IsNullOrEmpty(copyFrom) ? null : rules.Rules.Find(r => !IsDefault(r) && r.Name.Equals(copyFrom, StringComparison.OrdinalIgnoreCase)); MonstersPanel.Rule clone = CopyOfDefault(from ?? s, name); - if (from != null) { clone.OffhandId = from.OffhandId; clone.PetDamage = from.PetDamage; } // a name rule's own choices, kept + if (from != null) { clone.OffhandId = from.OffhandId; clone.PetDamage = from.PetDamage; clone.PreferredDamage = from.PreferredDamage; } // a name rule's own choices, kept rules.Rules.Insert(defIdx >= 0 ? defIdx + 1 : 0, clone); return clone; } /// - /// A new rule named with Default's settings. Off hand and pet are - /// left on "follow Default" (0 / PAuto) rather than copied, so a later change on the - /// DEFAULT line still reaches it. + /// A new rule named with Default's settings. Off hand, pet and preferred + /// damage are left on "follow Default" (0 / PAuto / Auto) rather than copied, so a later change + /// on the DEFAULT line still reaches it. /// private static MonstersPanel.Rule CopyOfDefault(MonstersPanel.Rule s, string name) => new() { Name = name, Category = s.Category, MatchExpression = "", // an exact-name rule matches by name, not by a (possibly false) expression Priority = s.Priority, DamageType = s.DamageType, WeaponId = s.WeaponId, OffhandId = 0, - ExVuln = s.ExVuln, PetDamage = "PAuto", + ExVuln = s.ExVuln, PetDamage = "PAuto", PreferredDamage = "Auto", Fester = s.Fester, Broadside = s.Broadside, GravityWell = s.GravityWell, Imperil = s.Imperil, Yield = s.Yield, Vuln = s.Vuln, UseArc = s.UseArc, UseBolt = s.UseBolt, UseRing = s.UseRing, UseStreak = s.UseStreak, UseBlast = s.UseBlast, UseWall = s.UseWall, @@ -787,6 +787,9 @@ internal static unsafe class DamageCommands public static readonly string[] DamageTypes = { "Auto", "Slash", "Pierce", "Bludgeon", "Fire", "Cold", "Lightning", "Acid", "Nether" }; + /// Rule.PreferredDamage choices: the kind of damage to fight with when the character uses more than one. + public static readonly string[] PreferredDamages = { "Auto", "Melee", "Missile", "War Magic", "Void Magic" }; + /// Rule.OffhandId as RynthAi reads it: 0 = follow the DEFAULT line, 1-4 a mode, anything else an item id. public static readonly string[] OffhandModeNames = { "Default", "Auto", "Shield", "Dual wield", "None" }; diff --git a/src/RynthCore.Engine/UI/Panels/ItemsPanel.cs b/src/RynthCore.Engine/UI/Panels/ItemsPanel.cs index e0f6cb1..fae56c5 100644 --- a/src/RynthCore.Engine/UI/Panels/ItemsPanel.cs +++ b/src/RynthCore.Engine/UI/Panels/ItemsPanel.cs @@ -79,6 +79,9 @@ internal static class ItemsPanel [JsonPropertyName("element")] public string Element { get; set; } = "Slash"; // "Weapon" or "Shield" (older settings may hold "Loot"). Round-tripped untouched. [JsonPropertyName("action")] public string Action { get; set; } = "Weapon"; + // Melee, Missile, "War Magic", "Void Magic", Shield, Ammo, or "" (not known). Set by RynthAi for + // display (the Items face groups by it); sent back untouched and ignored there. + [JsonPropertyName("kind")] public string Kind { get; set; } = string.Empty; public bool IsShield => string.Equals(Action, ItemsCommands.ShieldAction, StringComparison.OrdinalIgnoreCase); } diff --git a/src/RynthCore.Engine/UI/Panels/MonstersPanel.cs b/src/RynthCore.Engine/UI/Panels/MonstersPanel.cs index d7435ce..908af51 100644 --- a/src/RynthCore.Engine/UI/Panels/MonstersPanel.cs +++ b/src/RynthCore.Engine/UI/Panels/MonstersPanel.cs @@ -107,6 +107,8 @@ internal static class MonstersPanel public string MatchExpression { get; set; } = string.Empty; public int Priority { get; set; } = 1; public string DamageType { get; set; } = "Auto"; + /// Auto, Melee, Missile, "War Magic" or "Void Magic": the kind of damage to fight with. Off in rules saved before 2026-10-16. + public string PreferredDamage { get; set; } = "Auto"; public int WeaponId { get; set; } public bool Fester { get; set; } public bool Broadside { get; set; } @@ -1015,7 +1017,7 @@ internal static class MonstersPanel { var x = a[i]; var y = b[i]; if (x.Name != y.Name || x.Category != y.Category || x.Priority != y.Priority - || x.DamageType != y.DamageType || x.ExVuln != y.ExVuln || x.PetDamage != y.PetDamage + || x.DamageType != y.DamageType || x.PreferredDamage != y.PreferredDamage || x.ExVuln != y.ExVuln || x.PetDamage != y.PetDamage || x.WeaponId != y.WeaponId || x.OffhandId != y.OffhandId || x.MatchExpression != y.MatchExpression || x.Fester != y.Fester || x.Broadside != y.Broadside || x.GravityWell != y.GravityWell diff --git a/tools/HotkeyTests/Program.cs b/tools/HotkeyTests/Program.cs index ecc87f6..d7db410 100644 --- a/tools/HotkeyTests/Program.cs +++ b/tools/HotkeyTests/Program.cs @@ -39,6 +39,8 @@ internal static class Program Run("CommandParsing", CommandParsing); Run("VTankActions", VTankActions); Run("MetaStateParam", MetaStateParam); + Run("OneTouchHeal", OneTouchHeal); + Run("DefaultKeys", DefaultKeys); Run("IltPanelsOnlyOnIlt", IltPanelsOnlyOnIlt); } finally @@ -472,6 +474,71 @@ internal static class Program } // "Meta: set state...": the state is the binding's parameter (its Command), kept in the file. + // One-touch heal (2026-10-16): three built-ins that run RynthAi's /ra heal | stam | mana. + private static void OneTouchHeal() + { + var want = new[] { ("heal", "/ra heal"), ("stamina", "/ra stam"), ("mana", "/ra mana") }; + foreach (var (id, chat) in want) + { + HotkeyAction? a = HotkeyActions.Find(id); + Check(a != null && a.Chat == chat && a.Panel == null && a.Group.Length == 0 && !a.HasParam && a.Tip.Length > 20, $"{id}: a built-in that runs {chat}"); + Check(a != null && HotkeyActions.ChatFor(a, new HotkeyBinding(new KeyCombo(VK_F5, HotkeyMods.None), id)) == chat, $"{id}: the chat line"); + } + Check(HotkeyActions.Resolve("heal")?.Id == "heal", "Resolve: heal"); + Check(HotkeyActions.Resolve("Heal now (one touch)")?.Id == "heal", "Resolve: by name"); + Check(HotkeyActions.Resolve("Restore mana now (one touch)")?.Id == "mana", "Resolve: mana by name"); + Check(HotkeyActions.Resolve("stamina")?.Id == "stamina", "Resolve: stamina"); + Check(HotkeyActions.Describe(new HotkeyBinding(new KeyCombo(VK_F5, HotkeyMods.None), "heal")) == "Heal now (one touch)", "Describe"); + HotkeyCommand c = HotkeyCommandParser.Parse("add F6 heal"); + Check(c.Verb == HotkeyVerb.Add && c.Action == "heal", "/rc hotkey add F6 heal"); + Check(HotkeyActions.BuiltIns.Select(a => a.Id).Distinct(StringComparer.OrdinalIgnoreCase).Count() == HotkeyActions.BuiltIns.Length, "every id is unique"); + Check(HotkeyActions.Resolve("combat")?.Id == "combat" && HotkeyActions.Resolve("macro")?.Id == "macro", "older words still win"); + } + + // The default keys are offered once per version: only where neither the action nor the key is taken. + private static void DefaultKeys() + { + var f6 = new KeyCombo(0x75, HotkeyMods.None); + var f7 = new KeyCombo(0x76, HotkeyMods.None); + var f8 = new KeyCombo(0x77, HotkeyMods.None); + Check(HotkeyDefaults.All.Length == 3 && HotkeyDefaults.All[0] == (f6, "heal") && HotkeyDefaults.All[1] == (f7, "stamina") + && HotkeyDefaults.All[2] == (f8, "mana"), "F6 heal, F7 stamina, F8 mana"); + foreach (var (combo, action) in HotkeyDefaults.All) + Check(HotkeyActions.Find(action) != null && HotkeyConflicts.CommonAcKey(combo) == null, $"{combo}: a real action, no AC key warning"); + + // A new PC (no file): all three, saved with the version. + HotkeyFile empty = new(true, new List()); + HotkeyFile seeded = HotkeyDefaults.Apply(empty); + Check(!ReferenceEquals(seeded, empty) && seeded.DefaultsApplied == HotkeyDefaults.Version && seeded.Bindings.Count == 3, "empty file: three keys"); + Check(seeded.Bindings.All(b => b.Enabled && !b.IsCommand), "enabled built-ins"); + HotkeyFile back = HotkeyStore.Parse(HotkeyStore.Serialize(seeded)); + Check(back.DefaultsApplied == HotkeyDefaults.Version && back.Bindings.Count == 3 && back.Enabled, "the version and keys round-trip"); + Check(ReferenceEquals(HotkeyDefaults.Apply(back), back), "offered once: a second Apply changes nothing"); + + // A key the player removed does not come back once the file has been offered them. + HotkeyFile removed = back with { Bindings = back.Bindings.Where(b => b.Action != "heal").ToList() }; + Check(HotkeyDefaults.Apply(removed).Bindings.Count == 2, "a removed default stays removed"); + + // Nothing of the player's is taken: a bound key, or an action already bound elsewhere. + var mine = new List + { + new(f6, "macro"), // F6 is taken: no heal key + new(new KeyCombo(0x70, HotkeyMods.Ctrl), "mana"), // mana is bound: no F8 + }; + HotkeyFile kept = HotkeyDefaults.Apply(new HotkeyFile(false, mine)); + Check(!kept.Enabled, "the master switch is not touched"); + Check(kept.Bindings.Count == 3 && kept.Bindings[0].Action == "macro" && kept.Bindings[1].Action == "mana", "the player's bindings stay, first"); + Check(kept.Bindings[2] == new HotkeyBinding(f7, "stamina"), "only the free one is added: " + string.Join(", ", kept.Bindings.Select(b => b.Combo + " " + b.Action))); + Check(HotkeyDefaults.Apply(new HotkeyFile(true, new List { new(f7, "heal", Enabled: false) })).Bindings + .Count(b => b.Action == "heal") == 1, "a switched-off heal key counts as bound"); + + // An older file (no defaults= line) is offered them; an unreadable version counts as never. + HotkeyFile old = HotkeyStore.Parse("enabled=1\non\tCtrl+F1\tmacro\t\n"); + Check(old.DefaultsApplied == 0 && HotkeyDefaults.Apply(old).Bindings.Count == 4, "an older file gets them next to its own"); + Check(HotkeyStore.Parse("defaults=banana\n").DefaultsApplied == 0, "junk version = never offered"); + Check(HotkeyStore.Parse("defaults=-3\n").DefaultsApplied == 0, "negative version = never offered"); + } + private static void MetaStateParam() { var f6 = new KeyCombo(0x75, HotkeyMods.Ctrl);