Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison API/Objects/UnitEquipmentItem.cs @ 337:3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 03 Apr 2011 18:50:32 +0000 |
parents | |
children | 7e95b880f9cc |
comparison
equal
deleted
inserted
replaced
336:3631c1493c7f | 337:3c4a6403a88c |
---|---|
1 // This file (UnitEquipmentItem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. | |
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. | |
4 | |
5 using System; | |
6 using IBBoard.CustomMath; | |
7 using IBBoard.Limits; | |
8 using IBBoard.WarFoundry.API.Util; | |
9 using IBBoard.Lang; | |
10 //using IBBoard.WarFoundry.API.Objects; | |
11 | |
12 namespace IBBoard.WarFoundry.API.Objects | |
13 { | |
14 /// <summary> | |
15 /// Summary description for UnitEquipmentItem. | |
16 /// </summary> | |
17 public class UnitEquipmentItem : WarFoundryObject | |
18 { | |
19 private EquipmentItem item; | |
20 private bool required; | |
21 private bool roundUp; | |
22 private double costMultiplier; | |
23 private RoundType roundType; | |
24 private string[] mutexGroups; | |
25 private UnitType unitType; | |
26 private string slotName = ""; | |
27 private ILimit minLimit; | |
28 private ILimit maxLimit; | |
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 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 public GameSystem GameSystem | |
111 { | |
112 get { return EquipmentItem.GameSystem; } | |
113 } | |
114 | |
115 public String[] MutexGroups | |
116 { | |
117 get { return (string[]) mutexGroups.Clone(); } | |
118 } | |
119 | |
120 public UnitType EquipmentForUnit | |
121 { | |
122 get { return unitType; } | |
123 } | |
124 | |
125 public bool IsRatioLimit | |
126 { | |
127 get { return MinLimit is IPercentageLimit && MaxLimit is IPercentageLimit; } | |
128 } | |
129 | |
130 /// <summary> | |
131 /// Gets the Limit object for the minimum number of items that can be taken | |
132 /// </summary> | |
133 public ILimit MinLimit | |
134 { | |
135 get | |
136 { | |
137 ILimit limit = minLimit; | |
138 | |
139 if (limit == null) | |
140 { | |
141 if (maxLimit != null) | |
142 { | |
143 limit = maxLimit; | |
144 } | |
145 else | |
146 { | |
147 limit = new SimpleRoundedPercentageLimit(100, false); | |
148 } | |
149 } | |
150 | |
151 return limit; | |
152 } | |
153 set | |
154 { | |
155 if (value != null) | |
156 { | |
157 minLimit = value; | |
158 } | |
159 } | |
160 } | |
161 | |
162 /// <summary> | |
163 /// Gets the Limit object for the maximum number of items that can be taken | |
164 /// </summary> | |
165 public ILimit MaxLimit | |
166 { | |
167 get | |
168 { | |
169 ILimit limit = maxLimit; | |
170 | |
171 if (limit == null) | |
172 { | |
173 if (minLimit != null) | |
174 { | |
175 limit = minLimit; | |
176 } | |
177 else | |
178 { | |
179 limit = new SimpleRoundedPercentageLimit(100, false); | |
180 } | |
181 } | |
182 | |
183 return limit; | |
184 } | |
185 set | |
186 { | |
187 if (value != null) | |
188 { | |
189 maxLimit = value; | |
190 } | |
191 } | |
192 } | |
193 | |
194 public EquipmentItem EquipmentItem | |
195 { | |
196 get { return item; } | |
197 } | |
198 | |
199 public override string ToString() | |
200 { | |
201 return Translation.GetTranslation("UnitEquipmentItemName", "{0} ({1}{2} each)", Name, Cost, GameSystem.GetPointsAbbrev(Cost)); | |
202 } | |
203 | |
204 public bool HasAlternatives() | |
205 { | |
206 if (MutexGroups.Length == 0) | |
207 { | |
208 return false; | |
209 } | |
210 else if (EquipmentForUnit == null) | |
211 { | |
212 return false; | |
213 } | |
214 else | |
215 { | |
216 //If the number of items in the MutEx group is greater than one then it must be this item plus another | |
217 return EquipmentForUnit.GetEquipmentItemsByExclusionGroups(MutexGroups).Length > 1; | |
218 } | |
219 } | |
220 | |
221 public string Description | |
222 { | |
223 get { return EquipmentItem.Description; } | |
224 } | |
225 | |
226 public Race EquipmentForRace | |
227 { | |
228 get { return EquipmentItem.EquipmentForRace; } | |
229 } | |
230 | |
231 public bool CanBeUsedWithItem(EquipmentItem item) | |
232 { | |
233 return EquipmentItem.CanBeUsedWithItem(item); | |
234 } | |
235 | |
236 public string SlotName | |
237 { | |
238 get { return slotName; } | |
239 set | |
240 { | |
241 if (value != null && value != "") | |
242 { | |
243 slotName = value; | |
244 } | |
245 } | |
246 } | |
247 } | |
248 } |