diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 91bf9cf..882f980 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -2,6 +2,7 @@ namespace SOR.Game.Abilities; using System.Text.Json; +using Microsoft.Extensions.Logging; using SOR.Database.Enums; using SOR.Game.Abilities.Models; using SOR.Game.Grid; @@ -16,6 +17,14 @@ using SOR.Game.Grid; /// public static class AbilitySystem { + // ── Verbose debug logger (set from Program.cs via InitLogger) ───────────── + + private static ILogger? _log; + + /// Call once at startup to enable verbose ability-system logging. + public static void InitLogger(ILoggerFactory factory) => + _log = factory.CreateLogger("SOR.Game.AbilitySystem"); + // ── JSON options ─────────────────────────────────────────────────────────── private static readonly JsonSerializerOptions _jsonOpts = new() @@ -122,6 +131,11 @@ public static class AbilitySystem var ctx = new AbilityContext { State = state, ActorId = actorId, Source = source }; + _log?.LogDebug( + "[ABILITY] ActivateAbility START — actor={Actor} source={Source}({SourceId}) abilityIdx={Idx} abilityName={Name} ST={ST} SP={SP}", + actorId, source.Name, sourceInstanceId, abilityIndex, def.Name, + state.Players[actorId].CurrentSt, state.Players[actorId].CurrentSp); + // Source-side activation conditions are shared with card-active execution. if (!ValidateSourceActivationConditions(def, ctx, source)) throw new GameException("ABILITY_CONDITION_NOT_MET"); @@ -134,21 +148,44 @@ public static class AbilitySystem var effectiveActions = GetEffectiveActions(def, ctx, abilityIndex, def.Range, def.Duration); // GetEffectiveActions returns null when it emitted PendingActionGroupPick (OR/XOR, interactive). - if (effectiveActions is null) return state; + if (effectiveActions is null) + { + _log?.LogDebug("[ABILITY] ActivateAbility PAUSED — PendingActionGroupPick emitted, cost not yet paid"); + return state; + } if (def.CostGroup is { } cg) { + _log?.LogDebug("[ABILITY] PayCostGroup — ST={ST} SP={SP} before payment", + state.Players[actorId].CurrentSt, state.Players[actorId].CurrentSp); bool paused = PayCostGroup(cg, ctx, abilityIndex, effectiveActions, def.Range, def.Duration); + _log?.LogDebug("[ABILITY] PayCostGroup — ST={ST} SP={SP} after payment paused={Paused}", + state.Players[actorId].CurrentSt, state.Players[actorId].CurrentSp, paused); if (paused) return state; } else if (def.Cost is { Length: > 0 }) { + _log?.LogDebug("[ABILITY] PayCosts (legacy) — ST={ST} SP={SP} before payment", + state.Players[actorId].CurrentSt, state.Players[actorId].CurrentSp); bool paused = PayCosts(def.Cost, ctx, abilityIndex, effectiveActions, def.Range, def.Duration); + _log?.LogDebug("[ABILITY] PayCosts (legacy) — ST={ST} SP={SP} after payment paused={Paused}", + state.Players[actorId].CurrentSt, state.Players[actorId].CurrentSp, paused); if (paused) return state; // waiting for client cost pick } + else + { + _log?.LogDebug("[ABILITY] No cost defined — skipping payment"); + } + + _log?.LogDebug("[ABILITY] ExecuteActions — {Count} action(s) clientTargets={TargetCount}", + effectiveActions.Length, clientTargets?.Count ?? 0); ExecuteActions(effectiveActions, ctx, clientTargets, requireClientTargets: true, activationRange: def.Range, forceDuration: def.Duration); + _log?.LogDebug( + "[ABILITY] ActivateAbility END — actor={Actor} ST={ST} SP={SP}", + actorId, state.Players[actorId].CurrentSt, state.Players[actorId].CurrentSp); + return state; } @@ -745,13 +782,19 @@ public static class AbilitySystem switch (cost.Type) { case CostType.SpiritPoints: + _log?.LogDebug("[COST] SpiritPoints — player={Player} SP={Before} amount={Amount}", + player.AccountId, player.CurrentSp, cost.Amount); if (player.CurrentSp < cost.Amount) throw new GameException("INSUFFICIENT_SP"); player.CurrentSp -= cost.Amount; + _log?.LogDebug("[COST] SpiritPoints — SP after={After}", player.CurrentSp); break; case CostType.SacrificeTokens: + _log?.LogDebug("[COST] SacrificeTokens — player={Player} ST={Before} amount={Amount}", + player.AccountId, player.CurrentSt, cost.Amount); if (player.CurrentSt < cost.Amount) throw new GameException("INSUFFICIENT_ST"); player.CurrentSt -= cost.Amount; + _log?.LogDebug("[COST] SacrificeTokens — ST after={After}", player.CurrentSt); break; case CostType.DiscardFromHand: @@ -2886,14 +2929,31 @@ public static class AbilitySystem // ── §5.11 Token summoning ───────────────────────────────────────── case SummonTokenEffect ste when target is Coord coord: { + _log?.LogDebug("[EFFECT] SummonToken — coord=({X},{Y})", coord.X, coord.Y); var board = ctx.State.Board; - if (board is null) break; + if (board is null) + { + _log?.LogDebug("[EFFECT] SummonToken SKIP — board is null"); + break; + } var tile = board.GetTile(coord); - if (tile is null || !tile.IsEmpty) break; + if (tile is null || !tile.IsEmpty) + { + _log?.LogDebug("[EFFECT] SummonToken SKIP — tile null={TileNull} isEmpty={IsEmpty}", + tile is null, tile?.IsEmpty); + break; + } // TokenDefJson is deserialized directly as CardInstance field values. var proto = JsonSerializer.Deserialize(ste.TokenDefJson, _jsonOpts); - if (proto is null) break; + if (proto is null) + { + _log?.LogDebug("[EFFECT] SummonToken SKIP — failed to deserialize TokenDefJson"); + break; + } + + _log?.LogDebug("[EFFECT] SummonToken — token={Token} tokenAffinity={Affinity} tileBase1={Base1} tileBase2={Base2}", + proto.Name, proto.Affinity, tile.Base1, tile.Base2); // Enforce explicit TileFilter (e.g. TileAffinityMatches) — throw so the client // receives an error rather than silently swallowing a bad pick. @@ -2914,6 +2974,10 @@ public static class AbilitySystem ctx.State.Players[ctx.ActorId].Field.Add(tokenField); board.PlaceUnit(coord, tokenField.InstanceId, ctx.ActorId); + _log?.LogDebug("[EFFECT] SummonToken SUCCESS — token={Token} instanceId={Id} placed at ({X},{Y}) actor ST={ST}", + proto.Name, tokenField.InstanceId, coord.X, coord.Y, + ctx.State.Players[ctx.ActorId].CurrentSt); + FireTrigger(ctx.State, new TriggerOccurrence { Kind = TriggerEventKind.UnitEnterBattlefield, diff --git a/Server/src/SOR.Host/Program.cs b/Server/src/SOR.Host/Program.cs index d85df19..26281f9 100644 --- a/Server/src/SOR.Host/Program.cs +++ b/Server/src/SOR.Host/Program.cs @@ -240,6 +240,9 @@ app.MapGet("/cdn/{**path}", async (string path, HttpContext httpCtx, IHttpClient // ── RUN ─────────────────────────────────────────────────────────────────────── +// Wire verbose ability-system logger so debug output flows through Serilog. +SOR.Game.Abilities.AbilitySystem.InitLogger(app.Services.GetRequiredService()); + Log.Information("SOR Host starting. Services: {Services}", rawServices); // RunAsync blocks until the process receives a shutdown signal (SIGTERM, Ctrl+C). diff --git a/Server/src/SOR.Host/appsettings.json b/Server/src/SOR.Host/appsettings.json index 35bf181..71664b6 100644 --- a/Server/src/SOR.Host/appsettings.json +++ b/Server/src/SOR.Host/appsettings.json @@ -43,7 +43,8 @@ "Microsoft": "Warning", "Microsoft.AspNetCore": "Warning", "Grpc": "Warning", - "System": "Warning" + "System": "Warning", + "SOR.Game.AbilitySystem": "Debug" } }, "WriteTo": [