diff --git a/Client/origin-client/autoloads/Game.gd b/Client/origin-client/autoloads/Game.gd index d0983cb2..f454a45 100644 --- a/Client/origin-client/autoloads/Game.gd +++ b/Client/origin-client/autoloads/Game.gd @@ -89,6 +89,11 @@ signal reveal_choice_pick_request(request_data: Dictionary) ## cardInstanceId, cardDefinitionId, cardName, affinity, targets signal repentance_placeholder_visual(payload: Dictionary) +## Emitted when an Active ability fires with no custom animation asset. +## Payload keys: eventId, sessionId, actorAccountId, sourceInstanceId, +## abilityName, sourceAffinity, targets, targetMode +signal ability_placeholder_visual(payload: Dictionary) + # ── State ───────────────────────────────────────────────────────────────────── var session_id : String = "" @@ -828,3 +833,6 @@ func _on_server_push(type: String, payload: Variant) -> void: "game.visual.repentance_placeholder": repentance_placeholder_visual.emit(payload as Dictionary) + + "game.visual.ability_placeholder": + ability_placeholder_visual.emit(payload as Dictionary) diff --git a/Client/origin-client/scenes/game/components/effects/ability_placeholder_fx.gd b/Client/origin-client/scenes/game/components/effects/ability_placeholder_fx.gd new file mode 100644 index 0000000..fb15d77 --- /dev/null +++ b/Client/origin-client/scenes/game/components/effects/ability_placeholder_fx.gd @@ -0,0 +1,328 @@ +class_name AbilityPlaceholderFx +extends Node + +## Plays a placeholder VFX when an Active ability fires without a custom +## animation asset. Behaviour depends on targetMode from the server: +## +## "Self" — glow ring + radial burst on the source unit, no projectile +## "Unit" — orb projectile from source unit to target unit body +## "Tile" — orb projectile from source unit to tile centre +## "PlayerZone" — orb projectile from source unit to target player's ArchSpirit +## "None" — fallback self glow burst +## +## The source is always the activating unit, not the ArchSpirit. +## +## External refs (set by game_screen._ready): +## pathfinder — for coord_to_world +## 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.ability_placeholder_visual fires. +func play(payload: Dictionary) -> void: + var actor_id: String = str(payload.get("actorAccountId", "")) + var source_id: String = str(payload.get("sourceInstanceId", "")) + var affinity: String = str(payload.get("sourceAffinity", "")) + var target_mode: String = str(payload.get("targetMode", "None")) + var targets_raw: Variant = payload.get("targets", []) + var targets: Array = targets_raw as Array if targets_raw is Array else [] + + 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) + + var src_pos: Vector3 = _resolve_unit_pos(source_id) + + match target_mode: + "Self", "None": + _play_self_burst(src_pos, affinity_color, player_color) + "Unit": + var tgt_pos: Vector3 = _resolve_unit_target(targets, src_pos) + _spawn_projectile(src_pos, tgt_pos, affinity_color, player_color) + "Tile": + var tgt_pos: Vector3 = _resolve_tile_target(targets, src_pos) + _spawn_projectile(src_pos, tgt_pos, affinity_color, player_color) + "PlayerZone": + var tgt_pos: Vector3 = _resolve_player_arch_target(targets, src_pos) + _spawn_projectile(src_pos, tgt_pos, affinity_color, player_color) + _: + _play_self_burst(src_pos, affinity_color, player_color) + + +# ── Position resolution ─────────────────────────────────────────────────────── + +func _resolve_unit_pos(instance_id: String) -> Vector3: + if not instance_id.is_empty(): + var body: StaticBody3D = unit_bodies.get(instance_id) as StaticBody3D + if is_instance_valid(body): + return body.global_position + Vector3(0, 0.5, 0) + return Vector3.ZERO + + +func _resolve_unit_target(targets: Array, fallback: Vector3) -> Vector3: + 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) + return fallback + + +func _resolve_tile_target(targets: Array, fallback: Vector3) -> Vector3: + 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) + return fallback + + +func _resolve_player_arch_target(targets: Array, fallback: Vector3) -> Vector3: + 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 as unit body first (server may send ArchSpirit InstanceId directly). + var body: StaticBody3D = unit_bodies.get(inst_id) as StaticBody3D + if is_instance_valid(body): + return body.global_position + Vector3(0, 0.5, 0) + # Try as account id → ArchSpirit board 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) + return fallback + + +func _resolve_player_color(actor_id: String) -> Color: + 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 {} + + +# ── Self burst (no projectile) ──────────────────────────────────────────────── + +func _play_self_burst(pos: Vector3, affinity_color: Color, player_color: Color) -> void: + if units_root == null: + return + + var burst_dur: float = randf_range(0.45, 0.65) + + # Expanding glow ring. + var ring: MeshInstance3D = _make_impact_ring( + affinity_color.lerp(player_color, 0.25), pos, 0.12, 0.16) + units_root.add_child(ring) + + # Larger outer ring (player color accent). + var ring2: MeshInstance3D = _make_impact_ring( + player_color.lerp(affinity_color, 0.3), pos, 0.22, 0.28) + units_root.add_child(ring2) + + # Radial motes. + var rng: RandomNumberGenerator = RandomNumberGenerator.new() + rng.randomize() + var burst_root: Node3D = Node3D.new() + burst_root.name = "SelfBurst" + burst_root.position = pos + units_root.add_child(burst_root) + + for i: int in range(10): + var angle: float = TAU * float(i) / 10.0 + rng.randf_range(-0.15, 0.15) + var speed: float = rng.randf_range(0.18, 0.42) + var col: Color = affinity_color if i % 2 == 0 else player_color + var mote: MeshInstance3D = _make_orb(col, rng.randf_range(0.022, 0.05)) + mote.position = Vector3.ZERO + burst_root.add_child(mote) + var end_pos: Vector3 = Vector3(cos(angle) * speed, rng.randf_range(0.05, 0.28), sin(angle) * speed) + var mt: Tween = create_tween() + mt.set_parallel(true) + mt.tween_property(mote, "position", end_pos, burst_dur)\ + .set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT) + mt.tween_property(mote, "scale", Vector3.ZERO, burst_dur)\ + .set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_IN) + + # Animate rings outward and fade. + for ring_node: MeshInstance3D in [ring, ring2]: + var rt: Tween = create_tween() + rt.set_parallel(true) + rt.tween_property(ring_node, "scale", Vector3.ONE * 2.8, burst_dur)\ + .set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT) + var rmat: StandardMaterial3D = ring_node.material_override as StandardMaterial3D + if rmat != null: + rt.tween_method(func(a: float) -> void: rmat.albedo_color.a = a, + 0.75, 0.0, burst_dur) + + # Cleanup. + var cleanup: float = burst_dur + 0.3 + get_tree().create_timer(cleanup).timeout.connect(func() -> void: + if is_instance_valid(ring): ring.queue_free() + if is_instance_valid(ring2): ring2.queue_free() + if is_instance_valid(burst_root): burst_root.queue_free()) + + +# ── Projectile (non-self targets) ───────────────────────────────────────────── + +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 = "AbilityPlaceholderFx" + root.position = src + units_root.add_child(root) + + # Core orb (affinity color). + root.add_child(_make_orb(affinity_color, 0.09)) + # Inner spark (player color). + root.add_child(_make_orb(player_color, 0.045)) + + # Four trailing 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) + + 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) + + var ring: MeshInstance3D = _make_impact_ring( + affinity_color.lerp(player_color, 0.35), pos, 0.18, 0.22) + units_root.add_child(ring) + + 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) + + 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) + + var cleanup: float = impact_dur + 0.4 + get_tree().create_timer(cleanup).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, + inner: float, outer: float) -> MeshInstance3D: + var mi: MeshInstance3D = MeshInstance3D.new() + var mesh: TorusMesh = TorusMesh.new() + mesh.inner_radius = inner + mesh.outer_radius = outer + 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 diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 359716a..8bc6d09 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -48,6 +48,7 @@ var _sel_ctrl : SelectionController = null var _abt : AbilityTargeting = null var _prompt_handler: ServerPromptHandler = null var _repentance_fx : RepentancePlaceholderFx = null +var _ability_fx : AbilityPlaceholderFx = null # ── @onready node refs ──────────────────────────────────────────────────────── @@ -241,6 +242,13 @@ func _ready() -> void: _repentance_fx.units_root = _units_root add_child(_repentance_fx) + # AbilityPlaceholderFx + _ability_fx = AbilityPlaceholderFx.new() + _ability_fx.pathfinder = _pathfinder + _ability_fx.unit_bodies = _mesh_builder.unit_bodies + _ability_fx.units_root = _units_root + add_child(_ability_fx) + # BoardInputHandler _input_handler = BoardInputHandler.new() _input_handler.hold_timer = _hold_timer @@ -310,6 +318,7 @@ func _ready() -> void: Game.player_pick_request.connect(_prompt_handler.on_player_pick_request) Game.reveal_choice_pick_request.connect(_prompt_handler.on_reveal_choice_pick_request) Game.repentance_placeholder_visual.connect(_on_repentance_placeholder_visual) + Game.ability_placeholder_visual.connect(_on_ability_placeholder_visual) # ── 6. Camera, skybox, hover, chat ─────────────────────────────────────── _cam_ctrl.sync_cam_ctrl_panel() @@ -384,6 +393,8 @@ func _exit_tree() -> void: Game.reveal_choice_pick_request.disconnect(_prompt_handler.on_reveal_choice_pick_request) if Game.repentance_placeholder_visual.is_connected(_on_repentance_placeholder_visual): Game.repentance_placeholder_visual.disconnect(_on_repentance_placeholder_visual) + if Game.ability_placeholder_visual.is_connected(_on_ability_placeholder_visual): + Game.ability_placeholder_visual.disconnect(_on_ability_placeholder_visual) _skybox.clear_stars() _reset_unit_hover_glow() Chat.set_bubble_host(null) @@ -1133,6 +1144,11 @@ func _on_repentance_placeholder_visual(payload: Dictionary) -> void: _repentance_fx.play(payload) +func _on_ability_placeholder_visual(payload: Dictionary) -> void: + if _ability_fx != null: + _ability_fx.play(payload) + + func _place_highlight_quad(quad: MeshInstance3D, x: int, y: int, col: Color, texture: Texture2D = null) -> void: var tile_top: float = _board_ctrl.tile_visual_tops.get( diff --git a/Server/src/SOR.Game/GameMessages.cs b/Server/src/SOR.Game/GameMessages.cs index f6fa208..f42d66f 100644 --- a/Server/src/SOR.Game/GameMessages.cs +++ b/Server/src/SOR.Game/GameMessages.cs @@ -622,6 +622,26 @@ public sealed record RepentancePlaceholderVisualPush( string Affinity, IReadOnlyList Targets); +/// +/// Broadcast to every participant and spectator when an Active ability fires +/// and the ability has no usable custom animation asset. +/// TargetMode tells the client which visual behaviour to use: +/// "Self" — glow burst on the source unit, no projectile +/// "Unit" — projectile from source to target unit +/// "Tile" — projectile from source to tile centre +/// "PlayerZone" — projectile from source to that player's ArchSpirit +/// "None" — fallback self glow burst +/// +public sealed record AbilityPlaceholderVisualPush( + string EventId, + string SessionId, + string ActorAccountId, + string SourceInstanceId, + string AbilityName, + string SourceAffinity, + IReadOnlyList Targets, + string TargetMode); + // ── DTOs ───────────────────────────────────────────────────────────────────── /// diff --git a/Server/src/SOR.Game/Handlers/GameActivateAbilityHandler.cs b/Server/src/SOR.Game/Handlers/GameActivateAbilityHandler.cs index 4e05693..1889fd4 100644 --- a/Server/src/SOR.Game/Handlers/GameActivateAbilityHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameActivateAbilityHandler.cs @@ -2,6 +2,7 @@ namespace SOR.Game.Handlers; using System.Text.Json; using SOR.Database.Contexts; +using SOR.Game.Abilities; using SOR.Networking.Abstractions.Messaging; using SOR.Networking.Abstractions.Push; using SOR.Networking.Abstractions.Transport; @@ -42,7 +43,15 @@ internal sealed class GameActivateAbilityHandler : GameHandlerBase, IMessageHand var session = await LoadActiveSessionAsync(_gameDb, req.SessionId, actorId, ct); var prevStateJson = session.StateJson!; var state = GameEngine.Deserialize(prevStateJson); - var newState = GameEngine.ActivateAbility( + + // Capture source unit and ability definition before the engine mutates state. + var source = FindSourceUnit(state, req.SourceInstanceId); + var abilities = AbilitySystem.ParseAbilities(source?.AbilitiesJson); + var ability = req.AbilityIndex >= 0 && req.AbilityIndex < abilities.Length + ? abilities[req.AbilityIndex] + : null; + + var newState = GameEngine.ActivateAbility( state, actorId, req.SourceInstanceId, req.AbilityIndex, req.Targets); await SaveStateAsync(_gameDb, session, newState, actorId, "game.activate_ability", @@ -51,6 +60,34 @@ internal sealed class GameActivateAbilityHandler : GameHandlerBase, IMessageHand var dto = GameEngine.ToDto(newState, actorId); await PushStateToPlayersAsync(_clientPush, session, newState, ct, prevStateJson); + // Visual-only push when the ability has no custom animation asset. + if (source is not null && ability is not null) + { + var hasCustomAnim = ability.Animation is { } anim + && !string.IsNullOrEmpty(anim.AssetUrl); + + if (!hasCustomAnim) + { + var visualTargets = ComputeAbilityVisualTargets( + req.Targets, ability, newState, actorId, req.SourceInstanceId); + var targetMode = ComputeAbilityTargetMode( + visualTargets, newState, req.SourceInstanceId); + + var visualPush = ServerMessage.Push("game.visual.ability_placeholder", + new AbilityPlaceholderVisualPush( + EventId: Guid.NewGuid().ToString("N")[..8], + SessionId: session.Id.ToString(), + ActorAccountId: actorId, + SourceInstanceId: req.SourceInstanceId, + AbilityName: ability.Name ?? string.Empty, + SourceAffinity: source.Affinity, + Targets: visualTargets, + TargetMode: targetMode)); + + await BroadcastToAllViewersAsync(_clientPush, session, visualPush, ct); + } + } + return ServerMessage.Reply("game.activate_ability.ack", message.Seq, new GameActivateAbilityResponse(dto)); } diff --git a/Server/src/SOR.Game/Handlers/GameHandlerBase.cs b/Server/src/SOR.Game/Handlers/GameHandlerBase.cs index da596ea..5b40568 100644 --- a/Server/src/SOR.Game/Handlers/GameHandlerBase.cs +++ b/Server/src/SOR.Game/Handlers/GameHandlerBase.cs @@ -113,6 +113,123 @@ internal abstract class GameHandlerBase await Task.WhenAll(subs.Select(uid => clientPush.PushAsync(uid, push, ct))); } + // ── Visual push helpers ──────────────────────────────────────────────────── + + /// + /// Searches all players' Field lists and ArchSpirit slots for a unit with the + /// given instance ID. Returns null when not found. + /// + protected static CardInstance? FindSourceUnit(GameState state, string instanceId) + { + foreach (var player in state.Players.Values) + { + if (player.ArchSpirit?.InstanceId == instanceId) + return player.ArchSpirit; + var onField = player.Field.FirstOrDefault(c => c.InstanceId == instanceId); + if (onField is not null) + return onField; + } + return null; + } + + /// + /// Derives the best visual targets for a Repentance card placeholder VFX. + /// Prefers explicit client targets (InstanceId / Coord); falls back to the + /// first live enemy ArchSpirit so the projectile always has a destination. + /// + protected static IReadOnlyList ComputeVisualTargets( + IReadOnlyList? clientTargets, + GameState state, + string actorId) + { + 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; + } + + var enemyArch = state.GetEnemyIds(actorId) + .Select(id => state.Players[id].ArchSpirit) + .FirstOrDefault(a => a is not null); + + return enemyArch is not null + ? [new AbilityTarget(ActionIndex: 0, InstanceId: enemyArch.InstanceId)] + : []; + } + + /// + /// Derives the best visual targets for an Active ability placeholder VFX. + /// Self/ExactSelf-ownership and All-count abilities resolve to the source unit. + /// Other targetless cases fall back to the first live enemy ArchSpirit. + /// + protected static IReadOnlyList ComputeAbilityVisualTargets( + IReadOnlyList? clientTargets, + Abilities.Models.AbilityDefinition ability, + GameState state, + string actorId, + string sourceInstanceId) + { + 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; + } + + // Self/auto-resolved — point at the source unit. + var firstAction = GetFirstAction(ability); + if (firstAction is not null) + { + var own = firstAction.Target.Ownership; + if (own is Abilities.Models.TargetOwnership.Self + or Abilities.Models.TargetOwnership.ExactSelf + || firstAction.Target.Count.All) + return [new AbilityTarget(ActionIndex: 0, InstanceId: sourceInstanceId)]; + } + + // External target absent: aim at first live enemy ArchSpirit. + var enemyArch = state.GetEnemyIds(actorId) + .Select(id => state.Players[id].ArchSpirit) + .FirstOrDefault(a => a is not null); + + return enemyArch is not null + ? [new AbilityTarget(ActionIndex: 0, InstanceId: enemyArch.InstanceId)] + : []; + } + + /// + /// Derives the TargetMode string the client uses to choose its VFX behaviour. + /// + protected static string ComputeAbilityTargetMode( + IReadOnlyList visualTargets, + GameState state, + string sourceInstanceId) + { + if (visualTargets.Count == 0) return "None"; + var first = visualTargets[0]; + if (first.Coord is not null) return "Tile"; + var id = first.InstanceId ?? string.Empty; + if (id.Length == 0) return "None"; + if (id == sourceInstanceId) return "Self"; + if (state.Players.ContainsKey(id)) return "PlayerZone"; + return "Unit"; + } + + // Returns the first concrete Action from an ability definition, + // checking ActionGroup before the legacy Actions array. + private static Abilities.Models.Action? GetFirstAction( + Abilities.Models.AbilityDefinition ability) + { +#pragma warning disable CS0618 + if (ability.ActionGroup?.Actions is { Length: > 0 } ag) return ag[0]; + if (ability.Actions is { Length: > 0 } lx) return lx[0]; +#pragma warning restore CS0618 + return null; + } + /// /// Broadcast an arbitrary push message to all players and spectators in a session. /// diff --git a/Server/src/SOR.Game/Handlers/GamePlayCardHandler.cs b/Server/src/SOR.Game/Handlers/GamePlayCardHandler.cs index de52a6b..b969476 100644 --- a/Server/src/SOR.Game/Handlers/GamePlayCardHandler.cs +++ b/Server/src/SOR.Game/Handlers/GamePlayCardHandler.cs @@ -99,44 +99,4 @@ internal sealed class GamePlayCardHandler : GameHandlerBase, IMessageHandler return ServerMessage.Reply("game.play_card.ack", message.Seq, new GamePlayCardResponse(dto)); } - - /// - /// 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 live enemy ArchSpirit (different team, not eliminated) - /// via GameState.GetEnemyIds, so the projectile always has somewhere to travel - /// for targetless or server-resolved abilities without hitting an ally. - /// - private static IReadOnlyList ComputeVisualTargets( - IReadOnlyList? 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 enemy ArchSpirit. - // GetEnemyIds filters by different TeamIndex and !IsEliminated, covering both - // FFA and team modes without accidentally targeting an ally or a dead player. - var opponentArch = state.GetEnemyIds(actorId) - .Select(id => state.Players[id].ArchSpirit) - .FirstOrDefault(a => a is not null); - - if (opponentArch is not null) - return [new AbilityTarget(ActionIndex: 0, InstanceId: opponentArch.InstanceId)]; - - return []; - } }