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:
parent
ca968fc766
commit
3d26c8efde
9 changed files with 699 additions and 2 deletions
|
|
@ -1,3 +1,7 @@
|
|||
using System.Numerics;
|
||||
using AcDream.Core.Chat;
|
||||
using AcDream.Core.Combat;
|
||||
|
||||
namespace AcDream.UI.Abstractions.Panels.Chat;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -56,7 +60,10 @@ public sealed class ChatPanel : IPanel
|
|||
return;
|
||||
}
|
||||
|
||||
var lines = _vm.RecentLines();
|
||||
// Phase I.7: pull the typed-line view so combat entries can
|
||||
// route through TextColored. Non-combat entries still take
|
||||
// the plain Text path (visually identical to the I.4 panel).
|
||||
var lines = _vm.RecentLinesDetailed();
|
||||
if (lines.Count == 0)
|
||||
{
|
||||
renderer.Text("(no messages yet)");
|
||||
|
|
@ -69,7 +76,15 @@ public sealed class ChatPanel : IPanel
|
|||
renderer.Separator();
|
||||
for (int i = 0; i < lines.Count; i++)
|
||||
{
|
||||
renderer.Text(lines[i]);
|
||||
var line = lines[i];
|
||||
if (line.Kind == ChatKind.Combat && line.CombatKind is { } ck)
|
||||
{
|
||||
renderer.TextColored(ColorForCombat(ck), line.Text);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer.Text(line.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,4 +106,17 @@ public sealed class ChatPanel : IPanel
|
|||
|
||||
renderer.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phase I.7: per-severity color for combat-feedback chat lines.
|
||||
/// Maps onto holtburger's <c>color_for_tags</c> at chat.rs:330-333
|
||||
/// (info → yellowish, warning → red incoming, error → deep red).
|
||||
/// </summary>
|
||||
public static Vector4 ColorForCombat(CombatLineKind kind) => kind switch
|
||||
{
|
||||
CombatLineKind.Info => new Vector4(1.0f, 1.0f, 0.6f, 1.0f),
|
||||
CombatLineKind.Warning => new Vector4(1.0f, 0.5f, 0.5f, 1.0f),
|
||||
CombatLineKind.Error => new Vector4(1.0f, 0.3f, 0.3f, 1.0f),
|
||||
_ => new Vector4(1f, 1f, 1f, 1f),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using AcDream.Core.Chat;
|
||||
using AcDream.Core.Combat;
|
||||
|
||||
namespace AcDream.UI.Abstractions.Panels.Chat;
|
||||
|
||||
|
|
@ -111,6 +112,49 @@ public sealed class ChatVM
|
|||
// not the formatter).
|
||||
ChatKind.Emote => $"* {entry.Sender} {entry.Text}",
|
||||
ChatKind.SoulEmote => $"* {entry.Sender} {entry.Text}",
|
||||
// Phase I.7: combat-line entries are pre-formatted by
|
||||
// CombatChatTranslator using holtburger templates verbatim
|
||||
// (chat.rs:221-308). The translator owns the wording; the VM
|
||||
// just passes through. The panel uses TextColored based on
|
||||
// entry.CombatKind.
|
||||
ChatKind.Combat => entry.Text,
|
||||
_ => entry.Text,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Phase I.7: snapshot of the chat tail with kind metadata so
|
||||
/// <see cref="ChatPanel"/> can pick the right rendering primitive
|
||||
/// per entry (plain <c>Text</c> for most kinds; <c>TextColored</c>
|
||||
/// for combat lines, with the rgba chosen from
|
||||
/// <see cref="ChatEntry.CombatKind"/>).
|
||||
/// </summary>
|
||||
public IReadOnlyList<FormattedLine> RecentLinesDetailed()
|
||||
{
|
||||
var snap = _log.Snapshot();
|
||||
int start = Math.Max(0, snap.Length - _displayLimit);
|
||||
int count = snap.Length - start;
|
||||
if (count <= 0) return Array.Empty<FormattedLine>();
|
||||
|
||||
var lines = new FormattedLine[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var entry = snap[start + i];
|
||||
lines[i] = new FormattedLine(
|
||||
Text: FormatEntry(entry),
|
||||
Kind: entry.Kind,
|
||||
CombatKind: entry.CombatKind);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phase I.7: formatted chat line with kind metadata. The
|
||||
/// <see cref="ChatPanel"/> switches on <see cref="Kind"/> +
|
||||
/// <see cref="CombatKind"/> to pick a rendering primitive
|
||||
/// (<c>Text</c> vs <c>TextColored(rgba)</c>).
|
||||
/// </summary>
|
||||
public readonly record struct FormattedLine(
|
||||
string Text,
|
||||
ChatKind Kind,
|
||||
CombatLineKind? CombatKind);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue