Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/UnitEquipmentItem.cs @ 171:85dc413279a4
* Change imports to stop references to deprecated code
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 12 Oct 2009 18:41:17 +0000 |
parents | 3045a168714a |
children | f364a9e5463e |
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; | |
140 } | |
141 //TODO: Check Min<Max | |
142 } | |
143 } | |
144 | |
145 public int MaxNumber | |
146 { | |
147 get { return maxNum; } | |
148 set | |
149 { | |
150 if (value >= 0 || value == WarFoundryCore.INFINITY) | |
151 { | |
152 maxNum = value; | |
153 } | |
154 //TODO: Check Min<Max | |
155 } | |
156 } | |
157 | |
158 public double MinPercentage | |
159 { | |
160 get { return minPercentage; } | |
161 set | |
162 { | |
163 if (value >= 0 && value <= 100) | |
164 { | |
165 minPercentage = value; | |
166 } | |
167 //TODO: Check Min<Max | |
168 } | |
169 } | |
170 | |
171 public double MaxPercentage | |
172 { | |
173 get { return maxPercentage; } | |
174 set | |
175 { | |
176 if (value >= 0 && value <= 100) | |
177 { | |
178 maxPercentage = value; | |
179 } | |
180 //TODO: Check Min<Max | |
181 } | |
182 } | |
183 | |
184 public EquipmentItem EquipmentItem | |
185 { | |
186 get { return item; } | |
187 } | |
188 | |
189 public override string ToString() | |
190 { | |
191 return EquipmentItem.Name + " (" + Cost + "pts each)"; | |
192 } | |
193 | |
194 public bool HasAlternatives() | |
195 { | |
196 if (MutexGroups.Length == 0) | |
197 { | |
198 return false; | |
199 } | |
200 else if (EquipmentForUnit == null) | |
201 { | |
202 return false; | |
203 } | |
204 else | |
205 { | |
206 //If the number of items in the MutEx group is greater than one then it must be this item plus another | |
207 return EquipmentForUnit.GetEquipmentItemsByExclusionGroups(MutexGroups).Length > 1; | |
208 } | |
209 } | |
210 | |
211 public ArmourType ItemArmourType | |
212 { | |
213 get { return EquipmentItem.ItemArmourType; } | |
214 } | |
215 | |
216 public string Description | |
217 { | |
218 get { return EquipmentItem.Description; } | |
219 } | |
220 | |
221 public Race EquipmentForRace | |
222 { | |
223 get { return EquipmentItem.EquipmentForRace; } | |
224 } | |
225 | |
226 public bool CanBeUsedWithItem(EquipmentItem item) | |
227 { | |
228 return EquipmentItem.CanBeUsedWithItem(item); | |
229 } | |
230 | |
231 public bool CanBeUsedWithArmourType(ArmourType otherItemType) | |
232 { | |
233 return EquipmentItem.CanBeUsedWithArmourType(otherItemType); | |
234 } | |
235 | |
236 [Obsolete("Use UnitEquipmentUtil method instead")] | |
237 public bool IsMutuallyExclusive(UnitEquipmentItem item) | |
238 { | |
239 return UnitEquipmentUtil.ItemsAreMutuallyExclusive(this, item); | |
240 } | |
241 | |
242 public string SlotName | |
243 { | |
244 get { return slotName; } | |
245 set | |
246 { | |
247 if (value != null && value != "") | |
248 { | |
249 slotName = value; | |
250 } | |
251 } | |
252 } | |
82 | 253 } |
254 } |