/// <summary>
        /// Adds a special as a token into the list of tokens.
        /// </summary>
        /// <param name="token">The special we want tokenized.</param>
        public void AddToken(string token)
        {
            bool duplicate = HasToken(token);

            if (!duplicate)
            {
                listOfTokens.Add(new SpecialToken(Database_API.GetSpecial(token)));
            }
            else
            {
                listOfTokens[HasTokenPosition(token)].Increment();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Writes a list of all specials available in the database.
        /// </summary>
        /// <returns></returns>
        private static string WriteSpecials()
        {
            StringBuilder builder = new StringBuilder();

            int h = 0;
            int i = Database_API.GetSpecialsCount();

            while (h < i)
            {
                Special item = Database_API.GetSpecial(h);
                builder.Append(DisplayOrganizer.AddEntry(item.itemAffected, SPACING_NAME));
                builder.AppendLine(FormatSP(item, SPACING_NAME));
                h++;
            }
            return(builder.ToString());
        }
        /// <summary>
        /// Take an item and check to see if the amount of purchases of its type
        /// allows for a special.
        /// </summary>
        private void Consolidate(string key, TALLY_STATE state)
        {
            //TRUE when a deal is either possible or is about to be impossible.
            bool hasSpecial = Database_API.TryGetMatchingDeal(key, itemRosterTallyUsed[key]) ||
                              itemRosterTallyUsed[key] < 0;
            bool deferred = false;

            bool specialStateReset = false;

            if (hasSpecial)
            {
                Special special = Database_API.GetSpecial(key);
                if (itemRosterTallyUsed[key] >= special.itemsNeededToFire && state == TALLY_STATE.ADD)
                {
                    itemRosterTallyUsed[key] -= special.itemsNeededToFire;
                    stm.AddToken(special);
                    specialStateReset = true;
                }
                else if (itemRosterTallyUsed[key] < 0 && state == TALLY_STATE.REMOVE)
                {
                    itemRosterTallyUsed[key] += special.itemsNeededToFire;
                    stm.RemoveToken(special);
                    specialStateReset = true;
                }

                deferred = special.special_type == Special.SPECIAL_TT.DEFERRED;
            }

            //If we're removing, do a purge just in case.
            specialStateReset = state == TALLY_STATE.REMOVE;

            if (specialStateReset || deferred)
            {
                //Run if we're either removing, or else have a deferred special.
                PurgeSpecials(key);
            }
            ApplySpecials();
        }