using System;
using System.Collections.Generic;
namespace RynthCore.Plugin.RynthThreads.Threads;
/// One number in a modifier's description, with the form it was written in.
internal readonly struct ModNumber
{
/// "x1.38" multiplier.
public const string Mult = "mult";
/// "12%".
public const string Pct = "pct";
/// "+29" (or "-5"): a signed amount, e.g. a rating.
public const string Plus = "plus";
/// A plain number.
public const string Num = "num";
public readonly double Value;
public readonly string Kind;
/// As written ("x1.38", "12%", "+29", "75").
public readonly string Text;
public ModNumber(double value, string kind, string text)
{
Value = value;
Kind = kind;
Text = text;
}
}
/// One "Name - description" line of the gem's block.
internal sealed class GemModifier
{
public string Name = string.Empty;
public string Description = string.Empty;
public List Numbers = new();
}
///
/// One press at a Fragment Press, as the server told it in chat. Everything the server says is
/// kept as said (numbers raw): "Level 190, 4 entries." goes into ResultLevel and Entries without
/// guessing what entries are.
///
internal sealed class Press
{
/// Random id, so a press read back from the shared file isn't counted twice.
public string Id = string.Empty;
public DateTime TimeUtc;
public string Server = string.Empty;
public string Character = string.Empty;
/// "Raw Fragment" from "Using the Raw Fragment (Level 185) with the Fragment Press".
public string Fragment = string.Empty;
public int? FragmentLevel;
/// "Fragment Press".
public string Tool = string.Empty;
/// The "Pressed. ..." line ("Pressed. It holds."), or "" when none came.
public string Outcome = string.Empty;
/// A "Components selected: ..." (or "No components ...") line came.
public bool ComponentsSeen;
/// Sorted, case-insensitively.
public List Components = new();
/// The "... drawn at random." line, or "".
public string RandomNote = string.Empty;
public List Modifiers = new();
public int? ResultLevel;
public int? Entries;
/// Ended on its "Level N, M entries." line. False: timed out, or another "Using ..." line came first.
public bool Complete;
/// Why it ended: "done", "timeout", "next use", "logout".
public string End = string.Empty;
/// The press's own lines, in order.
public List Raw = new();
/// Lines that came while the press was open but didn't fit it (other players' chat, or text not known yet).
public List Extra = new();
/// The press says "It holds." (the only success text seen so far).
public bool Held => Outcome.IndexOf("holds", StringComparison.OrdinalIgnoreCase) >= 0;
/// Used by the inference: a finished press with its whole gem block.
public bool Usable => Complete && Modifiers.Count > 0;
public bool HasComponent(string name)
{
foreach (string c in Components)
if (string.Equals(c, name, StringComparison.OrdinalIgnoreCase)) return true;
return false;
}
public bool HasModifier(string name)
{
foreach (GemModifier m in Modifiers)
if (string.Equals(m.Name, name, StringComparison.OrdinalIgnoreCase)) return true;
return false;
}
public GemModifier? FindModifier(string name)
{
foreach (GemModifier m in Modifiers)
if (string.Equals(m.Name, name, StringComparison.OrdinalIgnoreCase)) return m;
return null;
}
public string ComponentsText => Components.Count == 0 ? "no components" : string.Join(", ", Components);
public static string NewId() => Guid.NewGuid().ToString("N").Substring(0, 16);
}