import { TB } from "../../../../config/data/schema";
import GRoleAttack from "../../../base/common/GRoleAttack";
import GRoleBase from "../../../base/role/GRoleBase";
import GRoleDefault from "../../../base/role/GRoleDefault";
import GSkillAngerBase from "../../GSkillAngerBase";
import GSkillCDBase from "../../GSkillCDBase";

export default class GSkillCDNormal extends GSkillCDBase{

    role:GRoleDefault;
    info: TB.TbGRoleSkill;

    bind(role:GRoleDefault,info: TB.TbGRoleSkill):GSkillCDNormal {
        //技能冷却
        this.cdTatal = parseInt(info.skillArgs[0]);
        this.role = role;
        this.info = info;
        return this;

    }

    onRelease(): boolean {

        let enemy = this.role.fsm.enemy;
        //关闭动画管理器
        this.role.fsmAnim.close();
        
        let attack = () => {
            if(!enemy.isDie){
                GRoleAttack.onNormalAttack(this.role,enemy);
            }
        };
        let end = () => {
            this.role.fsmAnim.open();
            this.role.fsmAnim.delEventListener("skillAttack",attack)
            this.role.fsmAnim.delEndListener("skill",end)
        }
        //监听伤害
        this.role.fsmAnim.addEventListener("skillAttack",attack)
        //播放妙蛙种子技能
        this.role.spine.setAnimation(0,"skill",false);
        this.role.fsmAnim.addEndListener("skill",end)

        return true;

    }


}

