Beispiel #1
0
    /// <summary>
    /// if 'item' is a currently wielded weapon, unwields it
    /// </summary>
    protected virtual void Unwield(vp_ItemInstance item)
    {
        if (!Application.isPlaying)
        {
            return;
        }

        if (WeaponHandler.CurrentWeaponIndex == 0)
        {
            return;
        }

        if (CurrentWeaponIdentifier == null)
        {
            MissingIdentifierError();
            return;
        }

        if (item.Type != CurrentWeaponIdentifier.Type)
        {
            return;
        }

        if ((CurrentWeaponIdentifier.ID != 0) && (item.ID != CurrentWeaponIdentifier.ID))
        {
            return;
        }

        Player.SetWeapon.TryStart(0);
        vp_Timer.In(0.35f, delegate() { Player.SetNextWeapon.Try(); });

        vp_Timer.In(1.0f, UnwieldMissingWeapon);
    }
Beispiel #2
0
    /// <summary>
    /// returns the first item instance associated with 'id' (if any).
    /// if 'id' is zero or lower, returns the first item of 'itemType'.
    /// this method uses a temporary dictionary to speed things up.
    /// if the item can't be found in the dictionary, tries to add it
    /// to the dictionary from the serialized list. returns null if
    /// 'itemType' is null or no matching item can be found
    /// </summary>
    public vp_ItemInstance GetItem(vp_ItemType itemType, int id)
    {
        //Debug.Log("GetItem @ " + Time.frameCount);

        // TIP: turn the comments in this method into debug output for
        // a very detailed look at the code flow at runtime

        if (itemType == null)
        {
            Debug.LogError("Error (" + vp_Utility.GetErrorLocation(1, true) + ") Sent a null itemType to 'GetItem'.");
            return(null);
        }

        if (id < 1)
        {
            //Debug.Log("no ID was specified: returning the first item of matching type");
            return(GetItem(itemType));
        }

        if (m_ItemDictionaryDirty)
        {
            //Debug.Log("resetting the dictionary");
            m_ItemDictionary.Clear();
            m_ItemDictionaryDirty = false;
        }

        //Debug.Log("we have an ID (" + id + "): try to fetch an associated instance from the dictionary");
        if (!m_ItemDictionary.TryGetValue(id, out m_GetItemResult))
        {
            //Debug.Log("DID NOT find item in the dictionary: trying to find it in the list");
            m_GetItemResult = GetItemFromList(itemType, id);
            if ((m_GetItemResult != null) && (id > 0))
            {
                //Debug.Log("found id '"+id+"' in the list! adding it to dictionary");
                m_ItemDictionary.Add(id, m_GetItemResult);
            }
        }
        else if (m_GetItemResult != null)
        {
            //Debug.Log("DID find a quick-match by ID ("+id+") in the dictionary: verifying the item type");
            if (m_GetItemResult.Type != itemType)
            {
                //Debug.Log("type (" + m_GetItemResult.Type + ") was wrong (expected " + itemType + ") trying to get item from the list");
                Debug.LogWarning("Warning: (vp_Inventory) Player has vp_FPWeapons with identical, non-zero vp_ItemIdentifier IDs! This is much slower than using zero or differing IDs.");
                m_GetItemResult = GetItemFromList(itemType, id);
            }
        }
        else
        {
            //Debug.Log("we found item in the dictionary but it was null");
            m_ItemDictionary.Remove(id);
            GetItem(itemType, id);
        }


        //if (m_GetItemResult != null)	Debug.Log("found item: " + m_GetItemResult + ", Type: " + m_GetItemResult.Type + ", ID: " + m_GetItemResult.ID);
        //else							Debug.Log("found no matching item");

        return(m_GetItemResult);
    }
    /// <summary>
    ///
    /// </summary>
    protected virtual void DoRemoveItem(vp_ItemInstance item)
    {
        ItemInstances.RemoveAt(ItemInstances.IndexOf(item));
        m_FirstItemsDirty = true;

        if (SpaceEnabled)
        {
            m_UsedSpace = Mathf.Max(0, (m_UsedSpace - item.Type.Space));
        }
        SetDirty();
    }
Beispiel #4
0
    /// <summary>
    ///
    /// </summary>
    public override void Reset()
    {
        m_PreviouslyOwnedItems.Clear();
        m_CurrentWeaponInstance = null;

        if (!m_Misc.ResetOnRespawn)
        {
            return;
        }

        base.Reset();
    }
    /// <summary>
    /// tries to remove an item instance directly
    /// </summary>
    public virtual bool TryRemoveItem(vp_ItemInstance item)
    {
        if (item == null)
        {
            return(false);
        }

        DoRemoveItem(item);
        SetDirty();

        return(true);
    }
Beispiel #6
0
    /// <summary>
    /// wields the vp_Weapon mapped to 'item' (if any)
    /// </summary>
    protected virtual void TryWield(vp_ItemInstance item)
    {
        if (!Application.isPlaying)
        {
            return;
        }

        if (Player.Dead.Active)
        {
            return;
        }

        if (!WeaponHandler.enabled)
        {
            return;
        }

        int index;
        vp_ItemIdentifier identifier;

        for (index = 1; index < WeaponHandler.Weapons.Count + 1; index++)
        {
            identifier = GetWeaponIdentifier(WeaponHandler.Weapons[index - 1]);

            if (identifier == null)
            {
                continue;
            }

            if (item.Type != identifier.Type)
            {
                continue;
            }

            if (identifier.ID == 0)
            {
                goto found;
            }

            if (item.ID != identifier.ID)
            {
                continue;
            }

            goto found;
        }
        return;

found:

        Player.SetWeapon.TryStart(index);
    }
Beispiel #7
0
    /// <summary>
    ///
    /// </summary>
    public vp_ItemInstance GetItemInstanceOfWeapon(vp_Weapon weapon)
    {
        vp_ItemIdentifier itemIdentifier = GetWeaponIdentifier(weapon);

        if (itemIdentifier == null)
        {
            return(null);
        }

        vp_ItemInstance ii = GetItem(itemIdentifier.Type);

        return(ii);
    }
    /// <summary>
    /// tries to remove an item record or unit from the player inventory
    /// </summary>
    protected virtual bool TryRemoveItem(vp_ItemType itemType, int units = 1, int id = 0)
    {
        //Debug.Log("TryRemoveItem: " + itemType.name + ", " + amount);

        if (Inventory == null)
        {
            Debug.LogError("Error (" + this + ") Tried to remove an item but there is no vp_Inventory!");
            return(false);
        }

        vp_ItemInstance i = null;

        if (id != 0)
        {
            i = Inventory.GetItem(itemType, id);
        }
        else
        {
            i = Inventory.GetItem(itemType.name);
        }

        if (i == null)
        {
            return(false);
        }

        id = i.ID;

        if (itemType is vp_UnitType)
        {
            if (!Inventory.TryRemoveUnits((itemType as vp_UnitType), units))
            {
                //Debug.Log("Failed to remove " + amount + " units of type: " + itemType);
                return(false);
            }
        }
        else
        {
            if (!Inventory.TryRemoveItems(itemType, 1))
            {
                //Debug.Log("Failed to remove an item of type: " + itemType);
                return(false);
            }
        }

        return(true);
    }
Beispiel #9
0
    /// <summary>
    ///
    /// </summary>
    protected virtual void DoRemoveItem(vp_ItemInstance item)
    {
        if (item as vp_UnitBankInstance != null)
        {
            DoRemoveUnitBank(item as vp_UnitBankInstance);
            return;
        }

        ItemInstances.Remove(item);

        m_FirstItemsDirty     = true;
        m_ItemDictionaryDirty = true;

        if (SpaceEnabled)
        {
            m_UsedSpace = Mathf.Max(0, (m_UsedSpace - item.Type.Space));
        }
        SetDirty();
    }
Beispiel #10
0
    /// <summary>
    ///
    /// </summary>
    protected virtual vp_Weapon GetWeaponOfItemInstance(vp_ItemInstance itemInstance)
    {
        if (m_ItemWeapons == null)
        {
            m_ItemWeapons = new Dictionary <vp_ItemInstance, vp_Weapon>();
        }

        vp_Weapon weapon;

        m_ItemWeapons.TryGetValue(itemInstance, out weapon);
        if (weapon != null)
        {
            return(weapon);
        }

        try
        {
            for (int v = 0; v < WeaponHandler.Weapons.Count; v++)
            {
                vp_ItemInstance i = GetItemInstanceOfWeapon(WeaponHandler.Weapons[v]);

                Debug.Log("weapon with index: " + v + ", item instance: " + ((i == null) ? "(have none)" : i.Type.ToString()));

                if (i != null)
                {
                    if (i.Type == itemInstance.Type)
                    {
                        weapon = WeaponHandler.Weapons[v];
                        m_ItemWeapons.Add(i, weapon);
                        return(weapon);
                    }
                }
            }
        }
        catch
        {
            Debug.LogError("Exception " + this + " Crashed while trying to get item instance for a weapon. Likely a nullreference.");
        }

        return(null);
    }
Beispiel #11
0
    /// <summary>
    /// returns the amount of items or units in the inventory by
    /// ItemType object name. WARNING: this event is potentially
    /// quite slow
    /// </summary>
    protected virtual int OnMessage_GetItemCount(string itemTypeObjectName)
    {
        vp_ItemInstance item = GetItem(itemTypeObjectName);

        if (item == null)
        {
            return(0);
        }

        // if item is an internal unitbank, return its unit count
        vp_UnitBankInstance unitBank = (item as vp_UnitBankInstance);

        if ((unitBank != null) && (unitBank.IsInternal))
        {
            return(GetItemCount(unitBank.UnitType));
        }

        // if it's a regular item or unitbank, return the amount
        // of similar instances
        return(GetItemCount(item.Type));
    }
Beispiel #12
0
    /// <summary>
    /// if 'item' is a currently wielded weapon, unwields it
    /// </summary>
    protected virtual void Unwield(vp_ItemInstance item)
    {
        // TODO: to wield next weapon here should perhaps be an optional bool

        if (!Application.isPlaying)
        {
            return;
        }

        if (WeaponHandler.CurrentWeaponIndex == 0)
        {
            return;
        }

        if (CurrentWeaponIdentifier == null)
        {
            MissingIdentifierError();
            return;
        }

        if (item.Type != CurrentWeaponIdentifier.Type)
        {
            return;
        }

        if ((CurrentWeaponIdentifier.ID != 0) && (item.ID != CurrentWeaponIdentifier.ID))
        {
            return;
        }

        Player.SetWeapon.Start(0);
        if (!Player.Dead.Active)
        {
            vp_Timer.In(0.35f, delegate() { Player.SetNextWeapon.Try(); });
        }

        vp_Timer.In(1.0f, UnwieldMissingWeapon);
    }
	/// <summary>
	/// 
	/// </summary>
	protected virtual void DoRemoveItem(vp_ItemInstance item)
	{

		if (item as vp_UnitBankInstance != null)
		{
			DoRemoveUnitBank(item as vp_UnitBankInstance);
			return;
		}
		
		ItemInstances.Remove(item);

		m_FirstItemsDirty = true;
		m_ItemDictionaryDirty = true;

		if (SpaceEnabled)
			m_UsedSpace = Mathf.Max(0, (m_UsedSpace - item.Type.Space));
		SetDirty();
	}
	/// <summary>
	/// 
	/// </summary>
	protected float DoItemsFoldout(Rect pos, SerializedProperty prop)
	{

		m_InitialY = pos.y;

		pos.height = 16;

		vp_Inventory inventory = ((vp_Inventory)prop.serializedObject.targetObject);

		GUI.backgroundColor = Color.white;

		pos.y += 
		((
		(inventory.ItemInstances.Count > 0) ||
		(inventory.UnitBankInstances.Count > 0) ||
		(inventory.InternalUnitBanks.Count > 0)) ?
		5 : -5); 
		pos.x += 20;
		pos.width -= 15;

		// --- draw internal unit banks ---

		for (int v = 0; v < inventory.InternalUnitBanks.Count; v++)
		{

			vp_UnitBankInstance ibank = inventory.InternalUnitBanks[v];

			if ((ibank == null) || (ibank.UnitType == null))
			{
				inventory.InternalUnitBanks.Remove(ibank);
				inventory.Refresh();
				continue;
			}

			string name = ibank.UnitType.ToString();
			name = name.Remove(name.IndexOf(" (")) + "s (Internal UnitBank)";

			int unitCount = inventory.GetItemCount(ibank.UnitType);

			vp_PropertyDrawerUtility.ItemCard(pos,
				((ibank == null) ? null : ibank.UnitType.Icon),
				name,
				((ibank == null) ? null : ibank.UnitType),
				ref unitCount,
				"Units",
				delegate()
				{
					inventory.TrySetUnitCount(ibank.UnitType, unitCount);
				},
				ref NO_VALUE,
				"",
				null,
				delegate()
				{
					m_UnitBankToRemove = ibank;
				});

			pos.y += 21;
		}

		// --- draw item unit bank instances (such as weapons) ---

		for (int v = 0; v < inventory.UnitBankInstances.Count; v++)
		{

			vp_UnitBankInstance bank = inventory.UnitBankInstances[v];

			int unitCount = bank.Count;

			if ((bank == null) || (bank.Type == null))
			{
				inventory.UnitBankInstances.Remove(bank);
				inventory.Refresh();
				continue;
			}

			string name = bank.Type.ToString();

			if (vp_PropertyDrawerUtility.ItemCard(pos,
				((bank == null) ? null : bank.Type.Icon),
				name,
				((bank == null) ? null : bank.Type),
				ref unitCount,
				"Units",
				delegate()
				{
					inventory.TrySetUnitCount(bank, unitCount);
				},
				ref bank.ID,
				"ID",
				null,	// no need to act on value change since it is handled by the ref above
				delegate()
				{
					m_UnitBankToRemove = bank;
				}))
			{
				inventory.ClearItemDictionaries();
				inventory.SetDirty();
			}

			pos.y += 21;

		}

		// --- draw item instances ---

		for (int v = 0; v < inventory.ItemInstances.Count; v++)
		{

			vp_ItemInstance item = inventory.ItemInstances[v];

			if ((item == null) || (item.Type == null))
			{
				inventory.ItemInstances.Remove(item);
				inventory.Refresh();
				continue;
			}

			string name = item.Type.ToString();

			if (vp_PropertyDrawerUtility.ItemCard(pos,
				((item == null) ? null : item.Type.Icon),
				name,
				((item == null) ? null : item.Type),
				ref item.ID,
				"ID",
				null,	// no need to act on value change since it is handled by the ref above
				ref NO_VALUE,
				"",
				null,
				delegate()
				{
					m_ItemToRemove = item;
				}, 45))
			{
				inventory.ClearItemDictionaries();
				inventory.SetDirty();
			}

			pos.y += 21;

		}

		// --- draw 'add object' box ---

		pos.y += 16;

		vp_PropertyDrawerUtility.AddObjectBox(pos, "n ItemType", typeof(vp_ItemType), delegate(Object itemType)
		{

			if (itemType is vp_UnitBankType)
			{
				vp_UnitBankType bank = (vp_UnitBankType)itemType;
				int cap = inventory.GetItemCap((vp_UnitBankType)itemType);

				if ((cap == -1) || (inventory.GetItemCount((vp_UnitBankType)itemType) < cap))
				{
					if (!inventory.TryGiveUnitBank(bank, bank.Capacity, 0))
						EditorUtility.DisplayDialog(m_InventoryFullCaption, string.Format(m_InventoryFullMessage, itemType), "OK");
				}
				else
					EditorUtility.DisplayDialog(m_InventoryFullCaption, string.Format(m_InventoryFullMessage, itemType), "OK");
			}
			else if (itemType is vp_UnitType)
			{
				if (!inventory.HaveInternalUnitBank((vp_UnitType)itemType))
				{
					vp_UnitType unitType = (vp_UnitType)itemType;
					if (!inventory.TryGiveUnits(unitType, 10))
						EditorUtility.DisplayDialog(m_InventoryFullCaption, string.Format(m_InventoryFullMessage, itemType), "OK");
				}
				else
					EditorUtility.DisplayDialog(m_UnitBankAlreadyExistsCaption, string.Format(m_UnitBankAlreadyExistsMessage, itemType), "OK");
			}
			else
			{
				if (!inventory.TryGiveItem((vp_ItemType)itemType, 0))
					EditorUtility.DisplayDialog(m_InventoryFullCaption, string.Format(m_InventoryFullMessage, itemType), "OK");
			}
			EditorUtility.SetDirty(inventory);
			inventory.Refresh();

		});

		pos.y += vp_PropertyDrawerUtility.CalcAddObjectBoxHeight - 5;

		// handle removed items
		if (m_UnitBankToRemove != null)
		{
			inventory.TryRemoveUnitBank(m_UnitBankToRemove);
			m_UnitBankToRemove = null;
		}
		else if (m_ItemToRemove != null)
		{
			inventory.TryRemoveItem(m_ItemToRemove);
			m_ItemToRemove = null;
		}

		return (pos.y - m_InitialY);

	}
	/// <summary>
	/// returns the first item instance associated with 'id' (if any).
	/// if 'id' is zero or lower, returns the first item of 'itemType'.
	/// this method uses a temporary dictionary to speed things up.
	/// if the item can't be found in the dictionary, tries to add it
	/// to the dictionary from the serialized list. returns null if
	/// 'itemType' is null or no matching item can be found
	/// </summary>
	public vp_ItemInstance GetItem(vp_ItemType itemType, int id)
	{

		//Debug.Log("GetItem @ " + Time.frameCount);

		// TIP: turn the comments in this method into debug output for
		// a very detailed look at the code flow at runtime

		if (itemType == null)
		{
			Debug.LogError("Error (" + vp_Utility.GetErrorLocation(1, true) + ") Sent a null itemType to 'GetItem'.");
			return null;
		}

		if (id < 1)
		{
			//Debug.Log("no ID was specified: returning the first item of matching type");
			return GetItem(itemType);
		}

		if (m_ItemDictionaryDirty)
		{
			//Debug.Log("resetting the dictionary");
			m_ItemDictionary.Clear();
			m_ItemDictionaryDirty = false;
		}

		//Debug.Log("we have an ID (" + id + "): try to fetch an associated instance from the dictionary");
		if (!m_ItemDictionary.TryGetValue(id, out m_GetItemResult))
		{

			//Debug.Log("DID NOT find item in the dictionary: trying to find it in the list");
			m_GetItemResult = GetItemFromList(itemType, id);
			if ((m_GetItemResult != null) && (id > 0))
			{

				//Debug.Log("found id '"+id+"' in the list! adding it to dictionary");
				m_ItemDictionary.Add(id, m_GetItemResult);
			}
		}
		else if (m_GetItemResult != null)
		{

			//Debug.Log("DID find a quick-match by ID ("+id+") in the dictionary: verifying the item type");
			if (m_GetItemResult.Type != itemType)
			{

				//Debug.Log("type (" + m_GetItemResult.Type + ") was wrong (expected " + itemType + ") trying to get item from the list");
				Debug.LogWarning("Warning: (vp_Inventory) Player has vp_FPWeapons with identical, non-zero vp_ItemIdentifier IDs! This is much slower than using zero or differing IDs.");
				m_GetItemResult = GetItemFromList(itemType, id);
			}
		}
		else
		{

			//Debug.Log("we found item in the dictionary but it was null");
			m_ItemDictionary.Remove(id);
			GetItem(itemType, id);
		}


		//if (m_GetItemResult != null)	Debug.Log("found item: " + m_GetItemResult + ", Type: " + m_GetItemResult.Type + ", ID: " + m_GetItemResult.ID);
		//else							Debug.Log("found no matching item");

		return m_GetItemResult;

	}
	/// <summary>
	/// tries to remove an item instance directly
	/// </summary>
	public virtual bool TryRemoveItem(vp_ItemInstance item)
	{

		if (item == null)
			return false;

		DoRemoveItem(item);
		SetDirty();

		return true;

	}
Beispiel #17
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void OnStop_SetWeapon()
 {
     m_CurrentWeaponInstance = null;
 }
Beispiel #18
0
 /// <summary>
 ///
 /// </summary>
 protected override void DoRemoveItem(vp_ItemInstance item)
 {
     Unwield(item);
     base.DoRemoveItem(item);
 }
	/// <summary>
	/// 
	/// </summary>
	public override void Reset()
	{

		m_PreviouslyOwnedItems.Clear();
		m_CurrentWeaponInstance = null;

		if (!m_Misc.ResetOnRespawn)
			return;

		base.Reset();

	}
	/// <summary>
	/// 
	/// </summary>
	protected virtual void OnStop_SetWeapon()
	{
		m_CurrentWeaponInstance = null;
	}
	/// <summary>
	/// if 'item' is a currently wielded weapon, unwields it
	/// </summary>
	protected virtual void Unwield(vp_ItemInstance item)
	{

		// TODO: to wield next weapon here should perhaps be an optional bool

		if (!Application.isPlaying)
			return;

		if (WeaponHandler.CurrentWeaponIndex == 0)
			return;

		if (CurrentWeaponIdentifier == null)
		{
			MissingIdentifierError();
			return;
		}

		if (item.Type != CurrentWeaponIdentifier.Type)
			return;

		if ((CurrentWeaponIdentifier.ID != 0) && (item.ID != CurrentWeaponIdentifier.ID))
			return;

		Player.SetWeapon.Start(0);
		if (!Player.Dead.Active)
			vp_Timer.In(0.35f, delegate()	{	Player.SetNextWeapon.Try();	});

		vp_Timer.In(1.0f, UnwieldMissingWeapon);

	}
	/// <summary>
	/// wields the vp_Weapon mapped to 'item' (if any)
	/// </summary>
	protected virtual void TryWield(vp_ItemInstance item)
	{

		if (!Application.isPlaying)
			return;

		if (Player.Dead.Active)
			return;

		if (!WeaponHandler.enabled)
			return;

		int index;
		vp_ItemIdentifier identifier;
		for (index = 1; index < WeaponHandler.Weapons.Count + 1; index++)
		{

			identifier = GetWeaponIdentifier(WeaponHandler.Weapons[index - 1]);

			if (identifier == null)
				continue;

			if (item.Type != identifier.Type)
				continue;

			if (identifier.ID == 0)
				goto found;

			if (item.ID != identifier.ID)
				continue;

			goto found;

		}
		return;

	found:

		Player.SetWeapon.TryStart(index);

	}
	/// <summary>
	/// 
	/// </summary>
	protected virtual vp_Weapon GetWeaponOfItemInstance(vp_ItemInstance itemInstance)
	{

		if (m_ItemWeapons == null)
		{
			m_ItemWeapons = new Dictionary<vp_ItemInstance, vp_Weapon>();
		}

		vp_Weapon weapon;
		m_ItemWeapons.TryGetValue(itemInstance, out weapon);
		if (weapon != null)
			return weapon;

		try
		{
			for (int v = 0; v < WeaponHandler.Weapons.Count; v++)
			{
				vp_ItemInstance i = GetItemInstanceOfWeapon(WeaponHandler.Weapons[v]);

				Debug.Log("weapon with index: " + v + ", item instance: " + ((i == null) ? "(have none)" : i.Type.ToString()));
				
				if (i != null)
				{
					if (i.Type == itemInstance.Type)
					{
						weapon = WeaponHandler.Weapons[v];
						m_ItemWeapons.Add(i, weapon);
						return weapon;
					}
				}
			}
		}
		catch
		{
			Debug.LogError("Exception " + this + " Crashed while trying to get item instance for a weapon. Likely a nullreference.");
		}

		return null;
	}
	/// <summary>
	/// if 'item' is a currently wielded weapon, unwields it
	/// </summary>
	protected virtual void Unwield(vp_ItemInstance item)
	{

		if (!Application.isPlaying)
			return;

		if (WeaponHandler.CurrentWeaponIndex == 0)
			return;

		if (CurrentWeaponIdentifier == null)
		{
			MissingIdentifierError();
			return;
		}

		if (item.Type != CurrentWeaponIdentifier.Type)
			return;

		if ((CurrentWeaponIdentifier.ID != 0) && (item.ID != CurrentWeaponIdentifier.ID))
			return;

		Player.SetWeapon.TryStart(0);
		vp_Timer.In(0.35f, delegate() { Player.SetNextWeapon.Try(); });

		vp_Timer.In(1.0f, UnwieldMissingWeapon);

	}
    /// <summary>
    ///
    /// </summary>
    protected float DoItemsFoldout(Rect pos, SerializedProperty prop)
    {
        m_InitialY = pos.y;

        pos.height = 16;

        vp_Inventory inventory = ((vp_Inventory)prop.serializedObject.targetObject);

        GUI.backgroundColor = Color.white;

        pos.y +=
            ((
                 (inventory.ItemInstances.Count > 0) ||
                 (inventory.UnitBankInstances.Count > 0) ||
                 (inventory.InternalUnitBanks.Count > 0)) ?
             5 : -5);
        pos.x     += 20;
        pos.width -= 15;

        // --- draw internal unit banks ---

        for (int v = 0; v < inventory.InternalUnitBanks.Count; v++)
        {
            vp_UnitBankInstance ibank = inventory.InternalUnitBanks[v];

            if ((ibank == null) || (ibank.UnitType == null))
            {
                inventory.InternalUnitBanks.Remove(ibank);
                inventory.Refresh();
                continue;
            }

            string name = ibank.UnitType.ToString();
            name = name.Remove(name.IndexOf(" (")) + "s (Internal UnitBank)";

            int unitCount = inventory.GetItemCount(ibank.UnitType);

            vp_PropertyDrawerUtility.ItemCard(pos,
                                              ((ibank == null) ? null : ibank.UnitType.Icon),
                                              name,
                                              ((ibank == null) ? null : ibank.UnitType),
                                              ref unitCount,
                                              "Units",
                                              delegate()
            {
                inventory.TrySetUnitCount(ibank.UnitType, unitCount);
            },
                                              ref NO_VALUE,
                                              "",
                                              null,
                                              delegate()
            {
                m_UnitBankToRemove = ibank;
            });

            pos.y += 21;
        }

        // --- draw item unit bank instances (such as weapons) ---

        for (int v = 0; v < inventory.UnitBankInstances.Count; v++)
        {
            vp_UnitBankInstance bank = inventory.UnitBankInstances[v];

            int unitCount = bank.Count;

            if ((bank == null) || (bank.Type == null))
            {
                inventory.UnitBankInstances.Remove(bank);
                inventory.Refresh();
                continue;
            }

            string name = bank.Type.ToString();

            if (vp_PropertyDrawerUtility.ItemCard(pos,
                                                  ((bank == null) ? null : bank.Type.Icon),
                                                  name,
                                                  ((bank == null) ? null : bank.Type),
                                                  ref unitCount,
                                                  "Units",
                                                  delegate()
            {
                inventory.TrySetUnitCount(bank, unitCount);
            },
                                                  ref bank.ID,
                                                  "ID",
                                                  null, // no need to act on value change since it is handled by the ref above
                                                  delegate()
            {
                m_UnitBankToRemove = bank;
            }))
            {
                inventory.ClearItemDictionaries();
                inventory.SetDirty();
            }

            pos.y += 21;
        }

        // --- draw item instances ---

        for (int v = 0; v < inventory.ItemInstances.Count; v++)
        {
            vp_ItemInstance item = inventory.ItemInstances[v];

            if ((item == null) || (item.Type == null))
            {
                inventory.ItemInstances.Remove(item);
                inventory.Refresh();
                continue;
            }

            string name = item.Type.ToString();

            if (vp_PropertyDrawerUtility.ItemCard(pos,
                                                  ((item == null) ? null : item.Type.Icon),
                                                  name,
                                                  ((item == null) ? null : item.Type),
                                                  ref item.ID,
                                                  "ID",
                                                  null, // no need to act on value change since it is handled by the ref above
                                                  ref NO_VALUE,
                                                  "",
                                                  null,
                                                  delegate()
            {
                m_ItemToRemove = item;
            }, 45))
            {
                inventory.ClearItemDictionaries();
                inventory.SetDirty();
            }

            pos.y += 21;
        }

        // --- draw 'add object' box ---

        pos.y += 16;

        vp_PropertyDrawerUtility.AddObjectBox(pos, "n ItemType", typeof(vp_ItemType), delegate(Object itemType)
        {
            if (itemType is vp_UnitBankType)
            {
                vp_UnitBankType bank = (vp_UnitBankType)itemType;
                int cap = inventory.GetItemCap((vp_UnitBankType)itemType);

                if ((cap == -1) || (inventory.GetItemCount((vp_UnitBankType)itemType) < cap))
                {
                    if (!inventory.TryGiveUnitBank(bank, bank.Capacity, 0))
                    {
                        EditorUtility.DisplayDialog(m_InventoryFullCaption, string.Format(m_InventoryFullMessage, itemType), "OK");
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog(m_InventoryFullCaption, string.Format(m_InventoryFullMessage, itemType), "OK");
                }
            }
            else if (itemType is vp_UnitType)
            {
                if (!inventory.HaveInternalUnitBank((vp_UnitType)itemType))
                {
                    vp_UnitType unitType = (vp_UnitType)itemType;
                    if (!inventory.TryGiveUnits(unitType, 10))
                    {
                        EditorUtility.DisplayDialog(m_InventoryFullCaption, string.Format(m_InventoryFullMessage, itemType), "OK");
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog(m_UnitBankAlreadyExistsCaption, string.Format(m_UnitBankAlreadyExistsMessage, itemType), "OK");
                }
            }
            else
            {
                if (!inventory.TryGiveItem((vp_ItemType)itemType, 0))
                {
                    EditorUtility.DisplayDialog(m_InventoryFullCaption, string.Format(m_InventoryFullMessage, itemType), "OK");
                }
            }
            EditorUtility.SetDirty(inventory);
            inventory.Refresh();
        });

        pos.y += vp_PropertyDrawerUtility.CalcAddObjectBoxHeight - 5;

        // handle removed items
        if (m_UnitBankToRemove != null)
        {
            inventory.TryRemoveUnitBank(m_UnitBankToRemove);
            m_UnitBankToRemove = null;
        }
        else if (m_ItemToRemove != null)
        {
            inventory.TryRemoveItem(m_ItemToRemove);
            m_ItemToRemove = null;
        }

        return(pos.y - m_InitialY);
    }
	/// <summary>
	/// 
	/// </summary>
	protected override void DoRemoveItem(vp_ItemInstance item)
	{

		Unwield(item);
		base.DoRemoveItem(item);

	}
	/// <summary>
	/// 
	/// </summary>
	protected virtual void DoRemoveItem(vp_ItemInstance item)
	{
		ItemInstances.RemoveAt(ItemInstances.IndexOf(item));
		m_FirstItemsDirty = true;

		if (SpaceEnabled)
			m_UsedSpace = Mathf.Max(0, (m_UsedSpace - item.Type.Space));
		SetDirty();
	}