Exemplo n.º 1
0
    /// <summary>
    /// <see cref="IAttrModifierTaker.TakeModifier(float, EAttrType, EAttrModifierLayer, bool)"/>
    /// </summary>
    /// <param name="layer"></param>
    /// <param name="type"></param>
    /// <param name="value"></param>
    /// <param name="isRefresh"></param>
    public void TakeModifier(float value, EAttrType type, EAttrModifierLayer layer, bool isRefresh = true)
    {
        attributes[(int)type].TakeModifier(value, type, layer, isRefresh);

        if (isRefresh)
        {
            RecalculateAttr(type);
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Recalculate a certain attribute.
    /// </summary>
    /// <param name="type"></param>
    private void RecalculateAttr(EAttrType type, bool isForced = false)
    {
        float _previous = GetAttr(type);

        attributes[(int)type].Recalculate(isForced);

        // trigger attribute change event
        OnAttrChange?.Invoke(type, _previous, GetAttr(type));
    }
Exemplo n.º 3
0
 private void Awake()
 {
     // initialize attribute containers
     attributes = new Attribute[EnumArray.AttrType.Length];
     for (int i = 0; i < attributes.Length; ++i)
     {
         EAttrType _type = (EAttrType)i;
         attributes[i] = FAttribute.Create(attrPreset.GetAttrPreset(_type), _type);
     }
 }
Exemplo n.º 4
0
    public static IAttribute Create(AttrPresetTpl attrPreset, EAttrType type)
    {
        bool _isInversed = false;

        // decide type of calculator
        switch (type)
        {
        case EAttrType.Dodge:
        case EAttrType.Armor:
            _isInversed = true;
            break;
        }

        return(new Attribute(attrPreset, _isInversed));
    }
Exemplo n.º 5
0
    /// <summary>
    /// Remove a modifier from this attribute.
    /// </summary>
    /// <param name="attrType"></param>
    /// <param name="layer"></param>
    /// <param name="value"></param>
    public void RemoveModifier(float value, EAttrType type, EAttrModifierLayer layer, bool isRefresh = true)
    {
        // keep track of independent
        if (layer == (int)EAttrModifierLayer.Independent)
        {
            independents.Remove(value);
        }
        else
        {
            modifiers[(int)layer] -= value;
        }

        // set dirty
        isModDirty = true;

        // recalculate attribute
        if (isRefresh)
        {
            Recalculate(false);
        }
    }
Exemplo n.º 6
0
 /// <summary>
 /// <see cref="IAttrModifierTaker.RemoveModifier(float, EAttrType, EAttrModifierLayer, bool)"/>
 /// </summary>
 /// <param name="layer"></param>
 /// <param name="type"></param>
 /// <param name="value"></param>
 /// <param name="isRefresh"></param>
 public void RemoveModifier(float value, EAttrType type, EAttrModifierLayer layer, bool isRefresh = true)
 {
     attributes[(int)type].RemoveModifier(value, type, layer, isRefresh);
 }
Exemplo n.º 7
0
 /// <summary>
 /// <see cref="IAttrHolder.GetAttr(EAttrType)"/>
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public float GetAttr(EAttrType type)
 {
     return(attributes[(int)type].ActualValue);
 }
Exemplo n.º 8
0
 public int GetAttr(EAttrType type)
 {
     return(Attrs[(int)type]);
 }
Exemplo n.º 9
0
 public void SetAttr(EAttrType type, int value)
 {
     Attrs[(int)type] = value;
 }
Exemplo n.º 10
0
 public AttrPresetTpl GetAttrPreset(EAttrType type)
 {
     return(attrPresets[(int)type].AttrTpl);
 }
Exemplo n.º 11
0
 public static string GetPupilAttUrl(EAttrType type)
 {
     return(UIPackage.GetItemURL("Common", "IconPupilAttr_" + (int)type));
 }