UnityTowerDefense/Assets/_Project/Scripts/Gameplay/BuilderSpells/FireballSpellDefinition.cs

51 lines
2 KiB
C#

// Assets/_Project/Scripts/Gameplay/BuilderSpells/FireballSpellDefinition.cs
using UnityEngine;
using TD.Core;
namespace TD.Gameplay.BuilderSpells
{
/// <summary>
/// Builder spell #1 — drop a fireball on a point, dealing direct damage to whatever's
/// there plus splash damage to nearby enemies.
/// </summary>
/// <remarks>
/// <see cref="BuilderSpellDefinition.TargetType"/> is <see cref="SpellTargetType.PointTarget"/>
/// — the cast controller shows only a fixed-size reticle, even though
/// <see cref="BuilderSpellDefinition.Radius"/> is still used internally here as the splash
/// radius (0 = no splash, direct hit only).
/// </remarks>
[CreateAssetMenu(fileName = "FireballSpell", menuName = "TD/Builder Spells/Fireball")]
public class FireballSpellDefinition : BuilderSpellDefinition
{
public override BuilderSpellKind Kind => BuilderSpellKind.Fireball;
[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);
// TEMP DEBUG — remove once cast resolution is confirmed working.
Debug.Log($"[FireballSpellDefinition] ServerCast at {targetPoint}, radius " +
$"{Mathf.Max(Radius, 0.01f):0.##}, found {count} colliders.");
bool hitAny = false;
for (int i = 0; i < count; i++)
{
var enemyHealth = s_overlapBuffer[i].GetComponent<EnemyHealth>();
if (enemyHealth == null || enemyHealth.IsDead) continue;
enemyHealth.TakeDamage(Damage, DamageType.Fire, owner);
hitAny = true;
}
return hitAny;
}
}
}