Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison api/Objects/UnitEquipmentItem.cs @ 183:36adabb1c3ea
Re #198: Add slots with counts to units
* Remove old Min/MaxNumber/Percentage for equipment and replace with limits
* Refactor equipment selections and remove "numeric for ratio" as the limits handle the upper/lower limit differences
* Stop equipment selections taking an amount of 0 for out of range amounts
* Add "IsValid" property for selections
* Removed use of "-1" as an 'infinity' limit - now use 100% as a more correct value
* Change "unlimitedSize" limit in schema to "unitSizeLimit"
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 26 Oct 2009 20:55:04 +0000 |
parents | e83fc7b493f4 |
children | cedf8bba1d52 |
comparison
equal
deleted
inserted
replaced
182:6fe336109128 | 183:36adabb1c3ea |
---|---|
2 // | 2 // |
3 // 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. | 3 // 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. |
4 | 4 |
5 using System; | 5 using System; |
6 using IBBoard.CustomMath; | 6 using IBBoard.CustomMath; |
7 using IBBoard.Limits; | |
7 using IBBoard.WarFoundry.API.Util; | 8 using IBBoard.WarFoundry.API.Util; |
8 | 9 |
9 namespace IBBoard.WarFoundry.API.Objects | 10 namespace IBBoard.WarFoundry.API.Objects |
10 { | 11 { |
11 /// <summary> | 12 /// <summary> |
14 public class UnitEquipmentItem : WarFoundryObject | 15 public class UnitEquipmentItem : WarFoundryObject |
15 { | 16 { |
16 private EquipmentItem item; | 17 private EquipmentItem item; |
17 private bool required; | 18 private bool required; |
18 private bool roundUp; | 19 private bool roundUp; |
19 private int minNum; | |
20 private int maxNum; | |
21 private double minPercentage; | |
22 private double maxPercentage; | |
23 private double costMultiplier; | 20 private double costMultiplier; |
24 private RoundType roundType; | 21 private RoundType roundType; |
25 private string[] mutexGroups; | 22 private string[] mutexGroups; |
26 private UnitType unitType; | 23 private UnitType unitType; |
27 private string slotName = ""; | 24 private string slotName = ""; |
25 private AbstractLimit minLimit; | |
26 private AbstractLimit maxLimit; | |
28 | 27 |
29 public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor) | 28 public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor) |
30 : this(equipmentItem, equipmentFor, new string[0]) | 29 : this(equipmentItem, equipmentFor, new string[0]) |
31 { | 30 { |
32 //Do nothing extra | 31 //Do nothing extra |
124 get { return unitType; } | 123 get { return unitType; } |
125 } | 124 } |
126 | 125 |
127 public bool IsRatioLimit | 126 public bool IsRatioLimit |
128 { | 127 { |
129 get { return minPercentage != 100 || maxPercentage != 100; } | 128 get { return MinLimit is IPercentageLimit && MaxLimit is IPercentageLimit; } |
130 } | 129 } |
131 | 130 |
132 public int MinNumber | 131 /// <summary> |
133 { | 132 /// Gets the Limit object for the minimum number of items that can be taken |
134 get { return minNum; } | 133 /// </summary> |
135 set | 134 public AbstractLimit MinLimit |
136 { | 135 { |
137 if (value >= 0 || value == WarFoundryCore.INFINITY) | 136 get |
137 { | |
138 return (minLimit == null ? new UnlimitedLimit() : minLimit); | |
139 } | |
140 set | |
141 { | |
142 if (value != null) | |
138 { | 143 { |
139 minNum = value; | 144 minLimit = value; |
140 CheckMaxNumber(); | 145 |
146 if (maxLimit == null) | |
147 { | |
148 maxLimit = minLimit; | |
149 } | |
141 } | 150 } |
142 } | 151 } |
143 } | 152 } |
144 | 153 |
145 private void CheckMaxNumber() | 154 /// <summary> |
146 { | 155 /// Gets the Limit object for the maximum number of items that can be taken |
147 if (MaxNumber < MinNumber || MinNumber == WarFoundryCore.INFINITY) | 156 /// </summary> |
148 { | 157 public AbstractLimit MaxLimit |
149 MaxNumber = MinNumber; | 158 { |
150 } | 159 get |
151 } | 160 { |
152 | 161 return (maxLimit == null ? new UnlimitedLimit() : maxLimit); |
153 public int MaxNumber | 162 } |
154 { | 163 set |
155 get { return maxNum; } | 164 { |
156 set | 165 if (value != null) |
157 { | |
158 if (value >= 0 || value == WarFoundryCore.INFINITY) | |
159 { | 166 { |
160 maxNum = value; | 167 maxLimit = value; |
161 CheckMinNumber(); | 168 |
162 } | 169 if (minLimit == null) |
163 } | 170 { |
164 } | 171 minLimit = maxLimit; |
165 | 172 } |
166 private void CheckMinNumber() | |
167 { | |
168 if ((MinNumber > MaxNumber && MaxNumber != WarFoundryCore.INFINITY) || (MinNumber == 0 && MaxNumber != 0)) | |
169 { | |
170 MinNumber = MaxNumber; | |
171 } | |
172 } | |
173 | |
174 public double MinPercentage | |
175 { | |
176 get { return minPercentage; } | |
177 set | |
178 { | |
179 if (value >= 0 && value <= 100) | |
180 { | |
181 minPercentage = value; | |
182 CheckMaxPercentage(); | |
183 } | 173 } |
184 } | |
185 } | |
186 | |
187 private void CheckMaxPercentage() | |
188 { | |
189 if (MaxPercentage < MinPercentage) | |
190 { | |
191 MaxPercentage = MinPercentage; | |
192 } | |
193 } | |
194 | |
195 public double MaxPercentage | |
196 { | |
197 get { return maxPercentage; } | |
198 set | |
199 { | |
200 if (value >= 0 && value <= 100) | |
201 { | |
202 maxPercentage = value; | |
203 CheckMinPercentage(); | |
204 } | |
205 } | |
206 } | |
207 | |
208 private void CheckMinPercentage() | |
209 { | |
210 if (MinPercentage > MaxPercentage|| (MinPercentage == 0 && MaxPercentage != 0)) | |
211 { | |
212 MinPercentage = MaxPercentage; | |
213 } | 174 } |
214 } | 175 } |
215 | 176 |
216 public EquipmentItem EquipmentItem | 177 public EquipmentItem EquipmentItem |
217 { | 178 { |