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
|
|
@ -310,6 +310,11 @@ public sealed class GameWindow : IDisposable
|
|||
// back to NullCommandBus.Instance.
|
||||
private AcDream.UI.Abstractions.LiveCommandBus? _commandBus;
|
||||
|
||||
// Phase I.7 — bridges CombatState's typed events into ChatLog as
|
||||
// retail-faithful "You hit ..." / "... evaded your attack." lines.
|
||||
// Disposable; lives for the duration of the live session.
|
||||
private AcDream.Core.Chat.CombatChatTranslator? _combatChatTranslator;
|
||||
|
||||
// Phase G.1-G.2 world lighting/time state.
|
||||
public readonly AcDream.Core.World.WorldTimeService WorldTime =
|
||||
new AcDream.Core.World.WorldTimeService(
|
||||
|
|
@ -1224,6 +1229,13 @@ public sealed class GameWindow : IDisposable
|
|||
_liveSession.GameEvents, Items, Combat, SpellBook, Chat, LocalPlayer,
|
||||
TurbineChat);
|
||||
|
||||
// Phase I.7: subscribe to CombatState events and emit
|
||||
// retail-faithful "You hit X for Y damage" chat lines into
|
||||
// the unified ChatLog. The translator owns the wording
|
||||
// (templates ported from holtburger chat.rs:221-308); the
|
||||
// panel renders combat entries via TextColored.
|
||||
_combatChatTranslator = new AcDream.Core.Chat.CombatChatTranslator(Combat, Chat);
|
||||
|
||||
// Phase H.1: feed inbound HearSpeech into the chat log.
|
||||
_liveSession.SpeechHeard += speech =>
|
||||
Chat.OnLocalSpeech(
|
||||
|
|
@ -1347,6 +1359,8 @@ public sealed class GameWindow : IDisposable
|
|||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"live: session failed: {ex.Message}");
|
||||
_combatChatTranslator?.Dispose();
|
||||
_combatChatTranslator = null;
|
||||
_liveSession?.Dispose();
|
||||
_liveSession = null;
|
||||
}
|
||||
|
|
@ -4931,6 +4945,9 @@ public sealed class GameWindow : IDisposable
|
|||
// state. The worker may still be processing a load job that references
|
||||
// _dats; Dispose cancels the token and waits up to 2s for the thread.
|
||||
_streamer?.Dispose();
|
||||
// Phase I.7: unsubscribe combat → chat translator before the
|
||||
// session it depends on goes away.
|
||||
_combatChatTranslator?.Dispose();
|
||||
_liveSession?.Dispose();
|
||||
_audioEngine?.Dispose(); // Phase E.2: stop all voices, close AL context
|
||||
_staticMesh?.Dispose();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue