# HG changeset patch # User IBBoard # Date 1256763130 0 # Node ID 6f67f16a67fb68d0779035f24da191c4239796ba # Parent 0b413f41e6e35c060b6649e4d58a53ec125ef577 Re #198: Add equipment slots * Add method for getting min equipment percentage * Remove percentage comparison between min and max limts diff -r 0b413f41e6e3 -r 6f67f16a67fb api/Util/UnitEquipmentUtil.cs --- 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; + } } }