//Simulate NPC shopping up to this point in time or until the end of the sweep time-period.
        //This method will add one items to cart at the rate specified by the constants above (currently an item per second for 60 seconds).
        public static void RunNpcSweep(this HttpSessionStateBase session, Cart cart, IEnumerable <Product> repoProdList, bool shopToEnd = false)
        {
            //ensure that the NPC sweep hasn't already finished.
            bool sweepCompleted = session.GetShoppingByNpcCompleted();

            if (sweepCompleted)
            {
                return;          //Operation has completed. No need to run cart sweep simulation.
            }

            int delayMilliseconds         = shoppingStartDelayMilliseconds;
            int maxItemLimit              = NpcShoppingItemLimit;
            int totalMilliseconds         = shoppingTimeMilliseconds;
            int currentTotalNpcQuantities = cart.ComputeTotalQuantitiesOther();

            //ensure we are within time. If so, calculate number of seconds of shopping time to simulate. If not, shop to end of period.
            int remainingMilliseconds = session.GetRemainingTime();

            if (remainingMilliseconds <= 0)
            { //if shopping time has expired, then shop to the end of the time period (NPC always completes a full sweep successfully) and set appropriate flag later.
                shopToEnd = true;
            }
            else
            {
                //Delay NPC sweep until set time from start, unless we are shopping to end anyway.
                if ((delayMilliseconds > totalMilliseconds - remainingMilliseconds) && (!shopToEnd))
                {
                    return;
                }
            }

            //initialise req'd variables
            int lastProdId    = 0;
            int numItemsToAdd = 0;

            //if shopping to end, shop for all remaining items. Else add items with respect to the current-expired time only (as a simple ratio, say).
            if (shopToEnd)
            {
                numItemsToAdd = maxItemLimit - currentTotalNpcQuantities;
            }
            else
            { // casting is req'd to stop integer ratios tending to zero.
                numItemsToAdd = (int)(maxItemLimit * (((double)totalMilliseconds - (double)remainingMilliseconds) / (double)totalMilliseconds)) - currentTotalNpcQuantities;
            }

            int rendom1or2 = session.GetCountdownRandomizerValue(); //set this variable from a session get.

            lastProdId = session.GetLastItemAddedByNpcPlayer();     //ditto

            //call the sweep DO method. An updated last prod id will be returned upon completion.
            lastProdId = DoSweep(cart, repoProdList, numItemsToAdd, lastProdId, rendom1or2);

            //set session properties where req'd.
            session.SetLastItemAddedByAIPlayer(lastProdId);
            if (shopToEnd) //if shopping time has completed, set appropriate flag.
            {
                session.SetShoppingByNpcCompleted(true);
            }
        }