40 lines
1.6 KiB
C#
40 lines
1.6 KiB
C#
// Assets/_Project/Scripts/Gameplay/EnemyAbilities/SplitOnDeathAbilityDefinition.cs
|
|
using UnityEngine;
|
|
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.
|
|
/// </summary>
|
|
[CreateAssetMenu(fileName = "SplitOnDeathAbility", menuName = "TD/Enemy Abilities/Split On Death")]
|
|
public class SplitOnDeathAbilityDefinition : EnemyAbilityDefinition
|
|
{
|
|
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.")]
|
|
[Min(1)]
|
|
public int SplitCount = 2;
|
|
|
|
[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)
|
|
{
|
|
if (SplitInto == null) return;
|
|
|
|
var movement = instance.GetComponent<EnemyMovement>();
|
|
var atTile = GridCoordinates.WorldToGrid(instance.transform.position);
|
|
var ownerSlot = movement != null ? movement.OriginZone : PlayerSlot.None;
|
|
|
|
WaveManager.Instance?.ServerSpawnSplitEnemies(SplitInto, SplitCount, atTile, ownerSlot, ScatterRadius);
|
|
}
|
|
}
|
|
}
|