feat(CT): CT2 — Runtime character-title ownership + wire
Campaign CT slice CT2: the client now learns the character's earned titles and current display title from the server, owns that state in Runtime, and can send a display-title change. No UI (CT3/CT4). Wire (Core.Net): - GameEvents.ParseCharacterTitleTable (0x0029 CharacterTitle): retail CharacterTitleTable::UnPack @0x005c6e90 skips a leading u32 into no field — its own Pack @0x005c6e40 always writes the literal 1 there, matching ACE's unconditional Writer.Write(1u) — then reads displayTitleId, then a count-prefixed PList<uint> of earned ids. - GameEvents.ParseUpdateTitle (0x002B UpdateTitle): titleId + setAsDisplay, per CM_Social::DispatchUI_AddOrSetCharacterTitle @0x006a54c0 -> Handle_Social__AddOrSetCharacterTitle @0x00564260, which ALWAYS adds (SendNotice_AddCharacterTitle, unconditional) and additionally sets display only when setAsDisplay != 0 (SendNotice_SetDisplayCharacterTitle, gated). - SocialActions.BuildTitleSet / WorldSession.SendSetTitle: outbound TitleSet (0x002C), u32 titleId, matching ACE's GameActionSetTitle. - GameEventWiring gains onCharacterTitleTable/onUpdateTitle delegate holes (Core.Net cannot reference AcDream.Runtime directly). Runtime: - New RuntimeCharacterTitleState (RuntimeCharacterState.Titles): earned title id set + display title id, TableReplaced/TitleAdded/ DisplayTitleChanged events matching retail's unconditional-add / gated-display-set contract, clears at generation reset. RuntimeCharacterOwnershipSnapshot/CaptureOwnership/IsConverged and RuntimeCharacterSnapshot extended (trailing optional fields, no existing call site broken). - IRuntimeCharacterCommands.SetTitle: generation-gated, sends TitleSet only — NO optimistic local mutation. Verified against retail's own CM_Social::Event_SetDisplayCharacterTitle @0x006a5720, which sends the wire message and touches no local field; the display title updates only from the server's own echo (the CA-campaign lesson: never re-add an optimistic write). Implemented on both hosts (DirectGameRuntimeCommandAdapter direct-send; CurrentGameRuntimeCommandAdapter via LiveCommandBus / LiveSessionCommandRouter's new SetTitleRuntimeCmd). - LiveSessionEventRouter wires the two inbound events unconditionally (RuntimeCharacterState.Titles is a required child, not an optional sibling like Fellowship/Allegiance). App (non-UI plumbing + resolver): - CharacterTitleResolver (src/AcDream.App/UI/Layout/): ports CharacterTitleTable::GetCharacterTitleFromID @0x005c6ed0 — titleId -> EnumMapper(0x22000041) canonical key -> compute_str_hash -> StringTable(0x2300000E) localized text. Runtime stays id-only; CT3/ CT4 consume this for display. DIDs hardcoded per the RetailKeyNames precedent (CT1 verified them end-to-end). Register: no new row. Retail's send path is non-optimistic and so is ours — no deviation to record for this slice. Tests: wire conformance (byte-exact + truncation) in CharacterTitleEventsTests.cs + SocialActionsTests.cs; Runtime owner unit tests in RuntimeCharacterTitleStateTests.cs plus integration in RuntimeCharacterStateTests.cs; a no-local-mutation command test in DirectGameRuntimeCommandAdapterTests.cs; an InstalledDat pin (CharacterTitleResolverLiveDatTests.cs, ids 0/1/2/3/5/13/14, run green with ACDREAM_RUN_INSTALLED_DAT_TESTS=1). Full solution build green; hermetic filtered suite green (15,380 passed / 0 failed). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
d38f71cb28
commit
bcfddc97e7
23 changed files with 1044 additions and 17 deletions
|
|
@ -436,6 +436,11 @@ public sealed class InteractionUiRuntimeSourcesTests
|
|||
RuntimeGenerationToken expectedGeneration) =>
|
||||
Accepted(expectedGeneration);
|
||||
|
||||
public RuntimeCommandResult SetTitle(
|
||||
RuntimeGenerationToken expectedGeneration,
|
||||
uint titleId) =>
|
||||
Accepted(expectedGeneration, titleId);
|
||||
|
||||
private RuntimeCommandResult Accepted(
|
||||
RuntimeGenerationToken generation,
|
||||
uint objectId = 0u)
|
||||
|
|
|
|||
|
|
@ -728,7 +728,8 @@ public sealed class LiveSessionCommandRouterTests
|
|||
RuntimeCommunicationState? communication = null,
|
||||
RuntimeCharacterState? characterState = null,
|
||||
Action<uint, bool>? sendSingleCharacterOption = null,
|
||||
Action? saveCharacterOptions = null) => new(
|
||||
Action? saveCharacterOptions = null,
|
||||
Action<uint>? sendSetTitle = null) => new(
|
||||
new LiveSessionCommandBindings(
|
||||
clientBindings ?? NewClientBindings(),
|
||||
chat ?? new ChatLog(),
|
||||
|
|
@ -767,6 +768,7 @@ public sealed class LiveSessionCommandRouterTests
|
|||
CharacterState: characterState ?? new RuntimeCharacterState(),
|
||||
SendSingleCharacterOption: sendSingleCharacterOption ?? ((_, _) => { }),
|
||||
SaveCharacterOptions: saveCharacterOptions ?? (() => { }),
|
||||
SendSetTitle: sendSetTitle ?? (_ => { }),
|
||||
SendFellowshipCreate: (_, _) => { },
|
||||
SendFellowshipRecruit: _ => { },
|
||||
SendFellowshipDismiss: _ => { },
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
using AcDream.App.UI.Layout;
|
||||
using AcDream.Content;
|
||||
using DatReaderWriter;
|
||||
|
||||
namespace AcDream.App.Tests.UI.Layout;
|
||||
|
||||
/// <summary>
|
||||
/// Campaign CT slice CT2 (2026-08-24) pin: <see cref="CharacterTitleResolver"/>
|
||||
/// against the installed DAT set, end to end (EnumMapper 0x22000041 ->
|
||||
/// compute_str_hash -> StringTable 0x2300000E). CT1's research doc
|
||||
/// (docs/research/2026-08-24-campaign-ct-dat-ground-truth.md §5) verified
|
||||
/// id 13 == "War Mage" against ACE's <c>CharacterTitle.WarMage</c>; this
|
||||
/// pin adds several more low-ordinal ids from the same enum
|
||||
/// (<c>CharacterTitle.cs</c>: Invalid=0, Adventurer=1, Archer=2,
|
||||
/// Blademaster=3, LifeMage=5, Wayfarer=14) so a DAT revision or resolver
|
||||
/// regression fails loudly instead of drifting unnoticed into CT3/CT4.
|
||||
/// Follows the durable-pin pattern of <see cref="ChatStringsLiveDatTests"/>.
|
||||
/// </summary>
|
||||
[Trait("Lane", "InstalledDat")]
|
||||
public sealed class CharacterTitleResolverLiveDatTests
|
||||
{
|
||||
private static string DatDirectory =>
|
||||
Path.Combine(
|
||||
System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile),
|
||||
"Documents", "Asheron's Call");
|
||||
|
||||
[InstalledDatFact]
|
||||
public void Resolve_PinsSeveralTitleIdsToTheirRetailDisplayStrings()
|
||||
{
|
||||
using var dats = new DatCollection(DatDirectory, DatReaderWriter.Options.DatAccessType.Read);
|
||||
var resolver = new CharacterTitleResolver(new DatCollectionAdapter(dats));
|
||||
|
||||
// Retail's own early-return: id 0 (Invalid) never resolves.
|
||||
Assert.Null(resolver.Resolve(0u));
|
||||
|
||||
Assert.Equal("Adventurer", resolver.Resolve(1u));
|
||||
Assert.Equal("Archer", resolver.Resolve(2u));
|
||||
Assert.Equal("Blademaster", resolver.Resolve(3u));
|
||||
Assert.Equal("Life Mage", resolver.Resolve(5u));
|
||||
Assert.Equal("War Mage", resolver.Resolve(13u));
|
||||
Assert.Equal("Wayfarer", resolver.Resolve(14u));
|
||||
}
|
||||
|
||||
[InstalledDatFact]
|
||||
public void Resolve_UnmappedId_ReturnsNull()
|
||||
{
|
||||
using var dats = new DatCollection(DatDirectory, DatReaderWriter.Options.DatAccessType.Read);
|
||||
var resolver = new CharacterTitleResolver(new DatCollectionAdapter(dats));
|
||||
|
||||
Assert.Null(resolver.Resolve(0xFFFFFFFEu));
|
||||
}
|
||||
|
||||
[InstalledDatFact]
|
||||
public void Resolve_CachesTheEnumMapperAcrossCalls()
|
||||
{
|
||||
// Not a durable behavioral pin — just confirms the lazy-load path
|
||||
// used by the assertions above resolves the SAME value on a second
|
||||
// call (the cached-mapper branch), not only on the first (cold) one.
|
||||
using var dats = new DatCollection(DatDirectory, DatReaderWriter.Options.DatAccessType.Read);
|
||||
var resolver = new CharacterTitleResolver(new DatCollectionAdapter(dats));
|
||||
|
||||
string? first = resolver.Resolve(13u);
|
||||
string? second = resolver.Resolve(13u);
|
||||
|
||||
Assert.Equal("War Mage", first);
|
||||
Assert.Equal(first, second);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
using System;
|
||||
using AcDream.Core.Net.Messages;
|
||||
using Xunit;
|
||||
|
||||
namespace AcDream.Core.Net.Tests.Messages;
|
||||
|
||||
/// <summary>
|
||||
/// Campaign CT slice CT2 (2026-08-24): golden-vector round-trip tests for
|
||||
/// the two character-title S→C parsers added to <see cref="GameEvents"/>.
|
||||
/// Fixtures are built with <see cref="AceWireWriter"/> (the ACE-mirror
|
||||
/// writer) so a pass proves agreement with ACE's own
|
||||
/// <c>GameEventCharacterTitle.cs</c> / <c>GameEventUpdateTitle.cs</c>
|
||||
/// writer shapes, not just with itself.
|
||||
/// </summary>
|
||||
public sealed class CharacterTitleEventsTests
|
||||
{
|
||||
// ── 0x0029 CharacterTitle ────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void ParseCharacterTitleTable_RoundTrips_DiscardsLeadingVersionTag()
|
||||
{
|
||||
byte[] wire = new AceWireWriter()
|
||||
.Write(1u) // ACE's literal pack-version tag — must be discarded
|
||||
.Write(13u) // displayTitleId
|
||||
.Write(3u) // count
|
||||
.Write(1u)
|
||||
.Write(5u)
|
||||
.Write(13u)
|
||||
.ToArray();
|
||||
|
||||
GameEvents.CharacterTitleTable? table = GameEvents.ParseCharacterTitleTable(wire);
|
||||
|
||||
Assert.NotNull(table);
|
||||
Assert.Equal(13u, table!.Value.DisplayTitleId);
|
||||
Assert.Equal(new uint[] { 1u, 5u, 13u }, table.Value.TitleIds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseCharacterTitleTable_IgnoresNonOneLeadingTag()
|
||||
{
|
||||
// Retail's own UnPack never reads the leading dword into any field —
|
||||
// it is advanced past unconditionally. A hostile/odd server value
|
||||
// there must not change the parse outcome.
|
||||
byte[] wire = new AceWireWriter()
|
||||
.Write(0xDEADBEEFu)
|
||||
.Write(7u)
|
||||
.Write(0u) // empty title list
|
||||
.ToArray();
|
||||
|
||||
GameEvents.CharacterTitleTable? table = GameEvents.ParseCharacterTitleTable(wire);
|
||||
|
||||
Assert.NotNull(table);
|
||||
Assert.Equal(7u, table!.Value.DisplayTitleId);
|
||||
Assert.Empty(table.Value.TitleIds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseCharacterTitleTable_EmptyTitleList_RoundTrips()
|
||||
{
|
||||
byte[] wire = new AceWireWriter()
|
||||
.Write(1u)
|
||||
.Write(0u) // displayTitleId — no display title yet
|
||||
.Write(0u) // count
|
||||
.ToArray();
|
||||
|
||||
GameEvents.CharacterTitleTable? table = GameEvents.ParseCharacterTitleTable(wire);
|
||||
|
||||
Assert.NotNull(table);
|
||||
Assert.Equal(0u, table!.Value.DisplayTitleId);
|
||||
Assert.Empty(table.Value.TitleIds);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // empty payload
|
||||
[InlineData(4)] // only the leading tag
|
||||
[InlineData(8)] // leading tag + displayTitleId, missing count
|
||||
public void ParseCharacterTitleTable_TruncatedHeader_ReturnsNull(int length)
|
||||
{
|
||||
byte[] wire = new byte[length];
|
||||
Assert.Null(GameEvents.ParseCharacterTitleTable(wire));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseCharacterTitleTable_CountExceedsAvailableTitleIds_ReturnsNull()
|
||||
{
|
||||
byte[] wire = new AceWireWriter()
|
||||
.Write(1u)
|
||||
.Write(1u)
|
||||
.Write(2u) // count says 2 title ids follow
|
||||
.Write(1u) // only 1 is actually present
|
||||
.ToArray();
|
||||
|
||||
Assert.Null(GameEvents.ParseCharacterTitleTable(wire));
|
||||
}
|
||||
|
||||
// ── 0x002B UpdateTitle ───────────────────────────────────────────────
|
||||
|
||||
[Theory]
|
||||
[InlineData(0u, false)]
|
||||
[InlineData(13u, true)]
|
||||
public void ParseUpdateTitle_RoundTrips(uint titleId, bool setAsDisplay)
|
||||
{
|
||||
byte[] wire = new AceWireWriter()
|
||||
.Write(titleId)
|
||||
.Write(setAsDisplay ? 1u : 0u)
|
||||
.ToArray();
|
||||
|
||||
GameEvents.UpdateTitle? update = GameEvents.ParseUpdateTitle(wire);
|
||||
|
||||
Assert.NotNull(update);
|
||||
Assert.Equal(titleId, update!.Value.TitleId);
|
||||
Assert.Equal(setAsDisplay, update.Value.SetAsDisplay);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseUpdateTitle_NonZeroSetAsDisplay_IsTrue()
|
||||
{
|
||||
// ACE writes Convert.ToUInt32(bool) (always 0 or 1), but retail's own
|
||||
// dispatch reads `!= 0`, not `== 1` — a non-1 truthy value must still
|
||||
// resolve true.
|
||||
byte[] wire = new AceWireWriter().Write(5u).Write(0xFFu).ToArray();
|
||||
|
||||
GameEvents.UpdateTitle? update = GameEvents.ParseUpdateTitle(wire);
|
||||
|
||||
Assert.NotNull(update);
|
||||
Assert.True(update!.Value.SetAsDisplay);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(4)] // only titleId, missing setAsDisplay
|
||||
public void ParseUpdateTitle_Truncated_ReturnsNull(int length)
|
||||
{
|
||||
byte[] wire = new byte[length];
|
||||
Assert.Null(GameEvents.ParseUpdateTitle(wire));
|
||||
}
|
||||
}
|
||||
|
|
@ -378,4 +378,31 @@ public sealed class SocialActionsTests
|
|||
Assert.Contains((0x68000002u, 3u), parsed.Value.DesiredComps);
|
||||
Assert.Contains((0x68000003u, 7u), parsed.Value.DesiredComps);
|
||||
}
|
||||
|
||||
// ── Campaign CT slice CT2 (2026-08-24): TitleSet (0x002C) ────────────────
|
||||
|
||||
[Fact]
|
||||
public void BuildTitleSet_GoldenByteVector()
|
||||
{
|
||||
byte[] body = SocialActions.BuildTitleSet(seq: 7, titleId: 13u);
|
||||
|
||||
byte[] expected =
|
||||
[
|
||||
0xB1, 0xF7, 0x00, 0x00, // envelope 0xF7B1
|
||||
0x07, 0x00, 0x00, 0x00, // seq 7
|
||||
0x2C, 0x00, 0x00, 0x00, // opcode 0x002C TitleSet
|
||||
0x0D, 0x00, 0x00, 0x00, // titleId 13
|
||||
];
|
||||
Assert.Equal(expected, body);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildTitleSet_HasOpcodeAndTitleId()
|
||||
{
|
||||
byte[] body = SocialActions.BuildTitleSet(seq: 1, titleId: 0xBEEFu);
|
||||
Assert.Equal(SocialActions.TitleSetOpcode,
|
||||
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
||||
Assert.Equal(0xBEEFu,
|
||||
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -285,5 +285,11 @@ public sealed class HeadlessCharacterOptionsSeederTests
|
|||
RuntimeCommandStatus.Accepted,
|
||||
expectedGeneration);
|
||||
}
|
||||
|
||||
public RuntimeCommandResult SetTitle(
|
||||
RuntimeGenerationToken expectedGeneration,
|
||||
uint titleId) =>
|
||||
throw new NotSupportedException(
|
||||
"HeadlessCharacterOptionsSeeder never calls SetTitle.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using AcDream.Core.Net.Messages;
|
|||
using AcDream.Core.Properties;
|
||||
using AcDream.Core.Spells;
|
||||
using AcDream.Core.Player;
|
||||
using AcDream.Runtime;
|
||||
using AcDream.Runtime.Gameplay;
|
||||
|
||||
namespace AcDream.Runtime.Tests.Gameplay;
|
||||
|
|
@ -1051,6 +1052,61 @@ public sealed class RuntimeCharacterStateTests
|
|||
Assert.True(state.CaptureOwnership().AutonomyIsDefault);
|
||||
}
|
||||
|
||||
// ── Campaign CT slice CT2 (2026-08-24): Titles owner integration ─────
|
||||
|
||||
[Fact]
|
||||
public void Titles_IsOwnedAsASiblingOfOptionsAndMovementSkills()
|
||||
{
|
||||
using var state = new RuntimeCharacterState();
|
||||
|
||||
state.Titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
||||
|
||||
Assert.Equal(13u, state.Titles.DisplayTitleId);
|
||||
Assert.Equal(3, state.Titles.EarnedTitleIds.Count);
|
||||
Assert.Equal(3, state.CaptureOwnership().TitleCount);
|
||||
Assert.False(state.CaptureOwnership().DisplayTitleIsDefault);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetSession_ClearsTitles()
|
||||
{
|
||||
using var state = new RuntimeCharacterState();
|
||||
state.Titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
||||
|
||||
state.ResetSession();
|
||||
|
||||
Assert.Equal(0u, state.Titles.DisplayTitleId);
|
||||
Assert.Empty(state.Titles.EarnedTitleIds);
|
||||
Assert.True(state.CaptureOwnership().TitleCount == 0);
|
||||
Assert.True(state.CaptureOwnership().DisplayTitleIsDefault);
|
||||
Assert.True(state.CaptureOwnership().IsConverged is false); // IsDisposed still false
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dispose_ClearsTitlesAndConverges()
|
||||
{
|
||||
var state = new RuntimeCharacterState();
|
||||
state.Titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
||||
|
||||
state.Dispose();
|
||||
|
||||
Assert.Equal(0u, state.Titles.DisplayTitleId);
|
||||
Assert.Empty(state.Titles.EarnedTitleIds);
|
||||
Assert.True(state.CaptureOwnership().IsConverged);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CharacterSnapshot_EmbedsTitlesSnapshot()
|
||||
{
|
||||
using var state = new RuntimeCharacterState();
|
||||
state.Titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
||||
|
||||
RuntimeCharacterSnapshot snapshot = state.View.Snapshot;
|
||||
|
||||
Assert.Equal(13u, snapshot.Titles.DisplayTitleId);
|
||||
Assert.Equal(3, snapshot.Titles.TitleCount);
|
||||
}
|
||||
|
||||
private static ActiveEnchantmentRecord MakeVitae(uint spellId, float val) =>
|
||||
new(
|
||||
spellId, LayerId: 0u, Duration: -1f, CasterGuid: 0u,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,193 @@
|
|||
using AcDream.Runtime.Gameplay;
|
||||
|
||||
namespace AcDream.Runtime.Tests.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// Campaign CT slice CT2 (2026-08-24): unit tests for
|
||||
/// <see cref="RuntimeCharacterTitleState"/> — the retail
|
||||
/// <c>CharacterTitleTable</c> port. Covers the full table replace
|
||||
/// (<c>0x0029 CharacterTitle</c>), the incremental add/set-display notice
|
||||
/// (<c>0x002B UpdateTitle</c>), the retail-verified unconditional-add /
|
||||
/// gated-display-set contract, and generation-reset clearing.
|
||||
/// </summary>
|
||||
public sealed class RuntimeCharacterTitleStateTests
|
||||
{
|
||||
[Fact]
|
||||
public void InitialState_IsEmptyWithDefaultDisplayTitle()
|
||||
{
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
|
||||
Assert.Equal(0u, titles.DisplayTitleId);
|
||||
Assert.Empty(titles.EarnedTitleIds);
|
||||
Assert.False(titles.HasEarnedTitle(13u));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReplaceTable_SetsEarnedIdsAndDisplayTitle_FiresTableReplaced()
|
||||
{
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
int tableReplacedCount = 0;
|
||||
titles.TableReplaced += () => tableReplacedCount++;
|
||||
|
||||
titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
||||
|
||||
Assert.Equal(13u, titles.DisplayTitleId);
|
||||
Assert.Equal(new HashSet<uint> { 1u, 5u, 13u }, titles.EarnedTitleIds.ToHashSet());
|
||||
Assert.True(titles.HasEarnedTitle(5u));
|
||||
Assert.False(titles.HasEarnedTitle(99u));
|
||||
Assert.Equal(1, tableReplacedCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReplaceTable_IsAWholesaleReplace_DropsIdsMissingFromTheNewTable()
|
||||
{
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
titles.ReplaceTable(1u, [1u, 2u, 3u]);
|
||||
|
||||
titles.ReplaceTable(1u, [1u]);
|
||||
|
||||
Assert.Equal(new uint[] { 1u }, titles.EarnedTitleIds.ToArray());
|
||||
Assert.False(titles.HasEarnedTitle(2u));
|
||||
Assert.False(titles.HasEarnedTitle(3u));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReplaceTable_DisplayTitleIdUnchanged_DoesNotFireDisplayTitleChanged()
|
||||
{
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
titles.ReplaceTable(13u, [13u]);
|
||||
var fired = new List<uint>();
|
||||
titles.DisplayTitleChanged += id => fired.Add(id);
|
||||
|
||||
titles.ReplaceTable(13u, [13u, 14u]);
|
||||
|
||||
Assert.Empty(fired);
|
||||
Assert.Equal(13u, titles.DisplayTitleId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReplaceTable_DisplayTitleIdChanges_FiresDisplayTitleChangedWithNewId()
|
||||
{
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
titles.ReplaceTable(13u, [13u, 14u]);
|
||||
var fired = new List<uint>();
|
||||
titles.DisplayTitleChanged += id => fired.Add(id);
|
||||
|
||||
titles.ReplaceTable(14u, [13u, 14u]);
|
||||
|
||||
Assert.Equal([14u], fired);
|
||||
Assert.Equal(14u, titles.DisplayTitleId);
|
||||
}
|
||||
|
||||
// ── 0x002B UpdateTitle: unconditional add, gated display-set ─────────
|
||||
// Retail's Handle_Social__AddOrSetCharacterTitle @0x00564260 ALWAYS
|
||||
// calls SendNotice_AddCharacterTitle, and additionally calls
|
||||
// SendNotice_SetDisplayCharacterTitle only when setAsDisplay != 0.
|
||||
|
||||
[Fact]
|
||||
public void ApplyUpdateTitle_AlwaysAddsAndFiresTitleAdded_EvenWhenNotSetAsDisplay()
|
||||
{
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
var added = new List<uint>();
|
||||
titles.TitleAdded += id => added.Add(id);
|
||||
var displayChanged = new List<uint>();
|
||||
titles.DisplayTitleChanged += id => displayChanged.Add(id);
|
||||
|
||||
titles.ApplyUpdateTitle(7u, setAsDisplay: false);
|
||||
|
||||
Assert.True(titles.HasEarnedTitle(7u));
|
||||
Assert.Equal([7u], added);
|
||||
Assert.Empty(displayChanged);
|
||||
Assert.Equal(0u, titles.DisplayTitleId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyUpdateTitle_SetAsDisplayTrue_AddsAndUpdatesDisplayTitle()
|
||||
{
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
var added = new List<uint>();
|
||||
titles.TitleAdded += id => added.Add(id);
|
||||
var displayChanged = new List<uint>();
|
||||
titles.DisplayTitleChanged += id => displayChanged.Add(id);
|
||||
|
||||
titles.ApplyUpdateTitle(13u, setAsDisplay: true);
|
||||
|
||||
Assert.True(titles.HasEarnedTitle(13u));
|
||||
Assert.Equal([13u], added);
|
||||
Assert.Equal([13u], displayChanged);
|
||||
Assert.Equal(13u, titles.DisplayTitleId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyUpdateTitle_AlreadyEarnedId_StillFiresTitleAddedUnconditionally()
|
||||
{
|
||||
// Retail's own broadcast is unconditional — it does not check
|
||||
// membership before firing the notice.
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
titles.ApplyUpdateTitle(7u, setAsDisplay: false);
|
||||
var added = new List<uint>();
|
||||
titles.TitleAdded += id => added.Add(id);
|
||||
|
||||
titles.ApplyUpdateTitle(7u, setAsDisplay: false);
|
||||
|
||||
Assert.Equal([7u], added);
|
||||
Assert.Single(titles.EarnedTitleIds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyUpdateTitle_SetAsDisplayOnAnUnearnedId_AddsItAndSetsDisplay()
|
||||
{
|
||||
// Retail sends UpdateTitle for a title the player just earned — the
|
||||
// id is not necessarily already in the earned set beforehand.
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
|
||||
titles.ApplyUpdateTitle(99u, setAsDisplay: true);
|
||||
|
||||
Assert.True(titles.HasEarnedTitle(99u));
|
||||
Assert.Equal(99u, titles.DisplayTitleId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetSession_ClearsEarnedIdsAndDisplayTitle()
|
||||
{
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
||||
|
||||
titles.ResetSession();
|
||||
|
||||
Assert.Equal(0u, titles.DisplayTitleId);
|
||||
Assert.Empty(titles.EarnedTitleIds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetSession_BumpsRevisionEvenWhenAlreadyEmpty()
|
||||
{
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
long before = titles.Revision;
|
||||
|
||||
titles.ResetSession();
|
||||
|
||||
Assert.True(titles.Revision > before);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Snapshot_ReflectsDisplayTitleAndCount()
|
||||
{
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
||||
|
||||
RuntimeCharacterTitleSnapshot snapshot = titles.Snapshot;
|
||||
|
||||
Assert.Equal(13u, snapshot.DisplayTitleId);
|
||||
Assert.Equal(3, snapshot.TitleCount);
|
||||
Assert.Equal(titles.Revision, snapshot.Revision);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReplaceTable_NullTitleIds_Throws()
|
||||
{
|
||||
var titles = new RuntimeCharacterTitleState();
|
||||
Assert.Throws<ArgumentNullException>(
|
||||
() => titles.ReplaceTable(1u, null!));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
using System.Buffers.Binary;
|
||||
using System.Net;
|
||||
using AcDream.Core.Combat;
|
||||
using AcDream.Core.Items;
|
||||
|
|
@ -345,6 +346,69 @@ public sealed class DirectGameRuntimeCommandAdapterTests
|
|||
runtime.Dispose();
|
||||
}
|
||||
|
||||
// ── Campaign CT slice CT2 (2026-08-24): SetTitle (TitleSet 0x002C) ───
|
||||
|
||||
[Fact]
|
||||
public void SetTitle_SendsTheWireActionWithoutAnyLocalMutation()
|
||||
{
|
||||
(GameRuntime runtime, DirectGameRuntimeCommandAdapter adapter, FixtureSessionOperations operations) =
|
||||
CreateStartedHarness();
|
||||
var gameActions = new List<byte[]>();
|
||||
operations.Sessions[^1].GameActionCapture = body => gameActions.Add(body);
|
||||
|
||||
RuntimeCommandResult result = adapter.Character.SetTitle(
|
||||
runtime.Generation,
|
||||
titleId: 13u);
|
||||
|
||||
Assert.True(result.Accepted);
|
||||
Assert.Single(gameActions);
|
||||
byte[] sent = gameActions[0];
|
||||
Assert.Equal(
|
||||
SocialActions.TitleSetOpcode,
|
||||
BinaryPrimitives.ReadUInt32LittleEndian(sent.AsSpan(8)));
|
||||
Assert.Equal(13u, BinaryPrimitives.ReadUInt32LittleEndian(sent.AsSpan(12)));
|
||||
|
||||
// CA-lesson: NO optimistic local mutation. RuntimeCharacterState.
|
||||
// Titles only updates from the server's own echo (0x002B/0x0029).
|
||||
Assert.Equal(0u, runtime.CharacterOwner.Titles.DisplayTitleId);
|
||||
Assert.Empty(runtime.CharacterOwner.Titles.EarnedTitleIds);
|
||||
runtime.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetTitle_ZeroTitleId_RejectsWithoutSendingAnything()
|
||||
{
|
||||
(GameRuntime runtime, DirectGameRuntimeCommandAdapter adapter, FixtureSessionOperations operations) =
|
||||
CreateStartedHarness();
|
||||
var gameActions = new List<byte[]>();
|
||||
operations.Sessions[^1].GameActionCapture = body => gameActions.Add(body);
|
||||
|
||||
RuntimeCommandResult result = adapter.Character.SetTitle(
|
||||
runtime.Generation,
|
||||
titleId: 0u);
|
||||
|
||||
Assert.Equal(RuntimeCommandStatus.Rejected, result.Status);
|
||||
Assert.Empty(gameActions);
|
||||
runtime.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetTitle_StaleGeneration_RejectsWithoutSendingAnything()
|
||||
{
|
||||
(GameRuntime runtime, DirectGameRuntimeCommandAdapter adapter, FixtureSessionOperations operations) =
|
||||
CreateStartedHarness();
|
||||
var gameActions = new List<byte[]>();
|
||||
operations.Sessions[^1].GameActionCapture = body => gameActions.Add(body);
|
||||
RuntimeGenerationToken stale = runtime.Generation;
|
||||
_ = adapter.Session.Reconnect(runtime.Generation);
|
||||
|
||||
RuntimeCommandResult result = adapter.Character.SetTitle(stale, titleId: 13u);
|
||||
|
||||
Assert.Equal(RuntimeCommandStatus.StaleGeneration, result.Status);
|
||||
Assert.Empty(gameActions);
|
||||
runtime.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveOptions_FlushesTheDirtyBlobThenNoOpsWhenClean()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue