comparison api/Objects/Unit.cs @ 161:81abc04b3dbe

Re #192: Improve "clean coding" practice * Move some calculation methods for equipment out of the encapsulation objects
author IBBoard <dev@ibboard.co.uk>
date Sun, 04 Oct 2009 12:00:16 +0000
parents eb9a6d91a6db
children 624422e91a1c
comparison
equal deleted inserted replaced
160:41b927998a41 161:81abc04b3dbe
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.Text; 7 using System.Text;
8 using System.Xml; 8 using System.Xml;
9 using IBBoard.Lang; 9 using IBBoard.Lang;
10 using IBBoard.WarFoundry.API.Util;
10 11
11 namespace IBBoard.WarFoundry.API.Objects 12 namespace IBBoard.WarFoundry.API.Objects
12 { 13 {
13 /// <summary> 14 /// <summary>
14 /// Summary description for UnitInstance. 15 /// Summary description for UnitInstance.
218 } 219 }
219 } 220 }
220 } 221 }
221 } 222 }
222 223
224 [Obsolete("Use UnitEquipmentUtil.GetAllowedEquipmentItems(Unit) instead")]
223 public UnitEquipmentItem[] GetAllowedAdditionalEquipment() 225 public UnitEquipmentItem[] GetAllowedAdditionalEquipment()
224 { 226 {
225 List<UnitEquipmentItem> list = new List<UnitEquipmentItem>(); 227 return UnitEquipmentUtil.GetAllowedEquipmentItems(this);
226 List<string> existingMutexGroups = new List<string>();
227
228 foreach (UnitEquipmentItem item in GetEquipment())
229 {
230 foreach (string mutex in item.MutexGroups)
231 {
232 existingMutexGroups.Add(mutex);
233 }
234 }
235
236 foreach (UnitEquipmentItem item in UnitType.GetEquipmentItems())
237 {
238 bool mutexMatch = false;
239
240 foreach (string mutex in item.MutexGroups)
241 {
242 if (existingMutexGroups.Contains(mutex))
243 {
244 mutexMatch = true;
245 break;
246 }
247 }
248
249 if (!mutexMatch)
250 {
251 list.Add(item);
252 }
253 }
254
255 return list.ToArray();
256 } 228 }
257 229
258 public UnitEquipmentItem[] GetEquipment() 230 public UnitEquipmentItem[] GetEquipment()
259 { 231 {
260 return DictionaryUtils.ToKeyArray(equipment); 232 return DictionaryUtils.ToKeyArray(equipment);
466 } 438 }
467 439
468 return canEquip; 440 return canEquip;
469 } 441 }
470 442
471 /// <summary> 443 [Obsolete("Use UnitEquipmentUtil.GetBlockingEquipmentItems(Unit, UnitEquipmentItem) instead")]
472 /// Gets a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code> because of mutex groups.
473 /// </summary>
474 /// <param name="item">The item to check blocking items for</param>
475 /// <returns>a list of all <see cref="UnitEquipmentItem"/>s that would stop the unit taking <code>item</code></returns>
476 public List<UnitEquipmentItem> GetBlockingEquipmentItems(UnitEquipmentItem item) 444 public List<UnitEquipmentItem> GetBlockingEquipmentItems(UnitEquipmentItem item)
477 { 445 {
478 List<UnitEquipmentItem> items = new List<UnitEquipmentItem>(); 446 return UnitEquipmentUtil.GetBlockingEquipmentItems(this, item);
479
480 foreach (UnitEquipmentItem unitItem in GetEquipment())
481 {
482 if (unitItem.IsMutuallyExclusive(item))
483 {
484 items.Add(unitItem);
485 }
486 }
487
488 return items;
489 } 447 }
490 448
491 public bool CanEquipWithItem(string equipID) 449 public bool CanEquipWithItem(string equipID)
492 { 450 {
493 return CanEquipWithItem(UnitType.GetEquipmentItem(equipID)); 451 return CanEquipWithItem(UnitType.GetEquipmentItem(equipID));