diff api/Objects/Unit.cs @ 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) no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Fri, 30 Oct 2009 21:02:48 +0000
parents 36adabb1c3ea
children 4d7ff70bb109
line wrap: on
line diff
--- a/api/Objects/Unit.cs	Fri Oct 30 20:58:19 2009 +0000
+++ b/api/Objects/Unit.cs	Fri Oct 30 21:02:48 2009 +0000
@@ -520,6 +520,36 @@
 			return amount;
 		}
 
+		/// <summary>
+		/// Gets the total amount of items taken for the item's slot, excluding the provided item
+		/// </summary>
+		/// <param name="item">the item to exclude from the count</param>
+		/// <returns>the total number of items</returns>
+		public int GetEquipmentAmountInSlotWithoutItem(UnitEquipmentItem item)
+		{
+			int amount = 0;
+
+			List<AbstractUnitEquipmentItemSelection> selections = DictionaryUtils.GetValue(equipmentSlots, item.SlotName);
+
+			if (selections != null)
+			{
+				RemoveSelectionFromList(item, selections);
+				amount = GetSelectionTotal(selections);
+			}
+
+			return amount;
+		}
+
+		private void RemoveSelectionFromList(UnitEquipmentItem item, List<AbstractUnitEquipmentItemSelection> selections)
+		{
+			AbstractUnitEquipmentItemSelection selection = GetEquipmentSelection(item);
+
+			if (selection != null)
+			{
+				selections.Remove(selection);
+			}
+		}
+
 		private int GetSelectionTotal (List<AbstractUnitEquipmentItemSelection> selections)
 		{
 			int amount = 0;