Server: - Add AbilityPlaceholderVisualPush DTO (sourceInstanceId, abilityName, sourceAffinity, targets, targetMode: Self|Unit|Tile|PlayerZone|None) - Promote ComputeVisualTargets to GameHandlerBase (protected static) - Add ComputeAbilityVisualTargets — extends Repentance logic with Self/ExactSelf + All-count detection, falls back to enemy ArchSpirit - Add ComputeAbilityTargetMode — derives mode from visual targets + sourceInstanceId (PlayerZone when target is a player account ID) - Add FindSourceUnit helper — searches Field + ArchSpirit across all players - GameActivateAbilityHandler captures source unit + ability def before ActivateAbility, skips push when Animation.AssetUrl is set Client: - Add ability_placeholder_visual signal and push router case in Game.gd - New AbilityPlaceholderFx component: Self/None → radial glow burst + two expanding rings on source; Unit/Tile/PlayerZone → orb projectile from source unit body to resolved target, impact ring + burst motes on arrival - Wire component in game_screen.gd (_ready, _exit_tree, handler) Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
95 lines
3.8 KiB
C#
95 lines
3.8 KiB
C#
namespace SOR.Game.Handlers;
|
|
|
|
using System.Text.Json;
|
|
using SOR.Database.Contexts;
|
|
using SOR.Game.Abilities;
|
|
using SOR.Networking.Abstractions.Messaging;
|
|
using SOR.Networking.Abstractions.Push;
|
|
using SOR.Networking.Abstractions.Transport;
|
|
using SOR.Shared.Networking;
|
|
|
|
/// <summary>
|
|
/// game.activate_ability — active player fires an Active ability on one of their field units.
|
|
///
|
|
/// AbilityIndex is 0-based into the source unit's AbilitiesJson ability array.
|
|
/// Targets is optional; required when the ability needs player-chosen targets.
|
|
/// </summary>
|
|
internal sealed class GameActivateAbilityHandler : GameHandlerBase, IMessageHandler
|
|
{
|
|
private readonly IMessageSerializer _serializer;
|
|
private readonly GameDbContext _gameDb;
|
|
private readonly IClientPush _clientPush;
|
|
|
|
public GameActivateAbilityHandler(
|
|
IMessageSerializer serializer,
|
|
GameDbContext gameDb,
|
|
IClientPush clientPush)
|
|
{
|
|
_serializer = serializer;
|
|
_gameDb = gameDb;
|
|
_clientPush = clientPush;
|
|
}
|
|
|
|
public string MessageType => "game.activate_ability";
|
|
|
|
public async Task<IServerMessage?> HandleAsync(
|
|
IClientMessage message,
|
|
AuthenticatedConnection connection,
|
|
CancellationToken ct)
|
|
{
|
|
var req = _serializer.DeserializePayload<GameActivateAbilityRequest>(message.Payload);
|
|
var actorId = connection.UserId;
|
|
|
|
var session = await LoadActiveSessionAsync(_gameDb, req.SessionId, actorId, ct);
|
|
var prevStateJson = session.StateJson!;
|
|
var state = GameEngine.Deserialize(prevStateJson);
|
|
|
|
// Capture source unit and ability definition before the engine mutates state.
|
|
var source = FindSourceUnit(state, req.SourceInstanceId);
|
|
var abilities = AbilitySystem.ParseAbilities(source?.AbilitiesJson);
|
|
var ability = req.AbilityIndex >= 0 && req.AbilityIndex < abilities.Length
|
|
? abilities[req.AbilityIndex]
|
|
: null;
|
|
|
|
var newState = GameEngine.ActivateAbility(
|
|
state, actorId, req.SourceInstanceId, req.AbilityIndex, req.Targets);
|
|
|
|
await SaveStateAsync(_gameDb, session, newState, actorId, "game.activate_ability",
|
|
JsonSerializer.Serialize(req), ct);
|
|
|
|
var dto = GameEngine.ToDto(newState, actorId);
|
|
await PushStateToPlayersAsync(_clientPush, session, newState, ct, prevStateJson);
|
|
|
|
// Visual-only push when the ability has no custom animation asset.
|
|
if (source is not null && ability is not null)
|
|
{
|
|
var hasCustomAnim = ability.Animation is { } anim
|
|
&& !string.IsNullOrEmpty(anim.AssetUrl);
|
|
|
|
if (!hasCustomAnim)
|
|
{
|
|
var visualTargets = ComputeAbilityVisualTargets(
|
|
req.Targets, ability, newState, actorId, req.SourceInstanceId);
|
|
var targetMode = ComputeAbilityTargetMode(
|
|
visualTargets, newState, req.SourceInstanceId);
|
|
|
|
var visualPush = ServerMessage.Push("game.visual.ability_placeholder",
|
|
new AbilityPlaceholderVisualPush(
|
|
EventId: Guid.NewGuid().ToString("N")[..8],
|
|
SessionId: session.Id.ToString(),
|
|
ActorAccountId: actorId,
|
|
SourceInstanceId: req.SourceInstanceId,
|
|
AbilityName: ability.Name ?? string.Empty,
|
|
SourceAffinity: source.Affinity,
|
|
Targets: visualTargets,
|
|
TargetMode: targetMode));
|
|
|
|
await BroadcastToAllViewersAsync(_clientPush, session, visualPush, ct);
|
|
}
|
|
}
|
|
|
|
return ServerMessage.Reply("game.activate_ability.ack", message.Seq,
|
|
new GameActivateAbilityResponse(dto));
|
|
}
|
|
}
|