Advertisement
ketura

stats.v.4

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