Example #1
0
        private void applyRangeAttributes(WeaponRange weaponRange, RangeBasedWeaponAttributesPatch rangePatch, WeaponAttributesWrapper weaponWrapper)
        {
            if (rangePatch == null)
            {
                return;
            }

            var ranges = weaponWrapper.Ranges;

            var newRanges = ranges.Where(r => r.Range < weaponRange);

            var range = ranges.SingleOrDefault(r => r.Range == weaponRange);

            using (logger.BeginScope($"RangeAttributes{weaponRange}:"))
            {
                if (rangePatch.Remove)
                {
                    logger.Log("(removed)");
                }
                else
                {
                    RangeBasedWeaponAttributesWrapper rangeWrapper;

                    if (range != null)
                    {
                        rangeWrapper = new RangeBasedWeaponAttributesWrapper(range);
                    }
                    else
                    {
                        logger.Log("(created)");
                        rangeWrapper = new RangeBasedWeaponAttributesWrapper(weaponRange);
                    }

                    ApplyRangeBasedWeaponAttributesPatch(rangePatch, rangeWrapper);

                    newRanges = newRanges.Concat(new[] { rangeWrapper });
                }
            }

            newRanges = newRanges.Concat(ranges.Where(r => r.Range > weaponRange));

            weaponWrapper.Ranges = newRanges.ToArray();
        }
Example #2
0
 public void ApplyRangeBasedWeaponAttributesPatch(RangeBasedWeaponAttributesPatch rangePatch, RangeBasedWeaponAttributesWrapper rangeWrapper)
 {
     applyPropertyPatch(rangePatch.Accuracy, () => rangeWrapper.Accuracy, x => Fixed64.UnsafeFromDouble(x));
     applyPropertyPatch(rangePatch.Distance, () => rangeWrapper.Distance, x => Fixed64.UnsafeFromDouble(x));
     applyPropertyPatch(rangePatch.MinDistance, () => rangeWrapper.MinDistance, x => Fixed64.UnsafeFromDouble(x));
 }