예제 #1
0
 public void AddResistValue(object effect, ValueType valueType, float value, DamageType damageType, DamageSource damageSource, CheckDamageDelegate handle)
 {
     if (valueType == ValueType.Point)
     {
         if (m_ResistPointValue.ContainsKey(effect))
         {
             m_ResistPointValue[effect] = new DamageResistValue(damageType, damageSource, value, handle);
         }
         else
         {
             m_ResistPointValue.Add(effect, new DamageResistValue(damageType, damageSource, value, handle));
         }
     }
     else
     {
         if (m_ResistPercentValue.ContainsKey(effect))
         {
             m_ResistPercentValue[effect] = new DamageResistValue(damageType, damageSource, value, handle);
         }
         else
         {
             m_ResistPercentValue.Add(effect, new DamageResistValue(damageType, damageSource, value, handle));
         }
     }
 }
예제 #2
0
    /// <summary>
    /// 处理
    /// </summary>
    /// <param name="damageType"></param>
    /// <param name="damageSource"></param>
    public void Process(ref Damage damage)
    {
        //计算点数
        float pointValue = 0;
        var   e          = m_ResistPointValue.GetEnumerator();

        while (e.MoveNext())
        {
            DamageResistValue value = e.Current.Value;
            if (value.CheckDamage(damage))
            {
                pointValue += value.value;
            }
        }
        //计算百分比
        float percentValue = 0;

        e = m_ResistPercentValue.GetEnumerator();
        while (e.MoveNext())
        {
            DamageResistValue value = e.Current.Value;
            if (value.CheckDamage(damage))
            {
                percentValue += value.value;
            }
        }

        float leftDamage = damage.receiveDamageValue - pointValue;

        if (leftDamage > 0)
        {
            leftDamage = leftDamage * (1 - percentValue);
        }
        else
        {
            leftDamage = 0;
        }
        damage.ModifyDamageByResist(leftDamage);
    }