Fix Repentance placeholder VFX: targets, colors, animation check
High: server now computes visual targets after resolution — prefers client-provided unit InstanceId or tile Coord, falls back to the first live opponent ArchSpirit so targetless/server-resolved effects always have a destination. Medium: source ArchSpirit fallback now looks up the actor's player in game state rather than get_my_player(), fixing opponent and spectator views. Medium: player color now uses teamIndex from the player DTO instead of deriving it from seatOrder, fixing team and multiplayer modes. Low: hasCustomAnimation check now scans all Active ability definitions for a non-empty AssetUrl, not just abilities[0]. Low: server no longer sends the push (or the HasCustomAnimation field) when a custom animation exists; client-side guard removed accordingly. 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>
This commit is contained in:
@@ -605,10 +605,11 @@ public sealed record GameActivityPush(string EventType, string SessionId);
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast to every participant and spectator when a Repentance card resolves
|
||||
/// and the ability has no usable custom animation asset.
|
||||
/// Clients use this to play a placeholder projectile VFX from the acting player's
|
||||
/// ArchSpirit to the ability target.
|
||||
/// Clients MUST ignore this push when HasCustomAnimation is true.
|
||||
/// without a custom animation asset. Only sent when no active ability on the card
|
||||
/// carries a non-empty Animation.AssetUrl, so clients can always play the effect.
|
||||
/// Targets contains the best available resolved visual targets:
|
||||
/// • explicit unit InstanceId or tile Coord if the player provided them, else
|
||||
/// • the first live opponent ArchSpirit InstanceId as a fallback.
|
||||
/// </summary>
|
||||
public sealed record RepentancePlaceholderVisualPush(
|
||||
string EventId,
|
||||
@@ -619,8 +620,7 @@ public sealed record RepentancePlaceholderVisualPush(
|
||||
string CardDefinitionId,
|
||||
string CardName,
|
||||
string Affinity,
|
||||
IReadOnlyList<AbilityTarget> Targets,
|
||||
bool HasCustomAnimation);
|
||||
IReadOnlyList<AbilityTarget> Targets);
|
||||
|
||||
// ── DTOs ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -65,28 +65,74 @@ internal sealed class GamePlayCardHandler : GameHandlerBase, IMessageHandler
|
||||
// Visual-only push for Repentance cards (no gameplay state, transient).
|
||||
if (card.CardType == "Repentance")
|
||||
{
|
||||
var archSpirit = newState.Players[actorId].ArchSpirit;
|
||||
var abilities = AbilitySystem.ParseAbilities(card.AbilitiesJson);
|
||||
var hasCustomAnim = abilities.Length > 0
|
||||
&& abilities[0].Animation is { } anim
|
||||
&& !string.IsNullOrEmpty(anim.AssetUrl);
|
||||
var archSpirit = newState.Players[actorId].ArchSpirit;
|
||||
var abilities = AbilitySystem.ParseAbilities(card.AbilitiesJson);
|
||||
|
||||
var visualPush = ServerMessage.Push("game.visual.repentance_placeholder",
|
||||
new RepentancePlaceholderVisualPush(
|
||||
EventId: Guid.NewGuid().ToString("N")[..8],
|
||||
SessionId: session.Id.ToString(),
|
||||
ActorAccountId: actorId,
|
||||
SourceArchSpiritInstanceId: archSpirit?.InstanceId ?? string.Empty,
|
||||
CardInstanceId: card.InstanceId,
|
||||
CardDefinitionId: card.CardDefinitionId.ToString(),
|
||||
CardName: card.Name,
|
||||
Affinity: card.Affinity,
|
||||
Targets: req.Targets ?? [],
|
||||
HasCustomAnimation: hasCustomAnim));
|
||||
// hasCustomAnimation is true only when at least one Active ability definition
|
||||
// carries an animation with a usable AssetUrl. Later ability indices can also
|
||||
// carry custom animations, so we scan the full active-ability set.
|
||||
var hasCustomAnim = abilities.Any(a =>
|
||||
a.Type == Abilities.Models.AbilityType.Active
|
||||
&& a.Animation is { } anim
|
||||
&& !string.IsNullOrEmpty(anim.AssetUrl));
|
||||
|
||||
await BroadcastToAllViewersAsync(_clientPush, session, visualPush, ct);
|
||||
// Only send placeholder when there is nothing custom to play.
|
||||
if (!hasCustomAnim)
|
||||
{
|
||||
var visualPush = ServerMessage.Push("game.visual.repentance_placeholder",
|
||||
new RepentancePlaceholderVisualPush(
|
||||
EventId: Guid.NewGuid().ToString("N")[..8],
|
||||
SessionId: session.Id.ToString(),
|
||||
ActorAccountId: actorId,
|
||||
SourceArchSpiritInstanceId: archSpirit?.InstanceId ?? string.Empty,
|
||||
CardInstanceId: card.InstanceId,
|
||||
CardDefinitionId: card.CardDefinitionId.ToString(),
|
||||
CardName: card.Name,
|
||||
Affinity: card.Affinity,
|
||||
Targets: ComputeVisualTargets(req.Targets, newState, actorId)));
|
||||
|
||||
await BroadcastToAllViewersAsync(_clientPush, session, visualPush, ct);
|
||||
}
|
||||
}
|
||||
|
||||
return ServerMessage.Reply("game.play_card.ack", message.Seq, new GamePlayCardResponse(dto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Derives the best available visual target list for the placeholder VFX.
|
||||
///
|
||||
/// Priority:
|
||||
/// 1. Client-provided targets that carry a unit InstanceId or tile Coord — already
|
||||
/// represent a player-chosen target and are valid for all ability types that
|
||||
/// require explicit targeting.
|
||||
/// 2. Player-style targets sent as InstanceId (account IDs for player-zone actions).
|
||||
/// 3. Fallback: the first non-actor opponent's ArchSpirit account ID, so the
|
||||
/// projectile always has somewhere to travel to for targetless abilities.
|
||||
/// </summary>
|
||||
private static IReadOnlyList<AbilityTarget> ComputeVisualTargets(
|
||||
IReadOnlyList<AbilityTarget>? clientTargets,
|
||||
GameState state,
|
||||
string actorId)
|
||||
{
|
||||
// Use whatever the client provided as long as it carries a usable ref or coord.
|
||||
if (clientTargets is { Count: > 0 })
|
||||
{
|
||||
var usable = clientTargets
|
||||
.Where(t => !string.IsNullOrEmpty(t.InstanceId) || t.Coord is not null)
|
||||
.ToList();
|
||||
if (usable.Count > 0)
|
||||
return usable;
|
||||
}
|
||||
|
||||
// Targetless / server-resolved: aim at the first live opponent ArchSpirit.
|
||||
var opponentArch = state.Players.Values
|
||||
.Where(p => p.AccountId.ToString() != actorId && p.ArchSpirit is not null)
|
||||
.Select(p => p.ArchSpirit!)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (opponentArch is not null)
|
||||
return [new AbilityTarget(ActionIndex: 0, InstanceId: opponentArch.InstanceId)];
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user