import { TD } from "../../../../App";
import GAttributeBase from "./GAttributeBase";

//属性类型
export enum GAttributeType{
    Attack = 110001,    //攻击
    Defend = 110002,    //防御
    Blood = 110003,     //血量
}

//属性类
export default class GAttribute {

    attributes:GAttributeBase[] = [];

    //属性最终信息 {属性Id:属性值}
    info:{[key:number]:number} = {};

    //添加一个属性类
    add(info:GAttributeBase){
        this.attributes.push(info);
    }

    //重置
    reset(){
        this.attributes = [];
        this.update();
    }

    //刷新属性
    update(){

        this.info = {};

        TD.TbGAttribute.getDataList().forEach(attr => {
            //初始化属性
            this.info[attr.id] = 0;
        });
        
        //累加全部属性
        this.attributes.forEach((attribute) => {
            attribute.update();
            for (const key in attribute.attributes) {
                if(this.info[key]){
                    this.info[key] = this.info[key] + attribute.attributes[key];
                }else{
                    this.info[key] = attribute.attributes[key];
                }
            }
        })

    }

}

