示例#1
0
    /// <summary>
    /// returns true if we managed to add new items of 'itemType',
    /// false if not
    /// </summary>
    protected static bool TryGiveItemAsNew(Transform recipient, vp_ItemType itemType, int amount)
    {
        System.Type type = itemType.GetType();

        if (type == typeof(vp_ItemType))
        {
            return(vp_TargetEventReturn <vp_ItemType, int, bool> .SendUpwards(recipient, "TryGiveItem", itemType, 0));
        }
        else if (type == typeof(vp_UnitBankType))
        {
            return(vp_TargetEventReturn <vp_UnitBankType, int, int, bool> .SendUpwards(recipient, "TryGiveUnitBank", (itemType as vp_UnitBankType), amount, 0));
        }
        else if (type == typeof(vp_UnitType))
        {
            return(vp_TargetEventReturn <vp_UnitType, int, bool> .SendUpwards(recipient, "TryGiveUnits", (itemType as vp_UnitType), amount));
        }
        else if (type.BaseType == typeof(vp_ItemType))
        {
            return(vp_TargetEventReturn <vp_ItemType, int, bool> .SendUpwards(recipient, "TryGiveItem", itemType, 0));
        }
        else if (type.BaseType == typeof(vp_UnitBankType))
        {
            return(vp_TargetEventReturn <vp_UnitBankType, int, int, bool> .SendUpwards(recipient, "TryGiveUnitBank", (itemType as vp_UnitBankType), amount, 0));
        }
        else if (type.BaseType == typeof(vp_UnitType))
        {
            return(vp_TargetEventReturn <vp_UnitType, int, bool> .SendUpwards(recipient, "TryGiveUnits", (itemType as vp_UnitType), amount));
        }

        return(false);
    }
示例#2
0
    /// <summary>
    /// returns true if inventory has items of 'itemType', and the
    /// amount of existing items is modified or unchanged. returns
    /// false if there are no matching items
    /// </summary>
    protected static bool TryMatchExistingItem(vp_Inventory inventory, Transform recipient, vp_ItemType itemType, int amount)
    {
        //Debug.Log("--- TryMatchExistingItem ---");
        //Debug.Log("recipient: " + recipient);
        //Debug.Log("item type: " + itemType);
        //Debug.Log("amount: " + amount);

        System.Type type = itemType.GetType();

        if ((type == typeof(vp_UnitBankType)) || (type.BaseType == typeof(vp_UnitBankType)))
        {
            vp_UnitBankInstance ui = inventory.GetItem(itemType) as vp_UnitBankInstance;
            if (ui != null)
            {
                ui.Count = amount;
                return(true);
            }
        }
        else if ((type == typeof(vp_UnitType)) || (type.BaseType == typeof(vp_UnitType)))
        {
            if (inventory.HaveInternalUnitBank(itemType as vp_UnitType))
            {
                vp_UnitBankInstance ui = inventory.GetInternalUnitBank(itemType as vp_UnitType);
                ui.Count = amount;
                return(true);
            }
        }
        else if ((type == typeof(vp_ItemType)) || (type.BaseType == typeof(vp_ItemType)))
        {
            int existing = inventory.GetItemCount(itemType);
            //Debug.Log("currently existing in inventory: " + existing);

            if (existing > 0)
            {
                int adjustment = (amount - existing);
                //Debug.Log("needed adjustment: " + adjustment);

                if (adjustment < 0)
                {
                    //Debug.Log("adjustment less than zero. running 'TryRemoveItems' with argument '" + adjustment + "' and result: " +
                    inventory.TryRemoveItems(itemType, Mathf.Abs(adjustment));
                    //);
                }
                else if (adjustment > 0)
                {
                    //Debug.Log("adjustment more than zero. running 'TryGiveItems' with argument '" + adjustment + "' and result: " +
                    inventory.TryGiveItems(itemType, adjustment);
                    //);
                }

                return(true);
            }
        }

        //Debug.Log("------------------------");

        return(false);
    }
示例#3
0
	/// <summary>
	/// returns true if we managed to add new items of 'itemType',
	/// false if not
	/// </summary>
	protected static bool TryGiveItemAsNew(Transform recipient, vp_ItemType itemType, int amount)
	{

		System.Type type = itemType.GetType();

		if (type == typeof(vp_ItemType))
			return vp_TargetEventReturn<vp_ItemType, int, bool>.SendUpwards(recipient, "TryGiveItem", itemType, 0);
		else if (type == typeof(vp_UnitBankType))
			return vp_TargetEventReturn<vp_UnitBankType, int, int, bool>.SendUpwards(recipient, "TryGiveUnitBank", (itemType as vp_UnitBankType), amount, 0);
		else if (type == typeof(vp_UnitType))
			return vp_TargetEventReturn<vp_UnitType, int, bool>.SendUpwards(recipient, "TryGiveUnits", (itemType as vp_UnitType), amount);
		else if (type.BaseType == typeof(vp_ItemType))
			return vp_TargetEventReturn<vp_ItemType, int, bool>.SendUpwards(recipient, "TryGiveItem", itemType, 0);
		else if (type.BaseType == typeof(vp_UnitBankType))
			return vp_TargetEventReturn<vp_UnitBankType, int, int, bool>.SendUpwards(recipient, "TryGiveUnitBank", (itemType as vp_UnitBankType), amount, 0);
		else if (type.BaseType == typeof(vp_UnitType))
			return vp_TargetEventReturn<vp_UnitType, int, bool>.SendUpwards(recipient, "TryGiveUnits", (itemType as vp_UnitType), amount);

		return false;

	}
示例#4
0
	/// <summary>
	/// returns true if inventory has items of 'itemType', and the
	/// amount of existing items is modified or unchanged. returns
	/// false if there are no matching items
	/// </summary>
	protected static bool TryMatchExistingItem(vp_Inventory inventory, Transform recipient, vp_ItemType itemType, int amount)
	{

		//Debug.Log("--- TryMatchExistingItem ---");
		//Debug.Log("recipient: " + recipient);
		//Debug.Log("item type: " + itemType);
		//Debug.Log("amount: " + amount);

		System.Type type = itemType.GetType();

		if ((type == typeof(vp_UnitBankType)) || (type.BaseType == typeof(vp_UnitBankType)))
		{

			vp_UnitBankInstance ui = inventory.GetItem(itemType) as vp_UnitBankInstance;
			if (ui != null)
			{
				ui.Count = amount;
				return true;
			}
		}
		else if ((type == typeof(vp_UnitType)) || (type.BaseType == typeof(vp_UnitType)))
		{
			if (inventory.HaveInternalUnitBank(itemType as vp_UnitType))
			{
				vp_UnitBankInstance ui = inventory.GetInternalUnitBank(itemType as vp_UnitType);
				ui.Count = amount;
				return true;
			}
		}
		else if ((type == typeof(vp_ItemType)) || (type.BaseType == typeof(vp_ItemType)))
		{

			int existing = inventory.GetItemCount(itemType);
			//Debug.Log("currently existing in inventory: " + existing);

			if (existing > 0)
			{
				int adjustment = (amount - existing);
				//Debug.Log("needed adjustment: " + adjustment);

				if (adjustment < 0)
				{
					//Debug.Log("adjustment less than zero. running 'TryRemoveItems' with argument '" + adjustment + "' and result: " +
					inventory.TryRemoveItems(itemType, Mathf.Abs(adjustment));
					//);
				}
				else if (adjustment > 0)
				{
					//Debug.Log("adjustment more than zero. running 'TryGiveItems' with argument '" + adjustment + "' and result: " +
					inventory.TryGiveItems(itemType, adjustment);
					//);
				}

				return true;
			}
		}

		//Debug.Log("------------------------");

		return false;

	}
示例#5
0
    /// <summary>
    ///
    /// </summary>
    protected virtual void TryWieldNewItem(vp_ItemType type, bool alreadyHaveIt)
    {
        bool haveHadItBefore = m_PreviouslyOwnedItems.ContainsKey(type);

        if (!haveHadItBefore)
        {
            m_PreviouslyOwnedItems.Add(type, null);
        }

        // --- see if we should try to wield a weapon because of this item pickup ---

        if (m_AutoWield.Always)
        {
            goto tryWield;
        }

        if (m_AutoWield.IfUnarmed && (WeaponHandler.CurrentWeaponIndex < 1))
        {
            goto tryWield;
        }

        if (m_AutoWield.IfOutOfAmmo &&
            (WeaponHandler.CurrentWeaponIndex > 0) &&
            (WeaponHandler.CurrentWeapon.AnimationType != (int)vp_Weapon.Type.Melee) &&
            m_Player.CurrentWeaponAmmoCount.Get() < 1)
        {
            goto tryWield;
        }

        if (m_AutoWield.IfNotPresent && !m_AutoWield.FirstTimeOnly && !alreadyHaveIt)
        {
            goto tryWield;
        }

        if (m_AutoWield.FirstTimeOnly && !haveHadItBefore)
        {
            goto tryWield;
        }

        return;

tryWield:

        if ((type is vp_UnitBankType))
        {
            TryWield(GetItem(type));
        }
        else if (type is vp_UnitType)
        {
            TryWieldByUnit(type as vp_UnitType);
        }
        else if (type is vp_ItemType)           // tested last since the others derive from it
        {
            TryWield(GetItem(type));
        }
        else
        {
            System.Type baseType = type.GetType();
            if (baseType == null)
            {
                return;
            }
            baseType = baseType.BaseType;
            if ((baseType == typeof(vp_UnitBankType)))
            {
                TryWield(GetItem(type));
            }
            else if (baseType == typeof(vp_UnitType))
            {
                TryWieldByUnit(type as vp_UnitType);
            }
            else if (baseType == typeof(vp_ItemType))
            {
                TryWield(GetItem(type));
            }
        }
    }
	/// <summary>
	/// 
	/// </summary>
	protected virtual void TryWieldNewItem(vp_ItemType type, bool alreadyHaveIt)
	{

		bool haveHadItBefore = m_PreviouslyOwnedItems.ContainsKey(type);
		if (!haveHadItBefore)
			m_PreviouslyOwnedItems.Add(type, null);

		// --- see if we should try to wield a weapon because of this item pickup ---

		if (m_AutoWield.Always)
			goto tryWield;

		if (m_AutoWield.IfUnarmed && (WeaponHandler.CurrentWeaponIndex < 1))
			goto tryWield;

		if (m_AutoWield.IfOutOfAmmo
			&& (WeaponHandler.CurrentWeaponIndex > 0)
			&& (WeaponHandler.CurrentWeapon.AnimationType != (int)vp_Weapon.Type.Melee)
			&& m_Player.CurrentWeaponAmmoCount.Get() < 1)
			goto tryWield;

		if (m_AutoWield.IfNotPresent && !m_AutoWield.FirstTimeOnly && !alreadyHaveIt)
			goto tryWield;

		if (m_AutoWield.FirstTimeOnly && !haveHadItBefore)
			goto tryWield;

		return;

	tryWield:

		if ((type is vp_UnitBankType))
			TryWield(GetItem(type));
		else if (type is vp_UnitType)
			TryWieldByUnit(type as vp_UnitType);
		else if (type is vp_ItemType)	// tested last since the others derive from it
			TryWield(GetItem(type));
		else
		{
			System.Type baseType = type.GetType();
			if (baseType == null)
				return;
			baseType = baseType.BaseType;
			if ((baseType == typeof(vp_UnitBankType)))
				TryWield(GetItem(type));
			else if (baseType == typeof(vp_UnitType))
				TryWieldByUnit(type as vp_UnitType);
			else if (baseType == typeof(vp_ItemType))
				TryWield(GetItem(type));
		}
		
	}