package com.yutian.minerwar.data;

import com.yutian.minerwar.MinerWar;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import tools.GameUtil;

public class GiftData {
    private String giftName;
    private String event;
    private String comple_type;
    private String sounds;
    private int amount = 0;

    public GiftData(String giftName, FileConfiguration yml){
        String str = "礼物设置."+giftName+".";
        this.giftName = giftName;
        this.comple_type = "NULL";
        if(yml.getString(str+"进度") != null){
            String[] stringSp = yml.getString(str+"进度").split("#");
            String tpye = stringSp[0];
            int a = Integer.parseInt(stringSp[1]);
            this.comple_type = tpye;
            this.amount = a;
        }
        this.sounds = yml.getString(str+"声音","NULL");
        this.event = yml.getString(str + "效果");
        if (comple_type.equalsIgnoreCase("NULL")) {
            Bukkit.getConsoleSender().sendMessage("事件: " + this.event + "  条件: " + giftName+"  声音: "+this.sounds);
        }else{
            if(comple_type.equalsIgnoreCase("take")){
                Bukkit.getConsoleSender().sendMessage("事件: " + this.event + "  条件: " + giftName+"  减"+amount+"赢");
            } else if(comple_type.equalsIgnoreCase("add")){
                Bukkit.getConsoleSender().sendMessage("事件: " + this.event + "  条件: " + giftName+"  加"+amount+"赢");
            }
        }
    }
    public String getEvent() {
        return event;
    }

    public String getComple_Show() {
        if(comple_type.equalsIgnoreCase("take")){
            return "§c赢-"+amount;
        }else if(comple_type.equalsIgnoreCase("add")){
            return "§b赢+"+amount;
        }
        return "";
    }

    public void OutCompleEvent(int amount) {
        int new_amount = this.amount * amount;
        if(comple_type.equalsIgnoreCase("take")){
            MinerWar.getGame().effect_takeComplete(new_amount);
            Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §c-"+new_amount);
        } else if(comple_type.equalsIgnoreCase("add")){
            MinerWar.getGame().effect_addComplete(new_amount);
            Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §b+"+new_amount);
        }
    }
    public void OutPlaySoundsEvent() {
        if(!sounds.equalsIgnoreCase("NULL")) {
            GameUtil.sendAllSound(sounds);
        }
    }
}
