Mercurial > repos > snowblizz-super-API-ideas
annotate api/Objects/Unit.cs @ 309:7e1b27843b0d
Fixes #99: Define "points" values in GameSystem
* Implement fall-back in case only one value has been set
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 20 Feb 2011 16:00:11 +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 (Unit.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 2007, 2008, 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; |
6 using System.Collections.Generic; | |
7 using System.Text; | |
0 | 8 using System.Xml; |
164 | 9 using IBBoard.Lang; |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
180
diff
changeset
|
10 using IBBoard.Limits; |
161
81abc04b3dbe
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
158
diff
changeset
|
11 using IBBoard.WarFoundry.API.Util; |
82 | 12 |
13 namespace IBBoard.WarFoundry.API.Objects | |
14 { | |
15 /// <summary> | |
16 /// Summary description for UnitInstance. | |
17 /// </summary> | |
143
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
18 public class Unit : WarFoundryObject, ICostedWarFoundryObject |
82 | 19 { |
20 private UnitType type; | |
21 private int size; | |
22 private Unit parentUnit; | |
23 private double points; | |
24 private ArmyCategory cat; | |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
25 private Dictionary<UnitEquipmentItem, AbstractUnitEquipmentItemSelection> equipment = new Dictionary<UnitEquipmentItem, AbstractUnitEquipmentItemSelection>(); |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
26 private Dictionary<string, List<AbstractUnitEquipmentItemSelection>> equipmentSlots = new Dictionary<string, List<AbstractUnitEquipmentItemSelection>>(); |
82 | 27 private List<Unit> containedUnits = new List<Unit>(); |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
28 |
82 | 29 public event DoubleValChangedDelegate PointsValueChanged; |
30 public event IntValChangedDelegate UnitSizeChanged; | |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
31 public event DoubleValChangedDelegate UnitEquipmentAmountChanged; |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
32 |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
33 public Unit(UnitType unitType, ArmyCategory parentArmyCat) : this(unitType, unitType.MinSize, parentArmyCat) |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
34 { |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
35 //Do nothing extra |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
36 } |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
37 |
123
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
38 public Unit(UnitType unitType, int startSize, ArmyCategory parentArmyCat) : this("", "", startSize, unitType, parentArmyCat) |
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
39 { |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
40 SetInitialEquipment(); |
279
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
41 UnitSizeChanged += new IntValChangedDelegate(RefreshUnitEquipmentAmounts); |
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
42 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
43 |
123
52e8c3cdde10
Re #127: Unit creation always assigns default equipment
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
44 public Unit(string id, string name, int startSize, UnitType unitType, ArmyCategory parentArmyCat) : base(id, name) |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
45 { |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
46 Category = parentArmyCat; |
82 | 47 type = unitType; |
48 Size = startSize; | |
49 CalcCost(); | |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
50 UnitEquipmentAmountChanged += new DoubleValChangedDelegate(UnitEquipmentAmountChangedHandler); |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
51 UnitSizeChanged += new IntValChangedDelegate(UnitSizeChangedHandler); |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
52 Translation.TranslationChanged += HandleTranslationChanged; |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
53 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
54 |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
55 private void UnitEquipmentAmountChangedHandler(WarFoundryObject obj, double oldVal, double newVal) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
56 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
57 CalcCost(); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
58 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
59 |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
60 private void UnitSizeChangedHandler(WarFoundryObject obj, int oldVal, int newVal) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
61 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
62 CalcCost(); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
63 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
64 if (HasDefaultName()) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
65 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
66 OnNameChanged("", Name); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
67 } |
82 | 68 } |
69 | |
70 protected override string DefaultName() | |
71 { | |
72 if (type != null) | |
73 { | |
74 if (size == 1) | |
75 { | |
76 return type.Name; | |
77 } | |
78 else | |
79 { | |
80 return String.Format(Translation.GetTranslation("defaultUnitName"), size, type.Name); | |
81 } | |
82 } | |
83 else | |
84 { | |
85 return "Unknown Unit"; | |
86 } | |
87 } | |
88 | |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
89 private void HandleTranslationChanged() |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
90 { |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
91 if (type != null && HasDefaultName() && size != 1) |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
92 { |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
93 OnNameChanged(null, DefaultName()); |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
94 } |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
95 } |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
96 |
82 | 97 private void SetInitialEquipment() |
98 { | |
99 foreach (UnitEquipmentItem unitEquip in UnitType.GetEquipmentItems()) | |
100 { | |
101 if (unitEquip.IsRequired) | |
102 { | |
103 if (CanEquipWithItem(unitEquip)) | |
104 { | |
265
6fe0cb1bf74f
Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
254
diff
changeset
|
105 ILimit minLimit = unitEquip.MinLimit; |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
180
diff
changeset
|
106 |
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
180
diff
changeset
|
107 if (minLimit is IPercentageLimit) |
151
1d13820b3d96
Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents:
149
diff
changeset
|
108 { |
204
3ef067225dc3
Fixes #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
109 SetEquipmentRatio(unitEquip, UnitEquipmentUtil.GetMinEquipmentPercentage(this, unitEquip)); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
110 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
111 else |
151
1d13820b3d96
Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents:
149
diff
changeset
|
112 { |
204
3ef067225dc3
Fixes #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
201
diff
changeset
|
113 SetEquipmentAmount(unitEquip, UnitEquipmentUtil.GetMinEquipmentCount(this, unitEquip)); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
114 } |
82 | 115 } |
116 } | |
117 } | |
118 } | |
119 | |
120 private void CalcCost() | |
121 { | |
122 double oldpoints = points; | |
123 points = type.CostPerTrooper * AdditionalTroopers + type.BaseUnitCost; | |
124 | |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
125 foreach (AbstractUnitEquipmentItemSelection equipSelection in equipment.Values) |
82 | 126 { |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
127 points += equipSelection.TotalCost; |
82 | 128 } |
129 | |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
130 if (oldpoints != points) |
82 | 131 { |
132 OnPointsValueChanged(oldpoints, points); | |
133 } | |
0 | 134 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
135 |
0 | 136 public int AdditionalTroopers |
137 { | |
138 get { return Math.Max(Size - type.BaseSize, 0); } | |
82 | 139 } |
140 | |
141 public int Size | |
142 { | |
143 get { return size; } | |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
144 set |
82 | 145 { |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
146 if (value != size) |
82 | 147 { |
148 int oldValue = size; | |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
149 size = (value > 0 ? value : 1); |
82 | 150 OnUnitSizeChanged(oldValue, size); |
151 } | |
152 } | |
153 } | |
154 | |
155 public UnitType UnitType | |
0 | 156 { |
82 | 157 get { return type; } |
158 } | |
159 | |
160 public Army Army | |
161 { | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
162 get { return (Category == null ? null : Category.ParentArmy); } |
82 | 163 } |
164 | |
165 public Race Race | |
166 { | |
167 get { return UnitType.Race; } | |
168 } | |
169 | |
170 public ArmyCategory Category | |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
171 { |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
172 get |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
173 { |
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
174 return cat; |
82 | 175 } |
176 set { cat = value; } | |
177 } | |
178 | |
143
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
179 public double Points |
7f13ffcb8765
Re #164: Show unit cost in army tree
IBBoard <dev@ibboard.co.uk>
parents:
134
diff
changeset
|
180 { |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
181 get |
82 | 182 { |
183 if (points == 0) | |
184 { | |
185 CalcCost(); | |
186 } | |
187 | |
188 return points; | |
189 } | |
61
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
190 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
191 |
61
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
192 public Unit[] ContainedUnits |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
193 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
194 get { return containedUnits.ToArray(); } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
195 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
196 |
61
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
197 public void AddContainedUnit(Unit unit) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
198 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
199 if (UnitType.CanContainUnit(unit)) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
200 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
201 if (!containedUnits.Contains(unit)) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
202 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
203 containedUnits.Add(unit); |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
204 } |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
205 |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
206 unit.ParentUnit = this; |
61
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
207 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
208 else |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
209 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
210 throw new InvalidContainershipException(this, unit); |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
211 } |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
212 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
213 |
61
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
214 public void RemoveContainedUnit(Unit unit) |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
215 { |
3c77722a02b5
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
216 containedUnits.Remove(unit); |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
217 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
218 |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
219 public Unit ParentUnit |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
220 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
221 get { return parentUnit; } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
222 set |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
223 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
224 if (!(parentUnit == value || (parentUnit != null && parentUnit.Equals(value)))) |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
225 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
226 parentUnit = value; |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
227 |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
228 if (value != null) |
65
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
229 { |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
230 value.AddContainedUnit(this); |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
231 } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
232 } |
aa2d05a9c635
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
233 } |
82 | 234 } |
235 | |
236 public UnitEquipmentItem[] GetEquipment() | |
237 { | |
238 return DictionaryUtils.ToKeyArray(equipment); | |
239 } | |
240 | |
241 public EquipmentItem[] GetRequiredEquipment() | |
242 { | |
243 List<EquipmentItem> list = new List<EquipmentItem>(); | |
244 | |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
245 foreach (UnitEquipmentItem item in GetEquipment()) |
82 | 246 { |
247 if (item.IsRequired) | |
248 { | |
249 list.Add(item.EquipmentItem); | |
250 } | |
251 } | |
252 | |
213 | 253 return list.ToArray(); |
254 } | |
255 | |
256 internal AbstractUnitEquipmentItemSelection GetEquipmentSelection(UnitEquipmentItem item) | |
257 { | |
258 return DictionaryUtils.GetValue(equipment, item); | |
82 | 259 } |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
260 |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
261 public void SetEquipmentAmount(UnitEquipmentItem equip, int amount) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
262 { |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
263 if (amount < 1 && amount != WarFoundryCore.INFINITY) |
82 | 264 { |
265 amount = 0; | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
266 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
267 |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
268 if (amount == 0) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
269 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
270 RemoveEquipmentItem(equip); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
271 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
272 else |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
273 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
274 AbstractUnitEquipmentItemSelection currSelection = DictionaryUtils.GetValue(equipment, equip); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
275 double oldAmount = (currSelection == null ? 0 : currSelection.AmountTaken); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
276 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
277 if (amount != oldAmount) |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
278 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
279 if (oldAmount == 0) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
280 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
281 AddEquipmentAmount(equip, amount); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
282 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
283 else if (currSelection is UnitEquipmentNumericSelection) |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
284 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
285 //A UnitEquipmentItem shouldn't change its IsRatio value, so assume we already have the right sub-type |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
286 currSelection.AmountTaken = amount; |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
287 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
288 else |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
289 { |
206
0ca96143aa03
Re #211: Swapping from percentage to numeric selection doesn't remove old selection
IBBoard <dev@ibboard.co.uk>
parents:
205
diff
changeset
|
290 RemoveEquipmentItem(equip); |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
291 AddEquipmentAmount(equip, amount); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
292 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
293 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
294 OnUnitEquipmentAmountChanged(equip, oldAmount, amount); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
295 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
296 } |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
297 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
298 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
299 private void AddEquipmentAmount(UnitEquipmentItem equip, int amount) |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
300 { |
183
36adabb1c3ea
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
180
diff
changeset
|
301 AbstractUnitEquipmentItemSelection newItem = new UnitEquipmentNumericSelection(this, equip, amount); |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
302 equipment[equip] = newItem; |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
303 List<AbstractUnitEquipmentItemSelection> selections = DictionaryUtils.GetValue(equipmentSlots, equip.SlotName); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
304 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
305 if (selections == null) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
306 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
307 selections = new List<AbstractUnitEquipmentItemSelection>(); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
308 equipmentSlots[equip.SlotName] = selections; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
309 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
310 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
311 selections.Add(newItem); |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
312 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
313 |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
314 public void SetEquipmentRatio(UnitEquipmentItem equip, double ratio) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
315 { |
80
aa66dd18cdae
Closes #81 - Resolve Unit Equipment problems in WinForms GUI
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
316 if (!equip.IsRatioLimit) |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
317 { |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
318 throw new InvalidOperationException("Equipment with ID " + equip.ID + " for unit of type " + UnitType.ID + " has an absolute limit, not a ratio limit"); |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
319 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
320 |
101
f7b9423c2a5a
Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
321 if (ratio > 100) |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
322 { |
101
f7b9423c2a5a
Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
323 ratio = 100; |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
324 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
325 else if (ratio < 0) |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
326 { |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
327 ratio = 0; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
328 } |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
329 |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
330 if (ratio == 0) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
331 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
332 RemoveEquipmentItem(equip); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
333 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
334 else |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
335 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
336 AbstractUnitEquipmentItemSelection currSelection = DictionaryUtils.GetValue(equipment, equip); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
337 double oldRatio = (currSelection == null ? 0 : currSelection.AmountTaken); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
338 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
339 if (ratio != oldRatio) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
340 { |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
341 if (oldRatio == 0) |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
342 { |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
343 AddEquipmentRatio(equip, ratio); |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
344 } |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
345 else if (currSelection is UnitEquipmentRatioSelection) |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
346 { |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
347 currSelection.AmountTaken = ratio; |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
348 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
349 else |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
350 { |
206
0ca96143aa03
Re #211: Swapping from percentage to numeric selection doesn't remove old selection
IBBoard <dev@ibboard.co.uk>
parents:
205
diff
changeset
|
351 RemoveEquipmentItem(equip); |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
352 AddEquipmentRatio(equip, ratio); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
353 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
354 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
355 OnUnitEquipmentAmountChanged(equip, oldRatio, ratio); |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
356 } |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
357 } |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
38
diff
changeset
|
358 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
359 |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
360 private void AddEquipmentRatio(UnitEquipmentItem equip, double ratio) |
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
361 { |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
362 UnitEquipmentRatioSelection newItem = new UnitEquipmentRatioSelection(this, equip, ratio); |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
363 equipment[equip] = newItem; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
364 List<AbstractUnitEquipmentItemSelection> selections = DictionaryUtils.GetValue(equipmentSlots, equip.SlotName); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
365 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
366 if (selections == null) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
367 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
368 selections = new List<AbstractUnitEquipmentItemSelection>(); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
369 equipmentSlots[equip.SlotName] = selections; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
370 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
371 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
372 selections.Add(newItem); |
98
4dd1c41c95b4
Fixes #119: Handle changing of equipment between absolute and ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
373 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
374 |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
375 private void RemoveEquipmentItem(UnitEquipmentItem equip) |
216 | 376 { |
214
1b718b67f7f6
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
213
diff
changeset
|
377 double oldAmount = UnitEquipmentUtil.GetEquipmentAmount(this, equip); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
378 |
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
379 if (oldAmount != 0) |
82 | 380 { |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
381 AbstractUnitEquipmentItemSelection selection = DictionaryUtils.GetValue(equipment, equip); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
382 equipment.Remove(equip); |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
383 List<AbstractUnitEquipmentItemSelection> slotSelections = DictionaryUtils.GetValue(equipmentSlots, equip.SlotName); |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
384 slotSelections.Remove(selection); |
96
ced5a18d9f52
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
385 OnUnitEquipmentAmountChanged(equip, oldAmount, 0); |
82 | 386 } |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
387 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
388 |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
389 public bool CanEquipWithItem(UnitEquipmentItem item) |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
390 { |
154
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
391 string[] mutexes = item.MutexGroups; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
392 bool canEquip = false; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
393 |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
394 if (mutexes.Length == 0) |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
395 { |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
396 canEquip = true; |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
397 } |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
398 else |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
399 { |
162
624422e91a1c
Re #192: Improve "clean coding" practice
IBBoard <dev@ibboard.co.uk>
parents:
161
diff
changeset
|
400 canEquip = UnitEquipmentUtil.GetBlockingEquipmentItems(this, item).Count == 0; |
64
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
401 } |
2094bd0ba652
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
61
diff
changeset
|
402 |
152
0c0e14f03785
Re #180: Add multiple mutex groups
IBBoard <dev@ibboard.co.uk>
parents:
151
diff
changeset
|
403 return canEquip; |
154
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
404 } |
4a02c07278e7
Re #185: Problems with decimals in race definitions
IBBoard <dev@ibboard.co.uk>
parents:
152
diff
changeset
|
405 |
82 | 406 public bool CanEquipWithItem(string equipID) |
407 { | |
408 return CanEquipWithItem(UnitType.GetEquipmentItem(equipID)); | |
409 } | |
410 | |
411 private void OnPointsValueChanged(double oldValue, double newValue) | |
412 { | |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
413 if (PointsValueChanged != null) |
82 | 414 { |
415 PointsValueChanged(this, oldValue, newValue); | |
416 } | |
417 } | |
418 | |
419 private void OnUnitSizeChanged(int oldValue, int newValue) | |
420 { | |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
421 if (UnitSizeChanged != null) |
82 | 422 { |
423 UnitSizeChanged(this, oldValue, newValue); | |
424 } | |
425 } | |
426 | |
427 private void OnUnitEquipmentAmountChanged(UnitEquipmentItem equip, double oldValue, double newValue) | |
428 { | |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
429 if (UnitEquipmentAmountChanged != null) |
82 | 430 { |
431 UnitEquipmentAmountChanged(equip, oldValue, newValue); | |
432 } | |
433 } | |
434 | |
254
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
435 public Stat[][] UnitStatsArrays |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
436 { |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
437 get { return UnitType.UnitStatsArrays; } |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
438 } |
81
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
439 |
254
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
440 public Stat[][] UnitStatsArraysWithName |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
441 { |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
442 get { return UnitType.UnitStatsArraysWithName; } |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
443 } |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
444 |
254
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
445 public string[] UnitStatsArrayIDs |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
446 { |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
447 get |
254
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
448 { |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
449 return UnitType.UnitStatsArrayIDs; |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
450 } |
cdda78975be1
Fixes #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
216
diff
changeset
|
451 } |
81
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
452 |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
453 public string GetStatValue(string statName) |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
454 { |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
455 return UnitType.GetStatValue(statName); |
82 | 456 } |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
457 |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
458 public int GetEquipmentAmountInSlot(string slotName) |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
459 { |
213 | 460 int amount = 0; |
461 | |
212
dce340f9cedc
Re #217: Rounding problem with equipment cost calculations
IBBoard <dev@ibboard.co.uk>
parents:
208
diff
changeset
|
462 List<AbstractUnitEquipmentItemSelection> selections = GetEquipmentSlotSelections(slotName); |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
463 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
464 if (selections != null) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
465 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
466 amount = GetSelectionTotal(selections); |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
467 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
468 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
469 return amount; |
213 | 470 } |
471 | |
472 internal List<AbstractUnitEquipmentItemSelection> GetEquipmentSlotSelections(string slotName) | |
473 { | |
474 return DictionaryUtils.GetValue(equipmentSlots, slotName); | |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
475 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
476 |
197
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
477 /// <summary> |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
478 /// Gets the total amount of items taken for the item's slot, excluding the provided item |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
479 /// </summary> |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
480 /// <param name="item">the item to exclude from the count</param> |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
481 /// <returns>the total number of items</returns> |
201
4d7ff70bb109
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
197
diff
changeset
|
482 public int GetEquipmentAmountInSlotExcludingItem(UnitEquipmentItem item) |
197
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
483 { |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
484 int amount = 0; |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
485 |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
486 List<AbstractUnitEquipmentItemSelection> selections = DictionaryUtils.GetValue(equipmentSlots, item.SlotName); |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
487 |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
488 if (selections != null) |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
489 { |
205
c0edb72a10ba
Fixes #210: Editing equipment in slot loses amount
IBBoard <dev@ibboard.co.uk>
parents:
204
diff
changeset
|
490 selections = new List<AbstractUnitEquipmentItemSelection>(selections); |
197
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
491 RemoveSelectionFromList(item, selections); |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
492 amount = GetSelectionTotal(selections); |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
493 } |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
494 |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
495 return amount; |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
496 } |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
497 |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
498 private void RemoveSelectionFromList(UnitEquipmentItem item, List<AbstractUnitEquipmentItemSelection> selections) |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
499 { |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
500 AbstractUnitEquipmentItemSelection selection = GetEquipmentSelection(item); |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
501 |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
502 if (selection != null) |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
503 { |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
504 selections.Remove(selection); |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
505 } |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
506 } |
ec1cfe3ef94e
* Add extra method for getting the number of items in a slot without including the given item (required when editing equipment in slots)
IBBoard <dev@ibboard.co.uk>
parents:
183
diff
changeset
|
507 |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
508 private int GetSelectionTotal(List<AbstractUnitEquipmentItemSelection> selections) |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
509 { |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
510 int amount = 0; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
511 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
512 foreach (AbstractUnitEquipmentItemSelection selection in selections) |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
513 { |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
514 amount += selection.NumberTaken; |
178
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
515 } |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
516 |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
517 return amount; |
ca2cd24f6872
Re #198: Add slots with counts to units
IBBoard <dev@ibboard.co.uk>
parents:
164
diff
changeset
|
518 } |
208
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
519 |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
520 /// <summary> |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
521 /// Default stub implementation of getting the unit's abilities - defaults to just the unit type's required abilities until we get a way to modify them |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
522 /// </summary> |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
523 public ICollection<Ability> Abilities |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
524 { |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
525 get |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
526 { |
e8e9026dd4ea
Fixes #216: Export unit abilities in to HTML
IBBoard <dev@ibboard.co.uk>
parents:
206
diff
changeset
|
527 return UnitType.GetRequiredAbilities(); |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
528 } |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
529 } |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
530 |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
531 private void RefreshUnitEquipmentAmounts(WarFoundryObject obj, int oldValue, int newValue) |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
532 { |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
533 foreach (UnitEquipmentItem item in equipment.Keys) |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
534 { |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
535 AbstractUnitEquipmentItemSelection selection = equipment[item]; |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
536 |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
537 if (selection is UnitEquipmentRatioSelection) |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
538 { |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
539 OnUnitEquipmentAmountChanged(item, selection.AmountTaken, selection.AmountTaken); |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
540 } |
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
279
diff
changeset
|
541 } |
279
51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
IBBoard <dev@ibboard.co.uk>
parents:
265
diff
changeset
|
542 } |
82 | 543 } |
544 } |