Example #1
0
    /// <summary>
    /// tries to add load ammo into a weapon in this inventory
    /// by weapon name and ammo count. note that the argument
    /// is of type 'object' and should be an object array
    /// containing a string and an int, respectively.
    /// </summary>
    protected virtual bool OnAttempt_AddAmmo(object arg)
    {
        // unbox object argument into an object array
        object[] args = (object[])arg;

        // get weapon name from the first argument
        string weaponName = (string)args[0];

        // if we have a 2nd argument, get ammo from it, otherwise set ammo to max (-1)
        int ammo = (args.Length == 2) ? (int)args[1] : -1;

        // fail if we don't have the weapon or it is unknown
        InventoryWeaponStatus weapon = GetWeaponStatus((string)weaponName);

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

        if (ammo == -1)
        {
            weapon.LoadedAmmo = weapon.MaxAmmo;                                                 // ammo '-1' means 'fill her up'
        }
        else
        {
            weapon.LoadedAmmo = Mathf.Min(weapon.LoadedAmmo + ammo, weapon.MaxAmmo);                    // add 'ammo' units, capping at max
        }
        return(true);
    }
Example #2
0
    /// <summary>
    /// temporary solution for cases where we can't get the
    /// current weapon status yet because the current weapon
    /// isn't done getting wielded (this should really be done
    /// using some sort of callback).
    /// </summary>
    protected void RefreshWeaponStatus()
    {
        // if new weapon isn't done getting wielded yet, reschedule
        // this method in 0.1 secs
        if (m_Player.CurrentWeaponWielded.Get() == false &&
            m_RefreshWeaponStatusIterations < 50)               // stop trying after 5 seconds
        {
            m_RefreshWeaponStatusIterations++;
            vp_Timer.In(0.1f, RefreshWeaponStatus);
            return;
        }
        m_RefreshWeaponStatusIterations = 0;

        // new weapon is in place; now fetch its type
        string weaponName = m_Player.CurrentWeaponName.Get();

        if (string.IsNullOrEmpty(weaponName))
        {
            return;
        }

        m_CurrentWeaponStatus = GetWeaponStatus(weaponName);
    }
	/// <summary>
	/// temporary solution for cases where we can't get the
	/// current weapon status yet because the current weapon
	/// isn't done getting wielded (this should really be done
	/// using some sort of callback).
	/// </summary>
	protected void RefreshWeaponStatus()
	{

		// if new weapon isn't done getting wielded yet, reschedule
		// this method in 0.1 secs
		if (m_Player.CurrentWeaponWielded.Get() == false &&
			m_RefreshWeaponStatusIterations < 50)	// stop trying after 5 seconds
		{
			m_RefreshWeaponStatusIterations++;
			vp_Timer.In(0.1f, RefreshWeaponStatus);
			return;
		}
		m_RefreshWeaponStatusIterations = 0;

		// new weapon is in place; now fetch its type
		string weaponName = m_Player.CurrentWeaponName.Get();
		if (string.IsNullOrEmpty(weaponName))
			return;

		m_CurrentWeaponStatus = GetWeaponStatus(weaponName);

	}