Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/Race.cs @ 279:51b3027a7dae
Re #295: Index out of bounds when changing unit size and clicking in equipment list
* Trigger 'fake' equipment amount changed events when the unit size changes for all ratio equipment - ratio won't have changed, but absolute number will
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 14 Jul 2010 20:01:14 +0000 |
parents | 3b395ab8784d |
children | cd657faa0c05 8981fc45fe17 |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
1 // This file (Race.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
0 | 2 // |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
85
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. |
0 | 4 |
82 | 5 using System; |
6 using System.Collections.Generic; | |
7 using System.IO; | |
0 | 8 using System.Xml; |
9 using IBBoard.IO; | |
10 using IBBoard.WarFoundry.API.Factories; | |
11 | |
12 namespace IBBoard.WarFoundry.API.Objects | |
13 { | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
14 public class Race : WarFoundryStagedLoadingObject |
0 | 15 { |
16 public static string SYSTEM_DEFAULT_RACE_ID = "GameDefault"; | |
82 | 17 |
0 | 18 private string subID; |
82 | 19 private GameSystem system; |
20 private Dictionary<Category, Dictionary<string, UnitType>> unitTypesByCat; | |
21 private Dictionary<string, UnitType> unitTypes = new Dictionary<string,UnitType>(); | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
22 private Dictionary<string, EquipmentItem> equipment = new Dictionary<string,EquipmentItem>(); |
82 | 23 private Dictionary<string, Ability> abilities = new Dictionary<string,Ability>(); |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
24 private Dictionary<string, Category> categories = new Dictionary<string,Category>(); |
252
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
25 private Dictionary<string, UnitMemberType> memberTypes = new Dictionary<string, UnitMemberType>(); |
0 | 26 |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
27 public Race(string raceID, string raceName, GameSystem gameSystem, IWarFoundryFactory creatingFactory) : this(raceID, "", raceName, gameSystem, creatingFactory) |
0 | 28 { |
29 } | |
30 | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
31 public Race(string raceID, string raceSubID, string raceName, GameSystem gameSystem, IWarFoundryFactory creatingFactory) : base(raceID + (raceSubID!="" ? "_"+raceSubID : ""), raceName, creatingFactory) |
0 | 32 { |
33 subID = (raceSubID == null ? "" : raceSubID); | |
54
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
34 system = gameSystem; |
3a90f70dac73
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
47
diff
changeset
|
35 } |
82 | 36 |
37 public string SubID | |
38 { | |
39 get { return subID; } | |
40 set { subID = (value == null ? "" : value.Trim()); } | |
41 } | |
42 | |
43 public GameSystem GameSystem | |
44 { | |
45 get { return system; } | |
0 | 46 set |
47 { | |
48 if (value == null) | |
49 { | |
50 throw new ArgumentException("Game system for a race cannot be null"); | |
51 } | |
52 | |
53 system = value; | |
82 | 54 } |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
55 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
56 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
57 public void AddCategory(Category cat) |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
58 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
59 categories[cat.ID] = cat; |
82 | 60 } |
0 | 61 |
62 /// <summary> | |
63 /// Gets a category from its ID. Attempts to get the category from the race's overrides, or else it falls back to getting the Game System's category with that ID. | |
64 /// </summary> | |
65 /// <param name="id"> | |
66 /// The ID of the category to get | |
67 /// </param> | |
68 /// <returns> | |
69 /// The <code>Category</code> with the specified ID, or null if one doesn't exist. | |
82 | 70 /// </returns> |
71 public Category GetCategory(string id) | |
0 | 72 { |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
73 EnsureFullyLoaded(); |
0 | 74 Category cat = null; |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
75 categories.TryGetValue(id, out cat); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
76 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
77 if (cat == null) |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
78 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
79 cat = GameSystem.GetCategory(id); |
0 | 80 } |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
81 |
82 | 82 return cat; |
83 } | |
0 | 84 |
82 | 85 public Category[] Categories |
86 { | |
87 get | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
88 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
89 EnsureFullyLoaded(); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
90 Category[] cats; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
91 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
92 if (!HasCategoryOverrides()) |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
93 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
94 cats = GameSystem.Categories; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
95 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
96 else |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
97 { |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
98 cats = DictionaryUtils.ToArray<string, Category>(categories); |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
99 } |
82 | 100 |
101 return cats; | |
102 } | |
103 } | |
104 | |
105 public bool HasCategoryOverrides() | |
106 { | |
118
d39de20f2ba1
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
107 EnsureFullyLoaded(); |
82 | 108 return categories.Count > 0; |
0 | 109 } |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
110 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
111 public void AddEquipmentItem(EquipmentItem item) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
112 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
113 //TODO: Throw DuplicateItemException |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
114 equipment.Add(item.ID, item); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
115 } |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
116 |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
117 public EquipmentItem GetEquipmentItem(string id) |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
118 { |
82 | 119 EnsureFullyLoaded(); |
85
46ad6f478203
Re #50: Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
120 return DictionaryUtils.GetValue(equipment, id); |
0 | 121 } |
122 | |
123 public List<EquipmentItem> GetEquipmentList() | |
124 { | |
118
d39de20f2ba1
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
125 EnsureFullyLoaded(); |
0 | 126 List<EquipmentItem> items = new List<EquipmentItem>(); |
127 | |
128 foreach (EquipmentItem item in equipment.Values) | |
129 { | |
130 items.Add(item); | |
131 } | |
132 | |
133 return items; | |
134 } | |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
135 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
136 public void AddUnitType(UnitType type) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
137 { |
13 | 138 CacheUnitType(type); |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
139 unitTypes.Add(type.ID, type); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
140 } |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
141 |
82 | 142 public UnitType[] GetUnitTypes(Category cat) |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
143 { |
118
d39de20f2ba1
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
144 EnsureFullyLoaded(); |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
145 BuildUnitTypesByCategoryCache(); |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
146 Dictionary<string, UnitType> unitTypesDictionary; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
147 unitTypesByCat.TryGetValue(cat, out unitTypesDictionary); |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
148 UnitType[] unitTypesArray; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
149 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
150 if (unitTypesDictionary == null) |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
151 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
152 unitTypesArray = new UnitType[0]; |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
153 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
154 else |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
155 { |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
156 unitTypesArray = DictionaryUtils.ToArray<string, UnitType>(unitTypesDictionary); |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
157 } |
82 | 158 |
159 return unitTypesArray; | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
160 } |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
161 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
162 private void CacheUnitType(UnitType unit) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
163 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
164 BuildUnitTypesByCategoryCache(); |
258
3b395ab8784d
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
165 |
3b395ab8784d
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
166 foreach (Category cat in unit.Categories) |
82 | 167 { |
258
3b395ab8784d
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
168 Dictionary<string, UnitType> catUnitTypes = DictionaryUtils.GetValue(unitTypesByCat, cat); |
3b395ab8784d
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
169 |
3b395ab8784d
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
170 if (catUnitTypes == null) |
3b395ab8784d
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
171 { |
3b395ab8784d
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
172 throw new InvalidFileException(String.Format("Unit type {0} with name {1} is a unit of an undefined category ({2})", unit.ID, unit.Name, cat.ID)); |
3b395ab8784d
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
173 } |
3b395ab8784d
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
174 |
3b395ab8784d
Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
252
diff
changeset
|
175 catUnitTypes.Add(unit.ID, unit); |
82 | 176 } |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
177 } |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
178 |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
179 private void BuildUnitTypesByCategoryCache() |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
180 { |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
181 if (unitTypesByCat == null) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
182 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
183 DoBuildUnitTypesByCategoryCache(); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
184 } |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
185 } |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
186 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
187 private void DoBuildUnitTypesByCategoryCache() |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
188 { |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
189 unitTypesByCat = new Dictionary<Category,Dictionary<string,UnitType>>(); |
0 | 190 |
82 | 191 foreach (Category category in Categories) |
192 { | |
193 unitTypesByCat.Add(category, new Dictionary<string, UnitType>()); | |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
194 } |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
195 |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
196 foreach (UnitType unit in unitTypes.Values) |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
197 { |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
198 CacheUnitType(unit); |
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
199 } |
82 | 200 } |
201 | |
202 public UnitType GetUnitType(string id) | |
11
5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
203 { |
118
d39de20f2ba1
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
204 EnsureFullyLoaded(); |
d39de20f2ba1
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
205 return DictionaryUtils.GetValue(unitTypes, id); |
0 | 206 } |
207 | |
208 public List<Ability> GetAbilityList() | |
209 { | |
118
d39de20f2ba1
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
210 EnsureFullyLoaded(); |
0 | 211 List<Ability> items = new List<Ability>(); |
55
9080366031c0
Re #9 - Refactor for small methods
IBBoard <dev@ibboard.co.uk>
parents:
54
diff
changeset
|
212 items.AddRange(abilities.Values); |
0 | 213 return items; |
214 } | |
215 | |
47
85f2b9c3609c
Re #13 - Use XPath for file loading
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
216 public void AddAbility(Ability newAbility) |
85f2b9c3609c
Re #13 - Use XPath for file loading
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
217 { |
85f2b9c3609c
Re #13 - Use XPath for file loading
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
218 //TODO: Throw DuplicateItemException |
85f2b9c3609c
Re #13 - Use XPath for file loading
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
219 abilities.Add(newAbility.ID, newAbility); |
85f2b9c3609c
Re #13 - Use XPath for file loading
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
220 } |
85f2b9c3609c
Re #13 - Use XPath for file loading
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
221 |
85f2b9c3609c
Re #13 - Use XPath for file loading
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
222 [Obsolete("Use AddAbility method instead")] |
0 | 223 public void SetAbilities(Dictionary<string, Ability> newAbilities) |
224 { | |
47
85f2b9c3609c
Re #13 - Use XPath for file loading
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
225 foreach (Ability ability in newAbilities.Values) |
85f2b9c3609c
Re #13 - Use XPath for file loading
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
226 { |
85f2b9c3609c
Re #13 - Use XPath for file loading
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
227 AddAbility(ability); |
85f2b9c3609c
Re #13 - Use XPath for file loading
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
228 } |
0 | 229 } |
230 | |
231 public Ability GetAbility(string id) | |
232 { | |
118
d39de20f2ba1
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
233 EnsureFullyLoaded(); |
d39de20f2ba1
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
234 return DictionaryUtils.GetValue(abilities, id); |
0 | 235 } |
82 | 236 |
0 | 237 protected virtual Dictionary<string, UnitType> RaceUnitTypes |
238 { | |
239 get { return RaceRawUnitTypes; } | |
240 set { RaceRawUnitTypes = value; } | |
241 } | |
82 | 242 |
0 | 243 protected virtual Dictionary<string, EquipmentItem> RaceEquipment |
244 { | |
245 get { return RaceRawEquipment; } | |
246 set { RaceRawEquipment = value; } | |
247 } | |
248 | |
249 protected virtual Dictionary<string, Ability> RaceAbilities | |
250 { | |
251 get { return RaceRawAbilities; } | |
252 set { RaceRawAbilities = value; } | |
253 } | |
82 | 254 |
0 | 255 protected Dictionary<string, UnitType> RaceRawUnitTypes |
256 { | |
257 get { return unitTypes; } | |
258 set { unitTypes = value; } | |
259 } | |
82 | 260 |
0 | 261 protected Dictionary<string, EquipmentItem> RaceRawEquipment |
262 { | |
263 get { return equipment; } | |
264 set { equipment = value; } | |
265 } | |
266 | |
267 protected Dictionary<string, Ability> RaceRawAbilities | |
268 { | |
269 get { return abilities; } | |
270 set { abilities = value; } | |
271 } | |
252
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
272 |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
273 public void AddUnitMemberType(UnitMemberType memberType) |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
274 { |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
275 memberTypes[memberType.ID] = memberType; |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
276 } |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
277 |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
278 /// <summary> |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
279 /// Gets a unit member type by its ID. |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
280 /// </summary> |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
281 /// <param name="id"> |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
282 /// The ID of the unit member type to get |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
283 /// </param> |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
284 /// <returns> |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
285 /// The <code>UnitMemberType</code> with the specified ID, or null if one doesn't exist. |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
286 /// </returns> |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
287 public UnitMemberType GetUnitMemberType(string id) |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
288 { |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
289 EnsureFullyLoaded(); |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
290 return DictionaryUtils.GetValue(memberTypes, id); |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
291 } |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
292 |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
293 public UnitMemberType[] UnitMemberTypes |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
294 { |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
295 get |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
296 { |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
297 EnsureFullyLoaded(); |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
298 return DictionaryUtils.ToArray(memberTypes); |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
299 } |
a54da5a8b5bb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
118
diff
changeset
|
300 } |
0 | 301 } |
302 } |