Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/UnitEquipmentItem.cs @ 252:a54da5a8b5bb
Re #268: Restructure stats for re-use
* Add "Member Type" class
* Add member type setting and getting to Race
* Load member types from XML files
* Make unit type pull stat line from stats or first member type, or fall back to a blank stat line
* Change Stats object to initialise blank values
* Change schema
* Make stats optional
* Add member type list to race
* Add optional member type references to units
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 25 Apr 2010 15:07:08 +0000 |
parents | 3ef067225dc3 |
children | 7933d852181e |
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; |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
7 using IBBoard.Limits; |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
157
diff
changeset
|
8 using IBBoard.WarFoundry.API.Util; |
82 | 9 |
10 namespace IBBoard.WarFoundry.API.Objects | |
11 { | |
12 /// <summary> | |
13 /// Summary description for UnitEquipmentItem. | |
170 | 14 /// </summary> |
15 public class UnitEquipmentItem : WarFoundryObject | |
16 { | |
17 private EquipmentItem item; | |
18 private bool required; | |
19 private bool roundUp; | |
20 private double costMultiplier; | |
21 private RoundType roundType; | |
22 private string[] mutexGroups; | |
23 private UnitType unitType; | |
24 private string slotName = ""; | |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
25 private AbstractLimit minLimit; |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
26 private AbstractLimit maxLimit; |
170 | 27 |
28 public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor) | |
29 : this(equipmentItem, equipmentFor, new string[0]) | |
30 { | |
31 //Do nothing extra | |
32 } | |
33 | |
34 public UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipmentFor, params string[] mutexGroups) | |
35 { | |
36 item = equipmentItem; | |
37 unitType = equipmentFor; | |
38 this.mutexGroups = mutexGroups; | |
39 unitType.AddEquipmentItem(this); | |
40 } | |
41 | |
42 public override string Name | |
43 { | |
44 get | |
45 { | |
46 return item.Name; | |
47 } | |
48 set | |
49 { | |
50 base.Name = value; | |
51 } | |
52 } | |
53 | |
54 public override string ID | |
55 { | |
56 get | |
57 { | |
58 return (EquipmentForUnit == null ? base.ID : EquipmentForUnit.ID) + EquipmentItemID; | |
59 } | |
60 set | |
61 { | |
62 base.ID = value; | |
63 } | |
64 } | |
65 | |
66 | |
67 public string EquipmentItemID | |
68 { | |
69 get { return item.ID; } | |
70 } | |
71 | |
72 public double Cost | |
73 { | |
74 get | |
75 { | |
76 return IBBMath.Round(EquipmentItem.Cost * CostMultiplier, CostRoundType); | |
77 } | |
78 } | |
79 | |
80 public double CostMultiplier | |
81 { | |
82 get { return costMultiplier; } | |
83 set | |
84 { | |
85 costMultiplier = value; | |
86 } | |
87 } | |
88 | |
89 public RoundType CostRoundType | |
90 { | |
91 get { return roundType; } | |
92 set | |
93 { | |
94 roundType = value; | |
95 } | |
96 } | |
97 | |
98 public bool IsRequired | |
99 { | |
100 get { return required; } | |
101 set { required = value; } | |
102 } | |
103 | |
104 public bool RoundNumberUp | |
105 { | |
106 get { return roundUp; } | |
107 set { roundUp = value; } | |
108 } | |
109 | |
110 [Obsolete("Use MutexGroups instead for greater flexibility")] | |
111 public string MutexGroup | |
112 { | |
113 get { return (mutexGroups.Length == 0 ? "" : mutexGroups[0]); } | |
114 } | |
115 | |
116 public String[] MutexGroups | |
117 { | |
118 get { return (string[]) mutexGroups.Clone(); } | |
119 } | |
120 | |
121 public UnitType EquipmentForUnit | |
122 { | |
123 get { return unitType; } | |
124 } | |
125 | |
126 public bool IsRatioLimit | |
127 { | |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
128 get { return MinLimit is IPercentageLimit && MaxLimit is IPercentageLimit; } |
170 | 129 } |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
130 |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
131 /// <summary> |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
132 /// Gets the Limit object for the minimum number of items that can be taken |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
133 /// </summary> |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
134 public AbstractLimit MinLimit |
170 | 135 { |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
136 get |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
137 { |
184 | 138 AbstractLimit limit = minLimit; |
139 | |
140 if (limit == null) | |
141 { | |
142 if (maxLimit != null) | |
143 { | |
144 limit = maxLimit; | |
145 } | |
146 else | |
147 { | |
193
12aa4b76d24e
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
184
diff
changeset
|
148 limit = new SimpleRoundedPercentageLimit(100, false); |
184 | 149 } |
150 } | |
151 | |
152 return limit; | |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
153 } |
170 | 154 set |
155 { | |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
156 if (value != null) |
170 | 157 { |
184 | 158 minLimit = value; |
170 | 159 } |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
160 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
161 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
162 |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
163 /// <summary> |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
164 /// Gets the Limit object for the maximum number of items that can be taken |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
165 /// </summary> |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
166 public AbstractLimit MaxLimit |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
167 { |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
168 get |
170 | 169 { |
184 | 170 AbstractLimit limit = maxLimit; |
171 | |
172 if (limit == null) | |
173 { | |
174 if (minLimit != null) | |
175 { | |
176 limit = minLimit; | |
177 } | |
178 else | |
204
3ef067225dc3
Fixes #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
193
diff
changeset
|
179 { |
193
12aa4b76d24e
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
184
diff
changeset
|
180 limit = new SimpleRoundedPercentageLimit(100, false); |
184 | 181 } |
182 } | |
183 | |
184 return limit; | |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
185 } |
170 | 186 set |
187 { | |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
188 if (value != null) |
170 | 189 { |
184 | 190 maxLimit = value; |
170 | 191 } |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
192 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
193 } |
170 | 194 |
195 public EquipmentItem EquipmentItem | |
196 { | |
197 get { return item; } | |
198 } | |
199 | |
200 public override string ToString() | |
201 { | |
202 return EquipmentItem.Name + " (" + Cost + "pts each)"; | |
203 } | |
204 | |
205 public bool HasAlternatives() | |
206 { | |
207 if (MutexGroups.Length == 0) | |
208 { | |
209 return false; | |
210 } | |
211 else if (EquipmentForUnit == null) | |
212 { | |
213 return false; | |
214 } | |
215 else | |
216 { | |
217 //If the number of items in the MutEx group is greater than one then it must be this item plus another | |
218 return EquipmentForUnit.GetEquipmentItemsByExclusionGroups(MutexGroups).Length > 1; | |
219 } | |
220 } | |
221 | |
222 public ArmourType ItemArmourType | |
223 { | |
224 get { return EquipmentItem.ItemArmourType; } | |
225 } | |
226 | |
227 public string Description | |
228 { | |
229 get { return EquipmentItem.Description; } | |
230 } | |
231 | |
232 public Race EquipmentForRace | |
233 { | |
234 get { return EquipmentItem.EquipmentForRace; } | |
235 } | |
236 | |
237 public bool CanBeUsedWithItem(EquipmentItem item) | |
238 { | |
239 return EquipmentItem.CanBeUsedWithItem(item); | |
240 } | |
241 | |
242 public bool CanBeUsedWithArmourType(ArmourType otherItemType) | |
243 { | |
244 return EquipmentItem.CanBeUsedWithArmourType(otherItemType); | |
245 } | |
246 | |
247 [Obsolete("Use UnitEquipmentUtil method instead")] | |
248 public bool IsMutuallyExclusive(UnitEquipmentItem item) | |
249 { | |
250 return UnitEquipmentUtil.ItemsAreMutuallyExclusive(this, item); | |
251 } | |
252 | |
253 public string SlotName | |
254 { | |
255 get { return slotName; } | |
256 set | |
257 { | |
258 if (value != null && value != "") | |
259 { | |
260 slotName = value; | |
261 } | |
262 } | |
263 } | |
82 | 264 } |
265 } |