acdream/tests/AcDream.UI.Abstractions.Tests/Panels/Chat/ChatVMCombatTests.cs
Erik 172c6f9aa3 feat(chat): Campaign CH slice CH1 — retail LogTextType color table
Retail colors chat lines by the 34-value wire LogTextType (ACE's
ChatMessageType), NOT by acdream's synthetic 9-value ChatKind. The old
ChatWindowController.RetailChatColor(ChatKind) collapsed distinct retail
colors onto one bucket per ChatKind — e.g. every Channel line rendered
colorLightBlue (Magic's slot) when retail's actual palette spans five
different colors across the Turbine rooms and legacy allegiance family.

Ports ChatInterface::BuildChatColorLookupTable @0x004F31C0 verbatim
(RetailChatColorTable, all 34 RGBA floats read from the PDB-paired
binary's .data section) and threads a new ChatEntry.LogTextType field
through every ingestion site to the correct retail wire value:
HearSpeech/Tell pass the wire chatType through verbatim; Emote/SoulEmote
hard-code 0x0C; the Tell self-echo hard-codes 0x04; legacy ChatChannel
broadcasts derive their type from the channel bit via the new
LegacyChannelChatType helper (ported from the decompiled
Handle_Communication__ChannelBroadcast dispatch, hear vs. own-send);
TurbineChat rooms map through TurbineChatDisplayNames.LogTextType;
CombatChatTranslator's hit/miss/evade lines map to ACE's CombatSelf/
CombatEnemy per Player_Combat.cs; kill/death lines use retail's
decompiled 0x00 Default (not a combat color). ChatWindowController's
transcript now folds LogTextType through RetailChatColorTable with
retail's exact "out-of-range keeps the previous line's color" carry
rule; ChatPanel's combat highlighting sources the same table.

Corrects HearSpeech.cs's doc-comment ChatType legend (4 of 6 entries
were wrong). Adds register row AP-175 for the pre-existing (unchanged)
Popup-renders-in-chat divergence and updates AP-39's stale per-ChatKind
description. Narrows ISSUES #139 — its chat-colors half is done.

Retail renders no chat timestamp prefix path exists in acdream today,
so the "timestamp is always colorGrey 0x0C" rule has nothing to attach
to; noted here per the research doc rather than left silent.

Research: docs/research/2026-08-09-chat-retail-color-table.md
Full Release suite: 11,833 passed / 4 skipped / 0 failed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-09 15:24:09 +02:00

97 lines
3.5 KiB
C#

using AcDream.Core.Chat;
using AcDream.Core.Combat;
using AcDream.UI.Abstractions.Panels.Chat;
namespace AcDream.UI.Abstractions.Tests.Panels.Chat;
/// <summary>
/// Phase I.7: <see cref="ChatVM"/> surfaces combat-kind entries through
/// <see cref="ChatVM.RecentLinesDetailed"/> with their original
/// <see cref="CombatLineKind"/> attached so the panel can pick a
/// <c>TextColored</c> color per line.
/// </summary>
public sealed class ChatVMCombatTests
{
[Fact]
public void FormatEntry_CombatKind_PassesThroughVerbatim()
{
var entry = new ChatEntry(
Kind: ChatKind.Combat,
Sender: "",
Text: "You hit Mosswart for 5 slashing damage (50.0%).",
SenderGuid: 0,
ChannelId: 0)
{ CombatKind = CombatLineKind.Info };
Assert.Equal(
"You hit Mosswart for 5 slashing damage (50.0%).",
ChatVM.FormatEntry(entry));
}
[Fact]
public void RecentLinesDetailed_CombatEntry_RetainsCombatKind()
{
var log = new ChatLog();
var vm = new ChatVM(log);
log.OnCombatLine("Mosswart hit you for 8 fire damage to your chest.",
CombatLineKind.Warning);
var lines = vm.RecentLinesDetailed();
var line = Assert.Single(lines);
Assert.Equal(ChatKind.Combat, line.Kind);
Assert.Equal(CombatLineKind.Warning, line.CombatKind);
Assert.Equal("Mosswart hit you for 8 fire damage to your chest.", line.Text);
}
[Fact]
public void RecentLinesDetailed_NonCombatEntry_HasNullCombatKind()
{
var log = new ChatLog();
var vm = new ChatVM(log);
log.OnLocalSpeech("Alice", "hi", senderGuid: 0xAA, isRanged: false);
var line = Assert.Single(vm.RecentLinesDetailed());
Assert.Equal(ChatKind.LocalSpeech, line.Kind);
Assert.Null(line.CombatKind);
Assert.Equal("Alice says, \"hi\"", line.Text);
}
[Fact]
public void ChatPanel_RendersCombatLine_ViaTextColored()
{
var log = new ChatLog();
var vm = new ChatVM(log);
log.OnLocalSpeech("Alice", "hi", senderGuid: 0xAA, isRanged: false);
log.OnCombatLine("You hit Mosswart for 5 slashing damage (50.0%).",
CombatLineKind.Info);
var panel = new ChatPanel(vm);
var bus = new RecordingChatBus();
var renderer = new FakePanelRenderer { InputTextSubmitNextSubmitted = null };
panel.Render(new PanelContext(0.016f, bus), renderer);
// Plain LocalSpeech entry → Text; combat entry → TextColored, now
// sourced from RetailChatColorTable (Campaign CH slice CH1) keyed
// by LogTextType, not ChatPanel.ColorForCombat's severity bucket.
// OnCombatLine's default logTextType (0x06, generic Combat slot,
// colorDarkRed) applies here since no explicit type was passed.
Assert.Contains(renderer.Calls, c =>
c.Method == "Text" && (string?)c.Args[0] == "Alice says, \"hi\"");
var coloredCall = Assert.Single(
renderer.Calls,
c => c.Method == "TextColored");
Assert.Equal(
"You hit Mosswart for 5 slashing damage (50.0%).",
(string?)coloredCall.Args[1]);
RetailChatColorTable.TryGetColor(0x06u, out var expectedColor);
Assert.Equal(
expectedColor,
(System.Numerics.Vector4)coloredCall.Args[0]!);
}
private sealed class RecordingChatBus : ICommandBus
{
public void Publish<T>(T command) where T : notnull { /* no-op */ }
}
}