Mercurial > repos > IBDev-IBBoard.WarFoundry.API
diff api/Objects/UnitEquipmentNumericSelection.cs @ 97:95746083d037
Fixes #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
* Add extra "NumericSelection" type so that ratio selections check the absolute value is within their ratio range
* Update structure of checking for valid values
* Move cost calculation for equipment selection in to abstract class and add abstract method to get "number of items taken"
* Handle numeric selection and numeric selection for ratio differently in Unit
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 09 Aug 2009 12:02:35 +0000 |
parents | ced5a18d9f52 |
children | f7b9423c2a5a |
line wrap: on
line diff
--- a/api/Objects/UnitEquipmentNumericSelection.cs Sun Aug 09 11:09:12 2009 +0000 +++ b/api/Objects/UnitEquipmentNumericSelection.cs Sun Aug 09 12:02:35 2009 +0000 @@ -6,6 +6,9 @@ namespace IBBoard.WarFoundry.API.Objects { + /// <summary> + /// An object to hold the selection of a unit's equipment where the selection was made as an absolute number + /// </summary> public class UnitEquipmentNumericSelection : AbstractUnitEquipmentItemSelection { public UnitEquipmentNumericSelection(Unit unit, UnitEquipmentItem item, double amount) : base(unit, item, amount) @@ -15,23 +18,36 @@ public UnitEquipmentNumericSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, item.MinNumber) { } - - public override double TotalCost + + public override int NumberTaken { get { - return CalculateAmount() * EquipmentItem.Cost; + return (AmountTaken == WarFoundryCore.INFINITY ? EquipmentForUnit.Size : (int) AmountTaken); } } - - private double CalculateAmount() - { - return (AmountTaken == WarFoundryCore.INFINITY ? EquipmentForUnit.Size : AmountTaken); - } - protected override bool IsValidValue (double newValue) + protected bool IsWholeNumber(double newValue) { return newValue == Math.Round(newValue); } + + protected override bool IsInRange(double newValue) + { + bool isInRange = IsWholeNumber(newValue); + + if (newValue == WarFoundryCore.INFINITY) + { + isInRange = (EquipmentItem.MaxNumber == WarFoundryCore.INFINITY); + } + else if (isInRange) + { + int minLimit = (EquipmentItem.MinNumber == WarFoundryCore.INFINITY ? EquipmentForUnit.Size : EquipmentItem.MinNumber); + int maxLimit = (EquipmentItem.MaxNumber == WarFoundryCore.INFINITY ? EquipmentForUnit.Size : EquipmentItem.MaxNumber); + isInRange = (minLimit <= newValue) && (newValue <= maxLimit); + } + + return isInRange; + } } }