77 lines
4.1 KiB
C#
77 lines
4.1 KiB
C#
using System.Globalization;
|
|
using RynthCore.Plugin.Shared;
|
|
|
|
namespace RynthCore.Plugin.RynthDefective.Model;
|
|
|
|
/// <summary>
|
|
/// The line /rdef answers with for the commands that used to say nothing (2026-10-28: every command
|
|
/// answers, Plugins/Shared/CommandReply.cs): a window shown or hidden, a use started, a test
|
|
/// selection. Pure, so RynthDefective.Tests checks every verb's line.
|
|
/// </summary>
|
|
internal static class DefReplies
|
|
{
|
|
/// <summary>A window after a show / hide / toggle: <paramref name="state"/> 1 shown, 0 hidden, -1 the engine can't say.</summary>
|
|
public static (bool Ok, string Text) Window(string title, int state) => state switch
|
|
{
|
|
1 => (true, CommandReply.Shown(title, true)),
|
|
0 => (true, CommandReply.Shown(title, false)),
|
|
_ => (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})."
|
|
: $"Using {slot.Label} (slot {number}).";
|
|
|
|
/// <summary>"/rdef use <name>" started: the item is looked up when the use runs.</summary>
|
|
public static string UseName(string name) => $"Using {name.Trim()}.";
|
|
|
|
/// <summary>The weapon picker after /rdef weapons [search].</summary>
|
|
public static string Weapons(bool shown, string search) =>
|
|
!shown ? "Weapon picker hidden."
|
|
: search.Trim().Length > 0 ? $"Weapon picker shown, searching '{search.Trim()}'."
|
|
: "Weapon picker shown.";
|
|
|
|
/// <summary>
|
|
/// "/rdef selection <0xId>" (the Selection window's test hook): the object id (hex, "0x" optional),
|
|
/// or false with the usage in <paramref name="why"/>.
|
|
/// </summary>
|
|
public static bool TryParseSelection(string text, out uint id, out string why)
|
|
{
|
|
why = string.Empty;
|
|
string t = text.Trim();
|
|
if (uint.TryParse(t.Replace("0x", "", System.StringComparison.OrdinalIgnoreCase), NumberStyles.HexNumber, null, out id)) return true;
|
|
why = $"'{t}' isn't an object id. Usage: /rdef selection [0x80001234 | stack]";
|
|
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.";
|
|
|
|
/// <summary>What a test selection did.</summary>
|
|
public static (bool Ok, string Text) Selected(uint id, bool selected, string? name) =>
|
|
selected ? (true, $"Selected 0x{id:X8}{(string.IsNullOrEmpty(name) ? "" : " (" + name + ")")}.")
|
|
: (false, $"The game didn't select 0x{id:X8}.");
|
|
}
|