Fix: blocked SFX plays when defender absorbs all attack damage
Move tracked_target consume before the early-return path so fully-blocked hits (zero HP change on all units) still trigger the defender's blockedSoundUrl after attack_remaining seconds, matching the timing of a landed hit. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -1219,7 +1219,24 @@ func _play_damage_animations(state: Dictionary) -> bool:
|
||||
if not seen_iids.has(iid):
|
||||
dying_iids[iid] = true
|
||||
|
||||
# Consume tracked target before any early return so it never bleeds into
|
||||
# the next state update (e.g. a fully-blocked hit with 0 HP change).
|
||||
var tracked_target : String = _last_attack_target_iid
|
||||
_last_attack_target_iid = ""
|
||||
|
||||
if damaged_iids.is_empty() and dying_iids.is_empty():
|
||||
# Fully-blocked attack: attacker is mid-swing but the defender's defense
|
||||
# absorbed all damage → no HP change, but play the blocked SFX.
|
||||
if attacker_iid != "" and not tracked_target.is_empty() \
|
||||
and tracked_target != attacker_iid:
|
||||
var blocked_iid := tracked_target
|
||||
if attack_remaining > 0.0:
|
||||
var tb := create_tween()
|
||||
tb.tween_callback(func() -> void:
|
||||
SFX.play(_sfx_for_unit(blocked_iid, "blockedSoundUrl"))
|
||||
).set_delay(attack_remaining)
|
||||
else:
|
||||
SFX.play(_sfx_for_unit(blocked_iid, "blockedSoundUrl"))
|
||||
return false
|
||||
|
||||
# ── Detect counterattack: attacker took damage while mid-attack ─────────
|
||||
@@ -1227,8 +1244,6 @@ func _play_damage_animations(state: Dictionary) -> bool:
|
||||
# rely on them being in damaged_iids. Use the tracked target from the last
|
||||
# send_attack() call as the primary source, and fall back to any other
|
||||
# damaged unit if the tracked target isn't available.
|
||||
var tracked_target : String = _last_attack_target_iid
|
||||
_last_attack_target_iid = "" # consume; don't bleed into the next update
|
||||
var is_counterattack : bool = false
|
||||
var defender_iid : String = ""
|
||||
if attacker_iid != "" and damaged_iids.has(attacker_iid):
|
||||
|
||||
Reference in New Issue
Block a user