Auto-retarget when the selected enemy dies (2026-11-25, Claude)
Janari asked: when the selected enemy dies, select another enemy that is fighting the player so skills keep working; if nobody is fighting, select nothing.
Behaviour
Scripts/Player/NativeCommandController.gdretarget_after_target_loss()runs first intick(). It fires only on the frame a live selection becomes unavailable (dead, freed, hidden, left the area). A manualselect_target(null)clearslive_target_id, so deselecting never auto-picks.- Pick order (
find_engaged_enemy()): the enemy that hit the player most recently (withinRECENT_ATTACKER_MSEC= 6 s) and is still aggroed on the player; otherwise the nearest enemy whoseaggro_targetis the player withaggro_time_left > 0; otherwise no target. - Recent attackers are recorded in
select_attacker_if_unselected(), whichPlayer.Hurt()already calls for every enemy hit (weakrefs, pruned when stale). - A running auto-attack or pending skill on the dead target is cancelled as before (
target_unavailable); the new target is only selected, no attack/move starts. Pressing a skill or Q then works on the new target immediately. - Online-compatible: the choice reads only the mob's own aggro fields, the same data a server snapshot would carry; nothing in online code was touched.
Tests
Scripts/Build/GameChecks/game_check_play.gd retarget_checks() (part of run_game_checks.ps1): hit keeps selection, death -> most recent attacker, death -> nearest aggroed, last death -> no target. The check silences ally alerts (ally_alert_radius = 0) because a hit/death normally aggroes nearby same-race allies, who then rightly become the next pick. Result 25.11: play 37/37 PASS. Full suite run with the editor open: stress_40 perf budget missed (73.9 FPS, worst 139 ms), most likely the concurrent editor; not caused by this change, rerun with editor closed.
Nothing was deleted; no archive needed (pure additions).