import { TB } from "../../config/data/schema";
import GRoleDefault from "../base/role/GRoleDefault";
import { GSkillBase, GSkillState } from "./GSkill";


//冷却技能基类 用于多长时间释放技能
export default abstract class GSkillCDBase implements GSkillBase {

    //冷却总时间
    cdTatal:number = 0;
    //冷却时间
    cdTime:number = 0;

    bind(role:GRoleDefault,info: TB.TbGRoleSkill):GSkillCDBase {
        return this;
    }

    //是否可以释放技能
    isRelease(): boolean {
        return this.cdTime >= this.cdTatal;
    }

    //释放技能
    release():boolean {
        //是否可以释放技能
        if(!this.isRelease()) return false;
        this.cdTime = 0;
        return this.onRelease();
    }

    //子类实现释放
    abstract onRelease():boolean;

    //查询状态
    state(): GSkillState {

        if(this.isReleasing()){
            return GSkillState.Releasing
        }

        if(this.isRelease())
            return GSkillState.Releasable
        else
            return GSkillState.NoRelease
        
    }

    //是否正在释放技能
    isReleasing(): boolean{
        return false;
    }

    //更新
    onUpdate(dt:number){

        if(this.state() == GSkillState.NoRelease){
            this.cdTime += (dt / 1000);
        }

    }

    //返回进度
    getProgress():number{
        return this.cdTime / this.cdTatal;
    }

}
