Example #1
0
        /// <summary>
        /// Buying needs in circle, by Procent in time
        /// return true if buying is zero (bought all what it wanted)
        /// </summary>
        internal bool buy(Producer buyer, StorageSet stillHaveToBuy, Procent buyInTime, StorageSet ofWhat)
        {
            bool buyingIsFinished = true;

            foreach (Storage what in ofWhat)
            {
                Storage consumeOnThisIteration = new Storage(what.getProduct(), what.get() * buyInTime.get());
                if (consumeOnThisIteration.isZero())
                {
                    return(true);
                }

                // check if consumeOnThisIteration is not bigger than stillHaveToBuy
                if (!stillHaveToBuy.has(consumeOnThisIteration))
                {
                    consumeOnThisIteration = stillHaveToBuy.getBiggestStorage(what.getProduct());
                }
                var reallyBought = buy(buyer, consumeOnThisIteration, null);

                stillHaveToBuy.subtract(reallyBought);

                if (stillHaveToBuy.getBiggestStorage(what.getProduct()).isNotZero())
                {
                    buyingIsFinished = false;
                }
            }
            return(buyingIsFinished);
        }