acdream/tests/AcDream.UI.Abstractions.Tests/Panels/Chat/ChatVMCombatTests.cs
Erik 3f7821c18d fix(chat): BuildTell wire field order + retail-style FormatEntry + suppress duplicate Channel echo
Three follow-up fixes from the 2026-04-25 live verify session.

1. CRITICAL: BuildTell wire field order. Our outbound layout was
   [target_name, message] but ACE's GameActionTell.Handle reads
   [message, target_name] (verified against
   references/ACE/.../GameActionTell.cs:17-18 verbatim). Result: every
   /tell since Phase I.3 has been failing with WeenieError 0x052B
   (CharacterNotAvailable) because ACE was looking up the message
   text as the recipient name. Swapped the field order in
   ChatRequests.BuildTell so message is written first; updated the
   pinned BuildTell test to expect the corrected layout. The
   WorldSessionChatTests round-trip continues to pass since SendTell
   delegates to BuildTell.

2. Retail-style FormatEntry. The user asked for the canonical retail
   strings:
     /say (own):       You say, "text"
     /say (incoming):  Name says, "text"
     /tell (own echo): You tell Caith, "text"
     /tell (incoming): Caith tells you, "text"
     channel:          [Trade] +Acdream says, "text"
     /shout (own):     You shout, "text"
     /shout (incoming):Name shouts, "text"

   Discriminators: SenderGuid == 0 distinguishes our own outbound
   echoes (set by OnSelfSent) from real incoming whispers (carry the
   sender's player guid). Sender == "" or "You" distinguishes our own
   /say echoes (OnLocalSpeech substitutes "You" when the wire sender
   is empty per holtburger client/messages.rs:476-487).

   ChatEntry gains a new ChannelName slot so Channel-kind entries
   render with the friendly room name ("Trade") instead of "ch 3".
   Falls back to "ch {ChannelId}" when ChannelName isn't populated
   (legacy ChatChannel inbound or older callers).

3. Suppress optimistic Channel echo. The user saw duplicates per
   /trade /lfg in the live trace:
     [ch 0] Trade: hello                     <-- our optimistic
     [ch 3] +Acdream: [Trade] hello          <-- ACE's TurbineChat broadcast
   ACE's TurbineChatHandler at Network/Handlers/TurbineChatHandler.cs
   broadcasts EventSendToRoom to ALL recipients in the room including
   the sender, so the canonical echo always arrives via 0xF7DE. Drop
   the optimistic OnSelfSent for Turbine kinds in GameWindow's
   SendChatCmd handler; trust the server. Legacy ChatChannel paths
   (Fellowship / Allegiance / Patron / Monarch / Vassals / CoVassals)
   keep the optimistic echo because the legacy 0x0147 broadcast may
   not always come back to the sender.

   Inbound TurbineChat also stops embedding "[Trade] " into the
   message text — passes the friendly name out-of-band via the new
   channelName parameter on ChatLog.OnChannelBroadcast.

11 tests updated for the new format strings (8 in ChatVMTests, 1 in
ChatVMCombatTests, 1 BuildTell, plus the format additions cover
incoming/outgoing variants per kind). Solution total: 1007 green
(243 + 114 + 650), 0 warnings.

Tells should now actually deliver. Channel echoes show as
[Trade] +Acdream says, "hello" without the duplicate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 20:49:02 +02:00

92 lines
3.2 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.
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]);
Assert.Equal(
ChatPanel.ColorForCombat(CombatLineKind.Info),
(System.Numerics.Vector4)coloredCall.Args[0]!);
}
private sealed class RecordingChatBus : ICommandBus
{
public void Publish<T>(T command) where T : notnull { /* no-op */ }
}
}