using UnityEngine;

public class ZoneEffect : MonoBehaviour, ISkillEffect
{
    public void Execute(SkillInstance skill, Transform caster, float chargeRatio)
    {
        Vector3 center = caster.position + caster.forward * skill.CurrentLevelData.Range;
        SpawnZone(skill, center);
    }

    public void ExecuteAtPosition(SkillInstance skill, Transform caster, Vector3 targetPos, float chargeRatio)
    {
        SpawnZone(skill, targetPos);
    }

    private void SpawnZone(SkillInstance skill, Vector3 position)
    {
        if (skill.Data.ZonePrefab == null) return;

        GameObject zoneObj = Instantiate(skill.Data.ZonePrefab, position, Quaternion.identity);
        ZoneEntity entity = zoneObj.GetComponent<ZoneEntity>();
        if (entity != null)
        {
            SkillLevelData data = skill.CurrentLevelData;
            float tickDmg = data.TickDamage > 0 ? data.TickDamage : data.Damage;
            entity.Init(tickDmg, data.Range, data.Duration, data.TickInterval, skill.Data.AppliedDebuffs);
        }
    }
}
