Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/UnitEquipmentItem.cs @ 306:886d28c1b6e5
Re #99: Define points systems
* Simplify the code and leave translations until we support them
Re #329 and re #327: Use "points" in UI
* Use new method in UnitEquipmentItem object's ToString() method
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 13 Feb 2011 16:24:12 +0000 |
parents | 92d10b06ab0f |
children |
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; |
306 | 8 using IBBoard.WarFoundry.API.Util; |
9 using IBBoard.Lang; | |
299 | 10 //using IBBoard.WarFoundry.API.Objects; |
82 | 11 |
12 namespace IBBoard.WarFoundry.API.Objects | |
13 { | |
14 /// <summary> | |
15 /// Summary description for UnitEquipmentItem. | |
170 | 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 = ""; | |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
27 private ILimit minLimit; |
306 | 28 private ILimit maxLimit; |
170 | 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 } | |
306 | 109 |
110 public GameSystem GameSystem | |
111 { | |
112 get { return EquipmentItem.GameSystem; } | |
113 } | |
170 | 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 { | |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
127 get { return MinLimit is IPercentageLimit && MaxLimit is IPercentageLimit; } |
170 | 128 } |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
129 |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
130 /// <summary> |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
131 /// 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
|
132 /// </summary> |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
133 public ILimit MinLimit |
170 | 134 { |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
135 get |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
136 { |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
137 ILimit limit = minLimit; |
184 | 138 |
139 if (limit == null) | |
140 { | |
141 if (maxLimit != null) | |
142 { | |
143 limit = maxLimit; | |
144 } | |
145 else | |
146 { | |
193
12aa4b76d24e
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
184
diff
changeset
|
147 limit = new SimpleRoundedPercentageLimit(100, false); |
184 | 148 } |
149 } | |
150 | |
151 return limit; | |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
152 } |
170 | 153 set |
154 { | |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
155 if (value != null) |
170 | 156 { |
184 | 157 minLimit = value; |
170 | 158 } |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
159 } |
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 |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
162 /// <summary> |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
163 /// 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
|
164 /// </summary> |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
165 public ILimit MaxLimit |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
166 { |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
167 get |
170 | 168 { |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
263
diff
changeset
|
169 ILimit limit = maxLimit; |
184 | 170 |
171 if (limit == null) | |
172 { | |
173 if (minLimit != null) | |
174 { | |
175 limit = minLimit; | |
176 } | |
177 else | |
204
3ef067225dc3
Fixes #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
193
diff
changeset
|
178 { |
193
12aa4b76d24e
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
184
diff
changeset
|
179 limit = new SimpleRoundedPercentageLimit(100, false); |
184 | 180 } |
181 } | |
182 | |
183 return limit; | |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
184 } |
170 | 185 set |
186 { | |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
173
diff
changeset
|
187 if (value != null) |
170 | 188 { |
184 | 189 maxLimit = value; |
170 | 190 } |
172
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
191 } |
f364a9e5463e
Fixes #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
171
diff
changeset
|
192 } |
170 | 193 |
194 public EquipmentItem EquipmentItem | |
195 { | |
196 get { return item; } | |
197 } | |
198 | |
199 public override string ToString() | |
200 { | |
306 | 201 return Translation.GetTranslation("UnitEquipmentItemName", "{0} ({1}{2} each)", Name, Cost, GameSystem.GetPointsAbbrev(Cost)); |
170 | 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 } | |
82 | 247 } |
248 } |