package com.yaohun.demonskills.skills.skillsapi;

import com.yaohun.demonskills.SkillsMain;
import com.yaohun.demonskills.component.DelayComponent;
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.core.Skill;
import com.yaohun.demonskills.data.PlayerData;
import com.yaohun.demonskills.manage.PlayerManager;
import com.yaohun.demonskills.target.ConeEnemiesSelector;
import org.bukkit.entity.Player;
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 = 20;
    private static final int needMagic = 10;
    private static final double cdReducePerLevel = 2.6;     // 每级减少1.2秒冷却
    private static final int mpIncreasePerLevel = 4;        // 每级增加3点魔力消耗
    private static final double minCooldown = 1.3;         // 最低冷却限制

    public static Skill getSkillItemStack(int skillLevel){
        double realCooldown = Math.max(cooldownTime - cdReducePerLevel * (skillLevel - 1), minCooldown);
        int realNeedMagic = needMagic + mpIncreasePerLevel * (skillLevel - 1);
        return new Skill(skillName, realNeedMagic, realCooldown, 1.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 = needMagic + mpIncreasePerLevel * (skillLevel - 1);
        double damageValue = AttributeAPI.getAttrData(player).getAttributeRandomValue("物理伤害");
        double damage = ((0.2 * skillLevel) * damageValue + 50) + damageValue;
        Skill skill = new Skill( // 技能 ID
                skillName,   // 技能名称
                realNeedMagic,      // 魔力需求
                realCooldown,      // 冷却时间
                1.5,
                Arrays.asList(
                        // 技能组件列表
                        new PlayerAnimationComponent("逐风三式",25),
                        new StandAnimationComponent("@游灵剑技1", "youling_skill1", 1, 25,0.1),
                        new SoundComponent("宝剑挥舞.ogg", 0.4f, 1.0f),
                        new DelayComponent(5L,Arrays.asList(
                                new DamageComponent(damage * 0.2 ,new ConeEnemiesSelector(6.5,45)),
                                new SoundComponent("宝剑挥舞.ogg", 0.4f, 1.0f),
                                new DelayComponent(5L,Arrays.asList(
                                        new DamageComponent(damage * 0.2,new ConeEnemiesSelector(6.5,45)),
                                        new SoundComponent("宝剑挥舞.ogg", 0.4f, 1.0f),
                                        new DelayComponent(5L,Arrays.asList(
                                                new DamageComponent(damage * 0.2,new ConeEnemiesSelector(6.5,45)),
                                                new SoundComponent("宝剑挥舞.ogg", 0.4f, 1.0f)
                                        ))
                                )
                        ))
                )));
        playerData.setCooldownData(skillName, realCooldown);
        return skill;
    }

}
