// ============================================================================ // RynthDefective - ShortcutBar/BarMapping.cs // Which slot a shortcut bar slot stands for, pure (the tests run it offline). // // usual bar slots 1-18 are AC's own shortcut slots (the retail // toolbar's, saved on the server; keys AC's UseQuickSlot_N), // bar slot 18+N is RynthDefective's own slot N. // independent (DefSettings.IndependentBar) every bar slot N is // RynthDefective's own slot N: AC's 18 are not on the bar, // clicks go through the use controller, keys are the engine's // hotkeys running /rdef use N. // // Also: the healing kit in one of AC's slots that a click uses on yourself // (RetailKit), and copying AC's 18 slots into the own ones (CopyRetail). // ============================================================================ using System; using System.Collections.Generic; using RynthCore.Plugin.RynthDefective.Items; using RynthCore.Plugin.RynthDefective.Model; namespace RynthCore.Plugin.RynthDefective.ShortcutBar; /// What copying AC's 18 slots into RynthDefective's own did (). internal sealed record BarCopyResult(int Copied, int Skipped, IReadOnlyList<(int From, int To)> Moved, string? Refused); internal static class BarMapping { /// Bar slot (1-based) is one of AC's own shortcut slots. public static bool IsRetail(int number, bool independent) => !independent && number >= 1 && number <= DefSettings.RetailSlots; /// RynthDefective's own slot (1-based) bar slot is; 0 for one of AC's. public static int OwnSlot(int number, bool independent) => IsRetail(number, independent) ? 0 : independent ? number : number - DefSettings.RetailSlots; /// The bar slot RynthDefective's own slot shows in. public static int BarNumber(int own, bool independent) => independent ? own : own + DefSettings.RetailSlots; /// What a bar slot's keys run: AC's keymap action for one of AC's slots, the engine command for an own one. public static string KeyAction(int number, bool independent) => IsRetail(number, independent) ? "UseQuickSlot_" + number : DefCommandParser.UseCommand(OwnSlot(number, independent)); /// /// A click on one of AC's slots holding : the healing (or stamina, mana) /// kit to use on yourself through the use controller, or null for AC's own use of the slot (a potion, /// a weapon, a spell, an item not in the pack). The kit test is the use controller's own /// (ItemKinds.Classify: the healer bit, else RynthAi's " Kit" name test). /// public static CarriedItem? RetailKit(uint objectId, IReadOnlyList items) { if (objectId == 0) return null; foreach (CarriedItem it in items) if (it.Id == objectId) return ItemKinds.Classify(it) == ItemKind.Kit ? it : null; return null; } /// /// Copies AC's 18 slots (, , slot 1 first) into the own /// slots 1-18, so an independent bar looks as the usual one did: the own slots that were after AC's /// (own N at bar 18+N) move to own 18+N, where an independent bar shows them. /// lists the moves of the slots that held something (their "/rdef use N" keys go with them). A spell goes /// in as a spell slot (2026-10-28); an item can't name can't go in an own slot: /// that slot stays empty (Skipped). /// Refused (nothing changed) when an own slot past 24 holds something: there is no room to move it. /// public static BarCopyResult CopyRetail(List own, ReadOnlySpan ids, ReadOnlySpan spells, Func resolve) { const int retail = DefSettings.RetailSlots, room = DefSettings.SlotsMax - DefSettings.RetailSlots; for (int n = room + 1; n <= own.Count; n++) if (!own[n - 1].Empty) return new BarCopyResult(0, 0, Array.Empty<(int, int)>(), $"Your slot {n} holds {own[n - 1].Label}: there is no room to move " + $"slots {room + 1}-{DefSettings.SlotsMax} after the game's {retail}. Empty them (or copy by hand) first."); var next = DefData.NewSlots(); var moved = new List<(int, int)>(); for (int n = 1; n <= Math.Min(room, own.Count); n++) { if (own[n - 1].Empty) continue; next[retail + n - 1] = own[n - 1]; moved.Add((n, retail + n)); } int copied = 0, skipped = 0; for (int i = 0; i < retail; i++) { uint id = i < ids.Length ? ids[i] : 0, spell = i < spells.Length ? spells[i] : 0; if (id == 0) { if (spell != 0) { next[i] = new DefSlot { SpellId = spell, SpellName = SpellTable.Name(spell) }; copied++; } continue; } ItemRef? r = resolve(id); if (r == null || string.IsNullOrWhiteSpace(r.Name)) { skipped++; continue; } next[i] = new DefSlot { Item = r, Mode = UseMode.Auto }; copied++; } for (int i = 0; i < own.Count && i < next.Count; i++) own[i] = next[i]; return new BarCopyResult(copied, skipped, moved, null); } /// How many of AC's slots hold an item or a spell (what a copy would bring over). public static int RetailShortcuts(ReadOnlySpan ids, ReadOnlySpan spells) { int n = 0; for (int i = 0; i < ids.Length; i++) if (ids[i] != 0 || (i < spells.Length && spells[i] != 0)) n++; return n; } /// "F9, Ctrl+1" as its keys. public static string[] SplitKeys(string keys) => string.IsNullOrEmpty(keys) ? Array.Empty() : keys.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); }