diff --git a/Plugins/RynthCore.Plugin.RynthDefective/Clock/DayNightWindow.cs b/Plugins/RynthCore.Plugin.RynthAi/DayNight/DayNightWindow.cs similarity index 81% rename from Plugins/RynthCore.Plugin.RynthDefective/Clock/DayNightWindow.cs rename to Plugins/RynthCore.Plugin.RynthAi/DayNight/DayNightWindow.cs index 264713c..e9a037a 100644 --- a/Plugins/RynthCore.Plugin.RynthDefective/Clock/DayNightWindow.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/DayNight/DayNightWindow.cs @@ -1,34 +1,35 @@ // ============================================================================ -// RynthDefective - Clock/DayNightWindow.cs +// RynthAi - DayNight/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). +// In RynthAi since 2026-12-02 (it was RynthDefective's; R-20261202-122606-0b16 had no RynthDefective +// loaded, and players shouldn't need RynthDefective for this small piece). // Plugins/Shared/DerethClock.cs has the math; RynthCore hosts the frameless // window (plugin API v90) and remembers where it is. // // A clear background by default (2026-12-01: no box, the sun or moon and the text shadowed, so it -// can sit on the radar or under the arrow without taking room); /rdef daynight box brings the -// dark box back (DefSettings.DayNightBox). While hovered a faint box shows where to grab it. +// can sit on the radar or under the arrow without taking room); /ra daynight box brings the +// dark box back (LegacyUiSettings.DayNightBox). While hovered a faint box shows where to grab it. // // anywhere drag to move; Ctrl+wheel: bigger or smaller (30-250%); -// right-click: hide it (/rdef daynight, the bar button, or +// right-click: hide it (/ra daynight, the bar button, or // Settings > Interface > In The Retail Toolbar's Place show it again). // -// AC's render thread; reads the view the tick built (DayNightView) and counts +// AC's render thread; reads the view RynthAiPlugin.DayNight.cs 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; +namespace RynthCore.Plugin.RynthAi.DayNight; /// The clock as the tick read it; Ready = in world with a usable reading. internal sealed record DayNightView(bool Ready, DerethNow Now, long ReadAtMs) @@ -110,8 +111,8 @@ internal sealed class DayNightWindow 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; - if (!box) PanelButtonsWindow.DrawIcon(dl, icon, at + sh, new Vector2(Px(Mark), rowH), Px(13), ShadowColor); - PanelButtonsWindow.DrawIcon(dl, icon, at, new Vector2(Px(Mark), rowH), Px(13), iconColor); + if (!box) DrawIcon(dl, icon, at + sh, new Vector2(Px(Mark), rowH), Px(13), ShadowColor); + 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; @@ -157,14 +158,31 @@ internal sealed class DayNightWindow 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).\n" - + "/rdef daynight box: the dark box; /rdef daynight clear: no background."; + + "Drag to move; Ctrl+wheel: bigger or smaller; right-click: hide (/ra daynight).\n" + + "/ra daynight box: the dark box; /ra daynight clear: no background."; 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; } + /// A Phosphor glyph centred in the box, across its em (from Ui18's bake). + private static unsafe void DrawIcon(ImDrawListPtr dl, string glyph, Vector2 min, Vector2 size, float px, uint color) + { + if (string.IsNullOrEmpty(glyph)) return; + ImFontPtr font = Font(RynthUiFont.Ui18); + if (font.NativePtr == null) return; + byte* g = (byte*)ImGuiNative.ImFont_FindGlyphNoFallback(font.NativePtr, glyph[0]); + if (g == null) return; + float advance = *(float*)(g + 4); + if (advance <= 0) return; + float* box = (float*)(g + 8); + float scale = px / advance; + Vector2 centre = new((box[0] + box[2]) * 0.5f * scale, (box[1] + box[3]) * 0.5f * scale); + Vector2 at = min + size * 0.5f - centre; + dl.AddText(font, font.FontSize * scale, new Vector2(MathF.Round(at.X), MathF.Round(at.Y)), color, glyph); + } + /// Whether the engine's atlas has (an icon baked after this engine was built isn't). private static unsafe bool HasGlyph(string glyph) { diff --git a/Plugins/RynthCore.Plugin.RynthAi/Huds/SectionsManifest.cs b/Plugins/RynthCore.Plugin.RynthAi/Huds/SectionsManifest.cs index 8a53751..50771a3 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Huds/SectionsManifest.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Huds/SectionsManifest.cs @@ -127,6 +127,12 @@ internal static class SectionsManifest /// public const string TradeShopTitle = RynthAiPlugin.TradeShopTitle, TradeShopSurface = RynthAiPlugin.TradeShopSurface; + /// + /// The Day/Night timer (RynthAiPlugin.DayNight.cs; RynthDefective's until 2026-12-02): frameless, one row, + /// a bar button of its own as it had. The same title as before, so RynthCore keeps its place and size. + /// + public const string DayNightTitle = RynthAiPlugin.DayNightTitle, DayNightSurface = RynthAiPlugin.DayNightSurface; + /// /// The manifest JSON for (UTF-8 text, schema version 1), with the dashboard /// window when , the Monster Stats window when , @@ -137,14 +143,14 @@ internal static class SectionsManifest /// public static string Build(IReadOnlyList views, IReadOnlyList
sections, bool dashboard = false, bool monsterStats = false, bool timedCommands = false, bool activeGear = false, bool featureSearch = false, bool acMaps = false, - bool commandButtons = false, bool tradeShop = false) + bool commandButtons = false, bool tradeShop = false, bool dayNight = false) { using var stream = new MemoryStream(4096); using (var w = new Utf8JsonWriter(stream)) { w.WriteStartObject(); w.WriteNumber("version", 1); - bool windows = dashboard || monsterStats || timedCommands || activeGear || featureSearch || acMaps || commandButtons || tradeShop; + bool windows = dashboard || monsterStats || timedCommands || activeGear || featureSearch || acMaps || commandButtons || tradeShop || dayNight; if (windows) w.WriteStartArray("windows"); if (dashboard) @@ -270,6 +276,24 @@ internal static class SectionsManifest w.WriteBoolean("edgeToEdge", true); w.WriteEndObject(); } + if (dayNight) + { + w.WriteStartObject(); + w.WriteString("id", "daynight"); + w.WriteString("title", DayNightTitle); + w.WriteString("surface", DayNightSurface); + w.WriteString("icon", RynthCore.Plugin.Shared.RynthUi.RynthIcons.Sun); + w.WriteNumber("width", 150); + w.WriteNumber("height", 26); + w.WriteNumber("minWidth", 70); + w.WriteNumber("minHeight", 20); + w.WriteBoolean("bar", true); + w.WriteBoolean("edgeToEdge", true); + w.WriteString("chrome", "none"); + w.WriteBoolean("fitHeight", true); + w.WriteString("scale", "draw"); + w.WriteEndObject(); + } if (windows) w.WriteEndArray(); w.WriteStartArray("sections"); diff --git a/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyDashboardRenderer.cs b/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyDashboardRenderer.cs index b2b8e7a..3e5718d 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyDashboardRenderer.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyDashboardRenderer.cs @@ -2338,6 +2338,7 @@ internal sealed partial class LegacyDashboardRenderer dst.CastBuffsOverItemBuffs = tmp.CastBuffsOverItemBuffs; dst.FastBuffChain = tmp.FastBuffChain; dst.SkipUnusableBuffs = tmp.SkipUnusableBuffs; + dst.DayNightBox = tmp.DayNightBox; dst.RecastDispelledInFight = tmp.RecastDispelledInFight; dst.UseFellowshipBuffs = tmp.UseFellowshipBuffs; dst.DisabledBuffs = tmp.DisabledBuffs; diff --git a/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyUiSettings.cs b/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyUiSettings.cs index 94cad07..479714a 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyUiSettings.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyUiSettings.cs @@ -619,6 +619,12 @@ public sealed class LegacyUiSettings /// public bool SkipUnusableBuffs = true; /// + /// The Day/Night timer's dark box (RynthAiPlugin.DayNight.cs; RynthDefective's setting until 2026-12-02). Off (the + /// default): a clear background, its sun or moon and text shadowed so they read over the radar or the world. + /// On: the dark box. /ra daynight clear | box. + /// + public bool DayNightBox; + /// /// Buffing > Recast dispelled buffs in a fight (on by default; 2026-12-01: recasting dispels is /// an option). On: a buff a monster dispels is recast at once, fight or not, like any buff at Rebuff With. /// Off: in a fight a dispelled (gone) buff waits until no monster is within Monster Range; a buff at or diff --git a/Plugins/RynthCore.Plugin.RynthAi/PluginExports.cs b/Plugins/RynthCore.Plugin.RynthAi/PluginExports.cs index d761331..a76f627 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/PluginExports.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/PluginExports.cs @@ -172,6 +172,12 @@ public static unsafe class PluginExports int drawn = plugin.RenderTimedCommands(popped, out want); if (drawn != 1) return drawn; } + else if (name.SequenceEqual("window:daynight"u8)) + { + // The Day/Night timer (RynthAiPlugin.DayNight.cs, was RynthDefective's): 1 drawn, 0 not ready, -2 failed. + int drawn = plugin.RenderDayNight(out want); + if (drawn != 1) return drawn; + } else if (name.SequenceEqual("window:commandbuttons"u8)) { // The Command Buttons window (RynthAiPlugin.CommandButtons.cs): 1 drawn, 0 not ready, -2 failed. diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.DayNight.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.DayNight.cs new file mode 100644 index 0000000..13b1e18 --- /dev/null +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.DayNight.cs @@ -0,0 +1,125 @@ +// ============================================================================ +// RynthAi - RynthAiPlugin.DayNight.cs +// The Day/Night timer: day or night in Dereth now and the real time until the +// next dawn or dusk (DayNight/DayNightWindow.cs draws it, Plugins/Shared/DerethClock.cs +// has the math). +// +// It was RynthDefective's (2026-11-04). R-20261202-122606-0b16: /rdef daynight box +// answered "Unknown command: rdef" because that player had no RynthDefective loaded. +// 2026-12-02: it lives in RynthAi, so players don't need RynthDefective for this +// small piece. Same window title ("Day/Night"), so +// RynthCore keeps its saved place, size and the Settings > Interface rows; +// /ra daynight [show|hide|clear|box], and /rdef daynight hands over to it. +// +// The clock is read on the render thread, at most twice a second while the window +// draws, and only in world: its address isn't mapped before world entry, and a fault +// there can't be caught (ExpressionEngine.ReadGameClock has the same guard). +// ============================================================================ + +using System; +using System.Numerics; +using ImGuiNET; +using RynthCore.Plugin.RynthAi.DayNight; +using RynthCore.Plugin.Shared; +using RynthCore.PluginSdk; + +namespace RynthCore.Plugin.RynthAi; + +public sealed partial class RynthAiPlugin +{ + internal const string DayNightTitle = DayNightWindow.Title, DayNightSurface = "window:daynight"; + + private DayNightWindow? _dayNightWindow; + private DayNightView _dayNightView = DayNightView.NotReady; + private long _nextDayNightReadMs; + private int _dayNightFailures; + + private bool DayNightWindowWanted => Host.HasUiTheme && Host.HasSetPanelOpen; + + /// + /// RynthPluginRenderEmbed "window:daynight": the timer, docked or popped out (the engine's current + /// context). 1 drawn, 0 not ready, -2 failed (three draws in a row threw). Render thread. + /// + internal int RenderDayNight(out Vector2 want) + { + want = default; + if (!_initialized || Host.ImGuiContext == IntPtr.Zero) return 0; + IntPtr previous = ImGui.GetCurrentContext(); + ImGui.SetCurrentContext(EmbedContext()); + try + { + long now = Environment.TickCount64; + if (now >= _nextDayNightReadMs) + { + _nextDayNightReadMs = now + 500; + _dayNightView = ReadDayNight(now); + } + _dayNightWindow ??= new DayNightWindow(Host); + float h = _dayNightWindow.Draw(_dayNightView, _dashboard?.Settings?.DayNightBox == true); + want = new Vector2(0, h); + _dayNightFailures = 0; + return 1; + } + catch (Exception ex) + { + Host.Log($"[RynthAi] day/night draw failed: {ex.GetType().Name}: {ex.Message}"); + return ++_dayNightFailures >= 3 ? -2 : 0; + } + finally + { + ImGui.SetCurrentContext(previous); + } + } + + /// Tests: the game clock's raw value instead of AC's memory (there is no AC in a test). + internal static Func? GameClockOverride; + + /// The clock now; NotReady out of world (never read then) or before the clock is set. + private DayNightView ReadDayNight(long now) + { + if (!_loginComplete || !Host.HasGetPlayerId || Host.GetPlayerId() == 0) return DayNightView.NotReady; + double raw = GameClockOverride?.Invoke() + ?? BitConverter.Int64BitsToDouble(System.Runtime.InteropServices.Marshal.ReadInt64(new IntPtr(unchecked((int)DerethClock.ClockAddress)))); + return DerethClock.IsUsable(raw) ? new DayNightView(true, DerethClock.At(raw), now) : DayNightView.NotReady; + } + + /// "/ra daynight [show|hide|toggle|clear|box]": the timer shown or hidden (with the time now), or its background. + private void HandleDayNightCommand(string[] parts) + { + string verb = parts.Length > 2 ? parts[2].ToLowerInvariant() : "toggle"; + string? look = verb switch + { + "clear" or "transparent" or "nobox" => "clear", + "box" or "background" => "box", + _ => null, + }; + if (look != null) + { + var s = _dashboard?.Settings; + if (s == null) { ReplyFail("[RynthAi] Settings aren't loaded yet (log in first)."); return; } + s.DayNightBox = look == "box"; + _dashboard?.SaveSettings(); + ReplyOk(s.DayNightBox + ? "[RynthAi] Day/Night timer: on its dark box (/ra daynight clear for no background)." + : "[RynthAi] Day/Night timer: on a clear background (/ra daynight box brings the dark box back)."); + return; + } + RynthPanelOpen? mode = verb switch + { + "show" or "on" or "open" => RynthPanelOpen.Open, + "hide" or "off" or "close" => RynthPanelOpen.Close, + "" or "toggle" => RynthPanelOpen.Toggle, + _ => null, + }; + if (mode == null) { ReplyFail($"[RynthAi] '{verb}' isn't show, hide, clear or box. Usage: /ra daynight [show|hide|clear|box]"); return; } + + DayNightView clock = ReadDayNight(Environment.TickCount64); + string time = clock.Ready + ? $" {(clock.Now.IsDay ? "Day" : "Night")} now ({clock.Now.HourName}); {clock.Now.Next.ToLowerInvariant()} in {DerethClock.Countdown(clock.Now.SecondsToChange)} of real time." + : ""; + if (!Host.HasSetPanelOpen) { ReplyFail("[RynthAi] This RynthCore has no Day/Night timer window (it needs plugin windows)." + time); return; } + int state = Host.SetPanelOpen(DayNightTitle, mode.Value); + if (state < 0) { ReplyFail("[RynthAi] The Day/Night timer isn't there yet (RynthCore adds it a few seconds after login). Try again in a moment." + time); return; } + ReplyOk((state == 1 ? "[RynthAi] Day/Night timer shown." : "[RynthAi] Day/Night timer hidden.") + time); + } +} diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.LocalFeatures.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.LocalFeatures.cs index 953e19b..8d71781 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.LocalFeatures.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.LocalFeatures.cs @@ -505,7 +505,7 @@ public sealed partial class RynthAiPlugin return Huds.SectionsManifest.Build(Huds.SectionsManifest.Views(), Huds.SectionsManifest.OwnSections, dashboard: DashboardWindowWanted, monsterStats: MonsterStatsWindowWanted, timedCommands: TimedCommandsWindowWanted, activeGear: ActiveGearWindowWanted, featureSearch: FeatureSearchWindowWanted, acMaps: AcMapsWindowWanted, - commandButtons: CommandButtonsWindowWanted, tradeShop: TradeShopWindowWanted); + commandButtons: CommandButtonsWindowWanted, tradeShop: TradeShopWindowWanted, dayNight: DayNightWindowWanted); } /// Chat Translate window in the dashboard colours (no-op while hidden). private void RenderTranslateWindow() diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs index 86f656a..ff720a0 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs @@ -1128,6 +1128,7 @@ public sealed partial class RynthAiPlugin : RynthPluginBase case "settingsprofile": if (int.TryParse(value, out int si)) dash.SelectProfileAtIndex(3, si); break; case "buffprofile": if (int.TryParse(value, out int bi)) dash.SelectProfileAtIndex(4, bi); break; case "spells": HandleSpellsCommand(value); break; // dashboard Spells button: toggle|show|hide + case "daynight": HandleDayNightCommand(new[] { "/ra", "daynight", value }); break; // /rdef daynight hands over (2026-12-02) case LootWhyAction: HandleLootWhyCommand(window: true); break; // "Why this loot rule?" buttons case "forcerebuff": dash.RequestForceRebuff(); break; case "cancelrebuff": dash.RequestCancelForceRebuff(); break; @@ -4281,6 +4282,7 @@ public sealed partial class RynthAiPlugin : RynthPluginBase case "timed": HandleTimedCommand(parts); break; // RynthAiPlugin.TimedCommands.cs case "button": case "buttons": HandleButtonsCommand(parts); break; // RynthAiPlugin.CommandButtons.cs + case "daynight": HandleDayNightCommand(parts); break; // RynthAiPlugin.DayNight.cs (was /rdef daynight) case "find": HandleFindCommand(parts); break; // RynthAiPlugin.FeatureSearch.cs case "acmaps": HandleAcMapsCommand(parts); break; // RynthAiPlugin.AcMaps.cs case "aetheria": HandleAetheriaCommand(parts); break; // RynthAiPlugin.Aetheria.cs diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthCore.Plugin.RynthAi.csproj b/Plugins/RynthCore.Plugin.RynthAi/RynthCore.Plugin.RynthAi.csproj index 77d64bb..7949662 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthCore.Plugin.RynthAi.csproj +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthCore.Plugin.RynthAi.csproj @@ -72,6 +72,8 @@ + + diff --git a/Plugins/RynthCore.Plugin.RynthDefective/Model/DefData.cs b/Plugins/RynthCore.Plugin.RynthDefective/Model/DefData.cs index 7d25d7d..ff1d1e1 100644 --- a/Plugins/RynthCore.Plugin.RynthDefective/Model/DefData.cs +++ b/Plugins/RynthCore.Plugin.RynthDefective/Model/DefData.cs @@ -121,7 +121,8 @@ internal sealed class DefSettings /// The Day/Night timer's dark box (2026-12-01: a clear background, so it takes no /// room of its own). Off (the default, and what a file from before reads as): the timer /// is drawn on a clear background, its sun or moon and text shadowed so they read over the radar, - /// the arrow or the world. On: the dark box as before. /rdef daynight clear | box. + /// the arrow or the world. On: the dark box as before. Unused since 2026-12-02: the timer is RynthAi's + /// (its own DayNightBox); kept so a settings file from before still loads. /// public bool DayNightBox; /// diff --git a/Plugins/RynthCore.Plugin.RynthDefective/Model/DefReplies.cs b/Plugins/RynthCore.Plugin.RynthDefective/Model/DefReplies.cs index 4f824ac..50db344 100644 --- a/Plugins/RynthCore.Plugin.RynthDefective/Model/DefReplies.cs +++ b/Plugins/RynthCore.Plugin.RynthDefective/Model/DefReplies.cs @@ -26,25 +26,8 @@ internal static class DefReplies _ => (false, $"The {title} isn't open: open it first (/rdef appraisal), then pop it out."), }; - /// - /// /rdef daynight [show|hide]: the Day/Night timer after it ( as ), - /// 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." - /// - 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); - } - - /// /rdef daynight clear | box: the timer's background after it. - public static (bool Ok, string Text) DayNightLook(bool box) => (true, box - ? "Day/Night timer: on its dark box (/rdef daynight clear for no background)." - : "Day/Night timer: on a clear background (/rdef daynight box brings the dark box back)."); + /// /rdef daynight when RynthAi can't take it: the timer is RynthAi's since 2026-12-02. + public const string DayNightMoved = "The Day/Night timer is part of RynthAi now: load RynthAi, then /ra daynight [show|hide|clear|box]."; /// A slot's use started (the result shows on the bar; a problem is said in chat). public static string UseSlot(DefSlot slot, int number) => slot.IsSpell diff --git a/Plugins/RynthCore.Plugin.RynthDefective/PluginExports.cs b/Plugins/RynthCore.Plugin.RynthDefective/PluginExports.cs index 1ebea56..c0ee2d8 100644 --- a/Plugins/RynthCore.Plugin.RynthDefective/PluginExports.cs +++ b/Plugins/RynthCore.Plugin.RynthDefective/PluginExports.cs @@ -107,7 +107,6 @@ public static unsafe class PluginExports else if (name == RynthDefectivePlugin.SelectionSurface) result = plugin.RenderSelection(out wantH); else if (name == RynthDefectivePlugin.AppraisalSurface) result = plugin.RenderAppraisal(popped, 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; diff --git a/Plugins/RynthCore.Plugin.RynthDefective/RynthDefectivePlugin.Bar.cs b/Plugins/RynthCore.Plugin.RynthDefective/RynthDefectivePlugin.Bar.cs index 7a6746e..9c494ca 100644 --- a/Plugins/RynthCore.Plugin.RynthDefective/RynthDefectivePlugin.Bar.cs +++ b/Plugins/RynthCore.Plugin.RynthDefective/RynthDefectivePlugin.Bar.cs @@ -106,11 +106,7 @@ 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\"}"; - // 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 Day/Night timer was here until 2026-12-02; it is RynthAi's now, RynthAiPlugin.DayNight.cs.) // The extra bars (an engine before v100 hosts at most 8 windows for a plugin: these five and up to three // of them; v100 hosts 12, and the Appraisal window makes nine). string extras = ""; @@ -119,7 +115,7 @@ public sealed partial class RynthDefectivePlugin : IBarActions + 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 + appraisal + corpses + dayNight + extras + "]}"; + return "{\"version\":1,\"windows\":[" + bar + panels + selection + appraisal + corpses + extras + "]}"; } /// "window:bar2" ... "window:bar4": an extra bar's surface, and its number. diff --git a/Plugins/RynthCore.Plugin.RynthDefective/RynthDefectivePlugin.DayNight.cs b/Plugins/RynthCore.Plugin.RynthDefective/RynthDefectivePlugin.DayNight.cs deleted file mode 100644 index 396e9ab..0000000 --- a/Plugins/RynthCore.Plugin.RynthDefective/RynthDefectivePlugin.DayNight.cs +++ /dev/null @@ -1,66 +0,0 @@ -// ============================================================================ -// 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; - - /// RynthPluginRenderEmbed "window:daynight". 1 drawn, 0 not ready, -2 failed (three in a row). Render thread. - 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, _session.Settings.DayNightBox); - _dayNightFailures = 0; - return 1; - } - catch (Exception ex) - { - Host.Log($"[RynthDefective] day/night draw failed: {ex.GetType().Name}: {ex.Message}"); - return ++_dayNightFailures >= 3 ? -2 : 0; - } - } - - /// Plugin tick: the clock's view while the window shows. - 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}"); } - } - - /// The clock now; NotReady out of world (never read then) or before the clock is set. - 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; - } -} diff --git a/Plugins/RynthCore.Plugin.RynthDefective/RynthDefectivePlugin.cs b/Plugins/RynthCore.Plugin.RynthDefective/RynthDefectivePlugin.cs index 1a29bc1..a5e6f31 100644 --- a/Plugins/RynthCore.Plugin.RynthDefective/RynthDefectivePlugin.cs +++ b/Plugins/RynthCore.Plugin.RynthDefective/RynthDefectivePlugin.cs @@ -136,7 +136,6 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase _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(); @@ -234,22 +233,10 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase else PrintFail("This RynthCore can't show the corpses window (it needs plugin API v90)."); break; case DefVerb.DayNight: - { - if (c.Text is "clear" or "box") - { - // The timer's background (2026-12-01): kept with the character's settings. - _session.Settings.DayNightBox = c.Text == "box"; - RequestSave(); - Answer(DefReplies.DayNightLook(_session.Settings.DayNightBox)); - break; - } - // 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)); + // The Day/Night timer is RynthAi's since 2026-12-02 (R-20261202-122606-0b16): handed over, RynthAi answers. + if (!(Host.HasSendPluginCommand && Host.SendPluginCommand("RynthAi", "daynight", c.Text))) + PrintFail(DefReplies.DayNightMoved); 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)."); @@ -501,7 +488,6 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase TickAppraisal(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 diff --git a/Tools/RynthCore.RynthAiHostTests/Tests/CommandReplyTests.cs b/Tools/RynthCore.RynthAiHostTests/Tests/CommandReplyTests.cs index dc14e3e..8469b85 100644 --- a/Tools/RynthCore.RynthAiHostTests/Tests/CommandReplyTests.cs +++ b/Tools/RynthCore.RynthAiHostTests/Tests/CommandReplyTests.cs @@ -7,6 +7,7 @@ using RynthCore.Plugin.RynthAi; using RynthCore.Plugin.RynthAi.LegacyUi; using RynthCore.Plugin.RynthAi.Meta; using RynthCore.PluginCore; +using RynthCore.Plugin.Shared; using RynthCore.RynthAiHostTests.Fakes; using RynthCore.RynthAiTests.Harness; @@ -25,6 +26,7 @@ internal static class CommandReplyTests public static void Register(Runner r) { r.Add("command replies: CommandReply - typed always answers, a script's success is quiet, errors once a minute", HelperRules); + r.Add("day/night timer (R-20261202-122606-0b16): RynthAi's now - its window in the manifest, /ra daynight show|hide|clear|box, /rdef's hand-over", DayNightInRynthAi); r.Add("command replies: every typed command answers in chat, never with the catch-all line", TypedAlwaysAnswers); r.Add("command replies: a typed command's wrong form answers with a failure line (the failure colour)", TypedWrongFormsFail); r.Add("command replies: a meta's command is quiet when it works; its error shows, a repeat not within a minute", MetaQuietOnSuccess); @@ -472,6 +474,57 @@ internal static class CommandReplyTests // ── The rig: a logged-in RynthAi with a meta manager, combat, a jumper and the fakes ── + // R-20261202-122606-0b16: /rdef daynight box said "Unknown command: rdef" (no RynthDefective loaded). + // 2026-12-02: the timer lives in RynthAi, so players don't need RynthDefective for it. + private static void DayNightInRynthAi() + { + // The window: in RynthAi's manifest, same title as before (RynthCore keeps its place), a bar button, frameless. + string json = RynthCore.Plugin.RynthAi.Huds.SectionsManifest.Build( + RynthCore.Plugin.RynthAi.Huds.SectionsManifest.Views(), RynthCore.Plugin.RynthAi.Huds.SectionsManifest.OwnSections, dayNight: true); + var m = RynthCore.Engine.UI.Sections.SectionManifestParser.Parse("RynthAi", json, out string error); + Check.Eq(error, string.Empty, "the manifest parses"); + var w = m.Windows.SingleOrDefault(x => x.Surface == "window:daynight"); + Check.True(w != null, "the Day/Night window is RynthAi's"); + Check.Eq(w!.Title, "Day/Night", "the same title as RynthDefective's (its saved place and the Settings rows)"); + Check.True(w.Bar && w.Frameless && w.FitHeight, "a bar button, frameless, its height from the draw"); + Check.False(RynthCore.Plugin.RynthAi.Huds.SectionsManifest.Build( + RynthCore.Plugin.RynthAi.Huds.SectionsManifest.Views(), RynthCore.Plugin.RynthAi.Huds.SectionsManifest.OwnSections).Contains("window:daynight"), + "not declared when the engine can't host it"); + + // The view counts down from its reading; the tooltip names RynthAi's command. + var v = new RynthCore.Plugin.RynthAi.DayNight.DayNightView(true, DerethClock.At(DerethClock.TicksInDay + 5715 - 100 - 3600), 1000); + Check.Near(v.SecondsLeft(3500), 97.5, 1e-9, "2.5 s after the reading"); + string tip = RynthCore.Plugin.RynthAi.DayNight.DayNightWindow.Tip(v, 100); + Check.True(tip.Contains("/ra daynight", StringComparison.Ordinal) && !tip.Contains("/rdef", StringComparison.Ordinal), "the tooltip says /ra daynight: " + tip); + + // Its background: clear by default, a profile from before loads clear; /ra daynight box | clear, said in chat. + Check.False(new LegacyUiSettings().DayNightBox, "clear by default"); + var old = System.Text.Json.JsonSerializer.Deserialize("{\"EnableBuffing\":true}", RynthAiJsonContext.Default.LegacyUiSettings); + Check.True(old != null && !old.DayNightBox, "a profile from before: clear"); + using var rig = new Rig(); + RynthAiPlugin.GameClockOverride = () => DerethClock.TicksInDay + 5715 - 3600; // dusk (no AC memory in a test) + try + { + var said = rig.Typed("/ra daynight box"); + Check.True(rig.S.DayNightBox, "/ra daynight box: the dark box"); + Check.True(said.Any(l => l.Text.Contains("dark box", StringComparison.Ordinal)), "said: " + string.Join(" | ", said.Select(l => l.Text))); + said = rig.Typed("/ra daynight clear"); + Check.False(rig.S.DayNightBox, "/ra daynight clear: no background"); + Check.True(said.Any(l => l.Text.Contains("clear background", StringComparison.Ordinal)), "said"); + said = rig.Typed("/ra daynight soon"); + Check.True(said.Any(l => l.Text.Contains("Usage: /ra daynight", StringComparison.Ordinal)), "a wrong word: the usage"); + said = rig.Typed("/ra daynight show"); + Check.True(said.Count > 0 && said.All(l => !l.Text.Contains("Unknown", StringComparison.Ordinal)), "show answers: " + string.Join(" | ", said.Select(l => l.Text))); + + // /rdef daynight hands over through the plugin-command broker ("daynight", the rest of the line). + Rig.Lines(() => rig.Call("ApplyRemoteCommand", "daynight", "box")); + Check.True(rig.S.DayNightBox, "RynthDefective's hand-over: box"); + Rig.Lines(() => rig.Call("ApplyRemoteCommand", "daynight", "clear")); + Check.False(rig.S.DayNightBox, "and clear"); + } + finally { RynthAiPlugin.GameClockOverride = null; } + } + private sealed class Rig : IDisposable { public readonly RynthAiPlugin P = new(); diff --git a/Tools/RynthDefective.Tests/ClockTests.cs b/Tools/RynthDefective.Tests/ClockTests.cs index 6128896..970a933 100644 --- a/Tools/RynthDefective.Tests/ClockTests.cs +++ b/Tools/RynthDefective.Tests/ClockTests.cs @@ -1,5 +1,4 @@ using System; -using RynthCore.Plugin.RynthDefective.Clock; using RynthCore.Plugin.RynthDefective.Model; using RynthCore.Plugin.Shared; @@ -120,18 +119,7 @@ namespace RynthDefective.Tests private static void ClockWindowAndCommand() { - // The window counts down from when the tick read the clock. - var v = new DayNightView(true, DerethClock.At(RawAt(5715 - 100)), 1000); - Eq(v.SecondsLeft(1000), 100.0, "at the reading"); - Eq(v.SecondsLeft(3500), 97.5, "2.5 s later"); - Eq(v.SecondsLeft(1_000_000), 0.0, "long after: 0, not negative"); - Check(!DayNightView.NotReady.Ready, "before the world: not ready"); - Eq(DayNightWindow.NotInWorld, "—", "out of world it shows a dash"); - Check(DayNightWindow.Tip(DayNightView.NotReady, 0).Contains("in the world", StringComparison.Ordinal), "tooltip out of world"); - string tip = DayNightWindow.Tip(v, 100); - Check(tip.Contains("Day now (Warmtide-and-Half)", StringComparison.Ordinal) && tip.Contains("Night comes at Evensong, in 1 min 40 s", StringComparison.Ordinal), "tooltip: " + tip); - - // /rdef daynight [show|hide]: parsed, and every answer says what happened. + // /rdef daynight [show|hide|clear|box]: still parsed; since 2026-12-02 it hands over to RynthAi (/ra daynight). Eq(DefCommandParser.Parse("daynight").Text, "", "alone: toggle"); Eq(DefCommandParser.Parse("daynight show").Text, "show", "show"); Eq(DefCommandParser.Parse("DayNight ON").Text, "show", "on = show, any case"); @@ -145,16 +133,7 @@ namespace RynthDefective.Tests Eq(DefCommandParser.Parse("daynight transparent").Text, "clear", "transparent = clear"); Eq(DefCommandParser.Parse("daynight box").Text, "box", "daynight box"); Check(DefCommandParser.Usage.Contains("daynight [show|hide|clear|box]", StringComparison.Ordinal), "clear and box in the usage"); - Check(!new DefSettings().DayNightBox, "a clear background by default (and for a settings file from before)"); - Check(DefReplies.DayNightLook(false).Text.Contains("clear background", StringComparison.Ordinal), "clear: said so"); - Check(DefReplies.DayNightLook(true).Text.Contains("dark box", StringComparison.Ordinal), "box: said so"); - - DerethNow dusk = DerethClock.At(RawAt(5715)); - Eq(DefReplies.DayNight(1, dusk), (true, "Day/Night timer shown. Night now (Evensong); day in 1h 4m of real time."), "shown, with the time"); - Eq(DefReplies.DayNight(0, null), (true, "Day/Night timer hidden."), "hidden, out of world: no time"); - var old = DefReplies.DayNight(-1, dusk); - Check(!old.Ok && old.Text.Contains("v90", StringComparison.Ordinal) && old.Text.Contains("day in 1h 4m", StringComparison.Ordinal), - "an engine without the window: why, and the time still"); + Check(DefReplies.DayNightMoved.Contains("/ra daynight", StringComparison.Ordinal), "without RynthAi: where it went"); } } } diff --git a/Tools/RynthDefective.Tests/Program.cs b/Tools/RynthDefective.Tests/Program.cs index 2efed92..6ceb59b 100644 --- a/Tools/RynthDefective.Tests/Program.cs +++ b/Tools/RynthDefective.Tests/Program.cs @@ -129,7 +129,7 @@ namespace RynthDefective.Tests Run("day/night: day or night, the hour and the real seconds to dawn or dusk", ClockDayNight); Run("day/night: the same as RynthAi's meta expressions, a countdown with no jumps", ClockMatchesRynthAi); Run("day/night: the countdown text (23m, 4m 10s, 45s)", ClockCountdownText); - Run("day/night: the window's view and tooltip, /rdef daynight and its answers", ClockWindowAndCommand); + Run("day/night: /rdef daynight is parsed and hands over to RynthAi", ClockWindowAndCommand); Run("appraisal: a weapon's lines (skill, damage, speed, bonuses, slayer, wield, workmanship, set, ratings)", AppraiseWeapon); Run("appraisal: armor's protections and coverage, mana, spellcraft, the flags", AppraiseArmorAndMana); Run("appraisal: a caster's bonuses", AppraiseCaster);