import { BattleBase } from "../base/BattleBase";
import { SkillConf } from "../conf/SkillConf";
import { BattleUtil } from "../data/BattleUtil";
import { BuffData } from "../data/BuffData";
import { BulletData } from "../data/BulletData";
import { EnemyData } from "../data/EnemyData";
import { HeroData } from "../data/HeroData";
import { MapData } from "../data/MapData";
import { BuffControl } from "./BuffControl";

//子弹控制类
export class SkillControl extends BattleBase{

    
    protected static instance:SkillControl;
    map:MapData = null
    
    
    
    static GetInstance():SkillControl{
        if(!SkillControl.instance){
            SkillControl.instance = new SkillControl();
        }
        return SkillControl.instance;
    }

    init(){
        this.map = MapData.GetInstance()
       
    }

    //技能释放
    useSkill(hero: HeroData, enemy: EnemyData, skillID: number) :Array<BuffData>{
        let skillData = SkillConf.data[skillID]
        let addBuffData:BuffData[] = []
        if(skillData == null) return [];
        
        //效果计算
        let effectList = skillData.EffectObjArr
        effectList.forEach((effectObj)=>{


            switch(effectObj.effectType){
                case "add_buff":{
                    let valueList:Array<number> = []
                    if(effectObj.eParam2){
                        valueList.push(effectObj.eParam2)
                    } else if(effectObj.eParam3){
                        valueList.push(effectObj.eParam3)
                    } else if(effectObj.eParam4){
                        valueList.push(effectObj.eParam4)
                    } else if(effectObj.eParam5){
                        valueList.push(effectObj.eParam5)
                    }

                    let buffData = this.map.addBuff(effectObj.buffID, effectObj.eParam, valueList, hero, enemy)
                    if(buffData){
                        addBuffData.push(buffData)
                    }
                    
                }
                    break;
            }
        })

        return addBuffData
    }

}