package com.yaohun.demonskills.skills.skillsapi;

import com.yaohun.demonskills.SkillsMain;
import com.yaohun.demonskills.component.*;
import com.yaohun.demonskills.component.damage.DamageComponent;
import com.yaohun.demonskills.component.particles.CircleParticlesComponent;
import com.yaohun.demonskills.component.particles.DiscParticlesComponent;
import com.yaohun.demonskills.component.particles.ParticlesComponent;
import com.yaohun.demonskills.component.projectile.ProjectileAdvanceComponent;
import com.yaohun.demonskills.core.Skill;
import com.yaohun.demonskills.data.PlayerData;
import com.yaohun.demonskills.manage.PlayerManager;
import com.yaohun.demonskills.target.NearestEnemiesSelector;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import org.serverct.ersha.jd.AttributeAPI;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Skill_BaoHuoLongJi {

    private static final String skillName = "爆火龙疾";
    private static final double cooldownTime = 60;
    private static final double cdReducePerLevel = 3.0;     // 每级减少1.2秒冷却
    private static final double minCooldown = 30.0;         // 最低冷却限制

    private static final Map<Integer, Integer> skillMagicMap = new HashMap<>();
    static {
        skillMagicMap.put(1, 1);
        skillMagicMap.put(2, 1);
        skillMagicMap.put(3, 2);
        skillMagicMap.put(4, 2);
        skillMagicMap.put(5, 3);
        skillMagicMap.put(6, 3);
        skillMagicMap.put(7, 4);
        skillMagicMap.put(8, 4);
    }

    public static Skill getSkillItemStack(int skillLevel){
        double realCooldown = Math.max(cooldownTime - cdReducePerLevel * (skillLevel - 1), minCooldown);
        int realNeedMagic = skillMagicMap.getOrDefault(skillLevel, 0);
        return new Skill(skillName, realNeedMagic, realCooldown,2.5, new ArrayList<>());
    }

    public static Skill getSkillData(Player player) {
        String playerName = player.getName();
        PlayerManager playerManager = SkillsMain.getPlayerManager();
        PlayerData playerData = playerManager.getPlayerData(playerName);
        int skillLevel = playerData.getSkillLevel(skillName);
        double realCooldown = Math.max(cooldownTime - cdReducePerLevel * (skillLevel - 1), minCooldown);
        int realNeedMagic = skillMagicMap.getOrDefault(skillLevel, 0);
        double damageValue = AttributeAPI.getAttrData(player).getAttributeRandomValue("物理伤害");
        double damage = 100 + (damageValue * 1.3) * skillLevel;
        Skill skill = new Skill( // 技能 ID
                skillName,   // 技能名称
                realNeedMagic,      // 魔力需求
                realCooldown,      // 冷却时间
                2.5,
                Arrays.asList(
                        // 实现漂浮效果 26L
                        new PotionEffectComponent(PotionEffectType.LEVITATION,26,0),
                        // 玩家向前冲刺 力度0.3  高度0.8
                        new ProjectileAdvanceComponent(0.3,0.8),
                        // 播放声音
                        new SoundComponent("ENTITY_ENDERDRAGON_FLAP",1.0f,1.0f),
                        // 播放  跟随粒子每次出现6个 范围2  播放次数 15次
                        new ParticlesComponent(Particle.REDSTONE,6,2,15),
                        // 生成脚下一圈粒子
                        new CircleParticlesComponent(Particle.REDSTONE,2,2,36,2),
                        // 延迟 16L
                        new DelayComponent(26L,Arrays.asList(
                                // 添加防摔CD
                                new CdTimeComponent("anti_fall",500),
                                // 玩家镶嵌冲刺 位移0.5 高度-1.5
                                new ProjectileAdvanceComponent(0.8,-1.0),
                                // 播放爆炸音效
                                new SoundComponent("ENTITY_GENERIC_EXPLODE",1.0f,1.0f),
                                // 播放 跟随岩浆粒子 5次
                                new ParticlesComponent(Particle.LAVA,5,0.2,5),
                                // 对周围3格范围内生物造成伤害
                                new DamageComponent(damage,new NearestEnemiesSelector(5)),
                                // 延迟5L
                                new DelayComponent(5L,Arrays.asList(
                                        // 播放  圆形粒子
                                        new DiscParticlesComponent(Particle.SMOKE_LARGE,1,20)
                                ))
                        ))
                )
        );
        playerData.setCooldownData(skillName, realCooldown);
        return skill;
    }
}
