RemoveTokens() public method

Remove a given number of tokens from the bucket
public RemoveTokens ( int amount ) : bool
amount int Number of tokens to remove from the bucket
return bool
コード例 #1
0
        /// <summary>
        /// Remove a given number of tokens from the bucket
        /// </summary>
        /// <param name="amount">Number of tokens to remove from the bucket</param>
        /// <param name="dripSucceeded">True if tokens were added to the bucket
        /// during this call, otherwise false</param>
        /// <returns>True if the requested number of tokens were removed from
        /// the bucket, otherwise false</returns>
        public bool RemoveTokens(int amount, out bool dripSucceeded)
        {
            if (maxBurst == 0)
            {
                dripSucceeded = true;
                return(true);
            }

            dripSucceeded = Drip();

            if (content - amount >= 0)
            {
                if (parent != null && !parent.RemoveTokens(amount))
                {
                    return(false);
                }

                content -= amount;
                return(true);
            }
            else
            {
                return(false);
            }
        }