ketura

stats.v.3

Aug 24th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.22 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. namespace test
  8. {
  9.     public interface IData : IComparable
  10.     {
  11.         string Name { get; }
  12.         string Description { get; }
  13.         string Notes { get; }
  14.  
  15.         Type DataType { get; }
  16.         object Data { get; }
  17.     }
  18.  
  19.     public abstract class Stat<T> : IData
  20.         where T :IComparable
  21.     {
  22.         public abstract T Value { get; protected set; }
  23.         public virtual object Data { get { return Value; } }
  24.         public virtual string Name { get; }
  25.         public virtual string Description { get; }
  26.         public virtual string Notes { get; }
  27.         public virtual Type DataType { get { return typeof(T); } }
  28.  
  29.         public virtual T Use() { return Value; }
  30.         public virtual T Use(int amount) { return Value; }
  31.  
  32.         public virtual T Set(T t)
  33.         {
  34.             Value = t;
  35.             return Value;
  36.         }
  37.         public virtual T SetAndUse(T t, int count = 1)
  38.         {
  39.             Set(t);
  40.             return Use(count);
  41.         }
  42.  
  43.         public abstract int CompareTo(object obj);
  44.  
  45.         public Stat() : this("UnnamedStat", default(T), null, null) { }
  46.         public Stat(string name) : this(name, default(T), null, null) { }
  47.         public Stat(string name, T value) : this(name, value, null, null) { }
  48.         public Stat(string name, T value, string desc, string notes)
  49.         {
  50.             Name = name;
  51.             Description = desc;
  52.             Notes = notes;
  53.             Value = value;
  54.         }
  55.     }
  56.  
  57.     public abstract class SimpleStat<T> : Stat<T>
  58.         where T : IComparable, IConvertible
  59.     {
  60.         public override T Value { get; protected set; }
  61.  
  62.         public override T Set(T t)
  63.         {
  64.             Value = t;
  65.             return t;
  66.         }
  67.  
  68.         public override int CompareTo(object obj)
  69.         {
  70.             if (obj == null)
  71.                 return 1;
  72.             //if(obj is T t)
  73.             if(obj is T)
  74.             {
  75.                 return Value.CompareTo(obj);
  76.             }
  77.  
  78.             if(obj is SimpleStat<T>)
  79.             {
  80.                 SimpleStat<T> other = (SimpleStat<T>)obj;
  81.                 return Value.CompareTo(other.Value);
  82.             }
  83.  
  84.             throw new ArgumentException("Object is not comparable");
  85.         }
  86.  
  87.         public SimpleStat() : this("UnnamedStat", default(T), null, null) { }
  88.         public SimpleStat(string name) : this(name, default(T), null, null) { }
  89.         public SimpleStat(string name, T value) : this(name, value, null, null) { }
  90.         public SimpleStat(string name, T value, string desc, string notes) : base(name, value, desc, notes) { }
  91.  
  92.     }
  93.  
  94.     public class StringStat : SimpleStat<string>
  95.     {
  96.         public StringStat() : this("UnnamedStat", null, null, null) { }
  97.         public StringStat(string name) : this(name, null, null, null) { }
  98.         public StringStat(string name, string value) : this(name, value, null, null) { }
  99.         public StringStat(string name, string value, string desc, string notes) : base(name, value, desc, notes) { }
  100.     }
  101.     public class BoolStat : SimpleStat<bool>
  102.     {
  103.         public BoolStat() : this("UnnamedStat", false, null, null) { }
  104.         public BoolStat(string name) : this(name, false, null, null) { }
  105.         public BoolStat(string name, bool value) : this(name, value, null, null) { }
  106.         public BoolStat(string name, bool value, string desc, string notes) : base(name, value, desc, notes) { }
  107.     }
  108.  
  109.     public interface NumericStat : IConvertible, IData { }
  110.  
  111.     public abstract class NumericStat<T> : Stat<T>, NumericStat
  112.             where T : struct, IComparable
  113.     {
  114.         public virtual T MaxLimit { get; }
  115.         public virtual T MinLimit { get; }
  116.         public virtual T MaxValue { get { return MaxLimit; } }
  117.         public virtual T MinValue { get { return MinLimit; } }
  118.  
  119.         public override T Value { get; protected set; }
  120.  
  121.         public override T Set(T amount)
  122.         {
  123.             Value = ClampValue(amount);
  124.             return Value;
  125.         }
  126.  
  127.         protected virtual T ClampValue(T value)
  128.         {
  129.             return (Value.CompareTo(MinValue) < 0) ? MinValue : ((Value.CompareTo(MaxValue) > 0) ? MaxValue : Value);
  130.         }
  131.  
  132.         public abstract TypeCode GetTypeCode();
  133.         public abstract bool ToBoolean(IFormatProvider provider);
  134.         public abstract char ToChar(IFormatProvider provider);
  135.         public abstract sbyte ToSByte(IFormatProvider provider);
  136.         public abstract byte ToByte(IFormatProvider provider);
  137.         public abstract short ToInt16(IFormatProvider provider);
  138.         public abstract ushort ToUInt16(IFormatProvider provider);
  139.         public abstract int ToInt32(IFormatProvider provider);
  140.         public abstract uint ToUInt32(IFormatProvider provider);
  141.         public abstract long ToInt64(IFormatProvider provider);
  142.         public abstract ulong ToUInt64(IFormatProvider provider);
  143.         public abstract float ToSingle(IFormatProvider provider);
  144.         public abstract double ToDouble(IFormatProvider provider);
  145.         public abstract decimal ToDecimal(IFormatProvider provider);
  146.         public abstract DateTime ToDateTime(IFormatProvider provider);
  147.         public abstract string ToString(IFormatProvider provider);
  148.         public abstract object ToType(Type conversionType, IFormatProvider provider);
  149.  
  150.         public virtual bool ToBoolean() { return ToBoolean(null); }
  151.         public virtual char ToChar() { return ToChar(null); }
  152.         public virtual sbyte ToSByte() { return ToSByte(null); }
  153.         public virtual byte ToByte() { return ToByte(null); }
  154.         public virtual short ToInt16() { return ToInt16(null); }
  155.         public virtual ushort ToUInt16() { return ToUInt16(null); }
  156.         public virtual int ToInt32() { return ToInt32(null); }
  157.         public virtual uint ToUInt32() { return ToUInt32(null); }
  158.         public virtual long ToInt64() { return ToInt64(null); }
  159.         public virtual ulong ToUInt64() { return ToUInt64(null); }
  160.         public virtual float ToSingle() { return ToSingle(null); }
  161.         public virtual double ToDouble() { return ToDouble(null); }
  162.         public virtual decimal ToDecimal() { return ToDecimal(null); }
  163.         public virtual DateTime ToDateTime() { return ToDateTime(null); }
  164.         public virtual string ToString() { return ToString(null); }
  165.         public virtual object ToType(Type conversionType) { return ToType(conversionType, null); }
  166.  
  167.         public NumericStat() : this("UnnamedStat", default(T), default(T), default(T), null, null) { }
  168.         public NumericStat(string name) : this(name, default(T), default(T), default(T), null, null) { }
  169.         public NumericStat(string name, T value) : this(name, value, default(T), default(T), null, null) { }
  170.         public NumericStat(string name, T value, T min, T max) : this(name, value, min, max, null, null) { }
  171.         public NumericStat(string name, T value, T min, T max, string desc, string notes) : base(name, value, desc, notes)
  172.         {
  173.             MaxLimit = max;
  174.             MinLimit = min;
  175.         }
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment