import { _decorator, Component, Node } from 'cc';
import { config } from '../../config';
import { buff_dun_chong } from './buff_dun_chong';
import { buff_dun } from './buff_dun';
import { buff_xi } from './buff_xi';
import { buff_xing } from './buff_xing';
import { effect_node } from './effect_node';
const { ccclass, property } = _decorator;

@ccclass('buff_manager')
export class buff_manager extends Component {
    @property(Node) buff_dun:Node = null
    @property(Node) buff_xi:Node = null
    @property(Node) buff_xing:Node = null
    @property(Node) buff_dun_chong:Node = null
    @property(Node) effect_node:Node = null
    private curShowBuffType:number = -1;
    public init(){
        this.curShowBuffType = -1;
        this.buff_dun_chong.getComponent(buff_dun_chong).init()
        this.effect_node.getComponent(effect_node).init()
        this.hideAll()
    }

    hideAll(){
        this.buff_dun.active = false
        this.buff_dun_chong.active = false
        this.buff_xi.active = false
        this.buff_xing.active = false
    }

    updateStatus(type:number){
        if(type===this.curShowBuffType){
            return
        }
        this.curShowBuffType = type
        // console.log("this.curShowBuffType",this.curShowBuffType)
        // this.hideAll()
        this.effect_node.getComponent(effect_node).updateStatus(this.curShowBuffType)
        switch (type) {
            case config.SHOW_BUFF_STATUS.DUN:
                this.buff_dun.active = true
                this.buff_dun_chong.active = true
                this.buff_dun.getComponent(buff_dun).playAnimation()
                this.buff_dun_chong.getComponent(buff_dun_chong).playAnimation()
            break;
        
            case config.SHOW_BUFF_STATUS.XI:
                this.buff_xi.active = true
                this.buff_xi.getComponent(buff_xi).playAnimation()
            break;

            case config.SHOW_BUFF_STATUS.XING:
                this.buff_xing.active = true
                this.buff_xing.getComponent(buff_xing).playAnimation()
            break;
        }
    }

    public cancelStatus(type:number){
        if(type===this.curShowBuffType){
            this.curShowBuffType=-1;
        }
        this.effect_node.getComponent(effect_node).cancelStatus(type)
        switch (type) {
            case config.SHOW_BUFF_STATUS.DUN:
                this.buff_dun.active = false
                this.buff_dun_chong.active = false
            break;
        
            case config.SHOW_BUFF_STATUS.XI:
                this.buff_xi.active = false
            break;

            case config.SHOW_BUFF_STATUS.XING:
                this.buff_xing.active = false
            break;
        }
    }


}


