Ability Range fix

This commit is contained in:
dingo
2026-03-13 17:36:57 -04:00
parent 60268fd310
commit 92f61dcd76
2 changed files with 33 additions and 4 deletions
@@ -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)