import { TD } from "../../../../../App";
import { PlayerPetOV } from "../../../../../consts/API";
import GAttributeBase from "../GAttributeBase";

//宠物属性
export default class GPetAttribute extends GAttributeBase{

    //宠物信息
    pet:PlayerPetOV;

    constructor(pet:PlayerPetOV){

        super();
        this.pet = pet;

        //固定属性直接计算
        this.compute();
        
    }

    //计算属性
    compute(){

        this.attributes = {};
        //*************** 宠物初始属性 **************************
        let baseAttribute = TD.TbGRoleBaseAttribute.get(this.pet.petTbId) || TD.TbGRoleBaseAttribute.get(0);

        //获取全部属性信息
        TD.TbGAttribute.getDataList().forEach(attr => {
            //保存初始属性 如果没有默认 0
            this.attributes[attr.id] = baseAttribute[attr.sign] || 0;
        });

        //计算升级成长属性
        let level = 1 + this.pet.petStar; //宠物等级
        let grow = TD.TbGRoleUpGrow.get(this.pet.petId) || TD.TbGRoleUpGrow.get(0); //成长

        TD.TbGAttribute.getDataList().forEach(attr => {
            
            //过滤没有的属性
            if(!baseAttribute[attr.sign] || !grow[attr.sign]) return;

            //计算 累加 ((base * value) * level)
            this.attributes[attr.id] = (baseAttribute[attr.sign] * grow[attr.sign]) * level;

        })

    }

    //刷新属性
    update(): void { }

}


