public static ItemAttributes operator -(ItemAttributes left, ItemAttributes right) { var target = new ItemAttributes(left); var type = target.GetType(); foreach (var fieldInfo in type.GetTypeInfo().DeclaredFields) { if (fieldInfo.Name != "UnmanagedAttributes" && fieldInfo.GetValue(right) != null) { var targetValueRange = (ItemValueRange)fieldInfo.GetValue(target); var rightValueRange = (ItemValueRange)fieldInfo.GetValue(right); if (targetValueRange == null) { targetValueRange = new ItemValueRange(); } targetValueRange -= rightValueRange; if (targetValueRange.Min == 0 && targetValueRange.Max == 0) { targetValueRange = null; } fieldInfo.SetValue(target, targetValueRange - rightValueRange); } } return(target); }
/// <summary> /// Sums up <paramref name="right"/> operand into <paramref name="left"/> operand. /// <paramref name="left"/> is updated by this method (used as a memory and speed optimization of <c>left = left + right</c>). /// </summary> /// <param name="left">Left operand of the addition, can't be <c>null</c>.</param> /// <param name="right">Right operand of the addition, can be <c>null</c>.</param> public static void SumIntoLeftOperand(ItemAttributes left, ItemAttributes right) { if (right == null) { return; } var typeInfo = left.GetType().GetTypeInfo(); var targetType = typeof(ItemValueRange); // TODO: find a better way to handle this particular case... var powerCooldownReductionPercentAll = left.powerCooldownReductionPercentAll; foreach (var fieldInfo in typeInfo.DeclaredFields) { if (fieldInfo.FieldType == targetType) { var rightValue = fieldInfo.GetValue(right); if (rightValue != null) { var leftValueRange = (ItemValueRange)fieldInfo.GetValue(left); var rightValueRange = (ItemValueRange)rightValue; if (leftValueRange == null) { fieldInfo.SetValue(left, new ItemValueRange(rightValueRange)); } else { fieldInfo.SetValue(left, leftValueRange + rightValueRange); } } } } // TODO: find a better way to handle this particular case... if (powerCooldownReductionPercentAll != null) { left.powerCooldownReductionPercentAll = powerCooldownReductionPercentAll; ItemValueRange.SumAsPercentOnRemainingIntoLeftOperand(left.powerCooldownReductionPercentAll, right.powerCooldownReductionPercentAll); } }
public static ItemAttributes operator *(ItemAttributes left, ItemAttributes right) { var target = new ItemAttributes(left); var type = target.GetType(); foreach (var fieldInfo in type.GetTypeInfo().DeclaredFields) { if (fieldInfo.Name != "UnmanagedAttributes" && fieldInfo.GetValue(right) != null) { var targetValueRange = (ItemValueRange)fieldInfo.GetValue(target); var rightValueRange = (ItemValueRange)fieldInfo.GetValue(right); if (targetValueRange == null) { targetValueRange = new ItemValueRange(1); } fieldInfo.SetValue(target, targetValueRange * rightValueRange); } } return target; }