Mercurial > repos > IBBoard.WarFoundry.API
view api/Objects/UnitEquipmentNumericSelection.cs @ 181:8c6f55d289b0
Fixes #200: Stats names should be case-insensitive
* ToLower() all stat names/IDs so that they are case-insensitive
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Oct 2009 15:18:00 +0000 |
parents | 2f3cafb69799 |
children | 36adabb1c3ea |
line wrap: on
line source
// This file (UnitEquipmentNumericSelection.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard // // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. using System; 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) { } public UnitEquipmentNumericSelection(Unit unit, UnitEquipmentItem item) : base(unit, item, item.MinNumber) { } public override int NumberTaken { get { return (AmountTaken == WarFoundryCore.INFINITY ? EquipmentForUnit.Size : (int) AmountTaken); } } 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; } public override string GetEquipmentAmountString () { return GetEquipmentAmountString(AmountTaken); } /// <summary> /// Gets a string representing the amount of equipment taken when the amount is a numeric selection /// </summary> /// <param name="amount"> /// A <see cref="System.Double"/> /// </param> /// <returns> /// A <see cref="System.String"/> /// </returns> public static string GetEquipmentAmountString(double amount) { string amountString; if (amount == WarFoundryCore.INFINITY) { amountString = "all"; //TODO: Translate } else { amountString = amount.ToString(); } return amountString; } } }