300 lines
15 KiB
C#
300 lines
15 KiB
C#
using AcDream.Content.CharGen;
|
|
using AcDream.Core.CharGen;
|
|
using DatReaderWriter;
|
|
using DatReaderWriter.Options;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace AcDream.Content.Tests.CharGen;
|
|
|
|
/// <summary>
|
|
/// Installed-DAT gate for <see cref="ChargenAppearanceCatalog"/> +
|
|
/// <see cref="ChargenAppearanceFactory"/> together: for every one of the 13
|
|
/// installed heritages' genders, composes a "pick the first offered option
|
|
/// everywhere, mid shade" selection and asserts it resolves with no missing
|
|
/// PalSet or ClothingTable dat ids — the CC6a task's explicit acceptance
|
|
/// bar ("every heritage/gender's default selection resolves to a complete
|
|
/// description with no missing dat ids"). ALSO pins the TS-82 measurement
|
|
/// with real assertions (not WriteLine-only diagnostics, per the CC6a
|
|
/// review fix round F7): the nine standard heritages with clothing UI shown
|
|
/// resolve zero <c>ClothingBaseEffects</c> gaps, and Undead resolves
|
|
/// EXACTLY the four measured gaps on both genders — see the class doc on
|
|
/// <see cref="ChargenClothingTable"/>'s deliberate scope cut.
|
|
///
|
|
/// <para>Env-gated skip (house pattern, matched from
|
|
/// <c>ChargenTableReaderInstalledDatTests</c>/<c>ContentConformanceDats</c>):
|
|
/// returns green with a console SKIP note when no installed dat directory is
|
|
/// configured, rather than a true xUnit Skipped status — no other Content
|
|
/// installed-DAT test in this project uses <c>Assert.Skip</c>, so this stays
|
|
/// consistent with the rest of the suite rather than introducing a new
|
|
/// convention.</para>
|
|
/// </summary>
|
|
[Trait("Lane", "InstalledDat")]
|
|
public sealed class ChargenAppearanceCatalogInstalledDatTests
|
|
{
|
|
private readonly ITestOutputHelper _out;
|
|
public ChargenAppearanceCatalogInstalledDatTests(ITestOutputHelper output) => _out = output;
|
|
|
|
// ACE ACE.Entity.Enum.HeritageGroup ids. Gearknight (6)/Olthoi (12)/
|
|
// OlthoiAcid (13) are deliberately not named here — see the WriteLine-only
|
|
// comment in the loop below for why they carry no pinned expectation.
|
|
private const uint TumerokId = 7u;
|
|
private const uint UndeadId = 11u;
|
|
|
|
/// <summary>
|
|
/// The 9 standard heritages whose UI actually shows clothing controls
|
|
/// AND whose default gear resolves with zero <c>ClothingBaseEffects</c>
|
|
/// gaps (measured, not the full "clothing UI shown" set — Undead is
|
|
/// ALSO clothing-UI-shown but is the one real gap, asserted separately
|
|
/// below). Aluvian/Gharu'ndim/Sho/Viamontian/Shadowbound/Tumerok/Lugian/
|
|
/// Empyrean/Penumbraen = every heritage id 1-10 except Gearknight (6).
|
|
/// </summary>
|
|
private static readonly uint[] StandardZeroGapHeritageIds = [1u, 2u, 3u, 4u, 5u, TumerokId, 8u, 9u, 10u];
|
|
|
|
/// <summary>
|
|
/// Measured (installed EoR dat, both genders, identical order): Undead's
|
|
/// default headgear/trousers/shirt/footwear choices' clothing tables, in
|
|
/// the factory's own Headgear→Trousers→Shirt→Footwear composition order.
|
|
/// ALL FOUR slots miss — not "headgear/trousers/footwear" (a three-slot
|
|
/// undercount an earlier draft of this row stated in error).
|
|
/// </summary>
|
|
private static readonly uint[] UndeadMeasuredMissingClothingTableIds =
|
|
[0x10000009u, 0x100000F9u, 0x10000001u, 0x10000007u];
|
|
|
|
private static string? ResolveDatDir()
|
|
{
|
|
string? fromEnv = Environment.GetEnvironmentVariable("ACDREAM_DAT_DIR");
|
|
if (!string.IsNullOrWhiteSpace(fromEnv) && Directory.Exists(fromEnv))
|
|
return fromEnv;
|
|
string def = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
|
"Documents", "Asheron's Call");
|
|
return Directory.Exists(def) ? def : null;
|
|
}
|
|
|
|
[Fact]
|
|
public void EveryHeritageGendersDefaultSelection_ResolvesWithNoMissingDatIds()
|
|
{
|
|
string? datDir = ResolveDatDir();
|
|
if (datDir is null)
|
|
{
|
|
_out.WriteLine("SKIP: installed retail DAT directory is unavailable.");
|
|
Assert.Fail("Lane=InstalledDat requires an installed retail DAT directory; see docs/release-gate.md.");
|
|
}
|
|
|
|
using var dats = new DatCollection(datDir, DatAccessType.Read);
|
|
using var adapter = new DatCollectionAdapter(dats);
|
|
|
|
ChargenOptions options = ChargenTableReader.Load(adapter);
|
|
Assert.NotEmpty(options.HeritagesById);
|
|
var catalog = new ChargenAppearanceCatalog(adapter);
|
|
|
|
int composed = 0;
|
|
var missingSummaries = new List<string>();
|
|
var baseEffectGapFailures = new List<string>();
|
|
|
|
foreach (ChargenHeritageOptions heritage in options.HeritagesById.Values)
|
|
{
|
|
foreach ((int genderKey, ChargenGenderOptions gender) in heritage.GendersByKey)
|
|
{
|
|
ChargenAppearanceSelection selection = MakeDefaultSelection(gender);
|
|
|
|
bool ok = ChargenAppearanceFactory.TryCompose(
|
|
options, heritage.HeritageId, genderKey, selection,
|
|
catalog, catalog, out ChargenAppearanceResult result);
|
|
|
|
Assert.True(ok, $"heritage=0x{heritage.HeritageId:X} gender={genderKey} failed to resolve heritage/gender");
|
|
composed++;
|
|
|
|
if (result.MissingPalSetIds.Count > 0 || result.MissingClothingTableIds.Count > 0)
|
|
{
|
|
missingSummaries.Add(
|
|
$"heritage={heritage.Name} gender={genderKey}: "
|
|
+ $"missingPalSets=[{string.Join(",", result.MissingPalSetIds.Select(id => $"0x{id:X8}"))}] "
|
|
+ $"missingClothingTables=[{string.Join(",", result.MissingClothingTableIds.Select(id => $"0x{id:X8}"))}]");
|
|
}
|
|
|
|
_out.WriteLine(
|
|
$"heritage={heritage.Name} (0x{heritage.HeritageId:X}) gender={genderKey} setup=0x{result.SetupId:X8}: "
|
|
+ $"{result.ClothingTablesMissingBaseEffectForSetup.Count} clothing table(s) with no "
|
|
+ "ClothingBaseEffects entry for this body setup "
|
|
+ $"[{string.Join(",", result.ClothingTablesMissingBaseEffectForSetup.Select(id => $"0x{id:X8}"))}]");
|
|
|
|
// TS-82's pinned measurement — real assertions, not WriteLine-only.
|
|
if (StandardZeroGapHeritageIds.Contains(heritage.HeritageId))
|
|
{
|
|
if (result.ClothingTablesMissingBaseEffectForSetup.Count != 0)
|
|
{
|
|
baseEffectGapFailures.Add(
|
|
$"heritage={heritage.Name} gender={genderKey}: expected ZERO ClothingBaseEffects "
|
|
+ $"gaps (a standard heritage with clothing UI shown), measured "
|
|
+ $"{result.ClothingTablesMissingBaseEffectForSetup.Count}: "
|
|
+ $"[{string.Join(",", result.ClothingTablesMissingBaseEffectForSetup.Select(id => $"0x{id:X8}"))}]");
|
|
}
|
|
}
|
|
else if (heritage.HeritageId == UndeadId)
|
|
{
|
|
if (!result.ClothingTablesMissingBaseEffectForSetup.SequenceEqual(UndeadMeasuredMissingClothingTableIds))
|
|
{
|
|
baseEffectGapFailures.Add(
|
|
$"heritage=Undead gender={genderKey}: expected EXACTLY "
|
|
+ $"[{string.Join(",", UndeadMeasuredMissingClothingTableIds.Select(id => $"0x{id:X8}"))}], measured "
|
|
+ $"[{string.Join(",", result.ClothingTablesMissingBaseEffectForSetup.Select(id => $"0x{id:X8}"))}]");
|
|
}
|
|
}
|
|
// Gearknight/Olthoi/OlthoiAcid: retail hides the clothing UI
|
|
// entirely for these three (gmCGAppearancePage::Update
|
|
// @0x0047E8F0's SetVisible(0) branches), so a real chargen
|
|
// selection never reaches this composer's clothing slots for
|
|
// them — no pinned expectation either way, WriteLine above
|
|
// is diagnostic only.
|
|
}
|
|
}
|
|
|
|
_out.WriteLine($"composed {composed} heritage/gender selections.");
|
|
Assert.True(
|
|
missingSummaries.Count == 0,
|
|
"Missing dat ids found:\n" + string.Join('\n', missingSummaries));
|
|
Assert.True(
|
|
baseEffectGapFailures.Count == 0,
|
|
"TS-82 measurement drifted from its pinned expectation:\n" + string.Join('\n', baseEffectGapFailures));
|
|
Assert.True(composed >= 13, $"Expected at least 13 heritage/gender combinations, composed {composed}.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// CC6a review fix round F1: retail's Setup-id "unset" sentinel is
|
|
/// <c>INVALID_DID</c> (0xFFFFFFFF), not 0
|
|
/// (<c>CharGenState::GetSetupID @ 0x005C5B22</c>). Sweeps EVERY hair
|
|
/// style of all 26 heritage/gender combinations and asserts the composed
|
|
/// SetupId always resolves to a REAL installed Setup dat entry — proving
|
|
/// neither sentinel value, wherever a hair style's <c>AlternateSetup</c>
|
|
/// field happens to store one, ever reaches <c>Get<Setup></c> as a
|
|
/// literal id.
|
|
/// </summary>
|
|
[Fact]
|
|
public void EveryHairStyleOfEveryHeritageGender_ComposesToARealInstalledSetupId()
|
|
{
|
|
string? datDir = ResolveDatDir();
|
|
if (datDir is null)
|
|
{
|
|
_out.WriteLine("SKIP: installed retail DAT directory is unavailable.");
|
|
Assert.Fail("Lane=InstalledDat requires an installed retail DAT directory; see docs/release-gate.md.");
|
|
}
|
|
|
|
using var dats = new DatCollection(datDir, DatAccessType.Read);
|
|
using var adapter = new DatCollectionAdapter(dats);
|
|
|
|
ChargenOptions options = ChargenTableReader.Load(adapter);
|
|
Assert.NotEmpty(options.HeritagesById);
|
|
var catalog = new ChargenAppearanceCatalog(adapter);
|
|
|
|
int sweptHairStyles = 0;
|
|
var unresolvedSetups = new List<string>();
|
|
|
|
foreach (ChargenHeritageOptions heritage in options.HeritagesById.Values)
|
|
{
|
|
foreach ((int genderKey, ChargenGenderOptions gender) in heritage.GendersByKey)
|
|
{
|
|
for (uint hairStyleIndex = 0; hairStyleIndex < (uint)gender.HairStyles.Count; hairStyleIndex++)
|
|
{
|
|
ChargenAppearanceSelection selection = ChargenAppearanceSelection.Default with
|
|
{
|
|
HairStyle = hairStyleIndex,
|
|
SkinShade = 0.5,
|
|
};
|
|
|
|
bool ok = ChargenAppearanceFactory.TryCompose(
|
|
options, heritage.HeritageId, genderKey, selection,
|
|
catalog, catalog, out ChargenAppearanceResult result);
|
|
Assert.True(ok);
|
|
sweptHairStyles++;
|
|
|
|
if (adapter.Get<DatReaderWriter.DBObjs.Setup>(result.SetupId) is null)
|
|
{
|
|
unresolvedSetups.Add(
|
|
$"heritage={heritage.Name} gender={genderKey} hairStyle={hairStyleIndex}: "
|
|
+ $"composed SetupId=0x{result.SetupId:X8} does not resolve to an installed Setup");
|
|
}
|
|
}
|
|
|
|
// Every gender is swept even with zero hair styles (still
|
|
// exercises the "no hair style selected" default-setup path).
|
|
if (gender.HairStyles.Count == 0)
|
|
{
|
|
bool ok = ChargenAppearanceFactory.TryCompose(
|
|
options, heritage.HeritageId, genderKey,
|
|
ChargenAppearanceSelection.Default with { SkinShade = 0.5 },
|
|
catalog, catalog, out ChargenAppearanceResult result);
|
|
Assert.True(ok);
|
|
sweptHairStyles++;
|
|
if (adapter.Get<DatReaderWriter.DBObjs.Setup>(result.SetupId) is null)
|
|
{
|
|
unresolvedSetups.Add(
|
|
$"heritage={heritage.Name} gender={genderKey} (no hair styles): "
|
|
+ $"composed SetupId=0x{result.SetupId:X8} does not resolve to an installed Setup");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
_out.WriteLine($"swept {sweptHairStyles} hair-style/no-hair-style selections across 26 heritage/gender combinations.");
|
|
Assert.True(
|
|
unresolvedSetups.Count == 0,
|
|
"Composed SetupId(s) that don't resolve to a real installed Setup:\n" + string.Join('\n', unresolvedSetups));
|
|
Assert.True(sweptHairStyles > 26, $"Expected more than 26 swept selections (multiple hair styles per gender), got {sweptHairStyles}.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// "Pick the first offered option everywhere, mid shade" — CC6a's own
|
|
/// default policy for exercising the factory end-to-end, NOT a claim
|
|
/// about retail's own CharGenState default selection (that policy is
|
|
/// CC3/CC6b's concern). Every index/shade starts at
|
|
/// <see cref="ChargenAppearanceSelection.Unset"/>/<see cref="ChargenAppearanceSelection.UnsetShade"/>
|
|
/// and is only set when the gender's own list actually offers an
|
|
/// option, so a heritage with e.g. no headgear choices exercises the
|
|
/// factory's "slot not selected" path rather than an out-of-range index.
|
|
/// </summary>
|
|
private static ChargenAppearanceSelection MakeDefaultSelection(ChargenGenderOptions gender)
|
|
{
|
|
const double midShade = 0.5;
|
|
ChargenAppearanceSelection selection = ChargenAppearanceSelection.Default;
|
|
|
|
if (gender.HairStyles.Count > 0)
|
|
selection = selection with { HairStyle = 0u };
|
|
if (gender.EyeStrips.Count > 0)
|
|
selection = selection with { EyesStrip = 0u };
|
|
if (gender.NoseStrips.Count > 0)
|
|
selection = selection with { NoseStrip = 0u };
|
|
if (gender.MouthStrips.Count > 0)
|
|
selection = selection with { MouthStrip = 0u };
|
|
if (gender.HairColors.Count > 0)
|
|
selection = selection with { HairColor = 0u, HairShade = midShade };
|
|
if (gender.EyeColors.Count > 0)
|
|
selection = selection with { EyeColor = 0u };
|
|
|
|
if (gender.Headgears.Count > 0)
|
|
selection = selection with { HeadgearStyle = 0u };
|
|
if (gender.Shirts.Count > 0)
|
|
selection = selection with { ShirtStyle = 0u };
|
|
if (gender.Pants.Count > 0)
|
|
selection = selection with { TrousersStyle = 0u };
|
|
if (gender.Footwear.Count > 0)
|
|
selection = selection with { FootwearStyle = 0u };
|
|
|
|
if (gender.ClothingColors.Count > 0)
|
|
{
|
|
selection = selection with
|
|
{
|
|
HeadgearColor = 0u,
|
|
HeadgearShade = midShade,
|
|
ShirtColor = 0u,
|
|
ShirtShade = midShade,
|
|
TrousersColor = 0u,
|
|
TrousersShade = midShade,
|
|
FootwearColor = 0u,
|
|
FootwearShade = midShade,
|
|
};
|
|
}
|
|
|
|
return selection with { SkinShade = midShade };
|
|
}
|
|
}
|