diff api/Objects/UnitEquipmentItem.cs @ 167:9ba56a8e5096

Re #198: Add slots with counts to units * Add initial API methods * Add value loading
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Oct 2009 14:59:54 +0000
parents 91f7b8da0b53
children 3045a168714a
line wrap: on
line diff
--- a/api/Objects/UnitEquipmentItem.cs	Tue Oct 06 14:47:06 2009 +0000
+++ b/api/Objects/UnitEquipmentItem.cs	Tue Oct 06 14:59:54 2009 +0000
@@ -10,230 +10,245 @@
 {
 	/// <summary>
 	/// Summary description for UnitEquipmentItem.
-	/// </summary>
-	public class UnitEquipmentItem : WarFoundryObject
-	{
-		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;
-
-		public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor) : this(equipmentItem, equipmentFor, new string[0])
-		{
-			//Do nothing extra
-		}
-		
-		public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor, params string[] mutexGroups)
-		{
-			item = equipmentItem;
-			unitType = equipmentFor;
-			this.mutexGroups = mutexGroups;
-			unitType.AddEquipmentItem(this);
-		}
-		
-		public override string Name
-		{
-			get 
-			{
-				return item.Name;
-			}
-			set
-			{
-				base.Name = value;
-			}
-		}
-
-		public override string ID {
-			get
-			{
-				return (EquipmentForUnit == null ? base.ID : EquipmentForUnit.ID) + EquipmentItemID;
-			}
-			set
-			{
-				base.ID = value;
-			}
-		}
-
-		
-		public string EquipmentItemID
-		{
-			get { return item.ID; }
-		}
-
-        public double Cost
-        {
-            get
-			{
-				return IBBMath.Round(EquipmentItem.Cost * CostMultiplier, CostRoundType);
-			}
-        }
-
-		public double CostMultiplier
-		{
-			get { return costMultiplier; }
-			set
-			{
-				costMultiplier = value;
-			}
-		}
-
-		public RoundType CostRoundType
-		{
-			get { return roundType; }
-			set
-			{
-				roundType = value;
-			}	
-		}
-
-		public bool IsRequired
-		{
-			get { return required; }
-			set { required = value; }
-		}
-
-		public bool RoundNumberUp
-		{
-			get { return roundUp; }
-			set { roundUp = value; }
-		}
-
-		[Obsolete("Use MutexGroups instead for greater flexibility")]
-		public string MutexGroup
-		{
-			get { return (mutexGroups.Length == 0 ? "" : mutexGroups[0]); }
-		}
-
-		public String[] MutexGroups
-		{
-			get { return (string[]) mutexGroups.Clone(); }
-		}
-
-		public UnitType EquipmentForUnit
-		{
-			get { return unitType; }
-		}
-		
-		public bool IsRatioLimit
-		{
-			get { return minPercentage!=100 || maxPercentage!=100; }
-		}
-		
-		public int MinNumber
-		{
-			get { return minNum; }
-			set
-			{
-				if (value >=0 || value == WarFoundryCore.INFINITY)
-				{
-					minNum = value;
-				}
-				//TODO: Check Min<Max
-			}
-		}
-		
-		public int MaxNumber
-		{
-			get { return maxNum; }
-			set
-			{
-				if (value >=0 || value == WarFoundryCore.INFINITY)
-				{
-					maxNum = value;
-				}
-				//TODO: Check Min<Max
-			}
-		}
-		
-		public double MinPercentage
-		{
-			get { return minPercentage; }
-			set
-			{
-				if (value >=0 && value <= 100)
-				{
-					minPercentage = value;
-				}
-				//TODO: Check Min<Max
-			}
-		}
-		
-		public double MaxPercentage
-		{
-			get { return maxPercentage; }
-			set
-			{
-				if (value >=0 && value <= 100)
-				{
-					maxPercentage = value;
-				}
-				//TODO: Check Min<Max
-			}
-		}
-
-		public EquipmentItem EquipmentItem
-		{
-			get { return item; }
-		}
-
-		public override string ToString()
-		{
-			return EquipmentItem.Name + " (" + Cost + "pts each)";
-		}
-
-		public bool HasAlternatives()
-		{
-			if (MutexGroups.Length == 0)
-			{
-				return false;
-			}
-			else if (EquipmentForUnit == null)
-			{
-				return false;
-			}
-			else
-			{
-				//If the number of items in the MutEx group is greater than one then it must be this item plus another
-				return EquipmentForUnit.GetEquipmentItemsByExclusionGroups(MutexGroups).Length > 1;
-			}
-		}
-
-		public ArmourType ItemArmourType
-		{
-			get { return EquipmentItem.ItemArmourType; }
-		}
-		
-		public string Description
-		{
-			get { return EquipmentItem.Description; }
-		}
-		
-		public Race EquipmentForRace
-		{
-			get { return EquipmentItem.EquipmentForRace; }
-		}
-
-		public bool CanBeUsedWithItem(EquipmentItem item)
-		{
-			return EquipmentItem.CanBeUsedWithItem(item);
-		}
-
-		public bool CanBeUsedWithArmourType(ArmourType otherItemType)
-		{
-			return EquipmentItem.CanBeUsedWithArmourType(otherItemType);
-		}
-
-		[Obsolete("Use UnitEquipmentUtil method instead")]
-		public bool IsMutuallyExclusive(UnitEquipmentItem item)
-		{
-			return UnitEquipmentUtil.ItemsAreMutuallyExclusive(this, item);
-		}
+	/// </summary>
+	public class UnitEquipmentItem : WarFoundryObject
+	{
+		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 = "";
+
+		public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor)
+			: this(equipmentItem, equipmentFor, new string[0])
+		{
+			//Do nothing extra
+		}
+
+		public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor, params string[] mutexGroups)
+		{
+			item = equipmentItem;
+			unitType = equipmentFor;
+			this.mutexGroups = mutexGroups;
+			unitType.AddEquipmentItem(this);
+		}
+
+		public override string Name
+		{
+			get
+			{
+				return item.Name;
+			}
+			set
+			{
+				base.Name = value;
+			}
+		}
+
+		public override string ID
+		{
+			get
+			{
+				return (EquipmentForUnit == null ? base.ID : EquipmentForUnit.ID) + EquipmentItemID;
+			}
+			set
+			{
+				base.ID = value;
+			}
+		}
+
+
+		public string EquipmentItemID
+		{
+			get { return item.ID; }
+		}
+
+		public double Cost
+		{
+			get
+			{
+				return IBBMath.Round(EquipmentItem.Cost * CostMultiplier, CostRoundType);
+			}
+		}
+
+		public double CostMultiplier
+		{
+			get { return costMultiplier; }
+			set
+			{
+				costMultiplier = value;
+			}
+		}
+
+		public RoundType CostRoundType
+		{
+			get { return roundType; }
+			set
+			{
+				roundType = value;
+			}
+		}
+
+		public bool IsRequired
+		{
+			get { return required; }
+			set { required = value; }
+		}
+
+		public bool RoundNumberUp
+		{
+			get { return roundUp; }
+			set { roundUp = value; }
+		}
+
+		[Obsolete("Use MutexGroups instead for greater flexibility")]
+		public string MutexGroup
+		{
+			get { return (mutexGroups.Length == 0 ? "" : mutexGroups[0]); }
+		}
+
+		public String[] MutexGroups
+		{
+			get { return (string[]) mutexGroups.Clone(); }
+		}
+
+		public UnitType EquipmentForUnit
+		{
+			get { return unitType; }
+		}
+
+		public bool IsRatioLimit
+		{
+			get { return minPercentage != 100 || maxPercentage != 100; }
+		}
+
+		public int MinNumber
+		{
+			get { return minNum; }
+			set
+			{
+				if (value >= 0 || value == WarFoundryCore.INFINITY)
+				{
+					minNum = value;
+				}
+				//TODO: Check Min<Max
+			}
+		}
+
+		public int MaxNumber
+		{
+			get { return maxNum; }
+			set
+			{
+				if (value >= 0 || value == WarFoundryCore.INFINITY)
+				{
+					maxNum = value;
+				}
+				//TODO: Check Min<Max
+			}
+		}
+
+		public double MinPercentage
+		{
+			get { return minPercentage; }
+			set
+			{
+				if (value >= 0 && value <= 100)
+				{
+					minPercentage = value;
+				}
+				//TODO: Check Min<Max
+			}
+		}
+
+		public double MaxPercentage
+		{
+			get { return maxPercentage; }
+			set
+			{
+				if (value >= 0 && value <= 100)
+				{
+					maxPercentage = value;
+				}
+				//TODO: Check Min<Max
+			}
+		}
+
+		public EquipmentItem EquipmentItem
+		{
+			get { return item; }
+		}
+
+		public override string ToString()
+		{
+			return EquipmentItem.Name + " (" + Cost + "pts each)";
+		}
+
+		public bool HasAlternatives()
+		{
+			if (MutexGroups.Length == 0)
+			{
+				return false;
+			}
+			else if (EquipmentForUnit == null)
+			{
+				return false;
+			}
+			else
+			{
+				//If the number of items in the MutEx group is greater than one then it must be this item plus another
+				return EquipmentForUnit.GetEquipmentItemsByExclusionGroups(MutexGroups).Length > 1;
+			}
+		}
+
+		public ArmourType ItemArmourType
+		{
+			get { return EquipmentItem.ItemArmourType; }
+		}
+
+		public string Description
+		{
+			get { return EquipmentItem.Description; }
+		}
+
+		public Race EquipmentForRace
+		{
+			get { return EquipmentItem.EquipmentForRace; }
+		}
+
+		public bool CanBeUsedWithItem(EquipmentItem item)
+		{
+			return EquipmentItem.CanBeUsedWithItem(item);
+		}
+
+		public bool CanBeUsedWithArmourType(ArmourType otherItemType)
+		{
+			return EquipmentItem.CanBeUsedWithArmourType(otherItemType);
+		}
+
+		[Obsolete("Use UnitEquipmentUtil method instead")]
+		public bool IsMutuallyExclusive(UnitEquipmentItem item)
+		{
+			return UnitEquipmentUtil.ItemsAreMutuallyExclusive(this, item);
+		}
+
+		public string SlotName
+		{
+			get { return slotName; }
+			set
+			{
+				if (value != null && value != "")
+				{
+					slotName = value;
+				}
+			}
+		}
 	}
 }