Mercurial > repos > IBDev-IBBoard.WarFoundry.API
changeset 203:df4e56e2ee71
Re #208: equipment slot issues
* Consolidate some code in to one line
* Make min/max percentage methods get the min/max of the calculated percentage and the percentage based on the numeric limit to ensure percentage is never greater than or less than (as appropriate) the numeric limit
Also:
* Remove Math.Min and Math.Max calls from Min/Max equipment count methods - we're assuming min < max in the percentages, so assume it here as well
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 06 Nov 2009 20:48:07 +0000 |
parents | 37ad50823531 |
children | 3ef067225dc3 |
files | api/Util/UnitEquipmentUtil.cs |
diffstat | 1 files changed, 12 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/api/Util/UnitEquipmentUtil.cs Fri Nov 06 20:11:30 2009 +0000 +++ b/api/Util/UnitEquipmentUtil.cs Fri Nov 06 20:48:07 2009 +0000 @@ -102,10 +102,8 @@ } public static int GetMaxEquipmentCount (Unit unit, UnitEquipmentItem equip) - { - int unitSize = unit.Size; - int max = Math.Max(equip.MinLimit.GetLimit(unitSize), equip.MaxLimit.GetLimit (unitSize)); - return GetEquipmentCountLimit (unit, max, equip); + { + return GetEquipmentCountLimit (unit, equip.MaxLimit.GetLimit(unit.Size), equip); } private static int GetEquipmentCountLimit (Unit unit, int currLimit, UnitEquipmentItem equip) @@ -129,10 +127,8 @@ public static int GetMinEquipmentCount (Unit unit, UnitEquipmentItem equip) - { - int unitSize = unit.Size; - int min = Math.Min (equip.MinLimit.GetLimit (unitSize), equip.MaxLimit.GetLimit (unitSize)); - return GetEquipmentCountLimit (unit, min, equip); + { + return GetEquipmentCountLimit (unit, equip.MinLimit.GetLimit(unit.Size), equip); } public static bool IsEquipmentRatioLimited(Unit unit, UnitEquipmentItem equip) @@ -143,7 +139,9 @@ public static double GetMaxEquipmentPercentage(Unit unit, UnitEquipmentItem equip) { - return GetMinOfSlotLimitAndEquipmentLimit(equip, equip.MaxLimit, unit); + double limitMax = GetMinOfSlotLimitAndEquipmentLimit(equip, equip.MaxLimit, unit); + double countMax = GetPercentageOfUnitSize(GetMaxEquipmentCount(unit, equip), unit); + return Math.Max(limitMax, countMax); } private static double GetPercentageOfUnitSize(int number, Unit unit) @@ -158,8 +156,7 @@ if (slotLimit is IPercentageLimit) { - limit = ((IPercentageLimit)slotLimit).Percentage; - limit = limit - GetPercentageOfUnitSize(unit.GetEquipmentAmountInSlotExcludingItem(equip), unit); + limit = ((IPercentageLimit)slotLimit).Percentage - GetPercentageOfUnitSize(unit.GetEquipmentAmountInSlotExcludingItem(equip), unit); } else { @@ -180,8 +177,10 @@ } public static double GetMinEquipmentPercentage(Unit unit, UnitEquipmentItem equip) - { - return GetMinOfSlotLimitAndEquipmentLimit(equip, equip.MinLimit, unit); + { + double limitMin = GetMinOfSlotLimitAndEquipmentLimit(equip, equip.MinLimit, unit); + double countMin = GetPercentageOfUnitSize(GetMinEquipmentCount(unit, equip), unit); + return Math.Min(limitMin, countMin); } } }