Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace test
- {
- public interface IData : IComparable
- {
- string Name { get; }
- string Description { get; }
- string Notes { get; }
- Type DataType { get; }
- object Data { get; }
- }
- public abstract class Stat<T> : IData
- where T :IComparable
- {
- public abstract T Value { get; protected set; }
- public virtual object Data { get { return Value; } }
- public virtual string Name { get; }
- public virtual string Description { get; }
- public virtual string Notes { get; }
- public virtual Type DataType { get { return typeof(T); } }
- public virtual T Use() { return Value; }
- public virtual T Use(int amount) { return Value; }
- public virtual T Set(T t)
- {
- Value = t;
- return Value;
- }
- public virtual T SetAndUse(T t, int count = 1)
- {
- Set(t);
- return Use(count);
- }
- public abstract int CompareTo(object obj);
- public Stat() : this("UnnamedStat", default(T), null, null) { }
- public Stat(string name) : this(name, default(T), null, null) { }
- public Stat(string name, T value) : this(name, value, null, null) { }
- public Stat(string name, T value, string desc, string notes)
- {
- Name = name;
- Description = desc;
- Notes = notes;
- Value = value;
- }
- }
- public abstract class SimpleStat<T> : Stat<T>
- where T : IComparable, IConvertible
- {
- public override T Value { get; protected set; }
- public override T Set(T t)
- {
- Value = t;
- return t;
- }
- public override int CompareTo(object obj)
- {
- if (obj == null)
- return 1;
- //if(obj is T t)
- if(obj is T)
- {
- return Value.CompareTo(obj);
- }
- if(obj is SimpleStat<T>)
- {
- SimpleStat<T> other = (SimpleStat<T>)obj;
- return Value.CompareTo(other.Value);
- }
- throw new ArgumentException("Object is not comparable");
- }
- public SimpleStat() : this("UnnamedStat", default(T), null, null) { }
- public SimpleStat(string name) : this(name, default(T), null, null) { }
- public SimpleStat(string name, T value) : this(name, value, null, null) { }
- public SimpleStat(string name, T value, string desc, string notes) : base(name, value, desc, notes) { }
- }
- public class StringStat : SimpleStat<string>
- {
- public StringStat() : this("UnnamedStat", null, null, null) { }
- public StringStat(string name) : this(name, null, null, null) { }
- public StringStat(string name, string value) : this(name, value, null, null) { }
- public StringStat(string name, string value, string desc, string notes) : base(name, value, desc, notes) { }
- }
- public class BoolStat : SimpleStat<bool>
- {
- public BoolStat() : this("UnnamedStat", false, null, null) { }
- public BoolStat(string name) : this(name, false, null, null) { }
- public BoolStat(string name, bool value) : this(name, value, null, null) { }
- public BoolStat(string name, bool value, string desc, string notes) : base(name, value, desc, notes) { }
- }
- public interface NumericStat : IConvertible, IData { }
- public abstract class NumericStat<T> : Stat<T>, NumericStat
- where T : struct, IComparable
- {
- public virtual T MaxLimit { get; }
- public virtual T MinLimit { get; }
- public virtual T MaxValue { get { return MaxLimit; } }
- public virtual T MinValue { get { return MinLimit; } }
- public override T Value { get; protected set; }
- public override T Set(T amount)
- {
- Value = ClampValue(amount);
- return Value;
- }
- protected virtual T ClampValue(T value)
- {
- return (Value.CompareTo(MinValue) < 0) ? MinValue : ((Value.CompareTo(MaxValue) > 0) ? MaxValue : value);
- }
- public abstract TypeCode GetTypeCode();
- public abstract bool ToBoolean(IFormatProvider provider);
- public abstract char ToChar(IFormatProvider provider);
- public abstract sbyte ToSByte(IFormatProvider provider);
- public abstract byte ToByte(IFormatProvider provider);
- public abstract short ToInt16(IFormatProvider provider);
- public abstract ushort ToUInt16(IFormatProvider provider);
- public abstract int ToInt32(IFormatProvider provider);
- public abstract uint ToUInt32(IFormatProvider provider);
- public abstract long ToInt64(IFormatProvider provider);
- public abstract ulong ToUInt64(IFormatProvider provider);
- public abstract float ToSingle(IFormatProvider provider);
- public abstract double ToDouble(IFormatProvider provider);
- public abstract decimal ToDecimal(IFormatProvider provider);
- public virtual DateTime ToDateTime(IFormatProvider provider)
- {
- throw new InvalidCastException("Numeric stat cannot be converted to DateTime.");
- }
- public abstract string ToString(IFormatProvider provider);
- public abstract object ToType(Type conversionType, IFormatProvider provider);
- public virtual bool ToBoolean() { return ToBoolean(null); }
- public virtual char ToChar() { return ToChar(null); }
- public virtual sbyte ToSByte() { return ToSByte(null); }
- public virtual byte ToByte() { return ToByte(null); }
- public virtual short ToInt16() { return ToInt16(null); }
- public virtual ushort ToUInt16() { return ToUInt16(null); }
- public virtual int ToInt32() { return ToInt32(null); }
- public virtual uint ToUInt32() { return ToUInt32(null); }
- public virtual long ToInt64() { return ToInt64(null); }
- public virtual ulong ToUInt64() { return ToUInt64(null); }
- public virtual float ToSingle() { return ToSingle(null); }
- public virtual double ToDouble() { return ToDouble(null); }
- public virtual decimal ToDecimal() { return ToDecimal(null); }
- public virtual DateTime ToDateTime() { return ToDateTime(null); }
- public virtual object ToType(Type conversionType) { return ToType(conversionType, null); }
- public NumericStat() : this("UnnamedStat", default(T), default(T), default(T), null, null) { }
- public NumericStat(string name) : this(name, default(T), default(T), default(T), null, null) { }
- public NumericStat(string name, T value) : this(name, value, default(T), default(T), null, null) { }
- public NumericStat(string name, T value, T min, T max) : this(name, value, min, max, null, null) { }
- public NumericStat(string name, T value, T min, T max, string desc, string notes) : base(name, value, desc, notes)
- {
- MaxLimit = max;
- MinLimit = min;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement