ketura

hybrid_stat.v.1

Aug 25th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using test;
  8.  
  9. namespace Stats
  10. {
  11.     class MoreStats
  12.     {
  13.         public interface HybridStat : IData
  14.         {
  15.             byte Decimals { get; }
  16.             double DecimalFactor { get; }
  17.             double DecimalPart { get; }
  18.         }
  19.  
  20.  
  21.         public abstract class LongHybridStat : NumericStat<long>, HybridStat
  22.         {
  23.             public static readonly byte MaxDecimals = 20;
  24.             public byte Decimals { get; }
  25.  
  26.             public virtual long RawValue { get; protected set; }
  27.  
  28.             //these might need cached since Decimals never changes
  29.             public override long MaxValue { get { return (long)(MaxLimit / DecimalFactor); } }
  30.             public override long MinValue { get { return (long)(MinLimit / DecimalFactor); } }
  31.             public virtual double DecimalFactor { get { return Math.Pow(10, Decimals); } }
  32.  
  33.             public virtual double DecimalPart { get { return (RawValue % DecimalFactor) / DecimalFactor; } }
  34.  
  35.             public override long Value
  36.             {
  37.                 get { return (long)(RawValue / DecimalFactor); }
  38.                 protected set
  39.                 {
  40.  
  41.                     RawValue = ClampValue((long)(value / DecimalFactor));
  42.                 }
  43.             }
  44.  
  45.             protected override long ClampValue(long value)
  46.             {
  47.                 return (value < MinValue) ? MinValue : ((value > MaxValue) ? MaxValue : value);
  48.             }
  49.         }
  50.  
  51.         public abstract class ULongHybridStat : NumericStat<ulong>, HybridStat
  52.         {
  53.             public static readonly byte MaxDecimals = 19;
  54.             public byte Decimals { get; }
  55.  
  56.             public virtual ulong RawValue { get; protected set; }
  57.  
  58.             //these might need cached since Decimals never changes
  59.             public override ulong MaxValue { get { return (ulong)(MaxLimit / DecimalFactor); } }
  60.             public override ulong MinValue { get { return (ulong)(MinLimit / DecimalFactor); } }
  61.             public virtual double DecimalFactor { get { return Math.Pow(10, Decimals); } }
  62.  
  63.             public virtual double DecimalPart { get { return (RawValue % DecimalFactor) / DecimalFactor; } }
  64.  
  65.             public override ulong Value
  66.             {
  67.                 get { return (ulong)(RawValue / DecimalFactor); }
  68.                 protected set
  69.                 {
  70.  
  71.                     RawValue = ClampValue((ulong)(value / DecimalFactor));
  72.                 }
  73.             }
  74.  
  75.             protected override ulong ClampValue(ulong value)
  76.             {
  77.                 return (value < MinValue) ? MinValue : ((value > MaxValue) ? MaxValue : value);
  78.             }
  79.         }
  80.  
  81.  
  82.         //------------------
  83.         //These will go in a mod
  84.         //------------------
  85.  
  86.         //public class ResourceStat<T, U> : ULongStat
  87.         //      where T : ULongHybridStat
  88.         //      where U : ULongHybridStat
  89.         //{
  90.         //  protected T BaseStat { get; set; }
  91.         //  public U CurrentStat { get; protected set; }
  92.  
  93.         //  public override ulong Value
  94.         //  {
  95.         //      get { return BaseStat.Value; }
  96.         //      protected set { BaseStat.Set(value); }
  97.         //  }
  98.  
  99.         //  public ulong Current
  100.         //  {
  101.         //      get { return CurrentStat.Value; }
  102.         //      protected set { CurrentStat.Set(value); }
  103.         //  }
  104.  
  105.         //  public override ulong Use()
  106.         //  {
  107.         //      return BaseStat.Use();
  108.         //  }
  109.  
  110.         //  [Obsolete("This version of Use does not work with a ResourceStat.  Call Use(ulong) instead.", false)]
  111.         //  public override ulong Use(int amount)
  112.         //  {
  113.         //      throw new NotSupportedException("This version of Use does not work with a ResourceStat.  Call Use(ulong) instead.");
  114.         //  }
  115.  
  116.         //  public virtual ulong Use(ulong amount)
  117.         //  {
  118.         //      Set()
  119.         //      return BaseStat.Use(u);
  120.         //  }
  121.  
  122.         //  public override ulong Set(ulong amount)
  123.         //  {
  124.         //      return CurrentStat.Set(amount);
  125.         //  }
  126.         //}
  127.  
  128.         ////------------------
  129.         ////These will go in a Renegade-specific mod
  130.         ////------------------
  131.  
  132.         //public class EVStat : UnsignedHybridStat
  133.         //{
  134.         //  public float ExcerciseAmount { get; }
  135.         //  public ulong UsageThreshold { get; }
  136.  
  137.         //  public override ulong Use()
  138.         //  {
  139.         //      return Use(1L);
  140.         //  }
  141.  
  142.         //  public override ulong Use(ulong u)
  143.         //  {
  144.         //      ulong oldValue = Value;
  145.         //      int count = Math.Max(u / UsageThreshold, 1);
  146.         //      Value = oldValue + (ExcerciseAmount * count);
  147.         //      return oldValue;
  148.         //  }
  149.         //}
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment