acdream/tests/AcDream.Runtime.Tests/CharGen/RuntimeCharacterCreationStateFixture.cs
Erik 9a84230c4f feat(runtime): Campaign CC slice CC3 — RuntimeCharacterCreationState
Ports retail's CharGenState as the one Runtime-owned character-creation
state machine, mirroring RuntimeCharacterSelectionState's exact pattern
(snapshot/delta/event-stream, borrow-only view, generation-gated
commands, one mutable owner, no App types). Every command ports a named
retail function: SetHeritageGroup, SetGender, SetTemplate/ApplyTemplate
(Custom = template 0, Olthoi force-lock), the six attribute setters plus
GetAbsRemainingCredits/BalanceAttributes (retail's literal round-robin
order and fairness cursor), SetSkillLevel plus ResetSkillLevels' free-skill
baseline (reusing CC1's ChargenSkillCreditMath two-tier cost lookup
verbatim), RandomizeStartArea, and DoFinish's complete gate sequence
(empty name / unspent attribute credits / already-Pending / client-side
roster-vs-slotCount cap).

LiveSessionController gained a sibling IRuntimeCharacterCreationCommands
implementation, a CreateCharacter wire hook, and a response handler that
reuses existing machinery rather than inventing new paths: the Ok
identity is appended to the roster via RuntimeCharacterSelectionState's
own ApplyRoster, and the "log straight in" behavior reuses the private
EnterSelectedCore. ILiveSessionLifecycleHost gained two default-no-op
hooks (ApplyCharacterCreated/ApplyCreationFailed) so AcDream.App needs
zero changes to keep compiling; wiring them to the status stream is a
CC4 follow-up.

Filed four divergence-register rows for the corners deliberately not
ported: the FPU-unrecoverable FitTemplateToCharacter auto-detect (AP-207,
ACE only reads the field for title text), the per-style color-count
approximation (AP-208, CC1's model has no per-style palette data), the
classID DAT-DID placeholder (AP-209, ACE ignores the field), and
ApplyTemplate's atomic-vs-sequential attribute apply (AP-210).

34 new tests: full state-machine coverage (every Finish gate, every
rejection-code mapping, duplicate-NameInUse tolerance, Olthoi lock,
attribute balance/lock interaction, uncostable-skill rejection) plus a
LiveSessionController integration suite proving the wire send is exactly
55 skill slots (decoded from a real WorldSession + GameMessageCapture)
and the full Ok/rejection round trip through WorldSession.ProcessDatagram.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-15 14:26:10 +02:00

206 lines
8.4 KiB
C#

using System.Numerics;
using AcDream.Core.CharGen;
namespace AcDream.Runtime.Tests.CharGen;
/// <summary>
/// A small, hand-authored <see cref="ChargenOptions"/> fixture for
/// <see cref="RuntimeCharacterCreationState"/> tests — NOT installed-DAT data
/// (that is CC1's <c>ChargenTableReaderInstalledDatTests</c> concern). Shapes
/// mirror retail's field semantics closely enough to exercise every gate:
/// two heritages (a normal one and an Olthoi variant that must force template
/// 0), a "Custom"/floor template plus a str-heavy preset, a mix of costed
/// (including two FREE skills exercising every <c>ResetSkillLevels</c>
/// baseline branch) and deliberately uncostable skill ids, and one gender
/// with small appearance-option lists to exercise index bounds.
/// </summary>
internal static class RuntimeCharacterCreationStateFixture
{
public const uint AluvianId = 1u;
public const uint OlthoiId = (uint)ChargenHeritageGroup.Olthoi;
public const uint ImpoverishedId = 90u;
public const uint MaleGenderKey = 1u;
/// <summary>str=10 end=10 coord=10 quick=10 focus=10 self=10 — the
/// budget-66 heritage leaves 6 credits unspent after this template,
/// matching retail's "Custom sits at the floor" finding.</summary>
public const uint CustomTemplateIndex = 0u;
/// <summary>str=16, everything else at floor — sum 66 (fully spent).</summary>
public const uint PresetTemplateIndex = 1u;
/// <summary>Costed only by the heritage's own list — Normal 4 / Primary 12.</summary>
public const uint SkillTrainSpecialize = 1u;
/// <summary>The Preset template's Primary (specialized) skill.</summary>
public const uint SkillPresetPrimary = 2u;
/// <summary>FREE and pre-specialized by <c>ResetSkillLevels</c>'s baseline
/// (NormalCost=0, PrimaryCost&lt;=0).</summary>
public const uint SkillFreeSpecialized = 3u;
/// <summary>FREE to train, costs to specialize
/// (NormalCost=0, PrimaryCost&gt;0).</summary>
public const uint SkillFreeTrained = 4u;
/// <summary>Uncostable in BOTH tiers — must never be settable (the CC1
/// R1 binding fact: keep the both-miss refund path unreachable).</summary>
public const uint SkillUncostable = 5u;
/// <summary>The Custom template's authored Normal skill.</summary>
public const uint SkillCustomNormal = 24u;
public static ChargenOptions Build()
{
var starterAreas = new List<ChargenStarterArea>
{
new(0, "Holtburg", [new ChargenPosition(1u, Vector3.Zero, Quaternion.Identity)]),
new(1, "Yaraq", [new ChargenPosition(2u, Vector3.Zero, Quaternion.Identity)]),
};
var skillCosts = new Dictionary<uint, ChargenSkillCost>
{
[SkillTrainSpecialize] = new(SkillTrainSpecialize, NormalCost: 4, PrimaryCost: 12),
[SkillPresetPrimary] = new(SkillPresetPrimary, NormalCost: 3, PrimaryCost: 9),
[SkillFreeSpecialized] = new(SkillFreeSpecialized, NormalCost: 0, PrimaryCost: 0),
[SkillFreeTrained] = new(SkillFreeTrained, NormalCost: 0, PrimaryCost: 5),
[SkillCustomNormal] = new(SkillCustomNormal, NormalCost: 2, PrimaryCost: 6),
};
var gender = new ChargenGenderOptions(
GenderKey: (int)MaleGenderKey,
Name: "Male",
Scale: 1u,
SetupId: 0x2000054u,
SoundTableId: 0u,
IconId: 0u,
BasePaletteId: 0u,
SkinPalSetId: 0u,
PhysicsTableId: 0u,
MotionTableId: 0u,
CombatTableId: 0u,
BaseObjDesc: ChargenObjDesc.Empty,
HairColors: [100u, 101u],
HairStyles:
[
new ChargenHairStyle(1u, Bald: false, AlternateSetup: 0u, ObjDesc: ChargenObjDesc.Empty),
new ChargenHairStyle(2u, Bald: true, AlternateSetup: 0u, ObjDesc: ChargenObjDesc.Empty),
],
EyeColors: [200u, 201u],
EyeStrips:
[
new ChargenEyeStrip(1u, 2u, ChargenObjDesc.Empty, ChargenObjDesc.Empty),
],
NoseStrips: [new ChargenFaceStrip(1u, ChargenObjDesc.Empty)],
MouthStrips: [new ChargenFaceStrip(1u, ChargenObjDesc.Empty)],
Headgears: [new ChargenGearOption("Cap", 1u, 300u)],
Shirts: [new ChargenGearOption("Shirt", 2u, 301u)],
Pants: [new ChargenGearOption("Pants", 3u, 302u)],
Footwear: [new ChargenGearOption("Boots", 4u, 303u)],
ClothingColors: [400u, 401u, 402u]);
var aluvianTemplates = new List<ChargenTemplate>
{
new(
"Custom",
IconId: 0u,
TitleStringId: 0u,
Attributes: new ChargenAttributeValues(10, 10, 10, 10, 10, 10),
NormalSkills: [SkillCustomNormal],
PrimarySkills: []),
new(
"Preset",
IconId: 0u,
TitleStringId: 0u,
Attributes: new ChargenAttributeValues(16, 10, 10, 10, 10, 10),
NormalSkills: [SkillTrainSpecialize],
PrimarySkills: [SkillPresetPrimary]),
};
var aluvian = new ChargenHeritageOptions(
AluvianId,
"Aluvian",
IconId: 0u,
SetupId: 0x2000054u,
EnvironmentSetupId: 0u,
AttributeCredits: 66u,
SkillCredits: 50u,
PrimaryStartAreaIndices: [0, 1],
SecondaryStartAreaIndices: [],
SkillCostsBySkillId: skillCosts,
Templates: aluvianTemplates,
GendersByKey: new Dictionary<int, ChargenGenderOptions> { [(int)MaleGenderKey] = gender });
var olthoiTemplates = new List<ChargenTemplate>
{
new(
"Custom",
IconId: 0u,
TitleStringId: 0u,
Attributes: new ChargenAttributeValues(10, 10, 10, 10, 10, 10),
NormalSkills: [],
PrimarySkills: []),
new(
"NeverChosen",
IconId: 0u,
TitleStringId: 0u,
Attributes: new ChargenAttributeValues(20, 20, 20, 20, 20, 20),
NormalSkills: [],
PrimarySkills: []),
};
var olthoi = new ChargenHeritageOptions(
OlthoiId,
"Olthoi",
IconId: 0u,
SetupId: 0x2000054u,
EnvironmentSetupId: 0u,
AttributeCredits: 60u,
SkillCredits: 0u,
PrimaryStartAreaIndices: [0],
SecondaryStartAreaIndices: [],
SkillCostsBySkillId: new Dictionary<uint, ChargenSkillCost>(),
Templates: olthoiTemplates,
GendersByKey: new Dictionary<int, ChargenGenderOptions> { [(int)MaleGenderKey] = gender });
// A deliberately impoverished heritage — just enough skill credits
// to train SkillTrainSpecialize but never specialize it — so a
// TrySpecializeSkill affordability refusal is directly testable
// without needing to hand-drain the richer Aluvian budget.
var impoverished = new ChargenHeritageOptions(
ImpoverishedId,
"Impoverished",
IconId: 0u,
SetupId: 0x2000054u,
EnvironmentSetupId: 0u,
AttributeCredits: 60u,
SkillCredits: 5u,
PrimaryStartAreaIndices: [0],
SecondaryStartAreaIndices: [],
SkillCostsBySkillId: new Dictionary<uint, ChargenSkillCost>
{
[SkillTrainSpecialize] = new(SkillTrainSpecialize, NormalCost: 4, PrimaryCost: 12),
},
Templates:
[
new ChargenTemplate(
"Custom",
IconId: 0u,
TitleStringId: 0u,
Attributes: new ChargenAttributeValues(10, 10, 10, 10, 10, 10),
NormalSkills: [],
PrimarySkills: []),
],
GendersByKey: new Dictionary<int, ChargenGenderOptions> { [(int)MaleGenderKey] = gender });
return new ChargenOptions(
starterAreas,
new Dictionary<uint, ChargenHeritageOptions>
{
[AluvianId] = aluvian,
[OlthoiId] = olthoi,
[ImpoverishedId] = impoverished,
},
new Dictionary<uint, ChargenSkillCost>());
}
}