ketura

CompositeStat

Aug 28th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. public delegate U CombineCompositeStat<T, U>(Dictionary<string, T> stats, List<U> add, List<float> multiply)
  2.         where T : IStatContainer<U>;
  3.  
  4.     public class CompositeStat<T, U> : IStatContainer<U>
  5.         where T : NumericStat, IStatContainer<U>
  6.     {
  7.         public U Value { get { return CombineFunc(Stats, AdditionFactors, MultiplicationFactors); } }
  8.  
  9.         public CombineCompositeStat<T, U> CombineFunc { get; protected set; }
  10.  
  11.         public static U DefaultCompositeCombine(Dictionary<string, T> stats, List<U> add, List<float> multiply)
  12.         {
  13.             T baseStat = stats.FirstOrDefault(x => x.Key.Contains("BASE")).Value;
  14.             T EV = stats.FirstOrDefault(x => x.Key.Contains("EV")).Value;
  15.             T IV = stats.FirstOrDefault(x => x.Key.Contains("IV")).Value;
  16.  
  17.             //U result = (baseStat.Value + IV.Value) * EV.Value;
  18.             return (U)typeof(U).GetDefaultValue();
  19.         }
  20.  
  21.         public Dictionary<string, T> Stats { get; protected set; }
  22.  
  23.         public List<U> AdditionFactors { get; protected set; }
  24.         public List<float> MultiplicationFactors { get; protected set; }
  25.  
  26.         public CompositeStat() : this(new List<T>(), DefaultCompositeCombine) { }
  27.         public CompositeStat(params T[] stats) : this(stats, DefaultCompositeCombine) { }
  28.         public CompositeStat(IEnumerable<T> stats, CombineCompositeStat<T, U> func, IEnumerable<U> adders=null, IEnumerable<float> multipliers=null)
  29.         {
  30.             CombineFunc = func;
  31.  
  32.             Stats = new Dictionary<string, T>();
  33.             foreach (var stat in stats)
  34.                 Stats.Add(stat.Name, stat);
  35.  
  36.             AdditionFactors = new List<U>();
  37.             AdditionFactors.AddRange(adders ?? new List<U>());
  38.  
  39.             MultiplicationFactors = new List<float>();
  40.             MultiplicationFactors.AddRange(multipliers ?? new List<float>());
  41.         }
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment