changeset 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 4bbf5624ced6
children c4cf4c7db7d5
files IBBoard.WarFoundry.API.csproj api/Objects/Unit.cs
diffstat 2 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/IBBoard.WarFoundry.API.csproj	Fri Oct 30 20:58:19 2009 +0000
+++ b/IBBoard.WarFoundry.API.csproj	Fri Oct 30 21:02:48 2009 +0000
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -45,6 +45,8 @@
     </None>
     <None Include="dtds\warfoundry-core.xsd">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+      <SubType>
+      </SubType>
     </None>
     <None Include="dtds\warfoundry-cats.xsd">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
--- 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;