simpler enemy split

This commit is contained in:
Ian Woods 2026-07-28 22:34:25 -07:00
parent 11ad19992d
commit 0a70f36838
3 changed files with 43 additions and 22 deletions

View file

@ -5,8 +5,11 @@ using TD.Core;
namespace TD.Gameplay.EnemyAbilities
{
/// <summary>
/// On death, spawns <see cref="SplitCount"/> copies of <see cref="SplitInto"/> at the corpse's
/// position, continuing on toward the goal instead of restarting from the wave's spawner.
/// On death, spawns <see cref="SplitCount"/> 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
/// <see cref="HpMultiplier"/>/<see cref="ScaleMultiplier"/>.
/// </summary>
[CreateAssetMenu(fileName = "SplitOnDeathAbility", menuName = "TD/Enemy Abilities/Split On Death")]
public class SplitOnDeathAbilityDefinition : EnemyAbilityDefinition
@ -14,13 +17,20 @@ namespace TD.Gameplay.EnemyAbilities
public override EnemyAbilityKind Kind => EnemyAbilityKind.SplitOnDeath;
[Header("Split")]
[Tooltip("Smaller enemy type spawned when this enemy dies.")]
public EnemyDefinition SplitInto;
[Tooltip("How many copies of SplitInto spawn on death.")]
[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)]
@ -28,18 +38,15 @@ namespace TD.Gameplay.EnemyAbilities
public override void ServerOnDeath(EnemyAbility instance, EnemyHealth health)
{
Debug.Log($"[SplitOnDeathAbility] ServerOnDeath fired for {instance.name}. " +
$"SplitInto={(SplitInto != null ? SplitInto.name : "null")}, " +
$"WaveManager.Instance={(WaveManager.Instance != null)}");
if (SplitInto == null) return;
var def = health.Definition;
if (def == null) return;
var movement = instance.GetComponent<EnemyMovement>();
var atTile = GridCoordinates.WorldToGrid(instance.transform.position);
var ownerSlot = movement != null ? movement.OriginZone : PlayerSlot.None;
Debug.Log($"[SplitOnDeathAbility] Spawning {SplitCount}x {SplitInto.name} at tile {atTile}.");
WaveManager.Instance?.ServerSpawnSplitEnemies(SplitInto, SplitCount, atTile, ownerSlot, ScatterRadius);
WaveManager.Instance?.ServerSpawnSplitEnemies(
def, SplitCount, atTile, ownerSlot, ScatterRadius, HpMultiplier, ScaleMultiplier);
}
}
}