package com.yaohun.demonskills.skills;

import com.yaohun.demonskills.SkillsMain;
import com.yaohun.demonskills.component.DelayComponent;
import com.yaohun.demonskills.component.PotionEffectComponent;
import com.yaohun.demonskills.component.projectile.ProjectileAdvanceComponent;
import com.yaohun.demonskills.component.SoundComponent;
import com.yaohun.demonskills.component.damage.DamageComponent;
import com.yaohun.demonskills.component.dragoncore.PlayerAnimationComponent;
import com.yaohun.demonskills.component.dragoncore.StandAnimationComponent;
import com.yaohun.demonskills.component.particles.ParticlesComponent;
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_赤焰旋风斩 {

    private static final String skillName = "赤焰旋风斩";
    private static final double cooldownTime = 35;
    private static final double cdReducePerLevel = 1.6;     // 每级减少1.6秒冷却
    private static final double minCooldown = 25.0;         // 最低冷却限制

    private static final Map<Integer, Integer> skillMagicMap = new HashMap<>();
    static {
        skillMagicMap.put(3, 1);
        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, 4.0,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 = ((0.2 * skillLevel) * damageValue) + damageValue;
        Skill skill = new Skill( // 技能 ID
                skillName,   // 技能名称
                realNeedMagic,      // 魔力需求
                realCooldown,      // 冷却时间
                4.5, // 核心技能冷却(冷却中无法施展其他技能 包括翻滚)
                Arrays.asList(
                        // 技能组件列表
                        new PlayerAnimationComponent("旋风斩"),
                        new StandAnimationComponent("战士技能", "旋风斩", 1, 86),
                        new SoundComponent("战士音效/旋风斩音效.ogg", 0.5f, 1.0f,10),
                        new DelayComponent(8L, Arrays.asList(
                                new PotionEffectComponent(PotionEffectType.SLOW,70,2),
                                new DamageComponent(damage*0.2,new NearestEnemiesSelector(5)),
                                new ProjectileAdvanceComponent(0.5,0.2,new NearestEnemiesSelector(5,true)),
                                new SoundComponent("战士音效/旋风斩音效.ogg", 0.5f, 1.0f,10),
                                new DelayComponent(10L, Arrays.asList(

                                        new DamageComponent(damage*0.2,new NearestEnemiesSelector(5)),
                                        new ProjectileAdvanceComponent(0.5,0.2,new NearestEnemiesSelector(5,true)),
                                        new SoundComponent("战士音效/旋风斩音效.ogg", 0.5f, 1.0f,10),
                                        new DelayComponent(10L, Arrays.asList(

                                                new DamageComponent(damage*0.2,new NearestEnemiesSelector(5)),
                                                new ProjectileAdvanceComponent(0.5,0.2,new NearestEnemiesSelector(5,true)),
                                                new SoundComponent("战士音效/旋风斩音效.ogg", 0.5f, 1.0f,10),
                                                new DelayComponent(10L, Arrays.asList(

                                                        new DamageComponent(damage*0.2,new NearestEnemiesSelector(5)),
                                                        new ProjectileAdvanceComponent(0.5,0.2,new NearestEnemiesSelector(5,true)),
                                                        new SoundComponent("战士音效/旋风斩音效.ogg", 0.5f, 1.0f,10),
                                                        new DelayComponent(10L, Arrays.asList(

                                                                new DamageComponent(damage*0.2,new NearestEnemiesSelector(5)),
                                                                new ProjectileAdvanceComponent(0.5,0.2,new NearestEnemiesSelector(5,true)),
                                                                new SoundComponent("战士音效/旋风斩音效.ogg", 0.5f, 1.0f,10),
                                                                new DelayComponent(10L,Arrays.asList(

                                                                        new DamageComponent(damage*0.2,new NearestEnemiesSelector(5)),
                                                                        new ProjectileAdvanceComponent(0.5,0.2,new NearestEnemiesSelector(5,true)),
                                                                        new SoundComponent("战士音效/旋风斩音效.ogg", 0.5f, 1.0f,10),
                                                                        new DelayComponent(10L,Arrays.asList(

                                                                                new DamageComponent(damage*0.2,new NearestEnemiesSelector(5)),
                                                                                new ProjectileAdvanceComponent(0.5,0.2,new NearestEnemiesSelector(5,true)),
                                                                                new SoundComponent("战士音效/旋风斩音效.ogg", 0.5f, 1.0f,10),
                                                                                new DelayComponent(10L,Arrays.asList(
                                                                                        // 播放爆炸音效
                                                                                        new SoundComponent("ENTITY_GENERIC_EXPLODE",1.0f,1.0f),
                                                                                        // 播放 跟随岩浆粒子 5次
                                                                                        new ParticlesComponent(Particle.LAVA,5,0.2,5),
                                                                                        new ProjectileAdvanceComponent(0.6,0.8,new NearestEnemiesSelector(3,true))
                                                                                ))
                                                                        ))
                                                                ))
                                                        )
                                                        ))
                                                ))
                                        ))
                                ))
                        ))
        );
        playerData.setCooldownData(skillName, realCooldown);
        return skill;
    }

}
