Add Repentance placeholder VFX — server broadcast + client effect
Server: - Add RepentancePlaceholderVisualPush DTO to GameMessages.cs - Add BroadcastToAllViewersAsync helper on GameHandlerBase - GamePlayCardHandler emits game.visual.repentance_placeholder to all players and spectators after a Repentance card resolves; sets hasCustomAnimation based on ability Animation.AssetUrl presence Client: - Add repentance_placeholder_visual signal and push-router case in Game.gd - New RepentancePlaceholderFx component: resolves source/target world positions, picks affinity + player team colors, tweens a glowing orb projectile to target and plays a torus ring + burst-mote impact - Wire component in game_screen.gd (_ready, _exit_tree, signal 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>
This commit is contained in:
@@ -0,0 +1,267 @@
|
||||
class_name RepentancePlaceholderFx
|
||||
extends Node
|
||||
|
||||
## Plays a placeholder projectile VFX when a Repentance card resolves without
|
||||
## a custom animation asset. Spawns a glowing orb that travels from the acting
|
||||
## player's ArchSpirit to the resolved target, then bursts into an impact ring.
|
||||
##
|
||||
## External refs (set by game_screen._ready):
|
||||
## pathfinder — for coord_to_world and board_distance
|
||||
## unit_bodies — Dictionary instanceId → StaticBody3D
|
||||
## units_root — Node3D that owns the 3D board unit nodes
|
||||
|
||||
# ── External refs ─────────────────────────────────────────────────────────────
|
||||
|
||||
var pathfinder : Pathfinder = null
|
||||
var unit_bodies : Dictionary = {} # instanceId → StaticBody3D
|
||||
var units_root : Node3D = null
|
||||
|
||||
# ── Public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
## 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 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 player_color: Color = _resolve_player_color(actor_id)
|
||||
|
||||
_spawn_projectile(src_pos, tgt_pos, affinity_color, player_color)
|
||||
|
||||
|
||||
# ── Position resolution ───────────────────────────────────────────────────────
|
||||
|
||||
func _resolve_arch_spirit_pos(arch_instance_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", {})
|
||||
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 Vector3.ZERO
|
||||
|
||||
|
||||
func _resolve_target_pos(targets: Array, actor_id: String, fallback: Vector3) -> Vector3:
|
||||
# 1. Unit instance id → current board body position.
|
||||
for t: Variant in targets:
|
||||
if not (t is Dictionary):
|
||||
continue
|
||||
var td: Dictionary = t as Dictionary
|
||||
var inst_id: String = str(td.get("instanceId", td.get("instance_id", "")))
|
||||
if inst_id.is_empty():
|
||||
continue
|
||||
var body: StaticBody3D = unit_bodies.get(inst_id) as StaticBody3D
|
||||
if is_instance_valid(body):
|
||||
return body.global_position + Vector3(0, 0.5, 0)
|
||||
|
||||
# 2. Tile coordinate.
|
||||
for t: Variant in targets:
|
||||
if not (t is Dictionary):
|
||||
continue
|
||||
var td: Dictionary = t as Dictionary
|
||||
var coord_v: Variant = td.get("coord")
|
||||
if coord_v is Dictionary and pathfinder != null:
|
||||
var cd: Dictionary = coord_v as Dictionary
|
||||
return pathfinder.coord_to_world(int(cd.get("x", 0)), int(cd.get("y", 0))) + Vector3(0, 0.6, 0)
|
||||
|
||||
# 3. Player ArchSpirit (target player given by instanceId = accountId in player-target actions).
|
||||
for t: Variant in targets:
|
||||
if not (t is Dictionary):
|
||||
continue
|
||||
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)
|
||||
|
||||
# 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.
|
||||
return Color(0.9, 0.7, 0.3)
|
||||
|
||||
|
||||
# ── Projectile spawning ───────────────────────────────────────────────────────
|
||||
|
||||
func _spawn_projectile(
|
||||
src: Vector3, tgt: Vector3,
|
||||
affinity_color: Color, player_color: Color) -> void:
|
||||
|
||||
if units_root == null:
|
||||
return
|
||||
|
||||
var dist: float = src.distance_to(tgt)
|
||||
var travel_dur: float = clampf(dist * 0.18, 0.35, 0.8)
|
||||
|
||||
var root: Node3D = Node3D.new()
|
||||
root.name = "RepentancePlaceholderFx"
|
||||
root.position = src
|
||||
units_root.add_child(root)
|
||||
|
||||
# Core orb (affinity color).
|
||||
var orb: MeshInstance3D = _make_orb(affinity_color, 0.09)
|
||||
root.add_child(orb)
|
||||
|
||||
# Inner spark (player color).
|
||||
var spark: MeshInstance3D = _make_orb(player_color, 0.045)
|
||||
root.add_child(spark)
|
||||
|
||||
# Trail motes orbiting the orb.
|
||||
for i: int in range(4):
|
||||
var angle: float = TAU * float(i) / 4.0
|
||||
var offset: Vector3 = Vector3(cos(angle) * 0.06, 0.0, sin(angle) * 0.06)
|
||||
var mote: MeshInstance3D = _make_orb(player_color.lerp(affinity_color, 0.4), 0.028)
|
||||
mote.position = offset
|
||||
root.add_child(mote)
|
||||
|
||||
# Travel tween.
|
||||
var tween: Tween = create_tween()
|
||||
tween.tween_property(root, "position", tgt, travel_dur)\
|
||||
.set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_IN)
|
||||
tween.tween_callback(func() -> void: _play_impact(root, tgt, affinity_color, player_color))
|
||||
|
||||
|
||||
func _play_impact(
|
||||
projectile: Node3D, pos: Vector3,
|
||||
affinity_color: Color, player_color: Color) -> void:
|
||||
|
||||
if is_instance_valid(projectile):
|
||||
projectile.queue_free()
|
||||
|
||||
if units_root == null:
|
||||
return
|
||||
|
||||
var impact_dur: float = randf_range(0.5, 0.8)
|
||||
|
||||
# Ring.
|
||||
var ring: MeshInstance3D = _make_impact_ring(
|
||||
affinity_color.lerp(player_color, 0.35), pos)
|
||||
units_root.add_child(ring)
|
||||
|
||||
# Burst motes.
|
||||
var rng: RandomNumberGenerator = RandomNumberGenerator.new()
|
||||
rng.randomize()
|
||||
var burst_root: Node3D = Node3D.new()
|
||||
burst_root.name = "ImpactBurst"
|
||||
burst_root.position = pos
|
||||
units_root.add_child(burst_root)
|
||||
|
||||
for i: int in range(8):
|
||||
var angle: float = TAU * float(i) / 8.0 + rng.randf_range(-0.2, 0.2)
|
||||
var speed: float = rng.randf_range(0.28, 0.56)
|
||||
var col: Color = affinity_color if i % 2 == 0 else player_color
|
||||
var mote: MeshInstance3D = _make_orb(col, rng.randf_range(0.024, 0.055))
|
||||
mote.position = Vector3.ZERO
|
||||
burst_root.add_child(mote)
|
||||
var end_pos: Vector3 = Vector3(cos(angle) * speed, rng.randf_range(0.0, 0.3), sin(angle) * speed)
|
||||
var mt: Tween = create_tween()
|
||||
mt.set_parallel(true)
|
||||
mt.tween_property(mote, "position", end_pos, impact_dur)\
|
||||
.set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT)
|
||||
mt.tween_property(mote, "scale", Vector3.ZERO, impact_dur)\
|
||||
.set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_IN)
|
||||
|
||||
# Ring scale + fade.
|
||||
var rt: Tween = create_tween()
|
||||
rt.set_parallel(true)
|
||||
rt.tween_property(ring, "scale", Vector3.ONE * 2.4, impact_dur)\
|
||||
.set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT)
|
||||
var ring_mat: StandardMaterial3D = ring.material_override as StandardMaterial3D
|
||||
if ring_mat != null:
|
||||
rt.tween_method(func(a: float) -> void:
|
||||
ring_mat.albedo_color.a = a, 0.75, 0.0, impact_dur)
|
||||
|
||||
# Cleanup.
|
||||
var cleanup_delay: float = impact_dur + 0.4
|
||||
get_tree().create_timer(cleanup_delay).timeout.connect(func() -> void:
|
||||
if is_instance_valid(ring): ring.queue_free()
|
||||
if is_instance_valid(burst_root): burst_root.queue_free())
|
||||
|
||||
|
||||
# ── Mesh helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
func _make_orb(color: Color, radius: float) -> MeshInstance3D:
|
||||
var mi: MeshInstance3D = MeshInstance3D.new()
|
||||
var mesh: SphereMesh = SphereMesh.new()
|
||||
mesh.radius = radius
|
||||
mesh.height = radius * 2.0
|
||||
mesh.radial_segments = 10
|
||||
mesh.rings = 5
|
||||
mi.mesh = mesh
|
||||
var mat: StandardMaterial3D = StandardMaterial3D.new()
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
mat.albedo_color = Color(color.r, color.g, color.b, 0.85)
|
||||
mat.emission_enabled = true
|
||||
mat.emission = color
|
||||
mat.emission_energy_multiplier = 2.8
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
mat.cull_mode = BaseMaterial3D.CULL_DISABLED
|
||||
mi.material_override = mat
|
||||
return mi
|
||||
|
||||
|
||||
func _make_impact_ring(color: Color, world_pos: Vector3) -> MeshInstance3D:
|
||||
var mi: MeshInstance3D = MeshInstance3D.new()
|
||||
var mesh: TorusMesh = TorusMesh.new()
|
||||
mesh.inner_radius = 0.18
|
||||
mesh.outer_radius = 0.22
|
||||
mesh.rings = 16
|
||||
mesh.ring_segments = 8
|
||||
mi.mesh = mesh
|
||||
mi.position = world_pos
|
||||
mi.rotation_degrees.x = 90.0
|
||||
var mat: StandardMaterial3D = StandardMaterial3D.new()
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
mat.albedo_color = Color(color.r, color.g, color.b, 0.75)
|
||||
mat.emission_enabled = true
|
||||
mat.emission = color
|
||||
mat.emission_energy_multiplier = 1.8
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
mat.cull_mode = BaseMaterial3D.CULL_DISABLED
|
||||
mi.material_override = mat
|
||||
return mi
|
||||
Reference in New Issue
Block a user