// Assets/_Project/Scripts/Gameplay/EnemyAbilities/SplitOnDeathAbilityDefinition.cs using UnityEngine; using TD.Core; namespace TD.Gameplay.EnemyAbilities { /// /// On death, spawns smaller copies of the dying enemy's own type at /// the corpse's position, continuing on toward the goal instead of restarting from the wave's /// spawner. There's no separate "minion" EnemyDefinition to author — the mini copies reuse /// whichever EnemyDefinition/prefab the dying enemy itself was spawned from, scaled down by /// /. /// [CreateAssetMenu(fileName = "SplitOnDeathAbility", menuName = "TD/Enemy Abilities/Split On Death")] public class SplitOnDeathAbilityDefinition : EnemyAbilityDefinition { public override EnemyAbilityKind Kind => EnemyAbilityKind.SplitOnDeath; [Header("Split")] [Tooltip("How many mini copies spawn on death.")] [Min(1)] public int SplitCount = 2; [Tooltip("Each mini copy's MaxHp = the dying enemy's own MaxHp * this multiplier.")] [Range(0.01f, 1f)] public float HpMultiplier = 0.5f; [Tooltip("Uniform transform scale applied to each mini copy, relative to the normal " + "prefab scale. Requires the enemy prefab's NetworkTransform to sync scale, " + "or the mini will render full-size on remote peers.")] [Range(0.1f, 1f)] public float ScaleMultiplier = 0.6f; [Tooltip("Random scatter radius (world units) applied to each split spawn so they don't " + "spawn exactly on top of each other.")] [Min(0f)] public float ScatterRadius = 0.5f; public override void ServerOnDeath(EnemyAbility instance, EnemyHealth health) { var def = health.Definition; if (def == null) return; var movement = instance.GetComponent(); var atTile = GridCoordinates.WorldToGrid(instance.transform.position); var ownerSlot = movement != null ? movement.OriginZone : PlayerSlot.None; WaveManager.Instance?.ServerSpawnSplitEnemies( def, SplitCount, atTile, ownerSlot, ScatterRadius, HpMultiplier, ScaleMultiplier); } } }