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
|
||||
@@ -150,6 +150,7 @@ func show_ability_panel(unit_id: String, unit: Dictionary) -> void:
|
||||
var idx: int = ab.get("index", 0)
|
||||
var ab_def: Dictionary = ab.get("def", {})
|
||||
btn.pressed.connect(func() -> void:
|
||||
hide_ability_panel()
|
||||
ability_unit_id = unit_id
|
||||
ability_idx = idx
|
||||
ability_def = get_ability_actions(ab_def)
|
||||
@@ -173,7 +174,9 @@ func show_ability_panel(unit_id: String, unit: Dictionary) -> void:
|
||||
btn.text = aa.get("label", "")
|
||||
btn.add_theme_font_size_override("font_size", 12)
|
||||
var fn: Callable = aa.get("fn", Callable())
|
||||
btn.pressed.connect(func() -> void: fn.call())
|
||||
btn.pressed.connect(func() -> void:
|
||||
hide_ability_panel()
|
||||
fn.call())
|
||||
vbox.add_child(btn)
|
||||
|
||||
panel.add_child(vbox)
|
||||
@@ -202,6 +205,16 @@ func current_target_mode() -> SelectionController.Mode:
|
||||
return SelectionController.Mode.ABILITY_TARGET
|
||||
|
||||
|
||||
func current_board_target_type() -> String:
|
||||
if ability_cur_action_idx < 0 or ability_cur_action_idx >= ability_def.size():
|
||||
return "Unit"
|
||||
if not (ability_def[ability_cur_action_idx] is Dictionary):
|
||||
return "Unit"
|
||||
var action: Dictionary = ability_def[ability_cur_action_idx] as Dictionary
|
||||
var target_sel: Dictionary = action.get("target", {})
|
||||
return str(target_sel.get("type", "Unit"))
|
||||
|
||||
|
||||
## Advance through ability actions, entering board-target mode, player-pick, or sending.
|
||||
func start_ability_targeting() -> void:
|
||||
print("AbilityTargeting:: start_ability_targeting")
|
||||
@@ -343,6 +356,81 @@ func highlight_ability_targets(action: Dictionary) -> void:
|
||||
emit_signal("highlight_add_requested", int(pos.get("x", 0)), int(pos.get("y", 0)), "ability")
|
||||
|
||||
|
||||
func is_valid_board_target(coord: Vector2i, unit_id: String) -> bool:
|
||||
if ability_cur_action_idx < 0 or ability_cur_action_idx >= ability_def.size():
|
||||
return false
|
||||
if not (ability_def[ability_cur_action_idx] is Dictionary):
|
||||
return false
|
||||
|
||||
var action: Dictionary = ability_def[ability_cur_action_idx] as Dictionary
|
||||
var target_sel: Dictionary = action.get("target", {})
|
||||
var type_: String = target_sel.get("type", "Unit")
|
||||
var ownership: String = target_sel.get("ownership", "Any")
|
||||
var filters_v: Variant = target_sel.get("filters", [])
|
||||
var filters: Array = filters_v as Array if filters_v is Array else []
|
||||
|
||||
if type_ == "Tile":
|
||||
return coord.x >= 0 and tile_passes_filters(coord.x, coord.y, filters) \
|
||||
and _target_coord_passes_range(coord)
|
||||
|
||||
if unit_id.is_empty():
|
||||
return false
|
||||
var unit: Dictionary = Game.get_unit_by_id(unit_id)
|
||||
if unit.is_empty():
|
||||
return false
|
||||
if type_ in ["Spirit", "ArchSpirit", "SpiritToken", "Ruin"] \
|
||||
and str(unit.get("cardType", "")).to_lower() != type_.to_lower():
|
||||
return false
|
||||
if not _target_unit_passes_ownership(unit_id, ownership):
|
||||
return false
|
||||
if not unit_passes_filters(unit, filters):
|
||||
return false
|
||||
return _target_unit_passes_range(unit)
|
||||
|
||||
|
||||
func _target_unit_passes_ownership(unit_id: String, ownership: String) -> bool:
|
||||
match ownership:
|
||||
"Enemy":
|
||||
return unit_registry == null or unit_registry.enemy_unit_ids.has(unit_id)
|
||||
"Owner", "Ally":
|
||||
return unit_registry == null or unit_registry.friendly_unit_ids.has(unit_id)
|
||||
"Any":
|
||||
return true
|
||||
_:
|
||||
return true
|
||||
|
||||
|
||||
func _target_unit_passes_range(unit: Dictionary) -> bool:
|
||||
var pos: Dictionary = unit.get("position", {})
|
||||
if pos.is_empty():
|
||||
return false
|
||||
return _target_coord_passes_range(Vector2i(int(pos.get("x", 0)), int(pos.get("y", 0))))
|
||||
|
||||
|
||||
func _target_coord_passes_range(coord: Vector2i) -> bool:
|
||||
var linear_only: bool = ability_range.get("linearonly", false)
|
||||
var requires_los: bool = ability_range.get("requireslos", false)
|
||||
if ability_range.is_empty() and not linear_only and not requires_los:
|
||||
return true
|
||||
|
||||
var src: Dictionary = Game.get_unit_by_id(ability_unit_id)
|
||||
var src_pos: Dictionary = src.get("position", {})
|
||||
if src_pos.is_empty():
|
||||
return false
|
||||
|
||||
var sx: int = int(src_pos.get("x", 0))
|
||||
var sy: int = int(src_pos.get("y", 0))
|
||||
if linear_only and not is_linear(sx, sy, coord.x, coord.y):
|
||||
return false
|
||||
if requires_los and pathfinder != null and not pathfinder.client_has_los(sx, sy, coord.x, coord.y):
|
||||
return false
|
||||
if not ability_range.is_empty() and pathfinder != null:
|
||||
var dist: int = pathfinder.board_distance(coord.x, coord.y, sx, sy)
|
||||
if dist < int(ability_range.get("min", 0)) or dist > int(ability_range.get("max", 999)):
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func unit_passes_filters(unit: Dictionary, filters: Array) -> bool:
|
||||
if filters.is_empty():
|
||||
return true
|
||||
|
||||
@@ -306,13 +306,10 @@ func _handle_unit_selected_click(coord: Vector2i, unit_id: String) -> void:
|
||||
|
||||
func _handle_sacrifice_click(coord: Vector2i, unit_id: String) -> void:
|
||||
var resolved: String = _resolve_occupant(coord, unit_id)
|
||||
if resolved.is_empty() or (unit_registry != null and not unit_registry.friendly_unit_ids.has(resolved)):
|
||||
if not _is_valid_sacrifice_target(resolved):
|
||||
set_mode(Mode.NONE)
|
||||
return
|
||||
var unit: Dictionary = Game.get_unit_by_id(resolved)
|
||||
if unit.is_empty() or unit.get("cardType", "") == "ArchSpirit":
|
||||
set_mode(Mode.NONE)
|
||||
return
|
||||
_confirm_sacrifice(resolved, unit.get("name", "this spirit"))
|
||||
|
||||
|
||||
@@ -329,11 +326,23 @@ func _handle_ability_target_click(coord: Vector2i, unit_id: String) -> void:
|
||||
Game.send_tile_pick_response(rid, coord.x, coord.y)
|
||||
return
|
||||
|
||||
var resolved: String = _resolve_occupant(coord, unit_id)
|
||||
if not ability_targeting.is_valid_board_target(coord, resolved):
|
||||
set_mode(Mode.NONE)
|
||||
return
|
||||
|
||||
var collected: bool = false
|
||||
if not unit_id.is_empty():
|
||||
if ability_targeting.current_board_target_type() == "Tile" and coord.x >= 0:
|
||||
ability_targeting.ability_targets.append({
|
||||
"actionIndex": ability_targeting.ability_cur_action_idx,
|
||||
"instanceId": unit_id
|
||||
"coord": { "x": coord.x, "y": coord.y }
|
||||
})
|
||||
ability_targeting.ability_targets_this_action += 1
|
||||
collected = true
|
||||
elif not resolved.is_empty():
|
||||
ability_targeting.ability_targets.append({
|
||||
"actionIndex": ability_targeting.ability_cur_action_idx,
|
||||
"instanceId": resolved
|
||||
})
|
||||
ability_targeting.ability_targets_this_action += 1
|
||||
collected = true
|
||||
@@ -353,6 +362,22 @@ func _handle_ability_target_click(coord: Vector2i, unit_id: String) -> void:
|
||||
|
||||
# ── ArchSpirit popup menu ─────────────────────────────────────────────────────
|
||||
|
||||
func _is_valid_sacrifice_target(unit_id: String) -> bool:
|
||||
if unit_id.is_empty():
|
||||
return false
|
||||
var unit: Dictionary = Game.get_unit_by_id(unit_id)
|
||||
if unit.is_empty() or unit.get("cardType", "") == "ArchSpirit":
|
||||
return false
|
||||
if unit_registry != null and not unit_registry.friendly_unit_ids.has(unit_id):
|
||||
return false
|
||||
if tile_target_resolver == null:
|
||||
return true
|
||||
for spirit: Dictionary in tile_target_resolver.valid_sacrifice_spirits():
|
||||
if str(spirit.get("instanceId", "")) == unit_id:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func show_arch_spirit_menu(unit_id: String, unit: Dictionary) -> void:
|
||||
var menu: PopupMenu = PopupMenu.new()
|
||||
add_child(menu)
|
||||
|
||||
Reference in New Issue
Block a user