Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/UnitEquipmentItem.cs @ 54:3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
* Remove min/max from EquipmentItem and add description
* Add min/max numbers and percentages to UnitEquipmentItem
* Make Race schema define min/max number without the ratio (which is the percentage)
* Replace use of EquipmentItem with UnitEquipmentItem because of increased use of UnitEquipmentItem for unit-specific data
* Use doubles instead of floats for equipment amounts
* Distinguish between ratio and absolute limits
* Delete UnitEquipmentItemObj helper class that was purely used for UI
Re #9 - Use smaller methods
* Deprecate long Race and EquipmentItem constructors and ensure all getters/setters exist
Also:
* Migrate Unit to using genericed collections
* Always use GameSystem object for Race, not ID string
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 05 Apr 2009 13:45:23 +0000 |
parents | 306558904c2a |
children | 284ebe05158c |
rev | line source |
---|---|
15 | 1 // This file (UnitEquipmentItem.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. |
2 // | |
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. | |
4 | |
0 | 5 using System; |
6 using System.Xml; | |
7 | |
8 namespace IBBoard.WarFoundry.API.Objects | |
9 { | |
10 /// <summary> | |
11 /// Summary description for UnitEquipmentItem. | |
12 /// </summary> | |
13 public class UnitEquipmentItem : WarFoundryObject | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
14 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
15 private EquipmentItem item; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
16 private bool required; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
17 private bool roundUp; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
18 private int minNum; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
19 private int maxNum; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
20 private double minPercentage; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
21 private double maxPercentage; |
0 | 22 private string mutexGroup; |
23 private UnitType unitType; | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
24 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
25 protected UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipForType) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
26 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
27 item = equipmentItem; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
28 EquipmentForUnit = equipForType; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
29 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
30 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
31 public override string Name |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
32 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
33 get { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
34 return item.Name; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
35 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
36 set { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
37 base.Name = value; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
38 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
39 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
40 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
41 public string EquipmentItemID |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
42 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
43 get { return item.ID; } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
44 } |
0 | 45 |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
46 public double Cost |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
47 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
48 get { return item.Cost; } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
49 } |
0 | 50 |
51 public bool IsRequired | |
52 { | |
53 get { return required; } | |
54 set { required = value; } | |
55 } | |
56 | |
57 public bool RoundNumberUp | |
58 { | |
59 get { return roundUp; } | |
60 set { roundUp = value; } | |
61 } | |
62 | |
63 public string MutexGroup | |
64 { | |
65 get { return mutexGroup; } | |
66 set { mutexGroup = (value == null ? "" : value.Trim()); } | |
67 } | |
68 | |
69 public UnitType EquipmentForUnit | |
70 { | |
71 get { return unitType; } | |
72 set | |
73 { | |
74 if (value != null) | |
75 { | |
76 unitType = value; | |
77 } | |
78 } | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
79 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
80 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
81 public bool IsRatioLimit |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
82 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
83 get { return minPercentage!=100 || maxPercentage!=100; } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
84 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
85 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
86 public int MinNumber |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
87 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
88 get { return minNum; } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
89 set |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
90 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
91 if (value >=0 || value == WarFoundryCore.INFINITY) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
92 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
93 minNum = value; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
94 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
95 //TODO: Check Min<Max |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
96 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
97 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
98 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
99 public int MaxNumber |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
100 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
101 get { return maxNum; } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
102 set |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
103 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
104 if (value >=0 || value == WarFoundryCore.INFINITY) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
105 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
106 maxNum = value; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
107 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
108 //TODO: Check Min<Max |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
109 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
110 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
111 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
112 public double MinPercentage |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
113 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
114 get { return minPercentage; } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
115 set |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
116 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
117 if (value >=0 && value <= 100) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
118 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
119 minPercentage = value; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
120 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
121 //TODO: Check Min<Max |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
122 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
123 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
124 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
125 public double MaxPercentage |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
126 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
127 get { return maxPercentage; } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
128 set |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
129 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
130 if (value >=0 && value <= 100) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
131 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
132 maxPercentage = value; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
133 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
134 //TODO: Check Min<Max |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
135 } |
0 | 136 } |
137 | |
138 public EquipmentItem EquipmentItem | |
139 { | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
140 get { return item; } |
0 | 141 } |
142 | |
143 public override string ToString() | |
144 { | |
145 return EquipmentItem.Name+ " ("+EquipmentItem.Cost+"pts each)"; | |
146 } | |
147 | |
148 public bool HasAlternatives() | |
149 { | |
150 if (MutexGroup=="") | |
151 { | |
152 return false; | |
153 } | |
154 else | |
155 { | |
156 //If the number of items in the MutEx group is greater than one then it must be this item plus another | |
157 return EquipmentForUnit.GetEquipmentItemsByExclusionGroup(MutexGroup).Length > 1; | |
158 } | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
159 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
160 |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
161 public static string FormatEquipmentAmount(UnitEquipmentItem item, double amount) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
162 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
163 if (item.IsRatioLimit) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
164 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
165 return Math.Round(amount * 100) + "%"; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
166 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
167 else |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
168 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
169 if (amount == WarFoundryCore.INFINITY) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
170 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
171 return "all"; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
172 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
173 else |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
174 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
175 return amount.ToString(); |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
176 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
177 } |
0 | 178 } |
179 } | |
180 } |