RynthSuite as of 2026-11-08 (internal 6ec9b64): release 2026.11.8.1
This commit is contained in:
parent
7166d256ce
commit
f8fa62b64c
196 changed files with 24980 additions and 633 deletions
155
Plugins/RynthCore.Plugin.RynthDefective/Clock/DayNightWindow.cs
Normal file
155
Plugins/RynthCore.Plugin.RynthDefective/Clock/DayNightWindow.cs
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
// ============================================================================
|
||||
// RynthDefective - Clock/DayNightWindow.cs
|
||||
// The Day/Night timer (2026-11-04, a request on 2026-11-01: a tiny window with
|
||||
// the real minutes until the next day/night change): a sun or a moon, then
|
||||
// "Night in 23m" / "Day in 4m 10s", and the hour's name when there's room.
|
||||
// "—" until the player is in world (the clock can't be read before).
|
||||
// Plugins/Shared/DerethClock.cs has the math; RynthCore hosts the frameless
|
||||
// window (plugin API v90) and remembers where it is.
|
||||
//
|
||||
// anywhere drag to move; Ctrl+wheel: bigger or smaller (30-250%);
|
||||
// right-click: hide it (/rdef daynight, the bar button, or
|
||||
// Settings > UI > Toolbar show it again).
|
||||
//
|
||||
// AC's render thread; reads the view the tick built (DayNightView) and counts
|
||||
// the seconds down from when it was read, so the seconds move every frame.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
using RynthCore.Plugin.RynthDefective.ShortcutBar;
|
||||
using RynthCore.Plugin.Shared;
|
||||
using RynthCore.Plugin.Shared.RynthUi;
|
||||
using RynthCore.PluginSdk;
|
||||
using static RynthCore.Plugin.Shared.RynthUi.RynthUi;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective.Clock;
|
||||
|
||||
/// <summary>The clock as the tick read it; Ready = in world with a usable reading.</summary>
|
||||
internal sealed record DayNightView(bool Ready, DerethNow Now, long ReadAtMs)
|
||||
{
|
||||
public static readonly DayNightView NotReady = new(false, default, 0);
|
||||
|
||||
/// <summary>The real seconds to the change at <paramref name="nowMs"/> (counted down from the reading).</summary>
|
||||
public double SecondsLeft(long nowMs) => Math.Max(0, Now.SecondsToChange - (nowMs - ReadAtMs) / 1000.0);
|
||||
}
|
||||
|
||||
internal sealed class DayNightWindow
|
||||
{
|
||||
public const string Title = "Day/Night";
|
||||
public const string NotInWorld = "—";
|
||||
|
||||
private readonly RynthCoreHost _host;
|
||||
private float _k = 1f, _r = 1f;
|
||||
|
||||
// The label, made again only when the second it shows changes (no string every frame).
|
||||
private long _shownSecond = -1;
|
||||
private bool _shownDay;
|
||||
private string _label = NotInWorld;
|
||||
|
||||
public DayNightWindow(RynthCoreHost host) => _host = host;
|
||||
|
||||
private float Px(float v) => v * _k;
|
||||
private float Fs(ImFontPtr f) => f.FontSize * _r;
|
||||
|
||||
private void Scale()
|
||||
{
|
||||
float fontK = Math.Max(0.5f, Font(RynthUiFont.Ui10).FontSize / 10f);
|
||||
int pct = _host.PanelScale(Title);
|
||||
_k = pct > 0 ? pct / 100f : fontK;
|
||||
_r = _k / fontK;
|
||||
}
|
||||
|
||||
private const float Pad = 5, RowH = 16, Mark = 14, Gap = 4, Radius = 4;
|
||||
|
||||
private static readonly uint SunColor = Argb(0xFFF2C14E), MoonColor = Argb(0xFFB8C7F0);
|
||||
private static uint A(uint c, float alpha) => WithAlpha(c, (uint)Math.Clamp(MathF.Round(alpha * 255f), 0f, 255f));
|
||||
|
||||
/// <summary>Draws the timer into the host's window; returns the height it needs (pixels). Render thread.</summary>
|
||||
public float Draw(DayNightView v)
|
||||
{
|
||||
Scale();
|
||||
uint bg = Color(RynthUiColor.Background), line = Color(RynthUiColor.Hairline);
|
||||
uint text = Color(RynthUiColor.Text), faint = Color(RynthUiColor.Faint);
|
||||
|
||||
Vector2 origin = ImGui.GetCursorScreenPos();
|
||||
origin = new Vector2(MathF.Round(origin.X), MathF.Round(origin.Y));
|
||||
float width = MathF.Floor(ImGui.GetContentRegionAvail().X);
|
||||
float pad = Px(Pad), rowH = Px(RowH);
|
||||
float height = MathF.Ceiling(2 * pad + rowH);
|
||||
if (width < 30) return height;
|
||||
ImDrawListPtr dl = ImGui.GetWindowDrawList();
|
||||
Vector2 max = origin + new Vector2(width, height);
|
||||
dl.AddRectFilled(origin, max, A(bg, 0.94f), Px(Radius));
|
||||
dl.AddRect(origin, max, line, Px(Radius));
|
||||
|
||||
// The whole window is the drag surface.
|
||||
ImGui.SetCursorScreenPos(origin);
|
||||
ImGui.InvisibleButton("##daynight_drag", new Vector2(width, height));
|
||||
_host.PanelDragWithLastItem();
|
||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Right)) _host.SetPanelOpen(Title, RynthPanelOpen.Close);
|
||||
bool hot = ImGui.IsItemHovered();
|
||||
|
||||
long nowMs = Environment.TickCount64;
|
||||
double left = v.Ready ? v.SecondsLeft(nowMs) : 0;
|
||||
string label = Label(v, left);
|
||||
|
||||
// The sun by day, the moon at night (an engine from before the moon was baked: a star).
|
||||
Vector2 at = origin + new Vector2(pad, pad);
|
||||
string icon = !v.Ready || v.Now.IsDay ? RynthIcons.Sun : HasGlyph(RynthIcons.Moon) ? RynthIcons.Moon : RynthIcons.Star;
|
||||
uint iconColor = !v.Ready ? faint : v.Now.IsDay ? SunColor : MoonColor;
|
||||
PanelButtonsWindow.DrawIcon(dl, icon, at, new Vector2(Px(Mark), rowH), Px(13), iconColor);
|
||||
|
||||
ImFontPtr nf = Font(RynthUiFont.NarrowBold11), sf = Font(RynthUiFont.Narrow9);
|
||||
float tx = at.X + Px(Mark) + Px(Gap), right = origin.X + width - pad;
|
||||
float lw = nf.CalcTextSizeA(Fs(nf), float.MaxValue, 0f, label).X;
|
||||
dl.AddText(nf, Fs(nf), new Vector2(MathF.Round(tx), MathF.Round(at.Y + (rowH - Fs(nf)) * 0.5f)), v.Ready ? text : faint, label);
|
||||
|
||||
// The hour's name, right-aligned, only when it fits whole.
|
||||
if (v.Ready)
|
||||
{
|
||||
string hour = v.Now.HourName;
|
||||
float hw = sf.CalcTextSizeA(Fs(sf), float.MaxValue, 0f, hour).X;
|
||||
if (tx + lw + Px(8) + hw <= right)
|
||||
dl.AddText(sf, Fs(sf), new Vector2(MathF.Round(right - hw), MathF.Round(at.Y + (rowH - Fs(sf)) * 0.5f)), faint, hour);
|
||||
}
|
||||
|
||||
if (hot) SafeImGui.SetItemTooltip(Tip(v, left));
|
||||
|
||||
ImGui.SetCursorScreenPos(origin);
|
||||
ImGui.Dummy(new Vector2(width, height));
|
||||
return height;
|
||||
}
|
||||
|
||||
private string Label(DayNightView v, double left)
|
||||
{
|
||||
if (!v.Ready) { _shownSecond = -1; return _label = NotInWorld; }
|
||||
long second = (long)Math.Ceiling(left);
|
||||
if (second != _shownSecond || v.Now.IsDay != _shownDay)
|
||||
{
|
||||
_shownSecond = second;
|
||||
_shownDay = v.Now.IsDay;
|
||||
_label = DerethClock.Label(v.Now, left);
|
||||
}
|
||||
return _label;
|
||||
}
|
||||
|
||||
/// <summary>The tooltip (built only while hovered).</summary>
|
||||
internal static string Tip(DayNightView v, double left)
|
||||
{
|
||||
const string help = "A Dereth day is 2 h 7 min of real time: 63.5 minutes of day, then 63.5 of night.\n"
|
||||
+ "Drag to move; Ctrl+wheel: bigger or smaller; right-click: hide (/rdef daynight).";
|
||||
if (!v.Ready) return "Day or night in Dereth, and the real minutes until it changes. Shown once you're in the world.\n" + help;
|
||||
TimeSpan t = TimeSpan.FromSeconds(Math.Ceiling(left));
|
||||
string until = t.TotalMinutes >= 1 ? $"{(int)t.TotalMinutes} min {t.Seconds} s" : $"{t.Seconds} s";
|
||||
return $"{(v.Now.IsDay ? "Day" : "Night")} now ({v.Now.HourName}). {v.Now.Next} comes at {v.Now.NextHourName}, in {until} of real time.\n" + help;
|
||||
}
|
||||
|
||||
/// <summary>Whether the engine's atlas has <paramref name="glyph"/> (an icon baked after this engine was built isn't).</summary>
|
||||
private static unsafe bool HasGlyph(string glyph)
|
||||
{
|
||||
ImFontPtr font = Font(RynthUiFont.Ui18);
|
||||
return font.NativePtr != null && ImGuiNative.ImFont_FindGlyphNoFallback(font.NativePtr, glyph[0]) != null;
|
||||
}
|
||||
}
|
||||
|
|
@ -67,18 +67,39 @@ internal sealed class DefSession
|
|||
|
||||
// ── Using ───────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>The slot's button or key: use what it holds. Returns what to tell the player when nothing could be queued.</summary>
|
||||
public string? UseSlot(int slotNumber)
|
||||
// A slot is on bar 0 (the main bar's own slots: DefData.Slots, /rdef use N) or on extra bar 2-4
|
||||
// (2026-11-04, ExtraBar: slots of its own, no keys). The slot actions below take the bar last.
|
||||
|
||||
/// <summary>"Slot 3", or "Bar 2 slot 3" for an extra bar's.</summary>
|
||||
public static string SlotName(int bar, int slotNumber) => bar == 0 ? $"Slot {slotNumber}" : $"Bar {bar} slot {slotNumber}";
|
||||
|
||||
/// <summary>The slot list slot <paramref name="slotNumber"/> of <paramref name="bar"/> is in; what is wrong when there is none.</summary>
|
||||
private string? Locate(int bar, int slotNumber, out List<DefSlot> slots)
|
||||
{
|
||||
if (slotNumber < 1 || slotNumber > DefSettings.SlotsMax) return $"There is no slot {slotNumber}.";
|
||||
DefSlot slot = Data.Slots[slotNumber - 1];
|
||||
slots = Data.Slots;
|
||||
if (bar == 0) return slotNumber < 1 || slotNumber > DefSettings.SlotsMax ? $"There is no slot {slotNumber}." : null;
|
||||
ExtraBar? b = Data.Extra(bar);
|
||||
if (b == null) return $"There is no Shortcuts bar {bar}.";
|
||||
slots = b.Slots;
|
||||
return slotNumber < 1 || slotNumber > ExtraBar.SlotsMax ? $"Bar {bar} has no slot {slotNumber}." : null;
|
||||
}
|
||||
|
||||
/// <summary>The slot's button or key: use what it holds. Returns what to tell the player when nothing could be queued.</summary>
|
||||
public string? UseSlot(int slotNumber, int bar = 0)
|
||||
{
|
||||
if (Locate(bar, slotNumber, out List<DefSlot> slots) is { } problem) return problem;
|
||||
DefSlot slot = slots[slotNumber - 1];
|
||||
string source = (bar == 0 ? "slot " : $"bar {bar} slot ") + slotNumber;
|
||||
if (slot.IsSpell)
|
||||
{
|
||||
Use.Request(UseRequest.Cast(slot.SpellId, slot.SpellLabel, "slot " + slotNumber, Now()));
|
||||
Use.Request(UseRequest.Cast(slot.SpellId, slot.SpellLabel, source, Now()));
|
||||
return null;
|
||||
}
|
||||
if (slot.Item == null) return $"Slot {slotNumber} is empty. Set it from the bar (Edit slots) or with /rdef set {slotNumber}.";
|
||||
Use.Request(new UseRequest(slot.Item, null, slot.Mode, "slot " + slotNumber, Now()));
|
||||
if (slot.Item == null)
|
||||
return bar == 0
|
||||
? $"Slot {slotNumber} is empty. Set it from the bar (Edit slots) or with /rdef set {slotNumber}."
|
||||
: $"{SlotName(bar, slotNumber)} is empty: drag an item onto it, or right-click it to put the selected item or one of your spells there.";
|
||||
Use.Request(new UseRequest(slot.Item, null, slot.Mode, source, Now()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -107,21 +128,21 @@ internal sealed class DefSession
|
|||
|
||||
// ── Slots ───────────────────────────────────────────────────────────────
|
||||
|
||||
public string SetFromSelected(int slotNumber)
|
||||
public string SetFromSelected(int slotNumber, int bar = 0)
|
||||
{
|
||||
uint sel = SelectedId();
|
||||
if (sel == 0) return "Select the item in the game first (click it in your pack), then set the slot.";
|
||||
CarriedItem? it = FindById(sel);
|
||||
if (it == null) return "The selected object isn't in your pack, so it can't go in a slot.";
|
||||
return SetSlot(slotNumber, it);
|
||||
return SetSlot(slotNumber, it, bar);
|
||||
}
|
||||
|
||||
/// <summary>An item dragged onto the slot (its object id).</summary>
|
||||
public string SetFromId(int slotNumber, uint objectId)
|
||||
public string SetFromId(int slotNumber, uint objectId, int bar = 0)
|
||||
{
|
||||
CarriedItem? it = FindById(objectId);
|
||||
if (it == null) return "That isn't in your pack, so it can't go in a slot.";
|
||||
return SetSlot(slotNumber, it);
|
||||
return SetSlot(slotNumber, it, bar);
|
||||
}
|
||||
|
||||
public string SetFromName(int slotNumber, string name)
|
||||
|
|
@ -131,17 +152,17 @@ internal sealed class DefSession
|
|||
return SetSlot(slotNumber, it);
|
||||
}
|
||||
|
||||
public string SetSlot(int slotNumber, CarriedItem it)
|
||||
public string SetSlot(int slotNumber, CarriedItem it, int bar = 0)
|
||||
{
|
||||
if (slotNumber < 1 || slotNumber > DefSettings.SlotsMax) return $"There is no slot {slotNumber}.";
|
||||
DefSlot slot = Data.Slots[slotNumber - 1];
|
||||
if (Locate(bar, slotNumber, out List<DefSlot> slots) is { } problem) return problem;
|
||||
DefSlot slot = slots[slotNumber - 1];
|
||||
slot.Item = ItemRef.From(it);
|
||||
slot.SpellId = 0;
|
||||
slot.SpellName = string.Empty;
|
||||
slot.Mode = UseMode.Auto;
|
||||
Save();
|
||||
ItemKind kind = ItemKinds.Classify(it);
|
||||
return $"Slot {slotNumber}: {it.FullName} ({UseModes.Describe(ItemKinds.DefaultAction(kind))} when pressed).";
|
||||
return $"{SlotName(bar, slotNumber)}: {it.FullName} ({UseModes.Describe(ItemKinds.DefaultAction(kind))} when pressed).";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -149,9 +170,9 @@ internal sealed class DefSession
|
|||
/// known spells; the engine can't tell which spell is selected in the game's spellbook). Refused for
|
||||
/// a spell the character doesn't know, when the spellbook can be read.
|
||||
/// </summary>
|
||||
public string SetSpell(int slotNumber, uint spellId)
|
||||
public string SetSpell(int slotNumber, uint spellId, int bar = 0)
|
||||
{
|
||||
if (slotNumber < 1 || slotNumber > DefSettings.SlotsMax) return $"There is no slot {slotNumber}.";
|
||||
if (Locate(bar, slotNumber, out List<DefSlot> slots) is { } problem) return problem;
|
||||
if (spellId == 0) return "That isn't a spell.";
|
||||
IReadOnlyList<SpellInfo> known = KnownSpells();
|
||||
SpellInfo? spell = null;
|
||||
|
|
@ -159,9 +180,9 @@ internal sealed class DefSession
|
|||
if (s.Id == spellId) { spell = s; break; }
|
||||
if (spell == null && known.Count > 0) return $"You don't know {SpellTable.Name(spellId)}, so it can't go in a slot.";
|
||||
SpellInfo info = spell ?? (SpellTable.TryGet(spellId, out SpellInfo t) ? t : new SpellInfo(spellId, SpellTable.Name(spellId), false, false));
|
||||
Data.Slots[slotNumber - 1] = new DefSlot { SpellId = spellId, SpellName = info.Name };
|
||||
slots[slotNumber - 1] = new DefSlot { SpellId = spellId, SpellName = info.Name };
|
||||
Save();
|
||||
return $"Slot {slotNumber}: {info.Name} ({SpellTargeting.Describe(info)} when pressed).";
|
||||
return $"{SlotName(bar, slotNumber)}: {info.Name} ({SpellTargeting.Describe(info)} when pressed).";
|
||||
}
|
||||
|
||||
/// <summary>/rdef spell <slot> <name>: one of the character's spells by what the player typed.</summary>
|
||||
|
|
@ -178,12 +199,12 @@ internal sealed class DefSession
|
|||
return SetSpell(slotNumber, found[0].Id);
|
||||
}
|
||||
|
||||
public string ClearSlot(int slotNumber)
|
||||
public string ClearSlot(int slotNumber, int bar = 0)
|
||||
{
|
||||
if (slotNumber < 1 || slotNumber > DefSettings.SlotsMax) return $"There is no slot {slotNumber}.";
|
||||
Data.Slots[slotNumber - 1] = new DefSlot();
|
||||
if (Locate(bar, slotNumber, out List<DefSlot> slots) is { } problem) return problem;
|
||||
slots[slotNumber - 1] = new DefSlot();
|
||||
Save();
|
||||
return $"Slot {slotNumber} cleared.";
|
||||
return $"{SlotName(bar, slotNumber)} cleared.";
|
||||
}
|
||||
|
||||
/// <summary>Swaps slot <paramref name="a"/> with <paramref name="b"/> (1-based), as moving one place.</summary>
|
||||
|
|
@ -226,6 +247,9 @@ internal sealed class DefSession
|
|||
bool changed = false;
|
||||
foreach (DefSlot s in Data.Slots)
|
||||
if (s.Item != null && ItemMatcher.Maintain(s.Item, items)) changed = true;
|
||||
foreach (ExtraBar bar in Data.ExtraBars)
|
||||
foreach (DefSlot s in bar.Slots)
|
||||
if (s.Item != null && ItemMatcher.Maintain(s.Item, items)) changed = true;
|
||||
foreach (ItemRef f in Data.Favourites)
|
||||
if (ItemMatcher.Maintain(f, items)) changed = true;
|
||||
foreach (ItemRef r in Data.Recent)
|
||||
|
|
@ -364,6 +388,55 @@ internal sealed class DefSession
|
|||
return string.IsNullOrWhiteSpace(name) ? null : new ItemRef { Id = id, Name = name.Trim() };
|
||||
}
|
||||
|
||||
// ── Extra bars (2026-11-04) ─────────────────────────────────────────────
|
||||
|
||||
/// <summary>Adds an extra Shortcuts bar (the lowest free number). <paramref name="added"/>: its number, 0 when none could be.</summary>
|
||||
public string AddBar(out int added)
|
||||
{
|
||||
ExtraBar? bar = Data.AddExtraBar();
|
||||
added = bar?.Number ?? 0;
|
||||
if (bar == null)
|
||||
return $"There are {ExtraBar.Max} extra Shortcuts bars already, as many as there can be (the engine hosts 8 windows for a plugin, "
|
||||
+ $"and RynthDefective draws 5 others). Remove one first: /rdef bars remove <{ExtraBar.FirstNumber}-{ExtraBar.LastNumber}>.";
|
||||
Save();
|
||||
return $"Shortcuts bar {bar.Number} added, {bar.SlotCount} slots: drag items from your pack onto it, or right-click a slot for "
|
||||
+ "the selected item or one of your spells. It shows in a moment; drag its title to move it.";
|
||||
}
|
||||
|
||||
/// <summary>Removes extra bar <paramref name="number"/>; its slots are forgotten.</summary>
|
||||
public string RemoveBar(int number)
|
||||
{
|
||||
if (number == 1) return "Bar 1 is the Shortcuts bar itself: it can't be removed (/rdef hides it).";
|
||||
ExtraBar? bar = Data.Extra(number);
|
||||
if (bar == null) return $"There is no Shortcuts bar {number}. {DescribeBars()}";
|
||||
int filled = bar.Filled;
|
||||
Data.RemoveExtraBar(number);
|
||||
Save();
|
||||
return $"Shortcuts bar {number} removed" + (filled > 0 ? $" ({filled} of its slots held an item or a spell: they are forgotten)." : ".");
|
||||
}
|
||||
|
||||
/// <summary>How many slots extra bar <paramref name="number"/> shows.</summary>
|
||||
public string SetBarSlots(int number, int count)
|
||||
{
|
||||
ExtraBar? bar = Data.Extra(number);
|
||||
if (bar == null) return $"There is no Shortcuts bar {number}. {DescribeBars()}";
|
||||
bar.SlotCount = Math.Clamp(count, ExtraBar.SlotsMin, ExtraBar.SlotsMax);
|
||||
Save();
|
||||
return $"Shortcuts bar {number} shows {bar.SlotCount} slot{(bar.SlotCount == 1 ? "" : "s")}"
|
||||
+ (count != bar.SlotCount ? $" ({ExtraBar.SlotsMin} to {ExtraBar.SlotsMax})." : ".");
|
||||
}
|
||||
|
||||
/// <summary>The extra bars in a line (/rdef bars).</summary>
|
||||
public string DescribeBars()
|
||||
{
|
||||
if (Data.ExtraBars.Count == 0)
|
||||
return "No extra Shortcuts bars. Add one: Add a shortcut bar in the bar's right-click menu, or /rdef bars add.";
|
||||
var parts = new List<string>(Data.ExtraBars.Count);
|
||||
foreach (ExtraBar b in Data.ExtraBars)
|
||||
parts.Add($"{b.Number} ({b.SlotCount} slots, {b.Filled} set)");
|
||||
return $"Extra Shortcuts bars: {string.Join(", ", parts)}; {ExtraBar.Max - Data.ExtraBars.Count} more can be added.";
|
||||
}
|
||||
|
||||
// ── Favourites ──────────────────────────────────────────────────────────
|
||||
|
||||
public string ToggleFavourite(ItemRef r)
|
||||
|
|
|
|||
|
|
@ -3,21 +3,34 @@ using System;
|
|||
namespace RynthCore.Plugin.RynthDefective.Model;
|
||||
|
||||
internal enum DefVerb { Toggle, Help, Use, Set, Clear, Bind, Unbind, Weapons, Favourite, Slots, List, Status, Error, Panels, Selection, Settings, Spell, Corpses,
|
||||
Quantity, Split, Give, Buy }
|
||||
Quantity, Split, Give, Buy, DayNight, Bars, Shortcuts }
|
||||
|
||||
/// <summary>
|
||||
/// A parsed "/rdef ..." line. Use: <see cref="Slot"/> (1-based) or <see cref="Text"/> (an item name).
|
||||
/// The quantity box's verbs (qty, split, give, buy): <see cref="Amount"/> (null = the box's number) and
|
||||
/// <see cref="Text"/> (split: the pack; buy: the item's name).
|
||||
/// Bars (the extra Shortcuts bars): <see cref="Text"/> what to do (list, add, remove, slots, show),
|
||||
/// <see cref="Slot"/> the bar's number, <see cref="Count"/> its slots.
|
||||
/// Shortcuts ("shortcuts clearbusy on|off"): <see cref="Text"/> "on", "off" or "" (say what it is).
|
||||
/// </summary>
|
||||
internal sealed record DefCommand(DefVerb Verb, int Slot = 0, string Text = "", string Error = "", QtyAmount? Amount = null);
|
||||
internal sealed record DefCommand(DefVerb Verb, int Slot = 0, string Text = "", string Error = "", QtyAmount? Amount = null, int Count = 0);
|
||||
|
||||
internal static class DefCommandParser
|
||||
{
|
||||
public const string Usage =
|
||||
"/rdef [use <slot or item name> | set <slot> [item name] | spell <slot> <spell name> | clear <slot> | bind <slot> <key> | unbind <slot> | "
|
||||
+ "weapons [search] | fav | slots <count> | list | status | settings | panels (the game panel buttons) | selection | corpses [clear] | "
|
||||
+ "qty [number|max|half] | split [number] [into <pack>] | give [number] | buy [number] [item name]]";
|
||||
+ "bars [add | remove <bar> | slots <bar> <count> | show <bar>] | shortcuts clearbusy [on|off] | "
|
||||
+ "qty [number|max|half] | split [number] [into <pack>] | give [number] | buy [number] [item name] | daynight [show|hide]]";
|
||||
|
||||
public const string DayNightUsage = "Usage: /rdef daynight [show|hide], e.g. /rdef daynight show (the Day/Night timer: real minutes to the next dawn or dusk)";
|
||||
|
||||
public const string ClearBusyUsage =
|
||||
"Usage: /rdef shortcuts clearbusy on|off, e.g. /rdef shortcuts clearbusy on (a press held only by a stuck busy count clears it first; off by default)";
|
||||
|
||||
public const string BarsUsage =
|
||||
"Usage: /rdef bars [list | add | remove <bar> | slots <bar> <count> | show <bar>], e.g. /rdef bars add or /rdef bars remove 2 "
|
||||
+ "(the extra Shortcuts bars are 2-4)";
|
||||
|
||||
public const string QtyUsage = "Usage: /rdef qty <number|max|half>, e.g. /rdef qty 25 (the Selection window's number)";
|
||||
public const string SplitUsage = "Usage: /rdef split [number|max|half] [into <pack>], e.g. /rdef split 25 or /rdef split 25 into Sack";
|
||||
|
|
@ -44,6 +57,15 @@ internal static class DefCommandParser
|
|||
case "selection": case "target":
|
||||
// "/rdef selection 0x80001234": select that object (a test hook for the Selection window).
|
||||
return new DefCommand(DefVerb.Selection, Text: rest);
|
||||
// The Day/Night timer (2026-11-04): Text "show", "hide" or "" (toggle).
|
||||
case "daynight":
|
||||
return rest.ToLowerInvariant() switch
|
||||
{
|
||||
"" or "toggle" => new DefCommand(DefVerb.DayNight),
|
||||
"show" or "on" or "open" => new DefCommand(DefVerb.DayNight, Text: "show"),
|
||||
"hide" or "off" or "close" => new DefCommand(DefVerb.DayNight, Text: "hide"),
|
||||
_ => Fail($"'{rest}' isn't show or hide. {DayNightUsage}"),
|
||||
};
|
||||
case "fav": case "favourite": case "favorite": return new DefCommand(DefVerb.Favourite);
|
||||
case "weapons": case "weapon": case "picker": return new DefCommand(DefVerb.Weapons, Text: rest);
|
||||
case "use": case "wield": case "equip":
|
||||
|
|
@ -79,6 +101,22 @@ internal static class DefCommandParser
|
|||
return int.TryParse(rest, out int count) && count >= DefSettings.SlotsMin && count <= DefSettings.SlotCountMax
|
||||
? new DefCommand(DefVerb.Slots, count)
|
||||
: Fail($"How many slots? {DefSettings.SlotsMin} to {DefSettings.SlotCountMax}, e.g. /rdef slots 10");
|
||||
// The extra Shortcuts bars (2026-11-04, ExtraBar).
|
||||
case "bars":
|
||||
return ParseBars(rest);
|
||||
// Shortcuts clear a stuck busy state (2026-11-04, DefSettings.ClearStuckBusy).
|
||||
case "shortcuts":
|
||||
{
|
||||
string[] words = rest.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (words.Length == 0 || words.Length > 2 || !words[0].Equals("clearbusy", StringComparison.OrdinalIgnoreCase)) return Fail(ClearBusyUsage);
|
||||
if (words.Length == 1) return new DefCommand(DefVerb.Shortcuts, Text: "");
|
||||
return words[1].ToLowerInvariant() switch
|
||||
{
|
||||
"on" or "true" or "1" or "yes" => new DefCommand(DefVerb.Shortcuts, Text: "on"),
|
||||
"off" or "false" or "0" or "no" => new DefCommand(DefVerb.Shortcuts, Text: "off"),
|
||||
_ => Fail($"'{words[1]}' isn't on or off. {ClearBusyUsage}"),
|
||||
};
|
||||
}
|
||||
// The quantity box (2026-10-30, Quantity/QuantityController.cs).
|
||||
case "qty": case "quantity": case "amount":
|
||||
{
|
||||
|
|
@ -110,6 +148,32 @@ internal static class DefCommandParser
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>"/rdef bars ...": list (alone too), add, remove N, slots N count, show N.</summary>
|
||||
private static DefCommand ParseBars(string rest)
|
||||
{
|
||||
string[] words = rest.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
string sub = words.Length == 0 ? "list" : words[0].ToLowerInvariant();
|
||||
int n = 0;
|
||||
bool hasBar = words.Length >= 2 && int.TryParse(words[1], out n);
|
||||
switch (sub)
|
||||
{
|
||||
case "list": case "ls":
|
||||
return words.Length <= 1 ? new DefCommand(DefVerb.Bars, Text: "list") : Fail(BarsUsage);
|
||||
case "add": case "new":
|
||||
return words.Length <= 1 ? new DefCommand(DefVerb.Bars, Text: "add") : Fail(BarsUsage);
|
||||
case "remove": case "delete": case "rm":
|
||||
return hasBar && words.Length == 2 ? new DefCommand(DefVerb.Bars, n, "remove") : Fail("Which bar? e.g. /rdef bars remove 2 (/rdef bars lists them)");
|
||||
case "show": case "hide": case "toggle":
|
||||
return hasBar && words.Length == 2 ? new DefCommand(DefVerb.Bars, n, "show") : Fail("Which bar? e.g. /rdef bars show 2 (shows it, or hides it when it shows)");
|
||||
case "slots":
|
||||
return hasBar && words.Length == 3 && int.TryParse(words[2], out int count) && count >= ExtraBar.SlotsMin && count <= ExtraBar.SlotsMax
|
||||
? new DefCommand(DefVerb.Bars, n, "slots", Count: count)
|
||||
: Fail($"How many slots? Usage: /rdef bars slots <bar> <count>, e.g. /rdef bars slots 2 12 ({ExtraBar.SlotsMin} to {ExtraBar.SlotsMax})");
|
||||
default:
|
||||
return Fail($"'{words[0]}' isn't something /rdef bars does. {BarsUsage}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The slot number a hotkey runs for slot <paramref name="slot"/> (1-based).</summary>
|
||||
public static string UseCommand(int slot) => "/rdef use " + slot;
|
||||
|
||||
|
|
|
|||
|
|
@ -117,6 +117,17 @@ internal sealed class DefSettings
|
|||
/// /rdef qty, split, give and buy work either way.
|
||||
/// </summary>
|
||||
public bool QuantityBox = true;
|
||||
/// <summary>
|
||||
/// Shortcuts clear a stuck busy state (2026-11-04, a player's ask): a press held only by the client's
|
||||
/// busy count (nothing of ours or RynthAi's in flight, no gesture, no "You're too busy" just now) resets
|
||||
/// the count as RynthAi's /ra clearbusy does (the engine's ForceResetBusyCount), then goes, once per
|
||||
/// press (Use/BusyGate.cs BusyClearRule). Off (the default, and what a file from before reads as): a
|
||||
/// reset also zeroes actions the server hasn't answered that RynthDefective can't see (the game's own
|
||||
/// clicks and toolbar keys, another plugin's), and each late answer then takes the count below zero;
|
||||
/// RynthAi stopped resetting it for that on 2026-10-06. The leftover rules let a press through anyway
|
||||
/// within 4 s; this only saves those seconds.
|
||||
/// </summary>
|
||||
public bool ClearStuckBusy;
|
||||
public bool BarOpen;
|
||||
public bool PickerOpen;
|
||||
|
||||
|
|
@ -131,6 +142,69 @@ internal sealed class DefSettings
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One of the extra Shortcuts bars (2026-11-04): a window of its own ("Shortcuts 2" ... "Shortcuts 4",
|
||||
/// the engine remembers its place, size and whether it shows), with slots of its own, filled as the
|
||||
/// main bar's own slots are (drag an item from the pack, the selected item, one of your spells) and
|
||||
/// clicked the same way. Its slots have no keys: the keys are the main bar's ("/rdef use N").
|
||||
/// Per character, with the main bar's slots.
|
||||
///
|
||||
/// At most <see cref="Max"/>: the engine hosts at most 8 windows per plugin (SectionManifest.MaxWindows,
|
||||
/// later ones are dropped without a word) and RynthDefective already draws 4 (the bar, Game Panels,
|
||||
/// Selection, Corpses). 4 extra bars of up to 24 slots are 96 slots more than the game's 18 and the
|
||||
/// main bar's 24.
|
||||
/// </summary>
|
||||
internal sealed class ExtraBar
|
||||
{
|
||||
public const int Max = 3, FirstNumber = 2, LastNumber = FirstNumber + Max - 1;
|
||||
public const int SlotsMin = 1, SlotsMax = 24, DefaultSlots = 10;
|
||||
|
||||
/// <summary>Its number, <see cref="FirstNumber"/>-<see cref="LastNumber"/> (the main bar is 1): its window's title and id.</summary>
|
||||
public int Number;
|
||||
/// <summary>How many slots it shows (<see cref="SlotsMin"/>-<see cref="SlotsMax"/>).</summary>
|
||||
public int SlotCount = DefaultSlots;
|
||||
/// <summary>Always <see cref="SlotsMax"/> entries: fewer slots hides them, it doesn't forget them.</summary>
|
||||
public List<DefSlot> Slots = NewSlots();
|
||||
|
||||
public ExtraBar(int number) => Number = number;
|
||||
|
||||
/// <summary>"Shortcuts 2": the window's title (the engine's key for its place, size and open state).</summary>
|
||||
public static string TitleOf(int number) => "Shortcuts " + number.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary>"window:bar2": the surface its window draws (RynthPluginRenderEmbed).</summary>
|
||||
public static string SurfaceOf(int number) => "window:bar" + number.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
public static bool ValidNumber(int number) => number >= FirstNumber && number <= LastNumber;
|
||||
|
||||
public string Title => TitleOf(Number);
|
||||
|
||||
/// <summary>How many of its slots (all of them, shown or not) hold an item or a spell.</summary>
|
||||
public int Filled
|
||||
{
|
||||
get
|
||||
{
|
||||
int n = 0;
|
||||
foreach (DefSlot s in Slots) if (!s.Empty) n++;
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<DefSlot> NewSlots()
|
||||
{
|
||||
var l = new List<DefSlot>(SlotsMax);
|
||||
for (int i = 0; i < SlotsMax; i++) l.Add(new DefSlot());
|
||||
return l;
|
||||
}
|
||||
|
||||
/// <summary>Pads or cuts the slot list to the fixed length; the count into its range.</summary>
|
||||
public void Fix()
|
||||
{
|
||||
while (Slots.Count < SlotsMax) Slots.Add(new DefSlot());
|
||||
if (Slots.Count > SlotsMax) Slots.RemoveRange(SlotsMax, Slots.Count - SlotsMax);
|
||||
SlotCount = Math.Clamp(SlotCount, SlotsMin, SlotsMax);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>One character's slots, favourites, recent weapons and settings.</summary>
|
||||
internal sealed class DefData
|
||||
{
|
||||
|
|
@ -142,6 +216,31 @@ internal sealed class DefData
|
|||
public List<ItemRef> Favourites = new();
|
||||
/// <summary>The weapons wielded from the picker or a slot, newest first.</summary>
|
||||
public List<ItemRef> Recent = new();
|
||||
/// <summary>The extra Shortcuts bars (2026-11-04), by number; at most <see cref="ExtraBar.Max"/>, none by default.</summary>
|
||||
public List<ExtraBar> ExtraBars = new();
|
||||
|
||||
/// <summary>Extra bar <paramref name="number"/>, or null.</summary>
|
||||
public ExtraBar? Extra(int number) => ExtraBars.Find(b => b.Number == number);
|
||||
|
||||
/// <summary>
|
||||
/// Adds an extra bar with the lowest free number (a removed bar's number is used again, so its window
|
||||
/// comes back where it was). Returns it, or null at <see cref="ExtraBar.Max"/>.
|
||||
/// </summary>
|
||||
public ExtraBar? AddExtraBar()
|
||||
{
|
||||
for (int n = ExtraBar.FirstNumber; n <= ExtraBar.LastNumber; n++)
|
||||
{
|
||||
if (Extra(n) != null) continue;
|
||||
var bar = new ExtraBar(n);
|
||||
ExtraBars.Add(bar);
|
||||
ExtraBars.Sort((a, b) => a.Number.CompareTo(b.Number));
|
||||
return bar;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Removes extra bar <paramref name="number"/> and forgets its slots. False when there is none.</summary>
|
||||
public bool RemoveExtraBar(int number) => ExtraBars.RemoveAll(b => b.Number == number) > 0;
|
||||
|
||||
public static List<DefSlot> NewSlots()
|
||||
{
|
||||
|
|
@ -177,7 +276,7 @@ internal sealed class DefData
|
|||
if (Recent.Count > MaxRecent) Recent.RemoveRange(MaxRecent, Recent.Count - MaxRecent);
|
||||
}
|
||||
|
||||
/// <summary>The slot (1-based number) that holds an item of this identity, or 0.</summary>
|
||||
/// <summary>The slot (1-based number) of the main bar's own slots that holds an item of this identity, or 0.</summary>
|
||||
public int SlotOf(ItemRef r)
|
||||
{
|
||||
for (int i = 0; i < Slots.Count; i++)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,21 @@ internal static class DefReplies
|
|||
_ => (false, $"This RynthCore has no {title} window (it needs plugin API v90)."),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// /rdef daynight [show|hide]: the Day/Night timer after it (<paramref name="state"/> as <see cref="Window"/>),
|
||||
/// then the time now when the clock can be read (null = not in world): "Day/Night timer shown. Night now
|
||||
/// (Evensong); day in 23m of real time."
|
||||
/// </summary>
|
||||
public static (bool Ok, string Text) DayNight(int state, DerethNow? now)
|
||||
{
|
||||
string time = now is { } n
|
||||
? $" {(n.IsDay ? "Day" : "Night")} now ({n.HourName}); {n.Next.ToLowerInvariant()} in {DerethClock.Countdown(n.SecondsToChange)} of real time."
|
||||
: "";
|
||||
return state < 0
|
||||
? (false, "This RynthCore has no Day/Night timer window (it needs plugin API v90)." + time)
|
||||
: (true, CommandReply.Shown("Day/Night timer", state == 1) + time);
|
||||
}
|
||||
|
||||
/// <summary>A slot's use started (the result shows on the bar; a problem is said in chat).</summary>
|
||||
public static string UseSlot(DefSlot slot, int number) => slot.IsSpell
|
||||
? $"Casting {slot.SpellLabel} (slot {number})."
|
||||
|
|
@ -45,6 +60,13 @@ internal static class DefReplies
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>"/rdef shortcuts clearbusy [on|off]": what the option is now.</summary>
|
||||
public static string ClearBusy(bool on) => on
|
||||
? "Shortcuts clear a stuck busy state: on. A press held only by the client's busy count (nothing of RynthDefective's or "
|
||||
+ "RynthAi's in flight, no animation, no 'too busy' from the server just now) resets the count as /ra clearbusy does, then goes."
|
||||
: "Shortcuts clear a stuck busy state: off (the default). A busy count left by a death or a login holds a press for up to 4 s, "
|
||||
+ "then is ignored; the count itself is left alone.";
|
||||
|
||||
/// <summary>"/rdef selection stack" with no stack in the pack.</summary>
|
||||
public const string NoStack = "No stack in your pack to select.";
|
||||
|
||||
|
|
|
|||
|
|
@ -69,35 +69,58 @@ internal sealed class DefStore
|
|||
st.WeaponsButtonOnBar = Bool(s, "weaponsButtonOnBar", st.WeaponsButtonOnBar); // missing (a file from before 2026-10-29): off
|
||||
st.IndependentBar = Bool(s, "independentBar", st.IndependentBar); // missing (a file from before 2026-10-27): off
|
||||
st.QuantityBox = Bool(s, "quantityBox", st.QuantityBox); // missing (a file from before 2026-10-30): on
|
||||
st.ClearStuckBusy = Bool(s, "clearStuckBusy", st.ClearStuckBusy); // missing (a file from before 2026-11-04): off
|
||||
st.BarOpen = Bool(s, "barOpen", st.BarOpen);
|
||||
st.PickerOpen = Bool(s, "pickerOpen", st.PickerOpen);
|
||||
st.Clamp();
|
||||
}
|
||||
|
||||
if (root.TryGetProperty("slots", out JsonElement slots) && slots.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (JsonElement e in slots.EnumerateArray())
|
||||
{
|
||||
if (i >= DefSettings.SlotsMax) break;
|
||||
DefSlot slot = d.Slots[i++];
|
||||
if (e.ValueKind != JsonValueKind.Object) continue;
|
||||
slot.Item = ParseRef(e, "item");
|
||||
int mode = Int(e, "mode", 0);
|
||||
slot.Mode = mode >= 0 && mode <= (int)UseMode.Equip ? (UseMode)mode : UseMode.Auto;
|
||||
// A spell (2026-10-28; a file from before has none): only in a slot without an item.
|
||||
if (slot.Item == null && e.TryGetProperty("spell", out JsonElement sp) && sp.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
slot.SpellId = UInt(sp, "id");
|
||||
slot.SpellName = slot.SpellId != 0 ? Str(sp, "name") : string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (root.TryGetProperty("slots", out JsonElement slots)) ParseSlots(slots, d.Slots);
|
||||
ParseRefs(root, "favourites", d.Favourites, DefData.MaxFavourites);
|
||||
ParseRefs(root, "recent", d.Recent, DefData.MaxRecent);
|
||||
|
||||
// The extra bars (2026-11-04; a file from before has none): a bad entry, a number out of range or
|
||||
// seen before, is skipped; at most ExtraBar.Max.
|
||||
if (root.TryGetProperty("extraBars", out JsonElement bars) && bars.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
foreach (JsonElement e in bars.EnumerateArray())
|
||||
{
|
||||
if (d.ExtraBars.Count >= ExtraBar.Max) break;
|
||||
if (e.ValueKind != JsonValueKind.Object) continue;
|
||||
int number = Int(e, "number", 0);
|
||||
if (!ExtraBar.ValidNumber(number) || d.Extra(number) != null) continue;
|
||||
var bar = new ExtraBar(number) { SlotCount = Int(e, "slotCount", ExtraBar.DefaultSlots) };
|
||||
if (e.TryGetProperty("slots", out JsonElement bs)) ParseSlots(bs, bar.Slots);
|
||||
bar.Fix();
|
||||
d.ExtraBars.Add(bar);
|
||||
}
|
||||
d.ExtraBars.Sort((a, b) => a.Number.CompareTo(b.Number));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
/// <summary>A "slots" array into <paramref name="into"/> (fixed length: the extra entries are ignored).</summary>
|
||||
private static void ParseSlots(JsonElement slots, List<DefSlot> into)
|
||||
{
|
||||
if (slots.ValueKind != JsonValueKind.Array) return;
|
||||
int i = 0;
|
||||
foreach (JsonElement e in slots.EnumerateArray())
|
||||
{
|
||||
if (i >= into.Count) break;
|
||||
DefSlot slot = into[i++];
|
||||
if (e.ValueKind != JsonValueKind.Object) continue;
|
||||
slot.Item = ParseRef(e, "item");
|
||||
int mode = Int(e, "mode", 0);
|
||||
slot.Mode = mode >= 0 && mode <= (int)UseMode.Equip ? (UseMode)mode : UseMode.Auto;
|
||||
// A spell (2026-10-28; a file from before has none): only in a slot without an item.
|
||||
if (slot.Item == null && e.TryGetProperty("spell", out JsonElement sp) && sp.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
slot.SpellId = UInt(sp, "id");
|
||||
slot.SpellName = slot.SpellId != 0 ? Str(sp, "name") : string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ParseRefs(JsonElement root, string name, List<ItemRef> into, int max)
|
||||
{
|
||||
if (!root.TryGetProperty(name, out JsonElement arr) || arr.ValueKind != JsonValueKind.Array) return;
|
||||
|
|
@ -168,26 +191,12 @@ internal sealed class DefStore
|
|||
w.WriteBoolean("weaponsButtonOnBar", s.WeaponsButtonOnBar);
|
||||
w.WriteBoolean("independentBar", s.IndependentBar);
|
||||
w.WriteBoolean("quantityBox", s.QuantityBox);
|
||||
w.WriteBoolean("clearStuckBusy", s.ClearStuckBusy);
|
||||
w.WriteBoolean("barOpen", s.BarOpen);
|
||||
w.WriteBoolean("pickerOpen", s.PickerOpen);
|
||||
w.WriteEndObject();
|
||||
|
||||
w.WriteStartArray("slots");
|
||||
foreach (DefSlot slot in d.Slots)
|
||||
{
|
||||
w.WriteStartObject();
|
||||
if (slot.Item != null) WriteRef(w, "item", slot.Item);
|
||||
else if (slot.SpellId != 0)
|
||||
{
|
||||
w.WriteStartObject("spell");
|
||||
w.WriteNumber("id", slot.SpellId);
|
||||
w.WriteString("name", slot.SpellLabel);
|
||||
w.WriteEndObject();
|
||||
}
|
||||
w.WriteNumber("mode", (int)slot.Mode);
|
||||
w.WriteEndObject();
|
||||
}
|
||||
w.WriteEndArray();
|
||||
WriteSlots(w, d.Slots);
|
||||
|
||||
w.WriteStartArray("favourites");
|
||||
foreach (ItemRef r in d.Favourites) WriteRefValue(w, r);
|
||||
|
|
@ -195,11 +204,42 @@ internal sealed class DefStore
|
|||
w.WriteStartArray("recent");
|
||||
foreach (ItemRef r in d.Recent) WriteRefValue(w, r);
|
||||
w.WriteEndArray();
|
||||
|
||||
w.WriteStartArray("extraBars");
|
||||
foreach (ExtraBar bar in d.ExtraBars)
|
||||
{
|
||||
w.WriteStartObject();
|
||||
w.WriteNumber("number", bar.Number);
|
||||
w.WriteNumber("slotCount", bar.SlotCount);
|
||||
WriteSlots(w, bar.Slots);
|
||||
w.WriteEndObject();
|
||||
}
|
||||
w.WriteEndArray();
|
||||
w.WriteEndObject();
|
||||
}
|
||||
return Encoding.UTF8.GetString(ms.ToArray()) + "\n";
|
||||
}
|
||||
|
||||
private static void WriteSlots(Utf8JsonWriter w, List<DefSlot> slots)
|
||||
{
|
||||
w.WriteStartArray("slots");
|
||||
foreach (DefSlot slot in slots)
|
||||
{
|
||||
w.WriteStartObject();
|
||||
if (slot.Item != null) WriteRef(w, "item", slot.Item);
|
||||
else if (slot.SpellId != 0)
|
||||
{
|
||||
w.WriteStartObject("spell");
|
||||
w.WriteNumber("id", slot.SpellId);
|
||||
w.WriteString("name", slot.SpellLabel);
|
||||
w.WriteEndObject();
|
||||
}
|
||||
w.WriteNumber("mode", (int)slot.Mode);
|
||||
w.WriteEndObject();
|
||||
}
|
||||
w.WriteEndArray();
|
||||
}
|
||||
|
||||
private static void WriteRef(Utf8JsonWriter w, string name, ItemRef r)
|
||||
{
|
||||
w.WritePropertyName(name);
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public static unsafe class PluginExports
|
|||
catch { return IntPtr.Zero; }
|
||||
}
|
||||
|
||||
/// <summary>The bar's and the panel buttons' window bodies ("window:bar", "window:panels"; ":popout" when popped out). 1 drawn, 0 not ready, -2 failed.</summary>
|
||||
/// <summary>The bar's and the panel buttons' window bodies ("window:bar", "window:panels", the extra bars' "window:bar2" ...; ":popout" when popped out). 1 drawn, 0 not ready, -2 failed.</summary>
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginRenderEmbed", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static int RenderEmbed(byte* surface, float width, float height, float* wantWidth, float* wantHeight)
|
||||
{
|
||||
|
|
@ -106,6 +106,8 @@ public static unsafe class PluginExports
|
|||
else if (name == RynthDefectivePlugin.PanelsSurface) result = plugin.RenderPanels(out wantH);
|
||||
else if (name == RynthDefectivePlugin.SelectionSurface) result = plugin.RenderSelection(out wantH);
|
||||
else if (name == RynthDefectivePlugin.CorpsesSurface) result = plugin.RenderCorpses(out wantH);
|
||||
else if (name == RynthDefectivePlugin.DayNightSurface) result = plugin.RenderDayNight(out wantH);
|
||||
else if (RynthDefectivePlugin.TryExtraSurface(name, out int extra)) result = plugin.RenderExtraBar(extra, popped, out wantH);
|
||||
else return 0;
|
||||
if (result != 1) return result;
|
||||
if (wantWidth != null) *wantWidth = width;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,17 @@ all three go.
|
|||
game's toolbar and its keys are not changed. Turning it off shows the game's 18 first again, RynthDefective's
|
||||
slot 1 at 19.
|
||||
|
||||
* **More bars** (up to 4: *Shortcuts 2* to *Shortcuts 5*): *Add a shortcut bar* in the bar's right-click menu
|
||||
(or Defective Settings, or `/rdef bars add`) opens another bar in a window of its own, to put anywhere: drag
|
||||
its title to move it, its edge to fit more slots in a row. Each has its own slots (10 to start, 1-24 with the
|
||||
edit button's - / + or the settings' slider), filled as the bar's own slots are: drag an item from the pack
|
||||
onto a slot, or right-click it for *Put the selected item here* or *Put a spell here...*. A click uses the
|
||||
item one-touch, as on the bar. Their slots have no keys (keys go on the bar's own slots). The engine remembers
|
||||
each bar's place, size and whether it shows; the slots are kept per character with the others. They have no
|
||||
RynthCore bar button: the Shortcuts bar's right-click menu shows or hides each, and removes one (*Remove a
|
||||
bar*, or *Remove this bar* in that bar's own menu; a bar that holds something asks once more, and its slots
|
||||
are forgotten). Why 4: the engine hosts at most 8 windows for a plugin, and RynthDefective draws 4 others.
|
||||
|
||||
On an older engine the bar below is a script window, with its settings under its *Settings* button.
|
||||
|
||||
## What it does
|
||||
|
|
@ -108,6 +119,16 @@ number (the game gets no keys while the box has the keyboard) or pick 1, 10, 100
|
|||
`/rdef buy` (below). It doesn't need the Inventory panel or RynthInventory.
|
||||
* Retail AC kept this number in its toolbar; RynthCore's *Hide retail toolbar* hides it with the toolbar.
|
||||
|
||||
## The Day/Night timer
|
||||
|
||||
A one-row window (its RynthCore bar button is the sun; `/rdef daynight [show|hide]`; Settings > UI > Toolbar >
|
||||
*Day/Night timer*): a sun by day, a moon at night, and the **real** time until the next change, "Night in 23m",
|
||||
"Day in 4m 10s" (seconds from 10 minutes down), with the Dereth hour's name when there is room. A Dereth day is
|
||||
16 hours of 476.25 s, 2 h 7 min of real time: day (Dawnsong to Warmtide-and-Half) and night (Evensong to
|
||||
Foredawn-and-Half) are 63.5 real minutes each; the clock and calendar are RynthAi's meta expressions'
|
||||
(`getisday`, `getminutesuntilnight`). It shows "—" until you're in the world: the game clock isn't read before.
|
||||
`/rdef daynight` also says the time in chat. Drag it anywhere; Ctrl+wheel resizes it; right-click hides it.
|
||||
|
||||
## Busy, combat and RynthAi
|
||||
|
||||
* One item action at a time: a request waits while the client is busy, a gesture animates, RynthAi waits on
|
||||
|
|
@ -118,8 +139,18 @@ number (the game gets no keys while the box has the keyboard) or pick 1, 10, 100
|
|||
up with nothing in flight after a death, a login or an interrupted action (and RynthAi's "waiting on the
|
||||
server" with it). A count that hasn't moved for 4 s with nothing of RynthDefective's in flight, a gesture
|
||||
that has "animated" for 4 s, or RynthAi's bit on for 5.5 s holds nothing (logged once); only a count above
|
||||
that leftover holds again. RynthDefective never resets the count itself (the engine owns it). If the server
|
||||
really is busy it answers "You're too busy" and the use is tried once more a second later.
|
||||
that leftover holds again. RynthDefective doesn't reset the count itself (the engine owns it) unless you turn
|
||||
on the option below. If the server really is busy it answers "You're too busy" and the use is tried once more
|
||||
a second later.
|
||||
* **Shortcuts clear a stuck busy state** (Defective Settings, `/rdef shortcuts clearbusy on|off`; per character,
|
||||
off by default): a press held only by the client's busy count, with nothing of RynthDefective's in flight or
|
||||
unanswered, no animation, RynthAi with no action of its own out, and no "You're too busy" from the server in
|
||||
the last 5 s, resets the count as RynthAi's `/ra clearbusy` does (the engine's busy-count reset; not its
|
||||
*stop moving*), then the item is used: once per press, logged. Off by default because a reset also wipes
|
||||
actions the server hasn't answered that RynthDefective can't see (a click in the game's own windows, its own
|
||||
toolbar keys, another plugin's), and their late answers then take the count below zero (the engine repairs
|
||||
that after 2 s); RynthAi stopped resetting the count for that reason. With it off a leftover holds a press
|
||||
for at most 4 s.
|
||||
* A key pressed in portal space (a death's too) is not kept for later: it says so.
|
||||
* After a wield from a fighting stance the stance follows the weapon (wand: magic, melee weapon: melee,
|
||||
launcher with ammunition in hand: missile) once the character is still. At peace you stay at peace. A bow
|
||||
|
|
@ -142,11 +173,15 @@ number (the game gets no keys while the box has the keyboard) or pick 1, 10, 100
|
|||
/rdef weapons [search] show the weapon picker
|
||||
/rdef fav make the selected weapon a favourite (or take it out)
|
||||
/rdef slots <n> how many slots the script-window bar shows (1-24)
|
||||
/rdef bars the extra Shortcuts bars; /rdef bars add | remove <2-5> | slots <2-5> <1-24> |
|
||||
show <2-5> (show or hide it)
|
||||
/rdef shortcuts clearbusy [on|off] a press held only by a stuck busy count clears it first (off by default)
|
||||
/rdef qty [n | max | half] the quantity box's number (alone: what it is and what it's of)
|
||||
/rdef split [n] [into <pack>] split n (or the box's number) off the selected stack; pack: main, a side
|
||||
pack's name, or open (the chest you have open)
|
||||
/rdef give [n] give n of the selected stack to the last player or NPC you selected
|
||||
/rdef buy [n] [item name] buy n of the selected vendor item (or the one named) from the open vendor
|
||||
/rdef daynight [show | hide] show / hide the Day/Night timer (alone: toggle); says the time now
|
||||
/rdef list | status | help
|
||||
```
|
||||
|
||||
|
|
@ -156,8 +191,10 @@ slot N is bar slot 18+N, or bar slot N when the bar is independent of the game's
|
|||
## Settings
|
||||
|
||||
Shortcuts bar: the windows shown, the quantity box under the selection (on by default), independent of the
|
||||
game's toolbar, slot picture size, allow weapon swaps under RynthAi, picker row icon size. Script-window bar: slots (1-24), slots per row, button size, picker row
|
||||
icon size, item icons on/off, counts and keys on/off, allow weapon swaps under RynthAi. Kept per character
|
||||
game's toolbar, slot picture size, shortcuts clear a stuck busy state (off by default), the extra bars (shown,
|
||||
slots, remove, add), allow weapon swaps under RynthAi, picker row icon size. Script-window bar: slots (1-24), slots per row, button size, picker row
|
||||
icon size, item icons on/off, counts and keys on/off, allow weapon swaps under RynthAi, shortcuts clear a stuck
|
||||
busy state. Kept per character
|
||||
with the slots, favourites and recent weapons in
|
||||
`<RynthSuite>\RynthDefective\characters\<server>_<character>.json`.
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
pictures) are checked first; so are the UseDone count (v63), wield/refusal info (v70) and
|
||||
the chat parser the key binding goes through. Below v71 it still uses items (/rdef use). -->
|
||||
<RynthPluginMinEngineApi>66</RynthPluginMinEngineApi>
|
||||
<RynthPluginDescription>Draws the Shortcuts bar (the game's 18 slots and its own), the Game Panels buttons and the Selection window (with a quantity box: split, give or buy that many): one-touch kits, potions, weapons and spells by slot or key, and a fast weapon picker. Settings: the bar's gear or /rdef settings.</RynthPluginDescription>
|
||||
<RynthPluginDescription>Draws the Shortcuts bar (the game's 18 slots and its own), the Game Panels buttons and the Selection window (with a quantity box: split, give or buy that many), and a Day/Night timer: one-touch kits, potions, weapons and spells by slot or key, and a fast weapon picker. Settings: the bar's gear or /rdef settings.</RynthPluginDescription>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -44,6 +44,8 @@
|
|||
<Compile Include="..\Shared\RynthInstallPaths.cs" Link="Shared\RynthInstallPaths.cs" />
|
||||
<!-- How a chat command answers (2026-10-28): the shared reply queue and colours. -->
|
||||
<Compile Include="..\Shared\CommandReply.cs" Link="Shared\CommandReply.cs" />
|
||||
<!-- Dereth's clock (2026-11-04): day or night and the real time to the change, for the Day/Night timer. -->
|
||||
<Compile Include="..\Shared\DerethClock.cs" Link="Shared\DerethClock.cs" />
|
||||
<!-- The active server (plugin API v86 GetServerStateJson) and its owner's "RynthServer.Profile"
|
||||
values (2026-10-31): whether its bank pays vendors, and how much, for the quantity box's buys. -->
|
||||
<Compile Include="..\Shared\EngineServerState.cs" Link="Shared\EngineServerState.cs" />
|
||||
|
|
|
|||
|
|
@ -14,11 +14,21 @@
|
|||
//
|
||||
// The tick: the window's clicks (queued from the render thread), the snapshot
|
||||
// it draws (4 times a second while it shows).
|
||||
//
|
||||
// Extra bars (2026-11-04, Model/DefData.cs ExtraBar): up to 4 more windows,
|
||||
// "Shortcuts 2" ... "Shortcuts 4", each with slots of its own (no AC slots, no
|
||||
// keys), drawn by the same ShortcutBarWindow class. They are in the manifest
|
||||
// while a character with them is logged in (the engine hosts them then, and
|
||||
// remembers each one's place, size and open state by its title); a new one
|
||||
// is opened once the engine hosts it (the manifest is read every ~2 s). No
|
||||
// RynthCore bar button: the Shortcuts bar's menu and the settings show them.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using RynthCore.Plugin.RynthDefective.Items;
|
||||
using RynthCore.Plugin.RynthDefective.Model;
|
||||
using RynthCore.Plugin.RynthDefective.ShortcutBar;
|
||||
using RynthCore.Plugin.Shared.RynthUi;
|
||||
|
|
@ -39,6 +49,26 @@ public sealed partial class RynthDefectivePlugin : IBarActions
|
|||
private long _barDrawnMs = long.MinValue / 2, _nextBarBuildMs;
|
||||
private int _barFailures;
|
||||
|
||||
// The extra bars, by number - ExtraBar.FirstNumber.
|
||||
private readonly ShortcutBarWindow?[] _extraWindows = new ShortcutBarWindow?[ExtraBar.Max]; // render thread
|
||||
private readonly ExtraBarActions?[] _extraActions = new ExtraBarActions?[ExtraBar.Max]; // render thread
|
||||
private readonly BarSnapshot[] _extraViews = NotReadyViews(); // tick writes, render reads (Volatile)
|
||||
private readonly long[] _extraDrawnMs = { long.MinValue / 2, long.MinValue / 2, long.MinValue / 2, long.MinValue / 2 };
|
||||
private readonly int[] _extraFailures = new int[ExtraBar.Max];
|
||||
/// <summary>The extra bars the manifest lists (the logged-in character's); empty when nobody is. Tick writes, any thread reads.</summary>
|
||||
private volatile int[] _extraNumbers = Array.Empty<int>();
|
||||
/// <summary>Extra bars to open once the engine hosts their window, and until when to try (tick only).</summary>
|
||||
private readonly Dictionary<int, long> _openWhenHosted = new();
|
||||
private const long OpenWhenHostedMs = 8000;
|
||||
private long _nextOpenTryMs;
|
||||
|
||||
private static BarSnapshot[] NotReadyViews()
|
||||
{
|
||||
var a = new BarSnapshot[ExtraBar.Max];
|
||||
Array.Fill(a, BarSnapshot.NotReady);
|
||||
return a;
|
||||
}
|
||||
|
||||
/// <summary>The engine has v90's shortcuts and frameless windows: the new bar, not the script window one.</summary>
|
||||
internal bool UsesShortcutBar => Host.HasShortcuts && Host.HasFramelessWindows;
|
||||
|
||||
|
|
@ -69,7 +99,62 @@ public sealed partial class RynthDefectivePlugin : IBarActions
|
|||
"\",\"icon\":\"\\u" + ((int)RynthIcons.Skull[0]).ToString("X4", CultureInfo.InvariantCulture) +
|
||||
"\",\"width\":290,\"height\":80,\"minWidth\":140,\"minHeight\":30,\"bar\":true,\"edgeToEdge\":true," +
|
||||
"\"chrome\":\"none\",\"fitHeight\":true,\"scale\":\"draw\"}";
|
||||
return "{\"version\":1,\"windows\":[" + bar + panels + selection + corpses + "]}";
|
||||
// Day or night and the real minutes to the change (a bar button of its own; one row, any width).
|
||||
string dayNight = ",{\"id\":\"daynight\",\"title\":\"" + Clock.DayNightWindow.Title + "\",\"surface\":\"" + DayNightSurface +
|
||||
"\",\"icon\":\"\\u" + ((int)RynthIcons.Sun[0]).ToString("X4", CultureInfo.InvariantCulture) +
|
||||
"\",\"width\":150,\"height\":26,\"minWidth\":70,\"minHeight\":20,\"bar\":true,\"edgeToEdge\":true," +
|
||||
"\"chrome\":\"none\",\"fitHeight\":true,\"scale\":\"draw\"}";
|
||||
// The extra bars (the engine hosts at most 8 windows for a plugin: these five and up to three of them).
|
||||
string extras = "";
|
||||
foreach (int n in _extraNumbers)
|
||||
extras += ",{\"id\":\"bar" + n.ToString(CultureInfo.InvariantCulture) + "\",\"title\":\"" + ExtraBar.TitleOf(n) + "\",\"surface\":\""
|
||||
+ ExtraBar.SurfaceOf(n) + "\",\"icon\":\"\\u" + ((int)RynthIcons.Lightning[0]).ToString("X4", CultureInfo.InvariantCulture) +
|
||||
"\",\"width\":300,\"height\":80,\"minWidth\":90,\"minHeight\":40,\"bar\":false,\"edgeToEdge\":true," +
|
||||
"\"chrome\":\"none\",\"fitHeight\":true,\"scale\":\"draw\"}";
|
||||
return "{\"version\":1,\"windows\":[" + bar + panels + selection + corpses + dayNight + extras + "]}";
|
||||
}
|
||||
|
||||
/// <summary>"window:bar2" ... "window:bar4": an extra bar's surface, and its number.</summary>
|
||||
internal static bool TryExtraSurface(string surface, out int number)
|
||||
{
|
||||
number = 0;
|
||||
const string prefix = "window:bar";
|
||||
if (surface.Length != prefix.Length + 1 || !surface.StartsWith(prefix, StringComparison.Ordinal)) return false;
|
||||
number = surface[^1] - '0';
|
||||
return ExtraBar.ValidNumber(number);
|
||||
}
|
||||
|
||||
/// <summary>The extra bars' numbers for the manifest, from the logged-in character's data (empty when nobody is).</summary>
|
||||
private void RefreshExtraNumbers()
|
||||
{
|
||||
if (!_identityKnown) { _extraNumbers = Array.Empty<int>(); return; }
|
||||
var list = _session.Data.ExtraBars;
|
||||
var a = new int[list.Count];
|
||||
for (int i = 0; i < a.Length; i++) a[i] = list[i].Number;
|
||||
_extraNumbers = a;
|
||||
for (int i = 0; i < ExtraBar.Max; i++)
|
||||
if (Array.IndexOf(a, i + ExtraBar.FirstNumber) < 0) System.Threading.Volatile.Write(ref _extraViews[i], BarSnapshot.NotReady);
|
||||
}
|
||||
|
||||
/// <summary>RynthPluginRenderEmbed "window:barN" (an extra bar). 1 drawn, 0 not ready, -2 failed (three in a row). Render thread.</summary>
|
||||
internal int RenderExtraBar(int number, bool popped, out float wantHeight)
|
||||
{
|
||||
wantHeight = 0;
|
||||
if (!UsesShortcutBar || !ExtraBar.ValidNumber(number)) return 0;
|
||||
int i = number - ExtraBar.FirstNumber;
|
||||
System.Threading.Volatile.Write(ref _extraDrawnMs[i], Environment.TickCount64);
|
||||
try
|
||||
{
|
||||
_extraWindows[i] ??= new ShortcutBarWindow(Host, _extraActions[i] ??= new ExtraBarActions(this, number), ExtraBar.TitleOf(number));
|
||||
wantHeight = _extraWindows[i]!.Draw(System.Threading.Volatile.Read(ref _extraViews[i]), popped);
|
||||
_extraFailures[i] = 0;
|
||||
return 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Host.Log($"[RynthDefective] shortcut bar {number} draw failed: {ex.GetType().Name}: {ex.Message}");
|
||||
return ++_extraFailures[i] >= 3 ? -2 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>RynthPluginRenderEmbed "window:panels". 1 drawn, 0 not ready, -2 failed (three in a row). Render thread.</summary>
|
||||
|
|
@ -120,11 +205,50 @@ public sealed partial class RynthDefectivePlugin : IBarActions
|
|||
catch (Exception ex) { Host.Log($"[RynthDefective] bar action failed: {ex.GetType().Name}: {ex.Message}"); }
|
||||
}
|
||||
if (!UsesShortcutBar || !_identityKnown) return;
|
||||
TickOpenBars(now);
|
||||
if (now < _nextBarBuildMs) return;
|
||||
bool shown = now - System.Threading.Volatile.Read(ref _barDrawnMs) < 2000;
|
||||
if (!shown || now < _nextBarBuildMs) return;
|
||||
int[] extras = _extraNumbers;
|
||||
bool extraShown = false;
|
||||
foreach (int n in extras) extraShown |= ExtraShown(n, now);
|
||||
if (!shown && !extraShown) return;
|
||||
_nextBarBuildMs = now + 250;
|
||||
_barBuilder ??= new BarSnapshotBuilder(Host);
|
||||
_barView = _barBuilder.Build(_session, _session.Items(), now);
|
||||
IReadOnlyList<CarriedItem> items = _session.Items();
|
||||
if (shown)
|
||||
{
|
||||
_barBuilder ??= new BarSnapshotBuilder(Host);
|
||||
_barView = _barBuilder.Build(_session, items, now);
|
||||
}
|
||||
foreach (int n in extras)
|
||||
if (ExtraShown(n, now))
|
||||
System.Threading.Volatile.Write(ref _extraViews[n - ExtraBar.FirstNumber], BarSnapshotBuilder.BuildExtra(_session, n, items, Host.HasCastSpell));
|
||||
}
|
||||
|
||||
/// <summary>Extra bar <paramref name="number"/>'s window was drawn in the last 2 s.</summary>
|
||||
private bool ExtraShown(int number, long now) =>
|
||||
ExtraBar.ValidNumber(number) && now - System.Threading.Volatile.Read(ref _extraDrawnMs[number - ExtraBar.FirstNumber]) < 2000;
|
||||
|
||||
/// <summary>Any extra bar shows (the inventory is kept fresh for it).</summary>
|
||||
private bool AnyExtraShown(long now)
|
||||
{
|
||||
foreach (int n in _extraNumbers) if (ExtraShown(n, now)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Opens the extra bars just added (or asked for) once the engine hosts their windows.</summary>
|
||||
private void TickOpenBars(long now)
|
||||
{
|
||||
if (_openWhenHosted.Count == 0 || now < _nextOpenTryMs) return;
|
||||
_nextOpenTryMs = now + 250;
|
||||
List<int>? done = null;
|
||||
foreach ((int n, long until) in _openWhenHosted)
|
||||
{
|
||||
bool open = Host.SetPanelOpen(ExtraBar.TitleOf(n), RynthPanelOpen.Open) >= 0;
|
||||
if (!open && now < until) continue;
|
||||
if (!open) Host.Log($"[RynthDefective] Shortcuts bar {n}: the engine didn't host its window within {OpenWhenHostedMs / 1000} s; not opened.");
|
||||
(done ??= new List<int>()).Add(n);
|
||||
}
|
||||
if (done != null) foreach (int n in done) _openWhenHosted.Remove(n);
|
||||
}
|
||||
|
||||
private void QueueBar(Action action)
|
||||
|
|
@ -132,6 +256,143 @@ public sealed partial class RynthDefectivePlugin : IBarActions
|
|||
if (_barActions.Count < 32) _barActions.Enqueue(action);
|
||||
}
|
||||
|
||||
// ── Extra bars: add, remove, show (the bars' menus, the settings window and /rdef bars) ──
|
||||
|
||||
/// <summary>Adds an extra bar; it opens once the engine hosts it. Tick only.</summary>
|
||||
private void AddExtraBar()
|
||||
{
|
||||
string text = _session.AddBar(out int n);
|
||||
if (n == 0) { PrintFail(text); return; }
|
||||
RefreshExtraNumbers();
|
||||
_openWhenHosted[n] = Environment.TickCount64 + OpenWhenHostedMs;
|
||||
_nextBarBuildMs = 0;
|
||||
Print(text);
|
||||
}
|
||||
|
||||
/// <summary>Removes extra bar <paramref name="number"/> (its window leaves with the next manifest read). Tick only.</summary>
|
||||
private void RemoveExtraBar(int number)
|
||||
{
|
||||
bool had = _session.Data.Extra(number) != null;
|
||||
string text = _session.RemoveBar(number);
|
||||
if (!had) { PrintFail(text); return; }
|
||||
_openWhenHosted.Remove(number);
|
||||
Host.SetPanelOpen(ExtraBar.TitleOf(number), RynthPanelOpen.Close); // at once: the manifest drops it at its next read
|
||||
RefreshExtraNumbers();
|
||||
_nextBarBuildMs = 0;
|
||||
Print(text);
|
||||
}
|
||||
|
||||
/// <summary>/rdef bars ...: list, add, remove N, slots N count, show N. Every one answers.</summary>
|
||||
private void RunBarsCommand(DefCommand c)
|
||||
{
|
||||
if (!UsesShortcutBar)
|
||||
{
|
||||
PrintFail("This RynthCore can't show more Shortcuts bars (they are plugin windows: plugin API v90).");
|
||||
return;
|
||||
}
|
||||
switch (c.Text)
|
||||
{
|
||||
case "add":
|
||||
AddExtraBar();
|
||||
break;
|
||||
case "remove":
|
||||
RemoveExtraBar(c.Slot);
|
||||
break;
|
||||
case "slots":
|
||||
if (_session.Data.Extra(c.Slot) == null) PrintFail(_session.SetBarSlots(c.Slot, c.Count));
|
||||
else { Print(_session.SetBarSlots(c.Slot, c.Count)); _nextBarBuildMs = 0; }
|
||||
break;
|
||||
case "show":
|
||||
if (c.Slot == 1) { Answer(DefReplies.Window("Shortcuts bar", Host.SetPanelOpen(ShortcutBarWindow.Title, RynthPanelOpen.Toggle))); break; }
|
||||
if (_session.Data.Extra(c.Slot) == null) { PrintFail($"There is no Shortcuts bar {c.Slot}. {_session.DescribeBars()}"); break; }
|
||||
int state = Host.SetPanelOpen(ExtraBar.TitleOf(c.Slot), RynthPanelOpen.Toggle);
|
||||
if (state >= 0) Answer(DefReplies.Window($"Shortcuts bar {c.Slot}", state));
|
||||
else
|
||||
{
|
||||
// Not hosted yet (just added, or the manifest not read since the login): open it when it is.
|
||||
_openWhenHosted[c.Slot] = Environment.TickCount64 + OpenWhenHostedMs;
|
||||
Print($"Shortcuts bar {c.Slot} shows in a moment.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Print(_session.DescribeBars());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What an extra bar's window asks (render thread: queue only): its own slots through the session's
|
||||
/// bar-aware slot actions; no keys; the rest is the Shortcuts bar's.
|
||||
/// </summary>
|
||||
private sealed class ExtraBarActions : IBarActions
|
||||
{
|
||||
private readonly RynthDefectivePlugin _p;
|
||||
private readonly int _bar;
|
||||
|
||||
public ExtraBarActions(RynthDefectivePlugin plugin, int bar)
|
||||
{
|
||||
_p = plugin;
|
||||
_bar = bar;
|
||||
}
|
||||
|
||||
private DefSession S => _p._session;
|
||||
|
||||
public void Use(int number) => _p.QueueBar(() =>
|
||||
{
|
||||
string? problem = S.UseSlot(number, _bar);
|
||||
if (problem != null) { S.SetStatus(problem, warning: true); _p.Print(problem); }
|
||||
});
|
||||
|
||||
public void SetFromSelected(int number) => _p.QueueBar(() => { _p.Print(S.SetFromSelected(number, _bar)); _p._nextBarBuildMs = 0; });
|
||||
|
||||
public void Clear(int number) => _p.QueueBar(() => { _p.Print(S.ClearSlot(number, _bar)); _p._nextBarBuildMs = 0; });
|
||||
|
||||
public void DropItem(int number, uint objectId) => _p.QueueBar(() => { _p.Print(S.SetFromId(number, objectId, _bar)); _p._nextBarBuildMs = 0; });
|
||||
|
||||
public void SetSpell(int number, uint spellId) => _p.QueueBar(() => { _p.Print(S.SetSpell(number, spellId, _bar)); _p._nextBarBuildMs = 0; });
|
||||
|
||||
public void ChangeSlotCount(int delta) => _p.QueueBar(() =>
|
||||
{
|
||||
ExtraBar? b = S.Data.Extra(_bar);
|
||||
if (b == null) return;
|
||||
b.SlotCount = Math.Clamp(b.SlotCount + delta, ExtraBar.SlotsMin, ExtraBar.SlotsMax);
|
||||
_p.RequestSave();
|
||||
_p._nextBarBuildMs = 0;
|
||||
});
|
||||
|
||||
public void KeysChanged() { }
|
||||
|
||||
public void ShowWeapons() => _p.ShowWeapons();
|
||||
|
||||
public void ShowSettings() => _p.ShowSettings();
|
||||
|
||||
public void Hide() => _p.QueueBar(() => _p.Host.SetPanelOpen(ExtraBar.TitleOf(_bar), RynthPanelOpen.Close));
|
||||
|
||||
public void AddBar() => _p.AddBar();
|
||||
|
||||
public void RemoveBar(int number) => _p.RemoveBar(number);
|
||||
|
||||
private const string NoKeys = "An extra Shortcuts bar's slots have no keys: keys go on the Shortcuts bar's own slots.";
|
||||
|
||||
public RynthKeyCheck CheckKey(BarSlot slot, string key, out string message)
|
||||
{
|
||||
message = NoKeys;
|
||||
return RynthKeyCheck.Invalid;
|
||||
}
|
||||
|
||||
public bool BindKey(BarSlot slot, string key, out string message)
|
||||
{
|
||||
message = NoKeys;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool UnbindKey(BarSlot slot, string key, out string message)
|
||||
{
|
||||
message = NoKeys;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Bar slot <paramref name="number"/> is one of AC's 18 (never on an independent bar).</summary>
|
||||
private bool IsRetail(int number) => BarMapping.IsRetail(number, _session.Settings.IndependentBar);
|
||||
|
||||
|
|
@ -268,4 +529,8 @@ public sealed partial class RynthDefectivePlugin : IBarActions
|
|||
public void ShowSettings() => QueueBar(() => ShowSettingsWindow(true));
|
||||
|
||||
public void Hide() => QueueBar(() => Host.SetPanelOpen(ShortcutBarWindow.Title, RynthPanelOpen.Close));
|
||||
|
||||
public void AddBar() => QueueBar(AddExtraBar);
|
||||
|
||||
public void RemoveBar(int number) => QueueBar(() => RemoveExtraBar(number));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
// ============================================================================
|
||||
// RynthDefective - RynthDefectivePlugin.DayNight.cs
|
||||
// The Day/Night timer (2026-11-04): day or night in Dereth now and the real
|
||||
// time until the next dawn or dusk (Clock/DayNightWindow.cs draws it,
|
||||
// Plugins/Shared/DerethClock.cs has the math).
|
||||
//
|
||||
// The tick reads the game clock twice a second while the window shows, and
|
||||
// only in world: the clock's address isn't readable before world entry, and
|
||||
// a fault there can't be caught (RynthAi's ReadGameClock has the same guard).
|
||||
// Before that the window shows "—".
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using RynthCore.Plugin.RynthDefective.Clock;
|
||||
using RynthCore.Plugin.Shared;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective;
|
||||
|
||||
public sealed partial class RynthDefectivePlugin
|
||||
{
|
||||
internal const string DayNightSurface = "window:daynight";
|
||||
|
||||
private DayNightWindow? _dayNightWindow; // render thread
|
||||
private volatile DayNightView _dayNightView = DayNightView.NotReady; // tick writes, render reads
|
||||
private long _dayNightDrawnMs = long.MinValue / 2, _nextDayNightMs;
|
||||
private int _dayNightFailures;
|
||||
|
||||
/// <summary>RynthPluginRenderEmbed "window:daynight". 1 drawn, 0 not ready, -2 failed (three in a row). Render thread.</summary>
|
||||
internal int RenderDayNight(out float wantHeight)
|
||||
{
|
||||
wantHeight = 0;
|
||||
if (!UsesShortcutBar) return 0;
|
||||
System.Threading.Volatile.Write(ref _dayNightDrawnMs, Environment.TickCount64);
|
||||
try
|
||||
{
|
||||
_dayNightWindow ??= new DayNightWindow(Host);
|
||||
wantHeight = _dayNightWindow.Draw(_dayNightView);
|
||||
_dayNightFailures = 0;
|
||||
return 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Host.Log($"[RynthDefective] day/night draw failed: {ex.GetType().Name}: {ex.Message}");
|
||||
return ++_dayNightFailures >= 3 ? -2 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Plugin tick: the clock's view while the window shows.</summary>
|
||||
private void TickDayNight(long now)
|
||||
{
|
||||
if (!UsesShortcutBar) return;
|
||||
if (now - System.Threading.Volatile.Read(ref _dayNightDrawnMs) > 2000 || now < _nextDayNightMs) return;
|
||||
_nextDayNightMs = now + 500;
|
||||
try { _dayNightView = ReadDayNight(now); }
|
||||
catch (Exception ex) { Host.Log($"[RynthDefective] day/night read failed: {ex.GetType().Name}: {ex.Message}"); }
|
||||
}
|
||||
|
||||
/// <summary>The clock now; NotReady out of world (never read then) or before the clock is set.</summary>
|
||||
private DayNightView ReadDayNight(long now)
|
||||
{
|
||||
if (!_inWorld || !_identityKnown || Host.GetPlayerId() == 0) return DayNightView.NotReady;
|
||||
long bits = System.Runtime.InteropServices.Marshal.ReadInt64(new IntPtr(unchecked((int)DerethClock.ClockAddress)));
|
||||
double raw = BitConverter.Int64BitsToDouble(bits);
|
||||
return DerethClock.IsUsable(raw) ? new DayNightView(true, DerethClock.At(raw), now) : DayNightView.NotReady;
|
||||
}
|
||||
}
|
||||
|
|
@ -98,6 +98,8 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
ShowWindow = (title, show) => Host.SetPanelOpen(title, show ? RynthPanelOpen.Open : RynthPanelOpen.Close),
|
||||
Tell = text => { _session.SetStatus(text); Print(text); _nextBarBuildMs = 0; },
|
||||
ShowWeapons = () => ShowPicker(true),
|
||||
AddBar = AddExtraBar,
|
||||
RemoveBar = RemoveExtraBar,
|
||||
};
|
||||
_settingsWindow = _ui.Add(new UiWindow("RynthDefective/Settings", "Defective Settings")
|
||||
{
|
||||
|
|
@ -126,12 +128,15 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
StopCorpses();
|
||||
_inWorld = false;
|
||||
_identityKnown = false;
|
||||
RefreshExtraNumbers(); // the extra bars leave with the character (the engine opens them again when they come back)
|
||||
_openWhenHosted.Clear();
|
||||
_session.LoggedIn = false;
|
||||
_session.Use.ResetSession();
|
||||
_world?.Reset();
|
||||
_qty.Reset();
|
||||
_qtyWorld?.Reset();
|
||||
_barView = RynthCore.Plugin.RynthDefective.ShortcutBar.BarSnapshot.NotReady;
|
||||
_dayNightView = Clock.DayNightView.NotReady;
|
||||
foreach (UiWindow? w in new[] { _barWindow, _pickerWindow, _settingsWindow })
|
||||
if (w != null) { w.Visible = false; w.NeedsPass = true; }
|
||||
_session.DeclineCopy();
|
||||
|
|
@ -225,6 +230,15 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
if (UsesShortcutBar) Answer(DefReplies.Window("Corpses window", Host.SetPanelOpen(Corpses.CorpsesWindow.Title, RynthPanelOpen.Toggle)));
|
||||
else PrintFail("This RynthCore can't show the corpses window (it needs plugin API v90).");
|
||||
break;
|
||||
case DefVerb.DayNight:
|
||||
{
|
||||
// The window shown or hidden, and the time now in the reply (an engine without the window: the time only).
|
||||
RynthPanelOpen mode = c.Text == "show" ? RynthPanelOpen.Open : c.Text == "hide" ? RynthPanelOpen.Close : RynthPanelOpen.Toggle;
|
||||
int state = UsesShortcutBar ? Host.SetPanelOpen(Clock.DayNightWindow.Title, mode) : -1;
|
||||
Clock.DayNightView clock = ReadDayNight(Environment.TickCount64);
|
||||
Answer(DefReplies.DayNight(state, clock.Ready ? clock.Now : null));
|
||||
break;
|
||||
}
|
||||
case DefVerb.Panels:
|
||||
if (UsesPanelButtons) Answer(DefReplies.Window("Game Panels buttons", Host.SetPanelOpen(RynthCore.Plugin.RynthDefective.ShortcutBar.PanelButtonsWindow.Title, RynthPanelOpen.Toggle)));
|
||||
else PrintFail("This RynthCore can't open the game's panels from buttons (it needs plugin API v90).");
|
||||
|
|
@ -281,6 +295,21 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
case DefVerb.Status:
|
||||
PrintStatus();
|
||||
break;
|
||||
case DefVerb.Bars:
|
||||
RunBarsCommand(c);
|
||||
break;
|
||||
case DefVerb.Shortcuts:
|
||||
{
|
||||
// Shortcuts clear a stuck busy state (per character; alone: what it is now).
|
||||
DefSettings st = _session.Settings;
|
||||
if (c.Text.Length > 0 && st.ClearStuckBusy != (c.Text == "on"))
|
||||
{
|
||||
st.ClearStuckBusy = c.Text == "on";
|
||||
RequestSave();
|
||||
}
|
||||
Print(DefReplies.ClearBusy(st.ClearStuckBusy));
|
||||
break;
|
||||
}
|
||||
case DefVerb.Quantity:
|
||||
case DefVerb.Split:
|
||||
case DefVerb.Give:
|
||||
|
|
@ -298,6 +327,9 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
if (UsesShortcutBar)
|
||||
Print("RynthDefective draws the Shortcuts bar, the Game Panels buttons and the Selection window. Its settings: /rdef settings, "
|
||||
+ "or the gear on the bar; right-click the bar's title to show or hide Game Panels and Selection.");
|
||||
if (UsesShortcutBar)
|
||||
Print($"More bars, anywhere on screen: Add a shortcut bar in the bar's right-click menu, or /rdef bars add (up to {ExtraBar.Max}); "
|
||||
+ "/rdef bars lists them, /rdef bars remove 2 takes one off.");
|
||||
Print("A key for a slot: /rdef bind 1 F9 (or Edit slots in the bar). Any item by name from Settings > Hotkeys: /rc hotkey add F9 /rdef use Stamina Kit.");
|
||||
Print("How many of a stack or a vendor's item: the box under it in the Selection window, or /rdef qty 25, then /rdef split, /rdef give "
|
||||
+ "(to the last player or NPC you selected) or /rdef buy (the selected vendor item, or /rdef buy 25 <item name>).");
|
||||
|
|
@ -330,7 +362,7 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
{
|
||||
int filled = 0;
|
||||
for (int i = 0; i < _session.Settings.SlotCount; i++) if (!_session.Data.Slots[i].Empty) filled++;
|
||||
Print($"{_character}: {filled}/{_session.Settings.SlotCount} slots set, {_session.Data.Favourites.Count} favourite weapons; "
|
||||
Print($"{_character}: {filled}/{_session.Settings.SlotCount} slots set, {_session.Data.ExtraBars.Count} extra bars, {_session.Data.Favourites.Count} favourite weapons; "
|
||||
+ $"{(_session.Use.InFlight ? "an action is in flight" : _session.Use.HasPending ? "an action is waiting" : "idle")}; file {_store.PathFor(_server, _character)}");
|
||||
}
|
||||
|
||||
|
|
@ -456,6 +488,7 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
TickSelection(now);
|
||||
TickQuantity(now);
|
||||
TickCorpses(now);
|
||||
TickDayNight(now);
|
||||
|
||||
// With the shortcut bar the old script-window bar stays shut (the weapon picker is still one), and
|
||||
// has no RynthBar button (one that opened a window shut again at once). Its settings have their
|
||||
|
|
@ -489,7 +522,8 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
/// <summary>Re-reads the inventory while a window shows or an action waits; slots follow their items.</summary>
|
||||
private void TickInventory()
|
||||
{
|
||||
bool barShown = Environment.TickCount64 - System.Threading.Volatile.Read(ref _barDrawnMs) < 2000;
|
||||
long now = Environment.TickCount64;
|
||||
bool barShown = now - System.Threading.Volatile.Read(ref _barDrawnMs) < 2000 || AnyExtraShown(now);
|
||||
bool wanted = (_barWindow?.Visible ?? false) || (_pickerWindow?.Visible ?? false) || barShown || _session.Use.HasPending;
|
||||
if (!wanted || _world == null) return;
|
||||
List<CarriedItem> items = _world.Snapshot(InventoryAgeMs);
|
||||
|
|
@ -515,6 +549,7 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
_session.Character = name;
|
||||
_session.LoggedIn = true;
|
||||
_identityKnown = true;
|
||||
RefreshExtraNumbers();
|
||||
_revisionSeen = -1;
|
||||
RefreshIconSupport();
|
||||
StartCorpses();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
// N is own slot N (BarMapping), and AC's toolbar isn't read at all.
|
||||
// An own slot can hold a spell (2026-10-28): its picture is the spell's, and
|
||||
// the snapshot carries the character's spells for the slot menu's search.
|
||||
// An extra bar (2026-11-04, ExtraBar: "Shortcuts 2" ...) is built the same
|
||||
// way from its own slots (BuildExtra): no AC slots, no keys.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
|
|
@ -57,6 +59,17 @@ internal sealed record BarSnapshot(BarSlot[] Slots, bool Ready, int IconSize, bo
|
|||
public static readonly BarSnapshot NotReady = new(Array.Empty<BarSlot>(), false, 36);
|
||||
|
||||
public IReadOnlyList<SpellInfo> KnownSpells => Spells ?? Array.Empty<SpellInfo>();
|
||||
|
||||
/// <summary>The extra bar this is (2-4; 0 = the Shortcuts bar itself): no AC slots, no keys.</summary>
|
||||
public int Bar { get; init; }
|
||||
/// <summary>The fewest and most slots the edit buttons allow.</summary>
|
||||
public int MinSlots { get; init; } = DefSettings.BarSlotsMin;
|
||||
public int MaxSlots { get; init; } = DefSettings.BarSlotsMax;
|
||||
/// <summary>The extra bars there are (number, slots holding something), for the bars' menus.</summary>
|
||||
public IReadOnlyList<(int Number, int Filled)> Extras { get; init; } = Array.Empty<(int, int)>();
|
||||
|
||||
/// <summary>Another extra bar can be added (fewer than <see cref="ExtraBar.Max"/>).</summary>
|
||||
public bool CanAddBar => Extras.Count < ExtraBar.Max;
|
||||
}
|
||||
|
||||
/// <summary>Builds the snapshot on the plugin tick (reads the host and the carried items).</summary>
|
||||
|
|
@ -94,12 +107,13 @@ internal sealed class BarSnapshotBuilder
|
|||
DefSettings st = session.Settings;
|
||||
IReadOnlyList<SpellInfo> spells = session.KnownSpells();
|
||||
bool canCast = _host.HasCastSpell;
|
||||
var extras = Extras(session);
|
||||
if (st.IndependentBar)
|
||||
{
|
||||
// Every slot is RynthDefective's own: AC's toolbar isn't read or shown (BarMapping).
|
||||
var own = new BarSlot[st.BarSlots];
|
||||
for (int n = 1; n <= st.BarSlots; n++) own[n - 1] = Own(n, BarMapping.OwnSlot(n, true), true, session, items, spells, _host);
|
||||
return new BarSnapshot(own, true, st.ButtonSize, true, spells, canCast, st.WeaponsButtonOnBar);
|
||||
return new BarSnapshot(own, true, st.ButtonSize, true, spells, canCast, st.WeaponsButtonOnBar) { Extras = extras };
|
||||
}
|
||||
if (_host.GetShortcuts(_ids, _spells) == 0) return BarSnapshot.NotReady;
|
||||
RefreshKeys(now);
|
||||
|
|
@ -109,7 +123,52 @@ internal sealed class BarSnapshotBuilder
|
|||
var slots = new BarSlot[st.BarSlots];
|
||||
for (int n = 1; n <= st.BarSlots; n++)
|
||||
slots[n - 1] = BarMapping.IsRetail(n, false) ? Retail(n, byId) : Own(n, BarMapping.OwnSlot(n, false), false, session, items, spells, _host);
|
||||
return new BarSnapshot(slots, true, st.ButtonSize, false, spells, canCast, st.WeaponsButtonOnBar);
|
||||
return new BarSnapshot(slots, true, st.ButtonSize, false, spells, canCast, st.WeaponsButtonOnBar) { Extras = extras };
|
||||
}
|
||||
|
||||
/// <summary>The extra bars there are, for the menus.</summary>
|
||||
private static (int, int)[] Extras(DefSession session)
|
||||
{
|
||||
var list = session.Data.ExtraBars;
|
||||
var a = new (int, int)[list.Count];
|
||||
for (int i = 0; i < list.Count; i++) a[i] = (list[i].Number, list[i].Filled);
|
||||
return a;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extra bar <paramref name="number"/> (2026-11-04): its own slots, the first SlotCount of them,
|
||||
/// shown as the main bar's own ones are (picture, count, spell), with no keys. Pure apart from the
|
||||
/// spell table: the tests build it offline.
|
||||
/// </summary>
|
||||
public static BarSnapshot BuildExtra(DefSession session, int number, IReadOnlyList<CarriedItem> items, bool canCast)
|
||||
{
|
||||
ExtraBar? bar = session.Data.Extra(number);
|
||||
if (bar == null) return BarSnapshot.NotReady;
|
||||
IReadOnlyList<SpellInfo> spells = session.KnownSpells();
|
||||
var slots = new BarSlot[bar.SlotCount];
|
||||
for (int n = 1; n <= bar.SlotCount; n++) slots[n - 1] = ExtraSlot(n, number, bar.Slots[n - 1], items, spells);
|
||||
DefSettings st = session.Settings;
|
||||
return new BarSnapshot(slots, true, st.ButtonSize, true, spells, canCast, st.WeaponsButtonOnBar)
|
||||
{
|
||||
Bar = number,
|
||||
MinSlots = ExtraBar.SlotsMin,
|
||||
MaxSlots = ExtraBar.SlotsMax,
|
||||
Extras = Extras(session),
|
||||
};
|
||||
}
|
||||
|
||||
private static BarSlot ExtraSlot(int n, int bar, DefSlot slot, IReadOnlyList<CarriedItem> items, IReadOnlyList<SpellInfo> spells)
|
||||
{
|
||||
string whose = $"Shortcuts bar {bar}: clicks only, no keys";
|
||||
if (slot.IsSpell) return OwnSpell(n, n, slot, whose, string.Empty, string.Empty, spells, keys: false);
|
||||
if (slot.Item == null)
|
||||
return new BarSlot(n, false, n, 0, 0, string.Empty, string.Empty, CountTone.Plain, string.Empty, string.Empty,
|
||||
$"Slot {n} ({whose}): empty.\nDrag an item from your pack onto it, or right-click: put the selected item or one of your spells here.");
|
||||
SlotStatus s = ItemMatcher.Status(slot.Item, items);
|
||||
string count = SlotText.Count(s, out uint color);
|
||||
CountTone tone = color == SlotText.InHand ? CountTone.InHand : color == SlotText.Missing ? CountTone.Missing : CountTone.Plain;
|
||||
string tip = SlotText.Tooltip(n, slot.Item, s, slot.Mode, null, keys: false) + $"\n({whose}.)";
|
||||
return new BarSlot(n, false, n, s.Item?.Id ?? 0, 0, s.Item?.FullName ?? slot.Item.FullName, count, tone, string.Empty, string.Empty, tip);
|
||||
}
|
||||
|
||||
private BarSlot Retail(int n, Dictionary<uint, CarriedItem> byId)
|
||||
|
|
@ -167,16 +226,17 @@ internal sealed class BarSnapshotBuilder
|
|||
/// A spell slot: the spell's picture and name. A spell the character doesn't know (another
|
||||
/// character's file, a spell lost) shows dimmed with "?" (when the spellbook can be read at all).
|
||||
/// </summary>
|
||||
private static BarSlot OwnSpell(int n, int own, DefSlot slot, string whose, string key, string all, IReadOnlyList<SpellInfo> spells)
|
||||
private static BarSlot OwnSpell(int n, int own, DefSlot slot, string whose, string key, string all, IReadOnlyList<SpellInfo> spells, bool keys = true)
|
||||
{
|
||||
string name = slot.SpellLabel;
|
||||
SpellInfo? info = SpellTable.TryGet(slot.SpellId, out SpellInfo si) ? si : null;
|
||||
bool known = spells.Count == 0;
|
||||
foreach (SpellInfo s in spells)
|
||||
if (s.Id == slot.SpellId) { known = true; break; }
|
||||
string tip = $"Slot {n}: {name}, a spell.\nClick or press the key: {SpellTargeting.Describe(info)} (Magic mode first)."
|
||||
string tip = $"Slot {n}: {name}, a spell.\n{(keys ? "Click or press the key" : "Click")}: {SpellTargeting.Describe(info)} (Magic mode first)."
|
||||
+ (known ? "" : "\nYou don't know this spell: pressing it does nothing.")
|
||||
+ (key.Length > 0 ? "\nKey: " + key : "\nNo key yet.") + $"\n({whose}.)\nRight-click: change the slot or its keys.";
|
||||
+ (!keys ? "" : key.Length > 0 ? "\nKey: " + key : "\nNo key yet.")
|
||||
+ $"\n({whose}.)\nRight-click: change the slot{(keys ? " or its keys" : "")}.";
|
||||
return new BarSlot(n, false, own, 0, slot.SpellId, name, known ? string.Empty : "?", known ? CountTone.Plain : CountTone.Missing,
|
||||
SlotText.ShortKey(key), all, tip);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@
|
|||
// /rdef use N. A key comes off whatever had it, after the player says so.
|
||||
// An independent bar (DefSettings.IndependentBar) has only RynthDefective's
|
||||
// own slots: every key is an engine hotkey (BarMapping, BarSlot.Own).
|
||||
// Extra bars (2026-11-04, ExtraBar): the same window class draws "Shortcuts
|
||||
// 2" ... with that bar's own slots (BarSnapshot.Bar): no AC slots and no keys,
|
||||
// 1-24 slots. The bars' menu adds one (at most ExtraBar.Max), shows or hides
|
||||
// them and removes one (its own menu: "Remove this bar").
|
||||
// Spells (2026-10-28): an own slot's menu has "Put a spell here...", a search
|
||||
// over the character's spells (the engine can't read the spell selected in
|
||||
// the game's spellbook); the slot then casts it (UseController).
|
||||
|
|
@ -62,6 +66,10 @@ internal interface IBarActions
|
|||
/// <summary>RynthDefective's settings window (the weapon swap switch, the independent bar ...).</summary>
|
||||
void ShowSettings();
|
||||
void Hide();
|
||||
/// <summary>Adds an extra Shortcuts bar (2026-11-04: "Shortcuts 2" ..., at most ExtraBar.Max).</summary>
|
||||
void AddBar();
|
||||
/// <summary>Removes extra bar <paramref name="number"/> and forgets its slots.</summary>
|
||||
void RemoveBar(int number);
|
||||
|
||||
// A slot's keys (any thread: the engine queues the change). AC's slot: AC's keymap action
|
||||
// UseQuickSlot_N; one of RynthDefective's own: its seam for own-slot keys (BindOwnSlotKey).
|
||||
|
|
@ -76,13 +84,16 @@ internal sealed class ShortcutBarWindow
|
|||
|
||||
private readonly RynthCoreHost _host;
|
||||
private readonly IBarActions _act;
|
||||
/// <summary>The window this one draws: <see cref="Title"/>, or an extra bar's ("Shortcuts 2", ExtraBar.TitleOf).</summary>
|
||||
private readonly string _title;
|
||||
private bool _edit;
|
||||
private float _k = 1f, _r = 1f;
|
||||
|
||||
public ShortcutBarWindow(RynthCoreHost host, IBarActions actions)
|
||||
public ShortcutBarWindow(RynthCoreHost host, IBarActions actions, string title = Title)
|
||||
{
|
||||
_host = host;
|
||||
_act = actions;
|
||||
_title = title;
|
||||
}
|
||||
|
||||
private float Px(float v) => v * _k;
|
||||
|
|
@ -97,7 +108,7 @@ internal sealed class ShortcutBarWindow
|
|||
private void Scale()
|
||||
{
|
||||
float fontK = Math.Max(0.5f, Font(RynthUiFont.Ui10).FontSize / 10f);
|
||||
int pct = _host.PanelScale(Title);
|
||||
int pct = _host.PanelScale(_title);
|
||||
_k = pct > 0 ? pct / 100f : fontK;
|
||||
_r = _k / fontK;
|
||||
}
|
||||
|
|
@ -154,7 +165,7 @@ internal sealed class ShortcutBarWindow
|
|||
ImGui.SetCursorScreenPos(origin);
|
||||
ImGui.Dummy(new Vector2(width, height));
|
||||
SlotMenu(view);
|
||||
BarMenu();
|
||||
BarMenu(view);
|
||||
if (_openKeyPopup)
|
||||
{
|
||||
_openKeyPopup = false;
|
||||
|
|
@ -193,12 +204,13 @@ internal sealed class ShortcutBarWindow
|
|||
bool menu = ImGui.IsItemClicked(ImGuiMouseButton.Right);
|
||||
_host.PanelDragWithLastItem();
|
||||
if (menu) ImGui.OpenPopup(BarMenuId);
|
||||
SafeImGui.SetItemTooltip("Drag to move the bar. Ctrl+wheel here: bigger or smaller. Right-click: settings, Game Panels, Selection.\n"
|
||||
SafeImGui.SetItemTooltip("Drag to move the bar. Ctrl+wheel here: bigger or smaller. Right-click: settings, Game Panels, Selection, more bars.\n"
|
||||
+ "Drag the window's edge to change how many slots fit in a row.");
|
||||
|
||||
ImFontPtr tf = Font(RynthUiFont.NarrowBold11);
|
||||
float size = Fs(tf) * 10f / 11f;
|
||||
float tx = Tracked(dl, tf, size, new Vector2(x0, MathF.Round(y + (h - size) * 0.5f)), _text, "SHORTCUTS", 0.18f * size);
|
||||
string name = view.Bar > 0 ? HeaderName(view.Bar) : "SHORTCUTS";
|
||||
float tx = Tracked(dl, tf, size, new Vector2(x0, MathF.Round(y + (h - size) * 0.5f)), _text, name, 0.18f * size);
|
||||
ImFontPtr nf = Font(RynthUiFont.Dash9);
|
||||
string count = view.Ready ? view.Slots.Length.ToString(System.Globalization.CultureInfo.InvariantCulture) : "";
|
||||
dl.AddText(nf, Fs(nf), new Vector2(MathF.Round(tx + Px(6)), MathF.Round(y + (h - Fs(nf)) * 0.5f + Px(1))), _faint, count);
|
||||
|
|
@ -218,11 +230,25 @@ internal sealed class ShortcutBarWindow
|
|||
"Settings (/rdef settings): weapon swaps under RynthAi, a bar independent of the game's toolbar,\nand showing the Game Panels buttons and the Selection window."))
|
||||
_act.ShowSettings();
|
||||
cx += chip + Px(1);
|
||||
if (Chip("##sb_hide", RynthIcons.X, new Vector2(cx, cy), _faint, "Hide the bar (/rdef shows it again). Its keys keep working."))
|
||||
if (Chip("##sb_hide", RynthIcons.X, new Vector2(cx, cy), _faint, view.Bar > 0
|
||||
? $"Hide this bar (the Shortcuts bar's right-click menu, or /rdef bars show {view.Bar}, shows it again)."
|
||||
: "Hide the bar (/rdef shows it again). Its keys keep working."))
|
||||
_act.Hide();
|
||||
return y + h;
|
||||
}
|
||||
|
||||
private static readonly string[] HeaderNames = BuildHeaderNames();
|
||||
|
||||
private static string[] BuildHeaderNames()
|
||||
{
|
||||
var a = new string[ExtraBar.LastNumber + 1];
|
||||
for (int n = ExtraBar.FirstNumber; n <= ExtraBar.LastNumber; n++) a[n] = "SHORTCUTS " + n;
|
||||
return a;
|
||||
}
|
||||
|
||||
/// <summary>"SHORTCUTS 2" (no string built per frame).</summary>
|
||||
private static string HeaderName(int bar) => bar >= 0 && bar < HeaderNames.Length && HeaderNames[bar] != null ? HeaderNames[bar] : "SHORTCUTS";
|
||||
|
||||
private bool Chip(string id, string icon, Vector2 pos, uint color, string tip, bool held = false)
|
||||
{
|
||||
Vector2 size = new(Px(ChipSize), Px(ChipSize));
|
||||
|
|
@ -256,7 +282,7 @@ internal sealed class ShortcutBarWindow
|
|||
|
||||
// Items dragged out of AC's UI: the slots' area takes them (the engine keeps the drop from AC).
|
||||
Vector2 areaMin = new(x0, y), areaMax = new(x0 + perRow * (cell + gap), y + rows * (cell + gap));
|
||||
uint dropped = _host.HasDropTargets ? _host.DropTarget(Title, areaMin, areaMax, true, out _dragging) : 0;
|
||||
uint dropped = _host.HasDropTargets ? _host.DropTarget(_title, areaMin, areaMax, true, out _dragging) : 0;
|
||||
int under = SlotAt(ImGui.GetIO().MousePos, x0, y, cell, gap, perRow, view.Slots.Length);
|
||||
_dropSlot = _dragging ? under : 0;
|
||||
if (dropped != 0 && under > 0) _act.DropItem(under, dropped);
|
||||
|
|
@ -266,7 +292,7 @@ internal sealed class ShortcutBarWindow
|
|||
int col = i % perRow, row = i / perRow;
|
||||
Vector2 p = new(MathF.Round(x0 + col * (cell + gap)), MathF.Round(y + row * (cell + gap)));
|
||||
if (i < view.Slots.Length) Slot(dl, view.Slots[i], p, cell);
|
||||
else EditButton(dl, i == view.Slots.Length ? -1 : 1, p, cell, view.Slots.Length, view.Independent);
|
||||
else EditButton(dl, i == view.Slots.Length ? -1 : 1, p, cell, view);
|
||||
}
|
||||
return y + rows * (cell + gap) - gap;
|
||||
}
|
||||
|
|
@ -345,16 +371,18 @@ internal sealed class ShortcutBarWindow
|
|||
}
|
||||
}
|
||||
|
||||
private void EditButton(ImDrawListPtr dl, int delta, Vector2 p, float cell, int count, bool independent)
|
||||
private void EditButton(ImDrawListPtr dl, int delta, Vector2 p, float cell, BarSnapshot view)
|
||||
{
|
||||
Vector2 size = new(cell, cell);
|
||||
bool can = delta < 0 ? count > DefSettings.BarSlotsMin : count < DefSettings.BarSlotsMax;
|
||||
int count = view.Slots.Length;
|
||||
bool can = delta < 0 ? count > view.MinSlots : count < view.MaxSlots;
|
||||
ImGui.SetCursorScreenPos(p);
|
||||
bool clicked = ImGui.InvisibleButton(delta < 0 ? "##sb_less" : "##sb_more", size);
|
||||
bool hot = can && ImGui.IsItemHovered();
|
||||
SafeImGui.SetItemTooltip(delta < 0
|
||||
? "One slot fewer (the last one's item stays: add the slot back and it is there)."
|
||||
: independent ? "One more slot (RynthCore's: this bar is independent of the game's toolbar)."
|
||||
: view.Bar > 0 ? $"One more slot (up to {view.MaxSlots})."
|
||||
: view.Independent ? "One more slot (RynthCore's: this bar is independent of the game's toolbar)."
|
||||
: count < DefSettings.RetailSlots ? "One more slot (the game's own, up to 18)."
|
||||
: "One more slot (RynthCore's: the game's toolbar holds 18).");
|
||||
float r = Px(3);
|
||||
|
|
@ -378,7 +406,7 @@ internal sealed class ShortcutBarWindow
|
|||
{
|
||||
BarSlot? s = _menuSlot >= 1 && _menuSlot <= view.Slots.Length ? view.Slots[_menuSlot - 1] : null;
|
||||
if (s == null) { ImGui.CloseCurrentPopup(); return; }
|
||||
ImGui.TextDisabled($"Slot {s.Number}{(s.Retail ? " (the game's own)" : " (RynthCore's)")}");
|
||||
ImGui.TextDisabled(view.Bar > 0 ? $"Slot {s.Number} (Shortcuts bar {view.Bar})" : $"Slot {s.Number}{(s.Retail ? " (the game's own)" : " (RynthCore's)")}");
|
||||
if (s.Name.Length > 0) SafeImGui.Text(s.Name);
|
||||
ImGui.Separator();
|
||||
bool hasSelection = _host.HasGetSelectedItemId && _host.GetSelectedItemId() != 0;
|
||||
|
|
@ -394,7 +422,13 @@ internal sealed class ShortcutBarWindow
|
|||
}
|
||||
if (ImGui.MenuItem("Empty this slot", null, false, !s.Empty)) _act.Clear(s.Number);
|
||||
ImGui.Separator();
|
||||
if (!_host.HasKeyBinding)
|
||||
if (view.Bar > 0)
|
||||
{
|
||||
// An extra bar's slots are clicked: the keys are the Shortcuts bar's own slots' (/rdef use N).
|
||||
ImGui.TextDisabled("No keys: click it");
|
||||
SafeImGui.SetItemTooltip("Keys go on the Shortcuts bar's own slots (right-click one there > Add a key).");
|
||||
}
|
||||
else if (!_host.HasKeyBinding)
|
||||
{
|
||||
ImGui.TextDisabled(s.AllKeys.Length > 0 ? "Keys: " + s.AllKeys
|
||||
: s.Retail ? "No key: bind UseQuickSlot_" + s.Number + " in Configure Keyboard." : "No key: /rdef bind " + s.Own + " F9");
|
||||
|
|
@ -425,7 +459,7 @@ internal sealed class ShortcutBarWindow
|
|||
|
||||
private const string BarMenuId = "##sb_bar_menu";
|
||||
|
||||
private void BarMenu()
|
||||
private void BarMenu(BarSnapshot view)
|
||||
{
|
||||
if (!ImGui.IsPopupOpen(BarMenuId)) return;
|
||||
ImGui.PushStyleColor(ImGuiCol.PopupBg, WithAlpha(_bg, 0xFA));
|
||||
|
|
@ -438,17 +472,82 @@ internal sealed class ShortcutBarWindow
|
|||
if (!open) return;
|
||||
try
|
||||
{
|
||||
ImGui.TextDisabled("RynthDefective's Shortcuts bar");
|
||||
ImGui.TextDisabled(view.Bar > 0 ? $"RynthDefective's Shortcuts bar {view.Bar}" : "RynthDefective's Shortcuts bar");
|
||||
ImGui.Separator();
|
||||
BarMenuItems();
|
||||
ImGui.Separator();
|
||||
MoreBarsItems(view);
|
||||
ImGui.Separator();
|
||||
if (ImGui.MenuItem("Weapons...")) _act.ShowWeapons();
|
||||
if (ImGui.MenuItem("Hide the bar")) _act.Hide();
|
||||
SafeImGui.SetItemTooltip("/rdef, or the lightning button on the RynthCore bar, shows it again. Its keys keep working.");
|
||||
if (ImGui.MenuItem(view.Bar > 0 ? "Hide this bar" : "Hide the bar")) _act.Hide();
|
||||
SafeImGui.SetItemTooltip(view.Bar > 0
|
||||
? $"The Shortcuts bar's right-click menu, Defective Settings, or /rdef bars show {view.Bar} shows it again."
|
||||
: "/rdef, or the lightning button on the RynthCore bar, shows it again. Its keys keep working.");
|
||||
}
|
||||
finally { ImGui.EndPopup(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The extra bars (2026-11-04): add one; on the Shortcuts bar, show or hide each (they have no RynthCore
|
||||
/// bar button) and remove one; on an extra bar, remove it. Removing asks once more (a submenu) when the
|
||||
/// bar holds something: its slots are forgotten.
|
||||
/// </summary>
|
||||
private void MoreBarsItems(BarSnapshot view)
|
||||
{
|
||||
if (ImGui.MenuItem("Add a shortcut bar", null, false, view.CanAddBar)) _act.AddBar();
|
||||
SafeImGui.SetItemTooltip(view.CanAddBar
|
||||
? $"Another bar of {ExtraBar.DefaultSlots} slots in a window of its own, to put anywhere (/rdef bars add).\n"
|
||||
+ "Fill it as this one: drag items from your pack onto it, or right-click a slot. Its slots are clicked; they have no keys."
|
||||
: $"There are {ExtraBar.Max} extra bars, as many as there can be. Remove one first.");
|
||||
if (view.Bar > 0)
|
||||
{
|
||||
int filled = 0;
|
||||
foreach ((int n, int f) in view.Extras) if (n == view.Bar) filled = f;
|
||||
RemoveItem("Remove this bar", view.Bar, filled);
|
||||
return;
|
||||
}
|
||||
if (view.Extras.Count == 0) return;
|
||||
foreach ((int n, _) in view.Extras)
|
||||
PanelToggle(ExtraBar.TitleOf(n), BarLabel(n), $"Show or hide Shortcuts bar {n} (/rdef bars show {n}).");
|
||||
if (ImGui.BeginMenu("Remove a bar"))
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach ((int n, int f) in view.Extras) RemoveItem(BarLabel(n), n, f);
|
||||
}
|
||||
finally { ImGui.EndMenu(); }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A bar's remove item: at once when it is empty, else a submenu that says what goes with it.</summary>
|
||||
private void RemoveItem(string label, int bar, int filled)
|
||||
{
|
||||
if (filled == 0)
|
||||
{
|
||||
if (ImGui.MenuItem(label)) _act.RemoveBar(bar);
|
||||
SafeImGui.SetItemTooltip($"Shortcuts bar {bar} is empty: it goes (/rdef bars remove {bar}).");
|
||||
return;
|
||||
}
|
||||
if (!ImGui.BeginMenu(label)) return;
|
||||
try
|
||||
{
|
||||
if (ImGui.MenuItem($"Remove bar {bar} and its {filled} slot{(filled == 1 ? "" : "s")}")) _act.RemoveBar(bar);
|
||||
SafeImGui.SetItemTooltip("Its slots are forgotten (the items stay in your pack).");
|
||||
}
|
||||
finally { ImGui.EndMenu(); }
|
||||
}
|
||||
|
||||
private static readonly string[] BarLabels = BuildBarLabels();
|
||||
|
||||
private static string[] BuildBarLabels()
|
||||
{
|
||||
var a = new string[ExtraBar.LastNumber + 1];
|
||||
for (int n = ExtraBar.FirstNumber; n <= ExtraBar.LastNumber; n++) a[n] = "Shortcuts bar " + n;
|
||||
return a;
|
||||
}
|
||||
|
||||
private static string BarLabel(int n) => n >= 0 && n < BarLabels.Length && BarLabels[n] != null ? BarLabels[n] : "Shortcuts bar " + n;
|
||||
|
||||
/// <summary>Settings..., and the two windows RynthDefective draws besides the bar (no RynthBar buttons of their own).</summary>
|
||||
private void BarMenuItems()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,11 +37,23 @@
|
|||
// After a death or a login RynthAi's stream of rebuffs kept the count moving,
|
||||
// so it never read "steady" and a press waited until it gave up.
|
||||
//
|
||||
// RynthDefective never resets the client's count itself (ForceResetBusyCount):
|
||||
// the count is the engine's (its reconciler and watchdogs own it), RynthAi
|
||||
// stopped resetting it on 2026-10-06 because a reset zeroes actions the server
|
||||
// hasn't answered yet (each later answer then drives it negative), and nothing
|
||||
// here needs it at zero: ignoring a leftover is enough to send.
|
||||
// RynthDefective doesn't reset the client's count itself (ForceResetBusyCount)
|
||||
// unless the player asks: the count is the engine's (its reconciler and
|
||||
// watchdogs own it), RynthAi stopped resetting it on 2026-10-06 because a reset
|
||||
// zeroes actions the server hasn't answered yet (each later answer then drives
|
||||
// it negative), and nothing here needs it at zero: ignoring a leftover is
|
||||
// enough to send.
|
||||
//
|
||||
// "Shortcuts clear a stuck busy state" (DefSettings.ClearStuckBusy, 2026-11-04,
|
||||
// off by default; a player's ask): a press held ONLY by the count (BusyHold.Busy
|
||||
// with nothing of ours in flight or unanswered, no gesture, RynthAi with no
|
||||
// action of its own, no "You're too busy" from the server in ServerBusyRecentMs)
|
||||
// sends the reset RynthAi's /ra clearbusy sends (the engine's
|
||||
// ForceResetBusyCount: the count to 0, the cursor re-read, every plugin's
|
||||
// mirror told), once per press, then the press goes (BusyClearRule; the use
|
||||
// controller waits ClearSettleMs for the reset to land on the game's tick,
|
||||
// then takes what is left as a leftover). Not /ra clearbusy's StopCompletely:
|
||||
// a press must not stop a run. Never with a real action in flight.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
|
|
@ -128,6 +140,34 @@ internal static class BusyRule
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether a press held by the busy count clears it first (DefSettings.ClearStuckBusy, off by default).
|
||||
/// Pure: the use controller asks, the tests check every case.
|
||||
/// </summary>
|
||||
internal static class BusyClearRule
|
||||
{
|
||||
/// <summary>The server answered "You're too busy" this recently: it really is busy, nothing is cleared.</summary>
|
||||
public const long ServerBusyRecentMs = 5000;
|
||||
|
||||
/// <param name="enabled">The player's option.</param>
|
||||
/// <param name="hold">What <see cref="BusyRule"/> says holds the press.</param>
|
||||
/// <param name="f">The readings it said it from.</param>
|
||||
/// <param name="ownInFlight">A use or cast of ours is in flight (sent, not answered or let go).</param>
|
||||
/// <param name="ownAnswered">Our own last use or cast was answered (UseDone, the item in hand, a refusal); false while one went unanswered.</param>
|
||||
/// <param name="sinceServerBusyMs">Since the server last answered "You're too busy".</param>
|
||||
public static bool ShouldClear(bool enabled, BusyHold hold, in BusyFacts f, bool ownInFlight, bool ownAnswered, long sinceServerBusyMs)
|
||||
{
|
||||
if (!enabled || hold != BusyHold.Busy || f.Count <= 0) return false; // only the count, and only when it holds
|
||||
if (ownInFlight) return false; // ours, under way
|
||||
if (f.SinceOwnSendMs < BusyRule.OwnTrustMs && !ownAnswered) return false; // ours, never answered: it may still be
|
||||
if (f.Animating) return false; // a gesture: the character is acting
|
||||
if (f.BotPaced == true) return false; // RynthAi's own action, unanswered
|
||||
// A RynthAi that doesn't say what it has in flight: its "waiting on the server" bit while fresh.
|
||||
if (f.BotPaced == null && f.BotWaiting == true && f.BotSteadyMs < BusyRule.BotTrustMs) return false;
|
||||
return sinceServerBusyMs >= ServerBusyRecentMs; // the server said busy just now
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The clocks behind <see cref="BusyRule"/>: how long each reading has read the same, our own last
|
||||
/// send, and the leftover count. <see cref="Observe"/> every tick (in or out of the world: a count
|
||||
|
|
@ -194,6 +234,15 @@ internal sealed class BusyGate
|
|||
/// <summary>Our own use or cast went out now.</summary>
|
||||
public void NoteOwnSend(long now) => _ownSendMs = now;
|
||||
|
||||
/// <summary>
|
||||
/// The count as it reads now is a leftover (after the player's clear: what the reset didn't take holds
|
||||
/// this press no more). Only a count above it holds again.
|
||||
/// </summary>
|
||||
public void AcceptLeftover()
|
||||
{
|
||||
if (_count > _leftover) _leftover = _count;
|
||||
}
|
||||
|
||||
public BusyFacts Facts(long now) => Facts(now, false);
|
||||
|
||||
/// <param name="pacedKnown">RynthAi holds for the press (its PacedAction bit is meaningful).</param>
|
||||
|
|
|
|||
|
|
@ -44,6 +44,14 @@ internal sealed unsafe class HostDefWorld : IDefWorld
|
|||
public bool HoldBot(uint ms) => BotYield.Hold(_host, ms);
|
||||
public void ReleaseBot() => BotYield.Release(_host);
|
||||
|
||||
/// <summary>The busy-count reset of /ra clearbusy (ForceResetBusyCount; the engine runs it on the game's thread).</summary>
|
||||
public bool ClearBusyCount()
|
||||
{
|
||||
if (!_host.HasForceResetBusyCount) return false;
|
||||
_host.ForceResetBusyCount();
|
||||
return true;
|
||||
}
|
||||
|
||||
public int RefusalSeq => _host.HasGetLastWeenieError && _host.TryGetLastWeenieError(out int seq, out _, out _, out _) ? seq : 0;
|
||||
|
||||
public bool RefusalNamed(uint objectId) =>
|
||||
|
|
|
|||
|
|
@ -39,6 +39,12 @@ internal interface IDefWorld
|
|||
bool HoldBot(uint ms);
|
||||
/// <summary>Ends the player's turn.</summary>
|
||||
void ReleaseBot();
|
||||
/// <summary>
|
||||
/// Resets the client's busy count as RynthAi's /ra clearbusy does (the engine's ForceResetBusyCount:
|
||||
/// the count to 0 and the cursor re-read, on the game's next tick; every plugin's copy of the count is
|
||||
/// told). False when this engine can't. Only for "Shortcuts clear a stuck busy state" (BusyClearRule).
|
||||
/// </summary>
|
||||
bool ClearBusyCount();
|
||||
/// <summary>Count of the server's UseDone events; 0 when the engine can't report them.</summary>
|
||||
int UseDoneSeq { get; }
|
||||
/// <summary>The error of the server's first UseDone after <paramref name="seqAtSend"/> (0x1D: "You're too busy"); 0 = none or unknown.</summary>
|
||||
|
|
@ -155,6 +161,10 @@ internal static class Stance
|
|||
/// behind that stream until it gave up. While RynthAi holds, it also says exactly what it has in
|
||||
/// flight, so only that and our own last use hold a press: the busy count beyond them is a leftover.
|
||||
///
|
||||
/// Shortcuts clear a stuck busy state (2026-11-04, Settings.ClearStuckBusy, off by default): a press held
|
||||
/// only by the busy count, with nothing real in flight (<see cref="BusyClearRule"/>), resets the count as
|
||||
/// /ra clearbusy does, once per press, then goes (<see cref="ClearSettleMs"/> for the reset to read; logged).
|
||||
///
|
||||
/// After a portal (2026-10-29): the engine takes no game action until 5 s after portal space ends
|
||||
/// (its world-transition gate: AC is still loading the new place), so a press then was refused and
|
||||
/// reported as "the client didn't take the request". Within <see cref="PortalRetryWindowMs"/> of
|
||||
|
|
@ -188,6 +198,11 @@ internal sealed class UseController
|
|||
public const long PortalRetryWindowMs = 6000;
|
||||
/// <summary>How often a refused use or cast is tried again after a portal.</summary>
|
||||
public const long RefusedRetryMs = 250;
|
||||
/// <summary>
|
||||
/// After "Shortcuts clear a stuck busy state" cleared the count for a press: it waits this long for the
|
||||
/// engine's reset (on the game's next tick) to read, then goes, what is left taken as a leftover.
|
||||
/// </summary>
|
||||
public const long ClearSettleMs = 500;
|
||||
|
||||
private enum Stage { Sent, WaitWield, Stance, Magic }
|
||||
|
||||
|
|
@ -227,6 +242,14 @@ internal sealed class UseController
|
|||
private long _worldBackMs = long.MinValue / 4;
|
||||
private long _refusedRetryAtMs = long.MinValue / 4;
|
||||
private UseRequest? _refusedSaid;
|
||||
// "Shortcuts clear a stuck busy state" (Settings.ClearStuckBusy): the press a clear was sent (or tried)
|
||||
// for, once per press; when; whether the engine took it. Our own last send answered; the server's last
|
||||
// "You're too busy".
|
||||
private UseRequest? _clearedFor;
|
||||
private long _clearedAtMs;
|
||||
private bool _clearSent;
|
||||
private bool _ownAnswered = true;
|
||||
private long _tooBusyAtMs = long.MinValue / 4;
|
||||
|
||||
/// <summary>The engine refused sends this soon after the character came out of portal space: they are tried again.</summary>
|
||||
private bool JustArrived(long now) => now - _worldBackMs < PortalRetryWindowMs;
|
||||
|
|
@ -277,6 +300,7 @@ internal sealed class UseController
|
|||
_lastWait = string.Empty;
|
||||
_retryNotBeforeMs = long.MinValue / 4;
|
||||
_refusedRetryAtMs = long.MinValue / 4;
|
||||
_clearedFor = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -288,6 +312,8 @@ internal sealed class UseController
|
|||
{
|
||||
Reset();
|
||||
_busy.Reset();
|
||||
_ownAnswered = true;
|
||||
_tooBusyAtMs = long.MinValue / 4;
|
||||
}
|
||||
|
||||
public void Tick(IDefWorld w)
|
||||
|
|
@ -340,7 +366,7 @@ internal sealed class UseController
|
|||
if (_pending == null) return;
|
||||
|
||||
UseRequest req = _pending;
|
||||
string? wait = WaitReason(w, now);
|
||||
string? wait = WaitReason(w, req, now);
|
||||
if (wait != null)
|
||||
{
|
||||
_lastWait = wait;
|
||||
|
|
@ -355,12 +381,18 @@ internal sealed class UseController
|
|||
Send(w, req, now);
|
||||
}
|
||||
|
||||
private string? WaitReason(IDefWorld w, long now)
|
||||
private string? WaitReason(IDefWorld w, UseRequest req, long now)
|
||||
{
|
||||
if (now - _lastDoneMs < MinGapMs) return "the last action just finished";
|
||||
if (now < _retryNotBeforeMs) return "the server said the character was busy";
|
||||
if (now < _refusedRetryAtMs) return "the game is still loading after the portal";
|
||||
return Hold(now) switch
|
||||
BusyHold hold = Hold(now);
|
||||
if (hold == BusyHold.Busy && Settings.ClearStuckBusy)
|
||||
{
|
||||
if (ClearStuckBusy(w, req, now) is { } clearing) return clearing;
|
||||
hold = Hold(now);
|
||||
}
|
||||
return hold switch
|
||||
{
|
||||
BusyHold.Busy => "the character is busy",
|
||||
BusyHold.Animation => "an animation is playing",
|
||||
|
|
@ -369,6 +401,40 @@ internal sealed class UseController
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "Shortcuts clear a stuck busy state": <paramref name="req"/> is held by the busy count. When nothing
|
||||
/// real is in flight (BusyClearRule) the count is reset as /ra clearbusy does, once for this press, and
|
||||
/// the press waits <see cref="ClearSettleMs"/> for the reset to read; then what is left is a leftover
|
||||
/// and it goes. Returns the wait while the clear settles, null for the usual rules (nothing cleared, or
|
||||
/// the clear has settled).
|
||||
/// </summary>
|
||||
private string? ClearStuckBusy(IDefWorld w, UseRequest req, long now)
|
||||
{
|
||||
const string Clearing = "a stuck busy state is being cleared";
|
||||
if (ReferenceEquals(_clearedFor, req))
|
||||
{
|
||||
if (!_clearSent) return null; // the engine couldn't: the usual rules
|
||||
if (now - _clearedAtMs < ClearSettleMs) return Clearing;
|
||||
_busy.AcceptLeftover();
|
||||
return null;
|
||||
}
|
||||
BusyFacts f = _busy.Facts(now, _botHeld);
|
||||
if (!BusyClearRule.ShouldClear(true, BusyHold.Busy, f, _flight != null, _ownAnswered, now - _tooBusyAtMs)) return null;
|
||||
_clearedFor = req;
|
||||
_clearedAtMs = now;
|
||||
_clearSent = w.ClearBusyCount();
|
||||
if (!_clearSent)
|
||||
{
|
||||
Log?.Invoke($"[RynthDefective] {req.Source}: held only by the client's busy count ({f.Count}), but this RynthCore can't reset it "
|
||||
+ "(ForceResetBusyCount): waiting as usual");
|
||||
return null;
|
||||
}
|
||||
Log?.Invoke($"[RynthDefective] {req.Source}: held only by the client's busy count ({f.Count}; nothing of ours or RynthAi's in flight, "
|
||||
+ "no gesture, no 'too busy' from the server): reset it as /ra clearbusy does (Shortcuts clear a stuck busy state), then the use");
|
||||
Say?.Invoke($"{req.Label}: clearing a stuck busy state...");
|
||||
return Clearing;
|
||||
}
|
||||
|
||||
/// <summary>The busy gate's verdict now; a leftover it ignores for the first time is logged.</summary>
|
||||
private BusyHold Hold(long now)
|
||||
{
|
||||
|
|
@ -444,6 +510,7 @@ internal sealed class UseController
|
|||
return;
|
||||
}
|
||||
_busy.NoteOwnSend(now);
|
||||
_ownAnswered = false;
|
||||
|
||||
_flight = new Flight
|
||||
{
|
||||
|
|
@ -602,6 +669,7 @@ internal sealed class UseController
|
|||
return true;
|
||||
}
|
||||
_busy.NoteOwnSend(now);
|
||||
_ownAnswered = false;
|
||||
f.Stage = Stage.Sent;
|
||||
f.SentMs = now;
|
||||
f.StageMs = now;
|
||||
|
|
@ -627,7 +695,12 @@ internal sealed class UseController
|
|||
{
|
||||
if (!answered && age >= UseTimeoutMs) Log?.Invoke($"[RynthDefective] no UseDone for {f.What} after {age} ms; carrying on");
|
||||
Finish(now);
|
||||
if (answered && w.UseDoneError(f.UseDoneAtSend) == TooBusyError) RetryTooBusy(f, now);
|
||||
if (answered) _ownAnswered = true;
|
||||
if (answered && w.UseDoneError(f.UseDoneAtSend) == TooBusyError)
|
||||
{
|
||||
_tooBusyAtMs = now; // the server really is busy: nothing is cleared for a while (BusyClearRule)
|
||||
RetryTooBusy(f, now);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -638,6 +711,7 @@ internal sealed class UseController
|
|||
if (live != null && live.Wielded)
|
||||
{
|
||||
Wielded?.Invoke(live);
|
||||
_ownAnswered = true; // a wield's answer is the item in hand
|
||||
f.Item = live;
|
||||
f.Stage = Stage.Stance;
|
||||
f.StageMs = now;
|
||||
|
|
@ -645,6 +719,7 @@ internal sealed class UseController
|
|||
}
|
||||
if (w.RefusalSeq != f.RefusalAtSend && w.RefusalNamed(f.Item.Id))
|
||||
{
|
||||
_ownAnswered = true;
|
||||
Warn?.Invoke($"{f.Item.FullName}: the server wouldn't let you wield it (a skill, level or slot requirement?).");
|
||||
Finish(now);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,13 @@ internal sealed class BarSettingsView
|
|||
public Action<string> Tell = _ => { };
|
||||
/// <summary>Opens the weapon picker (/rdef weapons).</summary>
|
||||
public Action ShowWeapons = () => { };
|
||||
/// <summary>Adds an extra Shortcuts bar (it opens once the engine hosts it; the plugin says so in chat).</summary>
|
||||
public Action AddBar = () => { };
|
||||
/// <summary>Removes extra bar N and forgets its slots.</summary>
|
||||
public Action<int> RemoveBar = _ => { };
|
||||
|
||||
/// <summary>The extra bar whose Remove was pressed: it asks once more (0 = none).</summary>
|
||||
private int _confirmRemove;
|
||||
|
||||
public BarSettingsView(DefSession session) => _s = session;
|
||||
|
||||
|
|
@ -81,6 +88,9 @@ internal sealed class BarSettingsView
|
|||
}
|
||||
w.SliderInt("Slot picture size", "set.button", st.ButtonSize, DefSettings.ButtonMin, DefSettings.ButtonMax, v => { st.ButtonSize = v; Changed(); });
|
||||
w.Tooltip("Ctrl+wheel over the bar's title makes the whole bar bigger or smaller.");
|
||||
ClearBusyBox(w, st, Changed);
|
||||
|
||||
MoreBars(w, Changed);
|
||||
|
||||
w.SeparatorText("Weapons");
|
||||
w.SmallButton("Weapon picker...", "set.weapons", () => ShowWeapons());
|
||||
|
|
@ -97,6 +107,56 @@ internal sealed class BarSettingsView
|
|||
+ "/rdef qty, /rdef split, /rdef give, /rdef buy, /rdef help.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The extra Shortcuts bars (2026-11-04): add one, and for each: shown, how many slots, remove (asked
|
||||
/// once more when it holds something). Only where the engine has the Shortcuts bar (they are its kind
|
||||
/// of window).
|
||||
/// </summary>
|
||||
private void MoreBars(UiWindow w, Action changed)
|
||||
{
|
||||
if (WindowShown(BarTitle) == null) return;
|
||||
w.SeparatorText("More shortcut bars");
|
||||
w.TextWrapped($"Up to {ExtraBar.Max} bars of their own, anywhere on screen. Fill them as the Shortcuts bar: drag items from your pack "
|
||||
+ "onto a slot, or right-click it for the selected item or one of your spells. Their slots are clicked; they have no keys.");
|
||||
foreach (ExtraBar bar in _s.Data.ExtraBars)
|
||||
{
|
||||
int n = bar.Number;
|
||||
WindowBox(w, bar.Title, $"Shortcuts bar {n}", $"set.xbar.{n}.shown", $"Shows or hides Shortcuts bar {n} (/rdef bars show {n}).");
|
||||
if (WindowShown(bar.Title) == null) w.TextDisabled($"Shortcuts bar {n}: opening...");
|
||||
w.SliderInt($"Bar {n} slots", $"set.xbar.{n}.slots", bar.SlotCount, ExtraBar.SlotsMin, ExtraBar.SlotsMax, v => { bar.SlotCount = v; changed(); });
|
||||
w.Tooltip($"How many slots Shortcuts bar {n} shows. Fewer hides the last ones; their items stay (/rdef bars slots {n} <count>).");
|
||||
if (_confirmRemove == n)
|
||||
{
|
||||
int filled = bar.Filled;
|
||||
w.TextColored(SlotText.Waiting, filled > 0
|
||||
? $"Remove Shortcuts bar {n}? {filled} of its slots hold an item or a spell: they are forgotten (the items stay in your pack)."
|
||||
: $"Remove Shortcuts bar {n}?");
|
||||
w.SmallButton("Remove it", $"set.xbar.{n}.yes", () => { _confirmRemove = 0; RemoveBar(n); });
|
||||
w.SameLine();
|
||||
w.SmallButton("Keep it", $"set.xbar.{n}.no", () => _confirmRemove = 0);
|
||||
}
|
||||
else w.SmallButton($"Remove bar {n}...", $"set.xbar.{n}.remove", () => _confirmRemove = n);
|
||||
}
|
||||
if (_s.Data.ExtraBars.Count < ExtraBar.Max)
|
||||
{
|
||||
w.SmallButton("Add a shortcut bar", "set.xbar.add", () => AddBar());
|
||||
w.Tooltip($"Another bar of {ExtraBar.DefaultSlots} slots in a window of its own (/rdef bars add). It opens in a moment: drag its title to move it.");
|
||||
}
|
||||
else w.TextDisabled($"{ExtraBar.Max} extra bars: as many as there can be.");
|
||||
}
|
||||
|
||||
/// <summary>"Shortcuts clear a stuck busy state" (DefSettings.ClearStuckBusy): here and on the script-window bar's settings.</summary>
|
||||
internal static void ClearBusyBox(UiWindow w, DefSettings st, Action changed)
|
||||
{
|
||||
w.Checkbox("Shortcuts clear a stuck busy state", "set.clearbusy", st.ClearStuckBusy, v => { st.ClearStuckBusy = v; changed(); });
|
||||
w.Tooltip("On: a slot pressed while only the client's busy count holds it (after a death or a login the count can stay up with\n"
|
||||
+ "nothing happening; nothing of RynthDefective's or RynthAi's in flight, no animation, no 'You're too busy' from the server\n"
|
||||
+ "just now) resets the count as /ra clearbusy does, then the item is used. Once per press, logged.\n"
|
||||
+ "Off (the default): such a count holds a press for up to 4 s, then is ignored. Off because a reset also wipes actions the\n"
|
||||
+ "server hasn't answered that RynthDefective can't see (a click in the game's own windows, its toolbar keys, another\n"
|
||||
+ "plugin's), and their late answers then take the count below zero. Kept for this character. Also: /rdef shortcuts clearbusy on|off.");
|
||||
}
|
||||
|
||||
private void WindowBox(UiWindow w, string title, string label, string id, string tip)
|
||||
{
|
||||
bool? shown = WindowShown(title);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ internal sealed class SettingsPanel
|
|||
w.Checkbox("Show counts and keys under the slots", "set.counts", st.ShowCounts, v => { st.ShowCounts = v; Changed(true); });
|
||||
w.Checkbox("Allow weapon swaps while RynthAi's macro runs", "set.swap", st.SwapWhileBotRuns, v => { st.SwapWhileBotRuns = v; Changed(false); });
|
||||
w.Tooltip("Off (the default): a weapon, wand or shield is not wielded while the RynthAi macro runs - it picks the weapon itself and would swap back. Kits, potions and other items always work.");
|
||||
BarSettingsView.ClearBusyBox(w, st, () => Changed(false));
|
||||
|
||||
w.SeparatorText("About");
|
||||
w.TextWrapped(Credit);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ internal static class SlotText
|
|||
return sb.Length == 0 ? "?" : sb.ToString();
|
||||
}
|
||||
|
||||
public static string Tooltip(int number, ItemRef? item, SlotStatus s, UseMode mode, string? key)
|
||||
/// <param name="keys">The slot can have a key (an extra Shortcuts bar's can't: clicks only).</param>
|
||||
public static string Tooltip(int number, ItemRef? item, SlotStatus s, UseMode mode, string? key, bool keys = true)
|
||||
{
|
||||
if (item == null) return $"Slot {number}: empty. Click to set it up.";
|
||||
var sb = new StringBuilder();
|
||||
|
|
@ -69,12 +70,12 @@ internal static class SlotText
|
|||
{
|
||||
ItemKind kind = ItemKinds.Classify(s.Item);
|
||||
UseAction action = UseModes.ActionFor(mode, kind);
|
||||
sb.Append("\nClick or press the key: ").Append(UseModes.Describe(action).Replace("used", "use it").Replace("wielded", "wield it"));
|
||||
sb.Append(keys ? "\nClick or press the key: " : "\nClick: ").Append(UseModes.Describe(action).Replace("used", "use it").Replace("wielded", "wield it"));
|
||||
if (s.Item.MaxUses > 0) sb.Append("\n").Append(s.Uses).Append(" uses left");
|
||||
if (s.Count > 1 || s.Item.MaxStack > 1) sb.Append(s.Item.MaxUses > 0 ? ", " : "\n").Append(s.Count).Append(" carried");
|
||||
if (s.Item.Wielded) sb.Append("\nIn your hands now.");
|
||||
}
|
||||
sb.Append(key != null ? "\nKey: " + key : "\nNo key yet (Edit slots).");
|
||||
if (keys) sb.Append(key != null ? "\nKey: " + key : "\nNo key yet (Edit slots).");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue