package com.yaohun.demonskills.listener;

import com.yaohun.demonskills.SkillsMain;
import com.yaohun.demonskills.manage.ComboManager;
import com.yaohun.demonskills.skills.attack.Skill_普通攻击;
import com.yaohun.demonskills.util.CDTimeAPI;
import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class CommonAttackListener implements Listener {

    @EventHandler
    public void onAttack(PlayerInteractEvent e){
        Player player = e.getPlayer();
        UUID uuid = player.getUniqueId();
        Action action = e.getAction();
        // 左键判断
        if (action != Action.LEFT_CLICK_AIR && action != Action.LEFT_CLICK_BLOCK) return;
        ItemStack item = player.getInventory().getItemInMainHand();
        if (!DemonAPI.itemIsNull(item) && item.getType().equals(Material.DIAMOND_SWORD)) {
            if(CDTimeAPI.isCD(uuid,"attack_cd"))return;
            // 当前连段阶段
            int stage = ComboManager.getComboStage(player);
            switch (stage) {
                case 0:
                    CDTimeAPI.setPlayerCD(uuid,"attack_cd",1230);
                    Skill_普通攻击.getAttack1().cast(player);
                    break;
                case 1:
                    CDTimeAPI.setPlayerCD(uuid,"attack_cd",1530);
                    Skill_普通攻击.getAttack2().cast(player);
                    break;
                case 2:
                    CDTimeAPI.setPlayerCD(uuid,"attack_cd",930);
                    Skill_普通攻击.getAttack3().cast(player);
                    break;
                default:
                    CDTimeAPI.setPlayerCD(uuid,"attack_cd",1170);
                    Skill_普通攻击.getAttack4().cast(player);
                    ComboManager.resetCombo(player); // 打完第4段重置
                    return;
            }
            ComboManager.nextComboStage(player);
        }
    }
}
