extends RefCounted ## Only primary attacks advance the hit counter. Extra damage never recurses. var progress: float = 0.0 var hit_count: int = 0 func step(unit, combatants: Array, delta: float) -> void: if not is_instance_valid(unit.target) or not unit.target.alive: progress = 0.0 return if unit.distance_to_unit(unit.target) > float(unit.data.attack_range) + 0.035: progress = 0.0 return progress += delta * unit.attack_speed_factor() while progress >= 1.0 - 0.000001 and unit.alive and unit.target.alive: progress = maxf(0.0, progress - 1.0) hit_count += 1 var target = unit.target var damage = float(unit.data.damage) * (1.0 + unit.damage_bonus()) if hit_count % 4 == 0: if str(unit.data.ability) == "g05": damage *= 1.5 elif str(unit.data.ability) == "g06": damage *= 1.75 target.receive_damage(damage, int(unit.data.attack_type)) unit.play_attack(target.position) unit.ability_component.on_hit(unit, target, combatants, hit_count)