RynthSuite/Plugins/RynthCore.Plugin.RynthInventory/Scanning/SpellTable.cs
BlankenshipG dc08e1abba feat: SK backlog from test through 2026.11.22.48 (Trade Shop, Oracle, quests, loot, nav)
Squash of test/main-merge-2026-10-25 onto aelrynth main 2026.11.19.1 for the standing sk PR. Includes Trade Shop, Oracle wiki/ILT tracker, quest runs, loot checklist, RynthNav, VTank import. HandWrittenVersion remains 0.5.0-legacy-ui. See Changelog/2026-11-22-sk-backlog-test-merge.md.
2026-11-23 00:08:38 -05:00

70 lines
3 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
namespace RynthCore.Plugin.RynthInventory.Scanning;
internal readonly record struct SpellInfo(string Name, double Duration, bool IsDebuff, int Family = 0, int Power = 0);
/// <summary>
/// Spell names and base durations from RynthAi's embedded spell table (SpellData.txt, linked
/// into this plugin): tab separated, id, name, category, family, words, duration (s, -1 none),
/// difficulty, then three flags, the second of which marks a debuff. Loaded on first use.
/// </summary>
internal static class SpellTable
{
private static Dictionary<uint, SpellInfo>? _spells;
public static bool TryGet(uint id, out SpellInfo info)
{
EnsureLoaded();
return _spells!.TryGetValue(id, out info);
}
public static string Name(uint id) => TryGet(id, out SpellInfo s) ? s.Name : $"Spell {id}";
/// <summary>Every spell in the table with its family and power (Global Inventory's filter spell lists).</summary>
public static List<RynthCore.Loot.Editing.LootSpellEntry> AllSpells()
{
EnsureLoaded();
var list = new List<RynthCore.Loot.Editing.LootSpellEntry>(_spells!.Count);
foreach (SpellInfo s in _spells.Values) list.Add(new RynthCore.Loot.Editing.LootSpellEntry(s.Name, s.Family, s.Power));
return list;
}
public static int Count
{
get { EnsureLoaded(); return _spells!.Count; }
}
private static void EnsureLoaded()
{
if (_spells != null) return;
var map = new Dictionary<uint, SpellInfo>();
try
{
using Stream? s = Assembly.GetExecutingAssembly().GetManifestResourceStream("RynthInventory.SpellData.txt");
if (s != null)
{
using var reader = new StreamReader(s, detectEncodingFromByteOrderMarks: true);
while (reader.ReadLine() is string line)
{
string[] c = line.Split('\t');
if (c.Length < 2 || !uint.TryParse(c[0].Trim(), NumberStyles.None, CultureInfo.InvariantCulture, out uint id)) continue;
double duration = c.Length > 5 && double.TryParse(c[5].Trim(), NumberStyles.Float | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out double d) ? d : -1;
bool debuff = c.Length > 8 && c[8].Trim().Equals("True", StringComparison.OrdinalIgnoreCase);
int family = c.Length > 2 && int.TryParse(c[2].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int fam) ? fam : 0;
int power = c.Length > 6 && int.TryParse(c[6].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int pw) ? pw : 0;
map[id] = new SpellInfo(c[1].Trim(), duration, debuff, family, power);
}
}
}
catch
{
// A missing table only costs names ("Spell 1234").
}
_spells = map;
}
}