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