Exemplo n.º 1
0
 private void CorruptInternal(object obj, int level, float strength, SPRNG rng)
 {
     foreach (var c in _corruptlets)
     {
         c.Corrupt(obj, rng, level);
     }
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 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;
     }
 }