changeset 190:6f67f16a67fb

Re #198: Add equipment slots * Add method for getting min equipment percentage * Remove percentage comparison between min and max limts
author IBBoard <dev@ibboard.co.uk>
date Wed, 28 Oct 2009 20:52:10 +0000
parents 0b413f41e6e3
children d63bef60bb51
files api/Util/UnitEquipmentUtil.cs
diffstat 1 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/api/Util/UnitEquipmentUtil.cs	Wed Oct 28 20:42:13 2009 +0000
+++ b/api/Util/UnitEquipmentUtil.cs	Wed Oct 28 20:52:10 2009 +0000
@@ -154,7 +154,7 @@
 			{
 				if (equip.IsRatioLimit)
 				{
-					limit = Math.Max(((IPercentageLimit)equip.MinLimit).Percentage, ((IPercentageLimit)equip.MaxLimit).Percentage);
+					limit = ((IPercentageLimit)equip.MaxLimit).Percentage;
 				}
 				else
 				{
@@ -170,5 +170,36 @@
 			
 			return limit;
 		}
+		
+		public static double GetMinEquipmentPercentage(Unit unit, UnitEquipmentItem equip)
+		{
+			double limit = 0;
+			AbstractLimit slotLimit = GetSlotLimitForItem(unit, equip);
+			
+			
+			if (!(slotLimit is IPercentageLimit || slotLimit is UnlimitedLimit) || unit.GetEquipmentAmountInSlot (equip.SlotName) != 0)
+			{
+				limit = (GetMinEquipmentCount(unit, equip) / (double)unit.Size) * 100.0;
+			}
+			else
+			{
+				if (equip.IsRatioLimit)
+				{
+					limit = ((IPercentageLimit)equip.MinLimit).Percentage;
+				}
+				else
+				{
+					int unitSize = unit.Size;
+					limit = (equip.MinLimit.GetLimit(unitSize) / (double)unitSize) * 100.0;
+				}
+				
+				if (slotLimit is IPercentageLimit)
+				{
+					limit = Math.Min(((IPercentageLimit)slotLimit).Percentage, limit);
+				}
+			}	
+			
+			return limit;
+		}
 	}
 }