saumwacht-godot/scripts/combat/targeting_component.gd
Martin Stickelbroeck c2b447610c Baseline: Saumwacht 0.15.0 (Phase 20A) vor dem Umbau zu Champions of Luneraria
Unveränderter Ausgangsstand inklusive Masterprompt und Konzeptbildern
unter assets/. .godot/ und docs/screenshots/ bleiben laut .gitignore
unversioniert; letztere sind unter ../backups gesichert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 20:00:36 +02:00

32 lines
1,010 B
GDScript

extends RefCounted
## Retains a living target, then applies the public formation target policy.
func choose(unit, combatants: Array):
if is_instance_valid(unit.target) and unit.target.alive:
if unit.distance_to_unit(unit.target) <= 10.0:
return unit.target
var candidates: Array = []
var nearby: Array = []
for other in combatants:
if not other.alive or other.team_id != unit.team_id or other.is_attacker == unit.is_attacker:
continue
candidates.append(other)
if unit.distance_to_unit(other) <= 8.0:
nearby.append(other)
if candidates.is_empty():
return null
var policy = 0 if unit.is_attacker or nearby.is_empty() else unit.target_policy
if not nearby.is_empty():
candidates = nearby
candidates.sort_custom(func(a, b):
var av = unit.distance_to_unit(a)
var bv = unit.distance_to_unit(b)
if policy == 1:
av = a.hp
bv = b.hp
elif policy == 2:
av = -a.max_hp
bv = -b.max_hp
return a.uid < b.uid if is_equal_approx(av, bv) else av < bv
)
return candidates[0]