private void CorruptInternal(object obj, int level, float strength, SPRNG rng) { foreach (var c in _corruptlets) { c.Corrupt(obj, rng, level); } }
public static void Corrupt(object obj, int level, float strength, SPRNG rng) { Corruptor c; if (!_corruptors.TryGetValue(obj.GetType(), out c)) { c = _corruptors[obj.GetType()] = new Corruptor(obj.GetType()); } c.CorruptInternal(obj, level, strength, rng); }
public void Corrupt(object obj, SPRNG rng, int level, float strength = 0.5f) { if (obj.GetType() != _field.DeclaringType) return; if (level < _rank) return; switch (_type) { case CorruptionType.Boolean: _field.SetValue(obj, rng.NextBoolean()); break; case CorruptionType.Int32: _field.SetValue(obj, Lerp((int)_field.GetValue(obj), rng.Next(rangeMinI, rangeMaxI - 1), strength)); break; case CorruptionType.Float: _field.SetValue(obj, Lerp((float)_field.GetValue(obj), rng.NextSingle(rangeMin, rangeMax), strength)); break; case CorruptionType.Double: _field.SetValue(obj, Lerp((double)_field.GetValue(obj), rng.NextDouble(rangeMin, rangeMax), strength)); break; case CorruptionType.Int64: _field.SetValue(obj, Lerp((long)_field.GetValue(obj), rng.NextLong(rangeMinI, rangeMaxI), strength)); break; } }