Mercurial > repos > IBBoard.WarFoundry.API
diff api/Objects/UnitEquipmentItem.cs @ 54:3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
* Remove min/max from EquipmentItem and add description
* Add min/max numbers and percentages to UnitEquipmentItem
* Make Race schema define min/max number without the ratio (which is the percentage)
* Replace use of EquipmentItem with UnitEquipmentItem because of increased use of UnitEquipmentItem for unit-specific data
* Use doubles instead of floats for equipment amounts
* Distinguish between ratio and absolute limits
* Delete UnitEquipmentItemObj helper class that was purely used for UI
Re #9 - Use smaller methods
* Deprecate long Race and EquipmentItem constructors and ensure all getters/setters exist
Also:
* Migrate Unit to using genericed collections
* Always use GameSystem object for Race, not ID string
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 05 Apr 2009 13:45:23 +0000 |
parents | 306558904c2a |
children | 284ebe05158c |
line wrap: on
line diff
--- a/api/Objects/UnitEquipmentItem.cs Wed Apr 01 19:20:27 2009 +0000 +++ b/api/Objects/UnitEquipmentItem.cs Sun Apr 05 13:45:23 2009 +0000 @@ -11,23 +11,42 @@ /// Summary description for UnitEquipmentItem. /// </summary> public class UnitEquipmentItem : WarFoundryObject - { - private bool required, roundUp; + { + private EquipmentItem item; + private bool required; + private bool roundUp; + private int minNum; + private int maxNum; + private double minPercentage; + private double maxPercentage; private string mutexGroup; private UnitType unitType; + + protected UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipForType) + { + item = equipmentItem; + EquipmentForUnit = equipForType; + } + + public override string Name + { + get { + return item.Name; + } + set { + base.Name = value; + } + } + + public string EquipmentItemID + { + get { return item.ID; } + } - /*public UnitEquipmentItem(XmlElement node, UnitType equipForType) - { - EquipmentForUnit = equipForType; - ID = node.GetAttribute("id"); - IsRequired = bool.Parse(node.GetAttribute("required")); - RoundNumberUp = "up".Equals(node.GetAttribute("roundDirection").ToLower()); - MutexGroup = node.GetAttribute("exclusivityGroup"); - }*/ - protected UnitEquipmentItem(UnitType equipForType) - { - EquipmentForUnit = equipForType; - } + public double Cost + { + get { return item.Cost; } + } public bool IsRequired { @@ -57,11 +76,68 @@ unitType = value; } } + } + + public bool IsRatioLimit + { + get { return minPercentage!=100 || maxPercentage!=100; } + } + + public int MinNumber + { + get { return minNum; } + set + { + if (value >=0 || value == WarFoundryCore.INFINITY) + { + minNum = value; + } + //TODO: Check Min<Max + } + } + + public int MaxNumber + { + get { return maxNum; } + set + { + if (value >=0 || value == WarFoundryCore.INFINITY) + { + maxNum = value; + } + //TODO: Check Min<Max + } + } + + public double MinPercentage + { + get { return minPercentage; } + set + { + if (value >=0 && value <= 100) + { + minPercentage = value; + } + //TODO: Check Min<Max + } + } + + public double MaxPercentage + { + get { return maxPercentage; } + set + { + if (value >=0 && value <= 100) + { + maxPercentage = value; + } + //TODO: Check Min<Max + } } public EquipmentItem EquipmentItem { - get { return EquipmentForUnit == null ? null : EquipmentForUnit.Race.GetEquipmentItem(ID); } + get { return item; } } public override string ToString() @@ -80,6 +156,25 @@ //If the number of items in the MutEx group is greater than one then it must be this item plus another return EquipmentForUnit.GetEquipmentItemsByExclusionGroup(MutexGroup).Length > 1; } + } + + public static string FormatEquipmentAmount(UnitEquipmentItem item, double amount) + { + if (item.IsRatioLimit) + { + return Math.Round(amount * 100) + "%"; + } + else + { + if (amount == WarFoundryCore.INFINITY) + { + return "all"; + } + else + { + return amount.ToString(); + } + } } } }