diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 9992e8d..00fc98a 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -159,6 +159,7 @@ var _local_is_p1 : bool = false # true when Auth.user_id == playerOneAccountI var _prev_unit_hp : Dictionary = {} # instanceId → int, HP snapshot for damage detection var _prev_unit_pos: Dictionary = {} # instanceId → Vector2i, position snapshot for move detection var _move_anims : Dictionary = {} # instanceId → Tween (active movement tweens) +var _last_attack_target_iid : String = "" # target of the most recent send_attack() call # Delayed rebuild: when animations need time to play we don't destroy unit nodes immediately. var _pending_rebuild : Dictionary = {} # latest state waiting for the delayed rebuild @@ -1008,14 +1009,25 @@ func _play_damage_animations(state: Dictionary) -> bool: if damaged_iids.is_empty() and dying_iids.is_empty(): return false - # ── Detect counterattack: attacker AND another unit both took damage ────── + # ── Detect counterattack: attacker took damage while mid-attack ───────── + # The defender may have blocked all HP damage (defense stat), so we can't + # 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) and damaged_iids.size() >= 2: - for iid: String in damaged_iids: - if iid != attacker_iid: - defender_iid = iid - break + if attacker_iid != "" and damaged_iids.has(attacker_iid): + # Prefer the unit we explicitly attacked (works even when they took 0 damage). + if tracked_target != "" and tracked_target != attacker_iid: + defender_iid = tracked_target + else: + # Fallback: any other damaged unit (original behaviour). + for iid: String in damaged_iids: + if iid != attacker_iid: + defender_iid = iid + break is_counterattack = defender_iid != "" # ── Schedule animations ─────────────────────────────────────────────────── @@ -1506,6 +1518,7 @@ func _handle_board_click(mouse_pos: Vector2) -> void: Mode.UNIT_SELECTED: if not unit_id.is_empty(): if _is_enemy_unit(unit_id): + _last_attack_target_iid = unit_id _play_unit_anim(_sel_unit_id, "attack") Game.send_attack(_sel_unit_id, unit_id) _set_mode(Mode.NONE)