import GAttribute, { GAttributeType } from "./attribute/GAttribute";
import GAttributeBase from "./attribute/GAttributeBase";

//宠物攻击类
export enum GRoleAttackType{
    NormalAttack,
}

//宠物数值 核心类
export default class GRoleValues {

    //宠物属性
    attribute:GAttribute;

    get attributes(){
        return this.attribute.info;
    }

    constructor(){

        //初始化属性
        this.attribute = new GAttribute();
        this.update();

    }

    //重置
    reset(attribute:GAttribute = new GAttribute()){
        //初始化属性
        this.attribute = attribute;
        this.update();
    }

    //添加属性类
    add(info:GAttributeBase){
        this.attribute.add(info);
    }

    //刷新属性
    update(){
        //刷新属性
        this.attribute.update();
    }

    //普通攻击
    onNormalAttack(){

        //普通攻击伤害 = 攻击
        return this.attributes[GAttributeType.Attack];

    }

    //受到普通攻击
    onUnderNormalAttack(under:number){

        //受到普通攻击伤害 = 受到伤害 - 防御
        return Math.max(0,under - this.attributes[GAttributeType.Defend]);

    }

    //受到攻击 统一方法
    onUnderAttack(type:GRoleAttackType,under:number){
        if(type == GRoleAttackType.NormalAttack){
            //受到普通攻击
            return this.onUnderNormalAttack(under);
        }
        return under;
    }

    //攻击 统一方法
    onAttack(type:GRoleAttackType){
        if(type == GRoleAttackType.NormalAttack){
            //普通攻击
            return this.onNormalAttack();
        }
        return 0;
    }

    //普通攻击某个目标
    onNormalAttackTarget(values:GRoleValues){
        return values.onUnderNormalAttack(this.onNormalAttack());
    }

    //血量
    onBlood(){

        //总血量 = 血量
        return this.attributes[GAttributeType.Blood];

    }
    

}

