package com.yaohun.demonskills.component.dragoncore;

import com.yaohun.demonskills.SkillsMain;
import com.yaohun.demonskills.api.SkillComponent;
import com.yaohun.demonskills.api.TargetSelector;
import com.yaohun.demonskills.util.RandomUtil;
import eos.moe.dragoncore.network.PacketSender;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.UUID;

public class ParticleSpawnCommponent implements SkillComponent {

    private final String particleName;
    private final int spawnTimer;
    private int spawnCount = 1;
    private TargetSelector selector = null;

    public ParticleSpawnCommponent(final String particleName, int spawnTimer) {
        this.particleName = particleName;
        this.spawnTimer = spawnTimer;
    }

    public ParticleSpawnCommponent(final String particleName, int spawnTimer,int spawnCount) {
        this.particleName = particleName;
        this.spawnTimer = spawnTimer;
        this.spawnCount = spawnCount;
    }


    @Override
    public void execute(Player caster) {
        UUID entityUUID = caster.getUniqueId();
        if (spawnCount == 1) {
            String particleUUID = UUID.randomUUID().toString();
            PacketSender.addParticle(caster, particleName + ".particle", particleUUID, entityUUID.toString(), "0,0,0", spawnTimer);
        } else {
            for (int i = 0; i < spawnCount; i++) {
                Bukkit.getScheduler().runTaskLater(SkillsMain.inst(), () -> {
                    String particleUUID = UUID.randomUUID().toString();
                    PacketSender.addParticle(caster, particleName + ".particle", particleUUID, entityUUID.toString(), "0,0,0", spawnTimer);
                },i*20L);
            }
        }
    }
}
