feat(chat): #20 CombatChatTranslator - retail-faithful combat -> ChatLog templates

Subscribes to CombatState's DamageDealtAccepted / DamageTaken /
MissedOutgoing / EvadedIncoming / AttackDone / KillLanded events
and emits chat-line text into ChatLog.OnCombatLine, mirroring
holtburger's templates verbatim from references/holtburger/apps/
holtburger-cli/src/pages/game/panels/chat.rs:221-308.

Pieces:
- ChatLog: new ChatKind.Combat value; new CombatLineKind enum
  (Info / Warning / Error) on ChatEntry; OnCombatLine(text, kind)
  adapter.
- CombatChatTranslator (Core, IDisposable). Static formatters:
  FormatDamageType (slashing/piercing/bludgeoning/fire/cold/acid/
  electric/nether), FormatDamageLocation (head/chest/abdomen/
  upper arm/lower arm/hand/upper leg/lower leg/foot), FormatPercent,
  FormatAttackConditionsSuffix.
- ChatVM.RecentLinesDetailed() returns FormattedLine records with
  kind metadata so panels can render combat lines colored.
- ChatPanel switches on Kind/CombatKind: combat-Info -> yellow,
  combat-Warning -> red incoming-damage, combat-Error -> deep red,
  all others -> existing renderer.Text path.
- GameWindow constructs translator after GameEventWiring.WireAll;
  disposes in OnClosing + live-session failure path.

Templates landed:
  Attacker:  "You hit {def} for {dmg} {dtype} damage ({hp%}). [Crit]{suffix}"
  Defender:  "{atk} hit you for {dmg} {dtype} damage to your {loc} ({hp%})..."
  Evade-out: "{def} evaded your attack."
  Evade-in:  "You evaded {atk}'s attack."
  AttackErr: "Attack sequence finished with {error}."
  Kill:      synthesized "You killed {name}." + server PlayerKilled
             death-message arrives separately via ChatLog.OnPlayerKilled.

Deviations from holtburger templates (documented in source):
- DamageDealt omits Critical-hit suffix until CombatState.DamageDealt
  carries the flag (defender-side has it; attacker-side doesn't yet).
- DamageTaken omits (health%) until CombatState.DamageIncoming
  parses the wire health-percent field.
- AttackConditions suffix is implemented but always empty until the
  bitflag is plumbed into CombatState records.

18 new tests (12 translator + 4 ChatVMCombat + 2 ChatLog).
Solution total: 978 green (243 Core.Net + 639 Core + 96 UI).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-25 19:55:15 +02:00
parent ca968fc766
commit 3d26c8efde
9 changed files with 699 additions and 2 deletions

View file

@ -166,6 +166,30 @@ public sealed class ChatLog
ChannelId: 0));
}
/// <summary>
/// Phase I.7: combat-translator emits a pre-formatted line. The
/// translator (<see cref="CombatChatTranslator"/>) subscribes to
/// <see cref="Combat.CombatState"/> events and renders the retail
/// template (e.g. "You hit Mosswart for 12 slashing damage (54.0%)
/// Critical hit.") and decorates the entry with a
/// <see cref="Combat.CombatLineKind"/> so the panel can color the
/// line. Maps to holtburger's <c>info().combat()</c> /
/// <c>warning().combat()</c> / <c>error().combat()</c> tag flow at
/// <c>chat.rs:221-308</c>.
/// </summary>
public void OnCombatLine(string text, Combat.CombatLineKind kind = Combat.CombatLineKind.Info)
{
Append(new ChatEntry(
Kind: ChatKind.Combat,
Sender: "",
Text: text,
SenderGuid: 0,
ChannelId: 0)
{
CombatKind = kind,
});
}
/// <summary>Echo the player's own outbound message after local send.</summary>
public void OnSelfSent(ChatKind kind, string text, string targetOrChannel = "")
{
@ -201,6 +225,14 @@ public enum ChatKind
Popup,
Emote,
SoulEmote,
/// <summary>
/// Phase I.7: a combat feedback line emitted by
/// <see cref="CombatChatTranslator"/> from <see cref="Combat.CombatState"/>
/// events. The accompanying <see cref="ChatEntry.CombatKind"/> field
/// drives panel coloring (info / warning / error per holtburger
/// <c>chat.rs:221-308</c>).
/// </summary>
Combat,
}
public readonly record struct ChatEntry(
@ -211,4 +243,11 @@ public readonly record struct ChatEntry(
uint ChannelId)
{
public DateTime Received { get; init; } = DateTime.UtcNow;
/// <summary>
/// Phase I.7: severity bucket for <see cref="ChatKind.Combat"/>
/// entries. Null for every other kind. Drives the
/// <see cref="ChatPanel"/>'s <c>TextColored</c> color choice.
/// </summary>
public Combat.CombatLineKind? CombatKind { get; init; }
}