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)
|
signal reveal_choice_pick_request(request_data: Dictionary)
|
||||||
|
|
||||||
## Emitted when a Repentance card resolves with no custom animation asset.
|
## 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,
|
## Payload keys: eventId, sessionId, actorAccountId, sourceArchSpiritInstanceId,
|
||||||
## cardInstanceId, cardDefinitionId, cardName, affinity, targets, hasCustomAnimation
|
## cardInstanceId, cardDefinitionId, cardName, affinity, targets
|
||||||
signal repentance_placeholder_visual(payload: Dictionary)
|
signal repentance_placeholder_visual(payload: Dictionary)
|
||||||
|
|
||||||
# ── State ─────────────────────────────────────────────────────────────────────
|
# ── State ─────────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -20,16 +20,13 @@ var units_root : Node3D = null
|
|||||||
|
|
||||||
## Called by game_screen when Game.repentance_placeholder_visual fires.
|
## Called by game_screen when Game.repentance_placeholder_visual fires.
|
||||||
func play(payload: Dictionary) -> void:
|
func play(payload: Dictionary) -> void:
|
||||||
if bool(payload.get("hasCustomAnimation", false)):
|
|
||||||
return
|
|
||||||
|
|
||||||
var actor_id: String = str(payload.get("actorAccountId", ""))
|
var actor_id: String = str(payload.get("actorAccountId", ""))
|
||||||
var arch_id: String = str(payload.get("sourceArchSpiritInstanceId", ""))
|
var arch_id: String = str(payload.get("sourceArchSpiritInstanceId", ""))
|
||||||
var affinity: String = str(payload.get("affinity", ""))
|
var affinity: String = str(payload.get("affinity", ""))
|
||||||
var targets_raw: Variant = payload.get("targets", [])
|
var targets_raw: Variant = payload.get("targets", [])
|
||||||
var targets: Array = targets_raw as Array if targets_raw is Array else []
|
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 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))
|
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 ───────────────────────────────────────────────────────
|
# ── 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():
|
if not arch_instance_id.is_empty():
|
||||||
var body: StaticBody3D = unit_bodies.get(arch_instance_id) as StaticBody3D
|
var body: StaticBody3D = unit_bodies.get(arch_instance_id) as StaticBody3D
|
||||||
if is_instance_valid(body):
|
if is_instance_valid(body):
|
||||||
return body.global_position + Vector3(0, 0.5, 0)
|
return body.global_position + Vector3(0, 0.5, 0)
|
||||||
|
|
||||||
# Fallback: my own ArchSpirit from game state.
|
# Fallback: resolve the actor's ArchSpirit from game state (works for
|
||||||
var my_arch: Dictionary = Game.get_my_player().get("archSpirit", {})
|
# opponent casts, spectators, and timing gaps during mesh rebuilds).
|
||||||
var pos: Dictionary = my_arch.get("position", {})
|
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:
|
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)
|
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:
|
for t: Variant in targets:
|
||||||
if not (t is Dictionary):
|
if not (t is Dictionary):
|
||||||
continue
|
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", "")))
|
var inst_id: String = str(td.get("instanceId", td.get("instance_id", "")))
|
||||||
if inst_id.is_empty():
|
if inst_id.is_empty():
|
||||||
continue
|
continue
|
||||||
# Try it as an account id — look for that player's arch spirit.
|
# Try it as an account id and look up that player's ArchSpirit position.
|
||||||
var all_players: Array = []
|
var pd: Dictionary = _player_by_id(inst_id)
|
||||||
var state: Dictionary = Game.state
|
var arch: Dictionary = pd.get("archSpirit", {})
|
||||||
for p: Variant in state.get("players", []):
|
var apos: Dictionary = arch.get("position", {})
|
||||||
all_players.append(p)
|
if not apos.is_empty() and pathfinder != null:
|
||||||
for p: Variant in all_players:
|
return pathfinder.coord_to_world(
|
||||||
if not (p is Dictionary):
|
int(apos.get("x", 0)), int(apos.get("y", 0))) + Vector3(0, 0.8, 0)
|
||||||
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)
|
|
||||||
|
|
||||||
# 4. Fallback to source.
|
# 4. Fallback to source.
|
||||||
return fallback
|
return fallback
|
||||||
|
|
||||||
|
|
||||||
func _resolve_player_color(actor_id: String) -> Color:
|
func _resolve_player_color(actor_id: String) -> Color:
|
||||||
var state: Dictionary = Game.state
|
# Use the teamIndex on the player DTO — it is always set correctly for FFA,
|
||||||
var team_colors: Dictionary = state.get("teamColors", {})
|
# Teams, and MultiTeam modes and directly keys into teamColors.
|
||||||
# Find the actor's seat to get their team index.
|
var player: Dictionary = _player_by_id(actor_id)
|
||||||
var seat_order: Array = []
|
var team_idx: int = int(player.get("teamIndex", -1))
|
||||||
var so_raw: Variant = state.get("seatOrder", [])
|
var team_colors: Dictionary = Game.state.get("teamColors", {})
|
||||||
if so_raw is Array:
|
var hex: String = str(team_colors.get(team_idx, team_colors.get(str(team_idx), "")))
|
||||||
seat_order = so_raw as Array
|
if hex.length() >= 6:
|
||||||
for i: int in seat_order.size():
|
return Color.html("#" + hex if not hex.begins_with("#") else hex)
|
||||||
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.
|
|
||||||
return Color(0.9, 0.7, 0.3)
|
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 ───────────────────────────────────────────────────────
|
# ── Projectile spawning ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
func _spawn_projectile(
|
func _spawn_projectile(
|
||||||
|
|||||||
@@ -605,10 +605,11 @@ public sealed record GameActivityPush(string EventType, string SessionId);
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Broadcast to every participant and spectator when a Repentance card resolves
|
/// Broadcast to every participant and spectator when a Repentance card resolves
|
||||||
/// and the ability has no usable custom animation asset.
|
/// without a custom animation asset. Only sent when no active ability on the card
|
||||||
/// Clients use this to play a placeholder projectile VFX from the acting player's
|
/// carries a non-empty Animation.AssetUrl, so clients can always play the effect.
|
||||||
/// ArchSpirit to the ability target.
|
/// Targets contains the best available resolved visual targets:
|
||||||
/// Clients MUST ignore this push when HasCustomAnimation is true.
|
/// • explicit unit InstanceId or tile Coord if the player provided them, else
|
||||||
|
/// • the first live opponent ArchSpirit InstanceId as a fallback.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed record RepentancePlaceholderVisualPush(
|
public sealed record RepentancePlaceholderVisualPush(
|
||||||
string EventId,
|
string EventId,
|
||||||
@@ -619,8 +620,7 @@ public sealed record RepentancePlaceholderVisualPush(
|
|||||||
string CardDefinitionId,
|
string CardDefinitionId,
|
||||||
string CardName,
|
string CardName,
|
||||||
string Affinity,
|
string Affinity,
|
||||||
IReadOnlyList<AbilityTarget> Targets,
|
IReadOnlyList<AbilityTarget> Targets);
|
||||||
bool HasCustomAnimation);
|
|
||||||
|
|
||||||
// ── DTOs ─────────────────────────────────────────────────────────────────────
|
// ── DTOs ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|||||||
@@ -65,28 +65,74 @@ internal sealed class GamePlayCardHandler : GameHandlerBase, IMessageHandler
|
|||||||
// Visual-only push for Repentance cards (no gameplay state, transient).
|
// Visual-only push for Repentance cards (no gameplay state, transient).
|
||||||
if (card.CardType == "Repentance")
|
if (card.CardType == "Repentance")
|
||||||
{
|
{
|
||||||
var archSpirit = newState.Players[actorId].ArchSpirit;
|
var archSpirit = newState.Players[actorId].ArchSpirit;
|
||||||
var abilities = AbilitySystem.ParseAbilities(card.AbilitiesJson);
|
var abilities = AbilitySystem.ParseAbilities(card.AbilitiesJson);
|
||||||
var hasCustomAnim = abilities.Length > 0
|
|
||||||
&& abilities[0].Animation is { } anim
|
|
||||||
&& !string.IsNullOrEmpty(anim.AssetUrl);
|
|
||||||
|
|
||||||
var visualPush = ServerMessage.Push("game.visual.repentance_placeholder",
|
// hasCustomAnimation is true only when at least one Active ability definition
|
||||||
new RepentancePlaceholderVisualPush(
|
// carries an animation with a usable AssetUrl. Later ability indices can also
|
||||||
EventId: Guid.NewGuid().ToString("N")[..8],
|
// carry custom animations, so we scan the full active-ability set.
|
||||||
SessionId: session.Id.ToString(),
|
var hasCustomAnim = abilities.Any(a =>
|
||||||
ActorAccountId: actorId,
|
a.Type == Abilities.Models.AbilityType.Active
|
||||||
SourceArchSpiritInstanceId: archSpirit?.InstanceId ?? string.Empty,
|
&& a.Animation is { } anim
|
||||||
CardInstanceId: card.InstanceId,
|
&& !string.IsNullOrEmpty(anim.AssetUrl));
|
||||||
CardDefinitionId: card.CardDefinitionId.ToString(),
|
|
||||||
CardName: card.Name,
|
|
||||||
Affinity: card.Affinity,
|
|
||||||
Targets: req.Targets ?? [],
|
|
||||||
HasCustomAnimation: hasCustomAnim));
|
|
||||||
|
|
||||||
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));
|
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