Verbose Attack Logging
This commit is contained in:
@@ -697,6 +697,33 @@ public static class GameEngine
|
||||
string attackerInstanceId,
|
||||
string targetInstanceId)
|
||||
{
|
||||
static string Pos(FieldCard c)
|
||||
=> c.Position.HasValue ? $"{c.Position.Value.X},{c.Position.Value.Y}" : "null";
|
||||
|
||||
string Locations(string instanceId)
|
||||
{
|
||||
var hits = new List<string>();
|
||||
foreach (var (pid, p) in state.Players)
|
||||
{
|
||||
var label = pid.Length > 8 ? pid[..8] : pid;
|
||||
if (p.ArchSpirit?.InstanceId == instanceId) hits.Add($"{label}:ArchSpirit");
|
||||
if (p.Hand.Any(c => c.InstanceId == instanceId)) hits.Add($"{label}:Hand");
|
||||
if (p.Deck.Any(c => c.InstanceId == instanceId)) hits.Add($"{label}:Deck");
|
||||
if (p.Field.Any(c => c.InstanceId == instanceId)) hits.Add($"{label}:Field");
|
||||
if (p.Discard.Any(c => c.InstanceId == instanceId)) hits.Add($"{label}:Discard");
|
||||
}
|
||||
return hits.Count == 0 ? "none" : string.Join(",", hits);
|
||||
}
|
||||
|
||||
static string UnitSummary(FieldCard c)
|
||||
=> $"{c.InstanceId} type={c.CardType} leader={c.IsLeader} hp={c.CurrentHealth}/{c.MaxHealth} " +
|
||||
$"def={c.CurrentDefense}/{c.MaxDefense} dmg={c.Damage} exhausted={c.IsExhausted} " +
|
||||
$"canAtk={c.CanAttack} canBeAtk={c.CanBeAttacked} mp={c.CurrentMp}/{c.MaxMp} pos={Pos(c)}";
|
||||
|
||||
Console.WriteLine(
|
||||
$"[GameEngine.Attack] START actor={actorId} attacker={attackerInstanceId} target={targetInstanceId} " +
|
||||
$"phase={state.Phase} active={state.ActivePlayerAccountId} ver={state.NextActionSequence}");
|
||||
|
||||
ValidateActivePlayer(state, actorId);
|
||||
ValidatePhase(state, GamePhase.Main);
|
||||
|
||||
@@ -705,6 +732,9 @@ public static class GameEngine
|
||||
var (opponentId, opponentPlayer) = FindTargetOwner(state, actorId, targetInstanceId);
|
||||
var target = GetFieldCard(opponentPlayer, targetInstanceId);
|
||||
|
||||
Console.WriteLine($"[GameEngine.Attack] attacker {UnitSummary(attacker)} locations={Locations(attacker.InstanceId)}");
|
||||
Console.WriteLine($"[GameEngine.Attack] target {UnitSummary(target)} owner={opponentId} locations={Locations(target.InstanceId)}");
|
||||
|
||||
if (attacker.IsExhausted) throw new GameException("CARD_EXHAUSTED");
|
||||
if (!attacker.CanAttack) throw new GameException("CARD_CANNOT_ATTACK");
|
||||
|
||||
@@ -716,16 +746,22 @@ public static class GameEngine
|
||||
var occupancy = state.Board.BuildOccupancyMap();
|
||||
var minRange = attacker.MinAttackRange ?? 1;
|
||||
var maxRange = attacker.MaxAttackRange ?? 1;
|
||||
var canAttack = AttackSystem.CanAttack(
|
||||
attacker.Position.Value, target.Position.Value,
|
||||
minRange, maxRange, attacker.RequiresLos,
|
||||
state.Board, occupancy);
|
||||
|
||||
if (!AttackSystem.CanAttack(
|
||||
attacker.Position.Value, target.Position.Value,
|
||||
minRange, maxRange, attacker.RequiresLos,
|
||||
state.Board, occupancy))
|
||||
Console.WriteLine(
|
||||
$"[GameEngine.Attack] range attackerPos={Pos(attacker)} targetPos={Pos(target)} " +
|
||||
$"min={minRange} max={maxRange} los={attacker.RequiresLos} allowed={canAttack}");
|
||||
|
||||
if (!canAttack)
|
||||
throw new GameException("TARGET_OUT_OF_RANGE");
|
||||
}
|
||||
|
||||
// Fire UnitAttack trigger before damage so triggered abilities can affect
|
||||
// attacker/target stats (e.g. bonus damage, damage reduction) before they land.
|
||||
Console.WriteLine("[GameEngine.Attack] trigger UnitAttack begin");
|
||||
AbilitySystem.FireTrigger(state, new TriggerOccurrence
|
||||
{
|
||||
Kind = TriggerEventKind.UnitAttack,
|
||||
@@ -737,12 +773,20 @@ public static class GameEngine
|
||||
TargetId = targetInstanceId,
|
||||
},
|
||||
});
|
||||
Console.WriteLine($"[GameEngine.Attack] trigger UnitAttack end attacker {UnitSummary(attacker)}");
|
||||
Console.WriteLine($"[GameEngine.Attack] trigger UnitAttack end target {UnitSummary(target)}");
|
||||
|
||||
// Attacker hits target.
|
||||
Console.WriteLine($"[GameEngine.Attack] attacker damage begin amount={attacker.Damage ?? 0} targetBefore={UnitSummary(target)}");
|
||||
ApplyDamage(target, attacker.Damage ?? 0);
|
||||
Console.WriteLine($"[GameEngine.Attack] attacker damage end targetAfter={UnitSummary(target)}");
|
||||
|
||||
// Target counter-attacks if able and still alive.
|
||||
if (target.CurrentHealth > 0 && target.CanAttack && !target.IsExhausted)
|
||||
var targetCanCounterByState = target.CurrentHealth > 0 && target.CanAttack && !target.IsExhausted;
|
||||
Console.WriteLine(
|
||||
$"[GameEngine.Attack] counter state hp={target.CurrentHealth} canAttack={target.CanAttack} " +
|
||||
$"exhausted={target.IsExhausted} eligible={targetCanCounterByState}");
|
||||
if (targetCanCounterByState)
|
||||
{
|
||||
var canCounterAttack = true;
|
||||
|
||||
@@ -756,29 +800,46 @@ public static class GameEngine
|
||||
target.Position.Value, attacker.Position.Value,
|
||||
targetMinRange, targetMaxRange, target.RequiresLos,
|
||||
state.Board, occupancy);
|
||||
Console.WriteLine(
|
||||
$"[GameEngine.Attack] counter range targetPos={Pos(target)} attackerPos={Pos(attacker)} " +
|
||||
$"min={targetMinRange} max={targetMaxRange} los={target.RequiresLos} allowed={canCounterAttack}");
|
||||
}
|
||||
|
||||
if (canCounterAttack)
|
||||
{
|
||||
Console.WriteLine($"[GameEngine.Attack] counter damage begin amount={target.Damage ?? 0} attackerBefore={UnitSummary(attacker)}");
|
||||
ApplyDamage(attacker, target.Damage ?? 0);
|
||||
Console.WriteLine($"[GameEngine.Attack] counter damage end attackerAfter={UnitSummary(attacker)}");
|
||||
}
|
||||
}
|
||||
|
||||
// Consume extra attack or exhaust normally.
|
||||
if (attacker.ExtraAttacksRemaining > 0)
|
||||
{
|
||||
attacker.ExtraAttacksRemaining--;
|
||||
Console.WriteLine($"[GameEngine.Attack] consume extra attack attacker={attacker.InstanceId} remaining={attacker.ExtraAttacksRemaining}");
|
||||
}
|
||||
else
|
||||
{
|
||||
attacker.IsExhausted = true;
|
||||
Console.WriteLine($"[GameEngine.Attack] exhaust attacker={attacker.InstanceId}");
|
||||
}
|
||||
|
||||
bool gameOver = false;
|
||||
var activePlayer = state.Players[actorId];
|
||||
|
||||
Console.WriteLine($"[GameEngine.Attack] death check attacker hp={attacker.CurrentHealth} leader={attacker.IsLeader} locations={Locations(attacker.InstanceId)}");
|
||||
if (attacker.CurrentHealth <= 0)
|
||||
{
|
||||
if (attacker.IsLeader)
|
||||
{
|
||||
Console.WriteLine($"[GameEngine.Attack] attacker leader death -> eliminate actor={actorId}");
|
||||
EliminatePlayer(state, activePlayer, out gameOver);
|
||||
Console.WriteLine($"[GameEngine.Attack] attacker eliminated gameOver={gameOver} phase={state.Phase}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"[GameEngine.Attack] attacker non-leader death -> discard attacker={attacker.InstanceId}");
|
||||
AbilitySystem.EvaluateAurasOnLeave(state, attacker.InstanceId);
|
||||
AbilitySystem.RevokePassivesForSource(state, attacker.InstanceId);
|
||||
if (state.Board is not null) state.Board.RemoveUnit(attacker.InstanceId);
|
||||
@@ -802,14 +863,18 @@ public static class GameEngine
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"[GameEngine.Attack] death check target hp={target.CurrentHealth} leader={target.IsLeader} locations={Locations(target.InstanceId)}");
|
||||
if (target.CurrentHealth <= 0)
|
||||
{
|
||||
if (target.IsLeader)
|
||||
{
|
||||
Console.WriteLine($"[GameEngine.Attack] target leader death -> eliminate opponent={opponentId}");
|
||||
EliminatePlayer(state, opponentPlayer, out gameOver);
|
||||
Console.WriteLine($"[GameEngine.Attack] target eliminated gameOver={gameOver} phase={state.Phase}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"[GameEngine.Attack] target non-leader death -> discard target={target.InstanceId}");
|
||||
AbilitySystem.EvaluateAurasOnLeave(state, target.InstanceId);
|
||||
AbilitySystem.RevokePassivesForSource(state, target.InstanceId);
|
||||
if (state.Board is not null) state.Board.RemoveUnit(target.InstanceId);
|
||||
@@ -833,6 +898,10 @@ public static class GameEngine
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine(
|
||||
$"[GameEngine.Attack] END gameOver={gameOver} phase={state.Phase} " +
|
||||
$"attackerLocations={Locations(attacker.InstanceId)} targetLocations={Locations(target.InstanceId)}");
|
||||
|
||||
return (state, gameOver);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user