Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison 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 |
comparison
equal
deleted
inserted
replaced
53:1b35eed503ef | 54:3a90f70dac73 |
---|---|
10 /// <summary> | 10 /// <summary> |
11 /// Summary description for UnitEquipmentItem. | 11 /// Summary description for UnitEquipmentItem. |
12 /// </summary> | 12 /// </summary> |
13 public class UnitEquipmentItem : WarFoundryObject | 13 public class UnitEquipmentItem : WarFoundryObject |
14 { | 14 { |
15 private bool required, roundUp; | 15 private EquipmentItem item; |
16 private bool required; | |
17 private bool roundUp; | |
18 private int minNum; | |
19 private int maxNum; | |
20 private double minPercentage; | |
21 private double maxPercentage; | |
16 private string mutexGroup; | 22 private string mutexGroup; |
17 private UnitType unitType; | 23 private UnitType unitType; |
18 | 24 |
19 /*public UnitEquipmentItem(XmlElement node, UnitType equipForType) | 25 protected UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipForType) |
20 { | 26 { |
21 EquipmentForUnit = equipForType; | 27 item = equipmentItem; |
22 ID = node.GetAttribute("id"); | |
23 IsRequired = bool.Parse(node.GetAttribute("required")); | |
24 RoundNumberUp = "up".Equals(node.GetAttribute("roundDirection").ToLower()); | |
25 MutexGroup = node.GetAttribute("exclusivityGroup"); | |
26 }*/ | |
27 protected UnitEquipmentItem(UnitType equipForType) | |
28 { | |
29 EquipmentForUnit = equipForType; | 28 EquipmentForUnit = equipForType; |
30 } | 29 } |
30 | |
31 public override string Name | |
32 { | |
33 get { | |
34 return item.Name; | |
35 } | |
36 set { | |
37 base.Name = value; | |
38 } | |
39 } | |
40 | |
41 public string EquipmentItemID | |
42 { | |
43 get { return item.ID; } | |
44 } | |
45 | |
46 public double Cost | |
47 { | |
48 get { return item.Cost; } | |
49 } | |
31 | 50 |
32 public bool IsRequired | 51 public bool IsRequired |
33 { | 52 { |
34 get { return required; } | 53 get { return required; } |
35 set { required = value; } | 54 set { required = value; } |
56 { | 75 { |
57 unitType = value; | 76 unitType = value; |
58 } | 77 } |
59 } | 78 } |
60 } | 79 } |
80 | |
81 public bool IsRatioLimit | |
82 { | |
83 get { return minPercentage!=100 || maxPercentage!=100; } | |
84 } | |
85 | |
86 public int MinNumber | |
87 { | |
88 get { return minNum; } | |
89 set | |
90 { | |
91 if (value >=0 || value == WarFoundryCore.INFINITY) | |
92 { | |
93 minNum = value; | |
94 } | |
95 //TODO: Check Min<Max | |
96 } | |
97 } | |
98 | |
99 public int MaxNumber | |
100 { | |
101 get { return maxNum; } | |
102 set | |
103 { | |
104 if (value >=0 || value == WarFoundryCore.INFINITY) | |
105 { | |
106 maxNum = value; | |
107 } | |
108 //TODO: Check Min<Max | |
109 } | |
110 } | |
111 | |
112 public double MinPercentage | |
113 { | |
114 get { return minPercentage; } | |
115 set | |
116 { | |
117 if (value >=0 && value <= 100) | |
118 { | |
119 minPercentage = value; | |
120 } | |
121 //TODO: Check Min<Max | |
122 } | |
123 } | |
124 | |
125 public double MaxPercentage | |
126 { | |
127 get { return maxPercentage; } | |
128 set | |
129 { | |
130 if (value >=0 && value <= 100) | |
131 { | |
132 maxPercentage = value; | |
133 } | |
134 //TODO: Check Min<Max | |
135 } | |
136 } | |
61 | 137 |
62 public EquipmentItem EquipmentItem | 138 public EquipmentItem EquipmentItem |
63 { | 139 { |
64 get { return EquipmentForUnit == null ? null : EquipmentForUnit.Race.GetEquipmentItem(ID); } | 140 get { return item; } |
65 } | 141 } |
66 | 142 |
67 public override string ToString() | 143 public override string ToString() |
68 { | 144 { |
69 return EquipmentItem.Name+ " ("+EquipmentItem.Cost+"pts each)"; | 145 return EquipmentItem.Name+ " ("+EquipmentItem.Cost+"pts each)"; |
79 { | 155 { |
80 //If the number of items in the MutEx group is greater than one then it must be this item plus another | 156 //If the number of items in the MutEx group is greater than one then it must be this item plus another |
81 return EquipmentForUnit.GetEquipmentItemsByExclusionGroup(MutexGroup).Length > 1; | 157 return EquipmentForUnit.GetEquipmentItemsByExclusionGroup(MutexGroup).Length > 1; |
82 } | 158 } |
83 } | 159 } |
160 | |
161 public static string FormatEquipmentAmount(UnitEquipmentItem item, double amount) | |
162 { | |
163 if (item.IsRatioLimit) | |
164 { | |
165 return Math.Round(amount * 100) + "%"; | |
166 } | |
167 else | |
168 { | |
169 if (amount == WarFoundryCore.INFINITY) | |
170 { | |
171 return "all"; | |
172 } | |
173 else | |
174 { | |
175 return amount.ToString(); | |
176 } | |
177 } | |
178 } | |
84 } | 179 } |
85 } | 180 } |