From 92f61dcd76105a4887b3c9cada261c519e990954 Mon Sep 17 00:00:00 2001 From: dingo Date: Fri, 13 Mar 2026 17:36:57 -0400 Subject: [PATCH] Ability Range fix --- .../origin-client/scenes/game/game_screen.gd | 19 ++++++++++++++++--- .../src/SOR.Game/Abilities/AbilitySystem.cs | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 8add5fe..00998bd 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -135,9 +135,10 @@ var _sac_arch_coord : Vector2i = Vector2i(-1, -1) var _ability_unit_id : String = "" var _ability_idx : int = -1 var _ability_panel : Control = null -var _ability_def : Array = [] # Actions array from parsed ability JSON -var _ability_targets : Array = [] # collected AbilityTarget dicts to send -var _ability_cur_action_idx : int = 0 # which Action we are currently collecting for +var _ability_def : Array = [] # Actions array from parsed ability JSON +var _ability_range : Dictionary = {} # Top-level range {min, max} from ability definition +var _ability_targets : Array = [] # collected AbilityTarget dicts to send +var _ability_cur_action_idx : int = 0 # which Action we are currently collecting for var _player_panel : Control = null # ── Unit ownership lookup ───────────────────────────────────────────────────── @@ -1010,6 +1011,7 @@ func _set_mode(new_mode: Mode) -> void: _ability_unit_id = "" _ability_idx = -1 _ability_def = [] + _ability_range = {} _ability_targets = [] _ability_cur_action_idx = 0 _clear_highlights() @@ -1239,6 +1241,7 @@ func _show_ability_panel(unit_id: String, unit: Dictionary) -> void: _ability_unit_id = unit_id _ability_idx = idx _ability_def = ab_def.get("actions", []) + _ability_range = ab_def.get("range", {}) _ability_targets = [] _ability_cur_action_idx = 0 _start_ability_targeting()) @@ -1344,10 +1347,20 @@ func _highlight_ability_targets(action: Dictionary) -> void: if not my_arch.is_empty(): targets.append(my_arch) + var src_pos_ab : Dictionary = {} + if not _ability_range.is_empty(): + src_pos_ab = Game.get_unit_by_id(_ability_unit_id).get("position", {}) + for u: Dictionary in targets: var pos : Dictionary = u.get("position", {}) if pos.is_empty(): continue if not _unit_passes_filters(u, filters): continue + if not _ability_range.is_empty(): + if src_pos_ab.is_empty(): continue + var dist := (absi(int(pos.get("x", 0)) - int(src_pos_ab.get("x", 0))) + + absi(int(pos.get("y", 0)) - int(src_pos_ab.get("y", 0)))) + if dist < int(_ability_range.get("min", 0)) or dist > int(_ability_range.get("max", 999)): + continue _add_highlight(pos.get("x", 0), pos.get("y", 0), HI_BLUE) diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 8781ea9..4b215e4 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -431,9 +431,10 @@ public static class AbilitySystem if (selector.Filters is { Length: > 0 }) candidates = candidates.Where(c => FiltersMatch(selector.Filters, c, ctx)).ToList(); + HashSet clientIds = []; if (clientTargets is not null) { - var clientIds = clientTargets + clientIds = clientTargets .Where(t => t.ActionIndex == actionIndex && t.InstanceId is not null) .Select(t => t.InstanceId!).ToHashSet(); if (clientIds.Count > 0) @@ -446,9 +447,24 @@ public static class AbilitySystem } if (activationRange is not null) + { + // If the client explicitly picked unit targets, validate range before filtering so the + // error is unambiguous (TARGET_OUT_OF_RANGE rather than INSUFFICIENT_TARGETS). + if (clientIds.Count > 0 && ctx.Source is FieldCard srcFc && srcFc.Position.HasValue) + { + bool anyOutOfRange = candidates + .OfType() + .Where(fc => clientIds.Contains(fc.InstanceId)) + .Any(fc => !fc.Position.HasValue || + !IsTargetInAbilityRange(ctx.State, srcFc.Position.Value, fc.Position.Value, activationRange)); + if (anyOutOfRange) + throw new GameException("TARGET_OUT_OF_RANGE"); + } + candidates = FilterTargetsByAbilityRange(candidates.Cast().ToList(), ctx, activationRange) .OfType() .ToList(); + } if (!selector.Count.All) {