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:
@@ -84,8 +84,9 @@ signal player_pick_request(request_data: Dictionary)
|
||||
signal reveal_choice_pick_request(request_data: Dictionary)
|
||||
|
||||
## Emitted when a Repentance card resolves with no custom animation asset.
|
||||
## Server only emits this when no active ability on the card has a usable AssetUrl.
|
||||
## Payload keys: eventId, sessionId, actorAccountId, sourceArchSpiritInstanceId,
|
||||
## cardInstanceId, cardDefinitionId, cardName, affinity, targets, hasCustomAnimation
|
||||
## cardInstanceId, cardDefinitionId, cardName, affinity, targets
|
||||
signal repentance_placeholder_visual(payload: Dictionary)
|
||||
|
||||
# ── State ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -20,16 +20,13 @@ var units_root : Node3D = null
|
||||
|
||||
## Called by game_screen when Game.repentance_placeholder_visual fires.
|
||||
func play(payload: Dictionary) -> void:
|
||||
if bool(payload.get("hasCustomAnimation", false)):
|
||||
return
|
||||
|
||||
var actor_id: String = str(payload.get("actorAccountId", ""))
|
||||
var arch_id: String = str(payload.get("sourceArchSpiritInstanceId", ""))
|
||||
var affinity: String = str(payload.get("affinity", ""))
|
||||
var targets_raw: Variant = payload.get("targets", [])
|
||||
var targets: Array = targets_raw as Array if targets_raw is Array else []
|
||||
|
||||
var src_pos: Vector3 = _resolve_arch_spirit_pos(arch_id)
|
||||
var src_pos: Vector3 = _resolve_arch_spirit_pos(arch_id, actor_id)
|
||||
var tgt_pos: Vector3 = _resolve_target_pos(targets, actor_id, src_pos)
|
||||
|
||||
var affinity_color: Color = GameConstants.AFFINITY_COLORS.get(affinity, Color(0.7, 0.55, 0.9))
|
||||
@@ -40,15 +37,17 @@ func play(payload: Dictionary) -> void:
|
||||
|
||||
# ── Position resolution ───────────────────────────────────────────────────────
|
||||
|
||||
func _resolve_arch_spirit_pos(arch_instance_id: String) -> Vector3:
|
||||
func _resolve_arch_spirit_pos(arch_instance_id: String, actor_id: String) -> Vector3:
|
||||
if not arch_instance_id.is_empty():
|
||||
var body: StaticBody3D = unit_bodies.get(arch_instance_id) as StaticBody3D
|
||||
if is_instance_valid(body):
|
||||
return body.global_position + Vector3(0, 0.5, 0)
|
||||
|
||||
# Fallback: my own ArchSpirit from game state.
|
||||
var my_arch: Dictionary = Game.get_my_player().get("archSpirit", {})
|
||||
var pos: Dictionary = my_arch.get("position", {})
|
||||
# Fallback: resolve the actor's ArchSpirit from game state (works for
|
||||
# opponent casts, spectators, and timing gaps during mesh rebuilds).
|
||||
var actor_player: Dictionary = _player_by_id(actor_id)
|
||||
var arch: Dictionary = actor_player.get("archSpirit", {})
|
||||
var pos: Dictionary = arch.get("position", {})
|
||||
if not pos.is_empty() and pathfinder != null:
|
||||
return pathfinder.coord_to_world(int(pos.get("x", 0)), int(pos.get("y", 0))) + Vector3(0, 0.8, 0)
|
||||
|
||||
@@ -82,50 +81,41 @@ func _resolve_target_pos(targets: Array, actor_id: String, fallback: Vector3) ->
|
||||
for t: Variant in targets:
|
||||
if not (t is Dictionary):
|
||||
continue
|
||||
var td: Dictionary = t as Dictionary
|
||||
var td: Dictionary = t as Dictionary
|
||||
var inst_id: String = str(td.get("instanceId", td.get("instance_id", "")))
|
||||
if inst_id.is_empty():
|
||||
continue
|
||||
# Try it as an account id — look for that player's arch spirit.
|
||||
var all_players: Array = []
|
||||
var state: Dictionary = Game.state
|
||||
for p: Variant in state.get("players", []):
|
||||
all_players.append(p)
|
||||
for p: Variant in all_players:
|
||||
if not (p is Dictionary):
|
||||
continue
|
||||
var pd: Dictionary = p as Dictionary
|
||||
var acc: String = str(pd.get("accountId", ""))
|
||||
if acc != inst_id:
|
||||
continue
|
||||
var arch: Dictionary = pd.get("archSpirit", {})
|
||||
var apos: Dictionary = arch.get("position", {})
|
||||
if not apos.is_empty() and pathfinder != null:
|
||||
return pathfinder.coord_to_world(
|
||||
int(apos.get("x", 0)), int(apos.get("y", 0))) + Vector3(0, 0.8, 0)
|
||||
# Try it as an account id and look up that player's ArchSpirit position.
|
||||
var pd: Dictionary = _player_by_id(inst_id)
|
||||
var arch: Dictionary = pd.get("archSpirit", {})
|
||||
var apos: Dictionary = arch.get("position", {})
|
||||
if not apos.is_empty() and pathfinder != null:
|
||||
return pathfinder.coord_to_world(
|
||||
int(apos.get("x", 0)), int(apos.get("y", 0))) + Vector3(0, 0.8, 0)
|
||||
|
||||
# 4. Fallback to source.
|
||||
return fallback
|
||||
|
||||
|
||||
func _resolve_player_color(actor_id: String) -> Color:
|
||||
var state: Dictionary = Game.state
|
||||
var team_colors: Dictionary = state.get("teamColors", {})
|
||||
# Find the actor's seat to get their team index.
|
||||
var seat_order: Array = []
|
||||
var so_raw: Variant = state.get("seatOrder", [])
|
||||
if so_raw is Array:
|
||||
seat_order = so_raw as Array
|
||||
for i: int in seat_order.size():
|
||||
if str(seat_order[i]) == actor_id:
|
||||
# teamColors keys are ints (team index); seat index maps 1:1 in non-team modes.
|
||||
var hex: String = str(team_colors.get(i, team_colors.get(str(i), "")))
|
||||
if hex.length() >= 6:
|
||||
return Color.html("#" + hex if not hex.begins_with("#") else hex)
|
||||
# Fallback.
|
||||
# Use the teamIndex on the player DTO — it is always set correctly for FFA,
|
||||
# Teams, and MultiTeam modes and directly keys into teamColors.
|
||||
var player: Dictionary = _player_by_id(actor_id)
|
||||
var team_idx: int = int(player.get("teamIndex", -1))
|
||||
var team_colors: Dictionary = Game.state.get("teamColors", {})
|
||||
var hex: String = str(team_colors.get(team_idx, team_colors.get(str(team_idx), "")))
|
||||
if hex.length() >= 6:
|
||||
return Color.html("#" + hex if not hex.begins_with("#") else hex)
|
||||
return Color(0.9, 0.7, 0.3)
|
||||
|
||||
|
||||
func _player_by_id(account_id: String) -> Dictionary:
|
||||
for p: Variant in Game.state.get("players", []):
|
||||
if p is Dictionary and str((p as Dictionary).get("accountId", "")).to_lower() == account_id.to_lower():
|
||||
return p as Dictionary
|
||||
return {}
|
||||
|
||||
|
||||
# ── Projectile spawning ───────────────────────────────────────────────────────
|
||||
|
||||
func _spawn_projectile(
|
||||
|
||||
@@ -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