Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. public abstract class Attribute {
  2.         private int min;
  3.         private int current;
  4.         private int max;
  5.  
  6.         public delegate void ChangeAction (int amount);
  7.         public event ChangeAction OnMinChange;
  8.         public event ChangeAction OnCurrentChange;
  9.         public event ChangeAction OnMaxChange;
  10.  
  11.         public Attribute () {
  12.             this.min = 0;
  13.             this.current = 0;
  14.             this.max = 0;
  15.         }
  16.  
  17.         public int Min {
  18.             get {
  19.                 return this.min;
  20.             }
  21.  
  22.             set {
  23.                 this.min = Math.Min(value, this.max);
  24.                 this.current = Math.Max(value, this.current);
  25.  
  26.                 if (this.OnMinChange != null) {
  27.                     this.OnMinChange(value);
  28.                 }
  29.             }
  30.         }
  31.  
  32.         public int Current {
  33.             get {
  34.                 return this.current;
  35.             }
  36.  
  37.             set {
  38.                 this.current = Math.Min(value, this.max);
  39.                 this.current = Math.Max(value, this.min);
  40.  
  41.                 if (this.OnCurrentChange != null) {
  42.                     this.OnCurrentChange(value);
  43.                 }
  44.             }
  45.         }
  46.  
  47.         public int Max {
  48.             get {
  49.                 return this.max;
  50.             }
  51.  
  52.             set {
  53.                 this.max = Math.Max(value, this.min);
  54.                 this.current = Math.Min(value, this.current);
  55.  
  56.                 if (this.OnMaxChange != null) {
  57.                     this.OnMaxChange(value);
  58.                 }
  59.             }
  60.         }
  61.     }