Refactor game HUD scenes and harden attack checks
This commit is contained in:
@@ -735,8 +735,9 @@ public static class GameEngine
|
||||
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");
|
||||
if (attacker.IsExhausted) throw new GameException("CARD_EXHAUSTED");
|
||||
if (!attacker.CanAttack) throw new GameException("CARD_CANNOT_ATTACK");
|
||||
if (attacker.CurrentHealth <= 0) throw new GameException("UNIT_IS_DEAD");
|
||||
|
||||
if (!target.CanBeAttacked) throw new GameException("TARGET_CANNOT_BE_ATTACKED");
|
||||
|
||||
@@ -828,10 +829,14 @@ public static class GameEngine
|
||||
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)}");
|
||||
// Use ArchSpirit InstanceId as fallback for leader detection in case IsLeader flag is stale.
|
||||
bool attackerIsLeader = attacker.IsLeader || activePlayer.ArchSpirit?.InstanceId == attacker.InstanceId;
|
||||
bool targetIsLeader = target.IsLeader || opponentPlayer.ArchSpirit?.InstanceId == target.InstanceId;
|
||||
|
||||
Console.WriteLine($"[GameEngine.Attack] death check attacker hp={attacker.CurrentHealth} leader={attacker.IsLeader} archLeader={attackerIsLeader} locations={Locations(attacker.InstanceId)}");
|
||||
if (attacker.CurrentHealth <= 0)
|
||||
{
|
||||
if (attacker.IsLeader)
|
||||
if (attackerIsLeader)
|
||||
{
|
||||
Console.WriteLine($"[GameEngine.Attack] attacker leader death -> eliminate actor={actorId}");
|
||||
EliminatePlayer(state, activePlayer, out gameOver);
|
||||
@@ -863,10 +868,10 @@ public static class GameEngine
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"[GameEngine.Attack] death check target hp={target.CurrentHealth} leader={target.IsLeader} locations={Locations(target.InstanceId)}");
|
||||
Console.WriteLine($"[GameEngine.Attack] death check target hp={target.CurrentHealth} leader={target.IsLeader} archLeader={targetIsLeader} locations={Locations(target.InstanceId)}");
|
||||
if (target.CurrentHealth <= 0)
|
||||
{
|
||||
if (target.IsLeader)
|
||||
if (targetIsLeader)
|
||||
{
|
||||
Console.WriteLine($"[GameEngine.Attack] target leader death -> eliminate opponent={opponentId}");
|
||||
EliminatePlayer(state, opponentPlayer, out gameOver);
|
||||
|
||||
Reference in New Issue
Block a user