package com.yutian.minerwar.liveevent;

import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.effects.PotionBlindness;
import com.yutian.minerwar.effects.ShoutArrow;
import com.yutian.minerwar.effects.SummonTheBee;
import com.yutian.minerwar.effects.SummonTheEvokerFang;
import com.yutian.minerwar.game.Game;
import com.yutian.minerwar.listener.KeepEntitiesOnDeath;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import tools.CDTimeAPI;
import tools.GameUtil;

import java.util.UUID;

public class GiftEventHandler {

    public static void SendHandLer(Player zhubo, String userName, String eventName){
        Game game = MinerWar.getGame();
        userName = GameUtil.hideName(userName);
        if (eventName.equalsIgnoreCase("螺旋升天")) {

        } else if (eventName.equalsIgnoreCase("瞬间加血")) {
            zhubo.addPotionEffect(new PotionEffect(PotionEffectType.HEAL,3,0));
            zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
            zhubo.getWorld().spawnParticle(Particle.VILLAGER_HAPPY,zhubo.getLocation().add(0,1,0),20,0.1,0.1,0.1,0.3);
        } else if (eventName.equalsIgnoreCase("天使庇护")) {
            UUID uuid = zhubo.getUniqueId();
            String timepieceKey = "angelicSanctuary";
            if(CDTimeAPI.isCD(uuid,timepieceKey)){
                long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (1000L * 10);
                CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
            } else {
                CDTimeAPI.setPlayerCD(uuid,timepieceKey,1000L * 10);
            }
            int deathAmount = 0;
            if(KeepEntitiesOnDeath.deathsVaule.get(zhubo) != null){
                deathAmount = KeepEntitiesOnDeath.deathsVaule.get(zhubo);
            }
            int newAmount = deathAmount - 3;
            if(newAmount <= 0){
                newAmount = 0;
            }
            KeepEntitiesOnDeath.deathsVaule.put(zhubo,newAmount);
        } else if (eventName.equalsIgnoreCase("超级挖掘")) {
            UUID uuid = zhubo.getUniqueId();
            String timepieceKey = "supermining";
            if(CDTimeAPI.isCD(uuid,timepieceKey)){
                long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (1000L * 30);
                CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
            } else {
                CDTimeAPI.setPlayerCD(uuid,timepieceKey,1000L * 30);
            }
            int deathAmount = 0;
            if(KeepEntitiesOnDeath.deathsVaule.get(zhubo) != null){
                deathAmount = KeepEntitiesOnDeath.deathsVaule.get(zhubo);
            }
            int newAmount = deathAmount - 1;
            if(newAmount <= 0){
                newAmount = 0;
            }
            KeepEntitiesOnDeath.deathsVaule.put(zhubo,newAmount);
        } else if (eventName.equalsIgnoreCase("致盲3秒")) {
            if(CDTimeAPI.isCD(zhubo.getUniqueId(),"angelicSanctuary")){return;}
            PotionBlindness.apply(game,zhubo,3);
        } else if (eventName.contains("小蜜蜂X")) {
            if(CDTimeAPI.isCD(zhubo.getUniqueId(),"angelicSanctuary")){return;}
            String[] eventSp = eventName.toUpperCase().split("X");
            int amount = Integer.parseInt(eventSp[1]);
            SummonTheBee.apply(game, zhubo, userName, amount);
        } else if (eventName.contains("箭头")) {
            if(CDTimeAPI.isCD(zhubo.getUniqueId(),"angelicSanctuary")){return;}
            int amount = 1;
            if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) {
                eventName = eventName.replace("*","X");
                String[] eventSp = eventName.toUpperCase().split("X");
                amount = Integer.parseInt(eventSp[1]);
            }
            ShoutArrow.apply(game, zhubo, userName, amount);
        } else if (eventName.contains("地刺")) {
            int amount = 1;
            if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) {
                eventName = eventName.replace("*","X");
                String[] eventSp = eventName.toUpperCase().split("X");
                amount = Integer.parseInt(eventSp[1]);
            }
            SummonTheEvokerFang.apply(game, zhubo, userName, amount);
        }
    }

}
