diff api/Objects/UnitEquipmentItem.cs @ 183:36adabb1c3ea

Re #198: Add slots with counts to units * Remove old Min/MaxNumber/Percentage for equipment and replace with limits * Refactor equipment selections and remove "numeric for ratio" as the limits handle the upper/lower limit differences * Stop equipment selections taking an amount of 0 for out of range amounts * Add "IsValid" property for selections * Removed use of "-1" as an 'infinity' limit - now use 100% as a more correct value * Change "unlimitedSize" limit in schema to "unitSizeLimit"
author IBBoard <dev@ibboard.co.uk>
date Mon, 26 Oct 2009 20:55:04 +0000
parents e83fc7b493f4
children cedf8bba1d52
line wrap: on
line diff
--- a/api/Objects/UnitEquipmentItem.cs	Sat Oct 24 18:59:04 2009 +0000
+++ b/api/Objects/UnitEquipmentItem.cs	Mon Oct 26 20:55:04 2009 +0000
@@ -4,6 +4,7 @@
 
 using System;
 using IBBoard.CustomMath;
+using IBBoard.Limits;
 using IBBoard.WarFoundry.API.Util;
 
 namespace IBBoard.WarFoundry.API.Objects
@@ -16,15 +17,13 @@
 		private EquipmentItem item;
 		private bool required;
 		private bool roundUp;
-		private int minNum;
-		private int maxNum;
-		private double minPercentage;
-		private double maxPercentage;
 		private double costMultiplier;
 		private RoundType roundType;
 		private string[] mutexGroups;
 		private UnitType unitType;
 		private string slotName = "";
+		private AbstractLimit minLimit;
+		private AbstractLimit maxLimit;
 
 		public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor)
 			: this(equipmentItem, equipmentFor, new string[0])
@@ -126,92 +125,54 @@
 
 		public bool IsRatioLimit
 		{
-			get { return minPercentage != 100 || maxPercentage != 100; }
+			get { return MinLimit is IPercentageLimit && MaxLimit is IPercentageLimit; }
 		}
-
-		public int MinNumber
+		
+		/// <summary>
+		/// Gets the Limit object for the minimum number of items that can be taken
+		/// </summary>
+		public AbstractLimit MinLimit
 		{
-			get { return minNum; }
+			get
+			{
+				return (minLimit == null ? new UnlimitedLimit() : minLimit);
+			}
 			set
 			{
-				if (value >= 0 || value == WarFoundryCore.INFINITY)
+				if (value != null)
 				{
-					minNum = value;
-					CheckMaxNumber();
+					minLimit = value;			
+					
+					if (maxLimit == null)
+					{
+						maxLimit = minLimit;
+					}
 				}
 			}
 		}
 		
-		private void CheckMaxNumber()
+		/// <summary>
+		/// Gets the Limit object for the maximum number of items that can be taken
+		/// </summary>
+		public AbstractLimit MaxLimit
 		{
-			if (MaxNumber < MinNumber || MinNumber == WarFoundryCore.INFINITY)
-			{
-				MaxNumber = MinNumber;
-			}
-		}
-
-		public int MaxNumber
-		{
-			get { return maxNum; }
-			set
+			get
 			{
-				if (value >= 0 || value == WarFoundryCore.INFINITY)
-				{
-					maxNum = value;
-					CheckMinNumber();
-				}				
+				return (maxLimit == null ? new UnlimitedLimit() : maxLimit);
 			}
-		}
-		
-		private void CheckMinNumber()
-		{
-			if ((MinNumber > MaxNumber && MaxNumber != WarFoundryCore.INFINITY) || (MinNumber == 0 && MaxNumber != 0))
-			{
-				MinNumber = MaxNumber;
-			}
-		}
-
-		public double MinPercentage
-		{
-			get { return minPercentage; }
 			set
 			{
-				if (value >= 0 && value <= 100)
+				if (value != null)
 				{
-					minPercentage = value;
-					CheckMaxPercentage();
+					maxLimit = value;					
+					
+					if (minLimit == null)
+					{
+						minLimit = maxLimit;
+					}
 				}
 			}
 		}
-		
-		private void CheckMaxPercentage()
-		{
-			if (MaxPercentage < MinPercentage)
-			{
-				MaxPercentage = MinPercentage;
-			}
-		}
-
-		public double MaxPercentage
-		{
-			get { return maxPercentage; }
-			set
-			{
-				if (value >= 0 && value <= 100)
-				{
-					maxPercentage = value;
-					CheckMinPercentage();
-				}
-			}
-		}
-		
-		private void CheckMinPercentage()
-		{
-			if (MinPercentage > MaxPercentage|| (MinPercentage == 0 && MaxPercentage != 0))
-			{
-				MinPercentage = MaxPercentage;
-			}
-		}
 
 		public EquipmentItem EquipmentItem
 		{