// Assets/_Project/Scripts/Gameplay/BuilderSpells/FireballSpellDefinition.cs
using UnityEngine;
using TD.Core;
namespace TD.Gameplay.BuilderSpells
{
///
/// Builder spell #1 — drop a fireball on a point, dealing direct damage to whatever's
/// there plus splash damage to nearby enemies.
///
///
/// is
/// — the cast controller shows only a fixed-size reticule, even though
/// is still used internally here as the splash
/// radius (0 = no splash, direct hit only).
///
[CreateAssetMenu(fileName = "FireballSpell", menuName = "TD/Builder Spells/Fireball")]
public class FireballSpellDefinition : BuilderSpellDefinition
{
public override BuilderSpellKind Kind => BuilderSpellKind.Fireball;
[Header("Impact VFX")]
[Tooltip("Prefab spawned at the target point on a successful cast. Optional — leave empty for no visual.")]
[SerializeField] private GameObject impactVfxPrefab;
[Tooltip("Seconds before the spawned VFX instance is destroyed.")]
[Min(0f)]
[SerializeField] private float impactVfxLifetime = 2f;
[Header("Fireball")]
[Tooltip("Damage dealt to every enemy within Radius of the target point.")]
[Min(0f)]
public float Damage = 50f;
public override bool ServerCast(ulong clientId, Vector3 targetPoint)
{
PlayerSlot owner = PlayerMatchState.SlotForClient(clientId);
int count = Physics.OverlapSphereNonAlloc(
targetPoint, Mathf.Max(Radius, 0.01f), s_overlapBuffer, enemyLayerMask);
bool hitAny = false;
for (int i = 0; i < count; i++)
{
var enemyHealth = s_overlapBuffer[i].GetComponent();
if (enemyHealth == null || enemyHealth.IsDead) continue;
enemyHealth.TakeDamage(Damage, DamageType.Fire, owner);
hitAny = true;
}
return hitAny;
}
public override void ClientPlayVfx(Vector3 targetPoint)
{
if (impactVfxPrefab != null)
Destroy(Instantiate(impactVfxPrefab, targetPoint, Quaternion.identity), impactVfxLifetime);
}
}
}