Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/UnitEquipmentItem.cs @ 173:e83fc7b493f4
Fixes #195: Setting max equipment without min may not function correctly
* Fix infinity ("equip all") issues
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 12 Oct 2009 19:51:19 +0000 |
parents | f364a9e5463e |
children | 36adabb1c3ea |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
101
diff
changeset
|
1 // This file (UnitEquipmentItem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
15 | 2 // |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
101
diff
changeset
|
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. |
15 | 4 |
82 | 5 using System; |
171
85dc413279a4
* Change imports to stop references to deprecated code
IBBoard <dev@ibboard.co.uk>
parents:
170
diff
changeset
|
6 using IBBoard.CustomMath; |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
157
diff
changeset
|
7 using IBBoard.WarFoundry.API.Util; |
82 | 8 |
9 namespace IBBoard.WarFoundry.API.Objects | |
10 { | |
11 /// <summary> | |
12 /// Summary description for UnitEquipmentItem. | |
170 | 13 /// </summary> |
14 public class UnitEquipmentItem : WarFoundryObject | |
15 { | |
16 private EquipmentItem item; | |
17 private bool required; | |
18 private bool roundUp; | |
19 private int minNum; | |
20 private int maxNum; | |
21 private double minPercentage; | |
22 private double maxPercentage; | |
23 private double costMultiplier; | |
24 private RoundType roundType; | |
25 private string[] mutexGroups; | |
26 private UnitType unitType; | |
27 private string slotName = ""; | |
28 | |
29 public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor) | |
30 : this(equipmentItem, equipmentFor, new string[0]) | |
31 { | |
32 //Do nothing extra | |
33 } | |
34 | |
35 public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor, params string[] mutexGroups) | |
36 { | |
37 item = equipmentItem; | |
38 unitType = equipmentFor; | |
39 this.mutexGroups = mutexGroups; | |
40 unitType.AddEquipmentItem(this); | |
41 } | |
42 | |
43 public override string Name | |
44 { | |
45 get | |
46 { | |
47 return item.Name; | |
48 } | |
49 set | |
50 { | |
51 base.Name = value; | |
52 } | |
53 } | |
54 | |
55 public override string ID | |
56 { | |
57 get | |
58 { | |
59 return (EquipmentForUnit == null ? base.ID : EquipmentForUnit.ID) + EquipmentItemID; | |
60 } | |
61 set | |
62 { | |
63 base.ID = value; | |
64 } | |
65 } | |
66 | |
67 | |
68 public string EquipmentItemID | |
69 { | |
70 get { return item.ID; } | |
71 } | |
72 | |
73 public double Cost | |
74 { | |
75 get | |
76 { | |
77 return IBBMath.Round(EquipmentItem.Cost * CostMultiplier, CostRoundType); | |
78 } | |
79 } | |
80 | |
81 public double CostMultiplier | |
82 { | |
83 get { return costMultiplier; } | |
84 set | |
85 { | |
86 costMultiplier = value; | |
87 } | |
88 } | |
89 | |
90 public RoundType CostRoundType | |
91 { | |
92 get { return roundType; } | |
93 set | |
94 { | |
95 roundType = value; | |
96 } | |
97 } | |
98 | |
99 public bool IsRequired | |
100 { | |
101 get { return required; } | |
102 set { required = value; } | |
103 } | |
104 | |
105 public bool RoundNumberUp | |
106 { | |
107 get { return roundUp; } | |
108 set { roundUp = value; } | |
109 } | |
110 | |
111 [Obsolete("Use MutexGroups instead for greater flexibility")] | |
112 public string MutexGroup | |
113 { | |
114 get { return (mutexGroups.Length == 0 ? "" : mutexGroups[0]); } | |
115 } | |
116 | |
117 public String[] MutexGroups | |
118 { | |
119 get { return (string[]) mutexGroups.Clone(); } | |
120 } | |
121 | |
122 public UnitType EquipmentForUnit | |
123 { | |
124 get { return unitType; } | |
125 } | |
126 | |
127 public bool IsRatioLimit | |
128 { | |
129 get { return minPercentage != 100 || maxPercentage != 100; } | |
130 } | |
131 | |
132 public int MinNumber | |
133 { | |
134 get { return minNum; } | |
135 set | |
136 { | |
137 if (value >= 0 || value == WarFoundryCore.INFINITY) | |
138 { | |
139 minNum = value; | |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
140 CheckMaxNumber(); |
170 | 141 } |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
142 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
143 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
144 |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
145 private void CheckMaxNumber() |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
146 { |
173
e83fc7b493f4
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
172
diff
changeset
|
147 if (MaxNumber < MinNumber || MinNumber == WarFoundryCore.INFINITY) |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
148 { |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
149 MaxNumber = MinNumber; |
170 | 150 } |
151 } | |
152 | |
153 public int MaxNumber | |
154 { | |
155 get { return maxNum; } | |
156 set | |
157 { | |
158 if (value >= 0 || value == WarFoundryCore.INFINITY) | |
159 { | |
160 maxNum = value; | |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
161 CheckMinNumber(); |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
162 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
163 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
164 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
165 |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
166 private void CheckMinNumber() |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
167 { |
173
e83fc7b493f4
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
172
diff
changeset
|
168 if ((MinNumber > MaxNumber && MaxNumber != WarFoundryCore.INFINITY) || (MinNumber == 0 && MaxNumber != 0)) |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
169 { |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
170 MinNumber = MaxNumber; |
170 | 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; | |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
182 CheckMaxPercentage(); |
170 | 183 } |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
184 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
185 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
186 |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
187 private void CheckMaxPercentage() |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
188 { |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
189 if (MaxPercentage < MinPercentage) |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
190 { |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
191 MaxPercentage = MinPercentage; |
170 | 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; | |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
203 CheckMinPercentage(); |
170 | 204 } |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
205 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
206 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
207 |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
208 private void CheckMinPercentage() |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
209 { |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
210 if (MinPercentage > MaxPercentage|| (MinPercentage == 0 && MaxPercentage != 0)) |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
211 { |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
212 MinPercentage = MaxPercentage; |
170 | 213 } |
214 } | |
215 | |
216 public EquipmentItem EquipmentItem | |
217 { | |
218 get { return item; } | |
219 } | |
220 | |
221 public override string ToString() | |
222 { | |
223 return EquipmentItem.Name + " (" + Cost + "pts each)"; | |
224 } | |
225 | |
226 public bool HasAlternatives() | |
227 { | |
228 if (MutexGroups.Length == 0) | |
229 { | |
230 return false; | |
231 } | |
232 else if (EquipmentForUnit == null) | |
233 { | |
234 return false; | |
235 } | |
236 else | |
237 { | |
238 //If the number of items in the MutEx group is greater than one then it must be this item plus another | |
239 return EquipmentForUnit.GetEquipmentItemsByExclusionGroups(MutexGroups).Length > 1; | |
240 } | |
241 } | |
242 | |
243 public ArmourType ItemArmourType | |
244 { | |
245 get { return EquipmentItem.ItemArmourType; } | |
246 } | |
247 | |
248 public string Description | |
249 { | |
250 get { return EquipmentItem.Description; } | |
251 } | |
252 | |
253 public Race EquipmentForRace | |
254 { | |
255 get { return EquipmentItem.EquipmentForRace; } | |
256 } | |
257 | |
258 public bool CanBeUsedWithItem(EquipmentItem item) | |
259 { | |
260 return EquipmentItem.CanBeUsedWithItem(item); | |
261 } | |
262 | |
263 public bool CanBeUsedWithArmourType(ArmourType otherItemType) | |
264 { | |
265 return EquipmentItem.CanBeUsedWithArmourType(otherItemType); | |
266 } | |
267 | |
268 [Obsolete("Use UnitEquipmentUtil method instead")] | |
269 public bool IsMutuallyExclusive(UnitEquipmentItem item) | |
270 { | |
271 return UnitEquipmentUtil.ItemsAreMutuallyExclusive(this, item); | |
272 } | |
273 | |
274 public string SlotName | |
275 { | |
276 get { return slotName; } | |
277 set | |
278 { | |
279 if (value != null && value != "") | |
280 { | |
281 slotName = value; | |
282 } | |
283 } | |
284 } | |
82 | 285 } |
286 } |