fix(spells): load complete retail DAT catalog

Replace the incomplete 3,956-row production CSV with one immutable projection of all 6,266 records in portal.dat. Preserve retail formula targeting, shared Spellbook/MagicRuntime metadata ownership, and fail startup when the required SpellTable is absent.

Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-15 21:17:13 +02:00
parent 09612f9981
commit 0eab7497c1
19 changed files with 633 additions and 114 deletions

View file

@ -16,6 +16,34 @@ public sealed class RetailSpellFormulaTests
=> Assert.Equal(expected,
RetailSpellFormula.InqSpellLevelByRoughHeuristic([component]));
[Theory]
[InlineData(0x31u, 0x10u)]
[InlineData(0x39u, 0x00088B8Fu)]
[InlineData(0x3Bu, 0x10010000u)]
[InlineData(0xBEu, 0x10u)]
[InlineData(0x30u, 0u)]
public void TargetComponent_UsesRetailItemTypeMask(uint component, uint expected)
=> Assert.Equal(expected,
RetailSpellFormula.GetTargetTypeFromComponentId(component));
[Fact]
public void TargetingType_UsesTargetFormulaSlotsOnly()
{
Assert.Equal(0x10u,
RetailSpellFormula.GetTargetingType([1u, 2u, 3u, 4u, 5u, 0x31u]));
Assert.Equal(0u,
RetailSpellFormula.GetTargetingType([1u, 2u, 3u, 0x31u]));
}
[Fact]
public void TargetingType_MapsFinalPopulatedFormulaComponent()
{
Assert.Equal(0x10u,
RetailSpellFormula.GetTargetingType([1u, 2u, 3u, 4u, 0x39u, 0x31u]));
Assert.Equal(0x00088B8Fu,
RetailSpellFormula.GetTargetingType([1u, 2u, 3u, 4u, 0x39u, 0u, 0x31u]));
}
[Fact]
public void CustomizeForAccount_IsDeterministic_AndOnlyChangesTapers()
{

View file

@ -27,6 +27,17 @@ public sealed class SpellTableTests
Assert.False(SpellTable.Empty.TryGet(1u, out _));
}
[Fact]
public void Create_RejectsDuplicateSpellIds()
{
SpellMetadata spell = new(
1u, "One", "War Magic", 0u, 0u, "", 0f, 0,
false, false, "", 0, 0, 0u, 0, false, false, true,
0f, 0u, 0u, 0u, 0);
Assert.Throws<ArgumentException>(() => SpellTable.Create([spell, spell]));
}
[Fact]
public void LoadFromReader_HeaderOnly_EmptyTable()
{

View file

@ -5,6 +5,25 @@ namespace AcDream.Core.Tests.Spells;
public sealed class SpellbookTests
{
[Fact]
public void InstallMetadata_InstallsOnceAndRefreshesExistingLearnedState()
{
var book = new Spellbook();
book.OnSpellLearned(1u);
int changes = 0;
book.SpellbookChanged += () => changes++;
SpellTable table = SpellTable.Create([TestSpell(1u)]);
book.InstallMetadata(table);
Assert.Same(table, book.Metadata);
Assert.True(book.TryGetMetadata(1u, out _));
Assert.Equal(1, changes);
book.InstallMetadata(table);
Assert.Throws<InvalidOperationException>(
() => book.InstallMetadata(SpellTable.Empty));
}
[Fact]
public void OnSpellLearned_FiresEvent_Idempotent()
{
@ -187,4 +206,9 @@ public sealed class SpellbookTests
StartTime: 10d,
SpellCategory: category,
PowerLevel: 7u);
private static SpellMetadata TestSpell(uint spellId) => new(
spellId, "Test", "War Magic", 0u, 0u, "", 0f, 0,
false, false, "", 0, 0, 0u, 0, false, false, true,
0f, 0u, 0u, 0u, 0);
}