namespace Aeshnidae.Trials;
///
/// The Trials in the Codex (Aeshnidae.Codex finds this class by reflection when
/// "Aeshnidae.Trials" is in its Sections): your bests, the records you hold, the
/// trophies you have won, then the server records.
///
public static class CodexPage
{
public static string Title => "Trials";
public static string[] Pages(Player player)
{
if (player is null || !TrialDb.Ready || !Mod.Settings.Enabled)
return Array.Empty();
try
{
var s = Mod.Settings;
var pages = new List();
var me = new StringBuilder();
me.AppendLine("TRIALS");
me.AppendLine();
me.AppendLine("A fresh personal copy of a listed dungeon, entered through its portal, is a timed course: kill everything and the clock stops. Leaving, dying or a teleport voids the run.");
me.AppendLine();
var bests = TrialDb.PersonalBests(player.Guid.Full);
me.AppendLine("Your bests:");
if (bests.Count == 0)
me.AppendLine(" none yet");
foreach (var b in bests)
me.AppendLine($" {Mod.TrialName(b.Landblock)}, tier {b.Tier}: {b.Time}");
var held = TrialDb.RecordsHeldBy(player.Guid.Full);
me.AppendLine();
me.AppendLine($"Records held: {held.Count}");
foreach (var r in held)
me.AppendLine($" {Mod.TrialName(r.Landblock)}, tier {r.Tier}: {r.Time}");
var won = TrialDb.AwardsOf(player.Guid.Full);
me.AppendLine();
me.AppendLine($"Trophies won: {won.Count}");
foreach (var a in won.Take(8))
me.AppendLine($" {Mod.TrialName(a.Landblock)}, week of {Weeks.Describe(a.Week, s)}: {a.Time} (tier {a.Tier})");
pages.Add(me.ToString().TrimEnd());
var sb = new StringBuilder();
sb.AppendLine("SERVER RECORDS");
sb.AppendLine();
var records = TrialDb.ServerBests();
foreach (var (landblock, _) in Mod.Trials.OrderBy(kv => kv.Key))
{
sb.AppendLine(Mod.TrialName(landblock).ToUpperInvariant());
var rows = records.Where(r => r.Landblock == landblock).OrderBy(r => r.Tier).ToList();
if (rows.Count == 0)
sb.AppendLine(" no clear yet");
foreach (var r in rows)
sb.AppendLine($" tier {r.Tier}: {r.Time} - {r.CharacterName}");
sb.AppendLine();
}
sb.AppendLine($"Trophies go out {s.AwardDayOfWeek}s at {s.AwardHour:00}:00. /trial for the boards.");
pages.Add(sb.ToString().TrimEnd());
return pages.ToArray();
}
catch (Exception ex)
{
ModManager.Log($"[{Mod.Name}] Codex page failed: {ex.Message}", ModManager.LogLevel.Warn);
return Array.Empty();
}
}
}