// Assets/_Project/Scripts/Gameplay/EnemyAbilities/BlinkAbilityDefinition.cs using UnityEngine; using TD.Core; namespace TD.Gameplay.EnemyAbilities { /// /// Every few seconds, the enemy teleports a short distance further along its path — skipping /// tiles, and the towers covering them. /// /// /// Blinks follow the path rather than cutting toward the goal, so the maze still shapes the /// route; the buff shortens time-under-fire rather than bypassing walls. See /// EnemyMovement.ServerBlinkForward. /// /// The cooldown lives in this enemy's own timer slot rather than on the asset. A field /// here would be shared by every enemy carrying the buff, so the whole wave would blink in /// perfect unison — which looks like a bug even when the timing is right. /// [CreateAssetMenu(fileName = "BlinkAbility", menuName = "TD/Enemy Abilities/Blink")] public class BlinkAbilityDefinition : EnemyAbilityDefinition { public override EnemyAbilityKind Kind => EnemyAbilityKind.Blink; [Header("Blink")] [Tooltip("Seconds between blinks.")] [Min(0.1f)] public float IntervalSeconds = 4f; [Tooltip("How many path waypoints to skip per blink. Note that path smoothing can make " + "one waypoint span several tiles, so this is a coarser dial than it looks.")] [Min(1)] public int BlinkWaypoints = 2; [Tooltip("Random spread (seconds) added to each enemy's first blink so a wave doesn't " + "blink in one synchronized block. Applied once, at spawn.")] [Min(0f)] public float StartJitterSeconds = 1.5f; public override void ServerOnSpawn(EnemyAbility instance, int abilityIndex) { // Seed each enemy's cooldown with a different negative offset so the wave's first // blink is staggered. Done once, here, rather than on the first tick — a tick-time // check would have to distinguish "never started" from "just blinked", and both // states read as a zero timer. if (StartJitterSeconds > 0f) instance.TimerFor(abilityIndex) = -Random.Range(0f, StartJitterSeconds); } public override void ServerTick(EnemyAbility instance, int abilityIndex, float dt) { ref float timer = ref instance.TimerFor(abilityIndex); timer += dt; if (timer < IntervalSeconds) return; timer = 0f; instance.GetComponent()?.ServerBlinkForward(BlinkWaypoints); } } }