예제 #1
0
파일: DealPicker.cs 프로젝트: zykour/TAPBot
        public DealEntry PickDeal(Random random, int reroll)
        {
            if (steamItems.Count == 0)
            {
                Initialize();
            }

            DealEntry dealEntry = new DealEntry();

            // Pick the first deal, if there is a reroll factor to consider, we'll reroll as many times as required by the reroll factor

            int dealNumber = random.Next(1, steamItems.Count() + 1);

            // By default reroll is set to 1, meaning there is no reroll unless it's more than or equal to 2

            for (int i = 1; i < reroll; i++)
            {
                dealNumber = random.Next(1, steamItems.Count() + 1);
            }

            String line = steamItems.ElementAt(dealNumber - 1);

            Match match         = inventoryCmd.Match(line);
            int   originalPrice = 0;

            if (match.Success)
            {
                dealEntry.Quantity = Int32.Parse(match.Groups[1].ToString().Trim());
                dealEntry.Name     = match.Groups[3].ToString();
                originalPrice      = Int32.Parse(match.Groups[2].ToString().Trim());
                if (match.Groups[5].Success)
                {
                    dealEntry.AppID = match.Groups[5].ToString();
                }
            }

            int discountNum = random.Next(1, 36);

            // Uses the same logic as above for rerolling the deal, we want to make sure the discount percentage is also rerolled the same number of times

            for (int i = 1; i < reroll; i++)
            {
                discountNum = random.Next(1, 36);
            }

            if (discountNum < 13)
            {
                dealEntry.DiscountAmount = 33;
            }
            else if (discountNum < 18)
            {
                dealEntry.DiscountAmount = 40;
            }
            else if (discountNum < 26)
            {
                dealEntry.DiscountAmount = 50;
            }
            else if (discountNum < 30)
            {
                dealEntry.DiscountAmount = 66;
            }
            else if (discountNum < 35)
            {
                dealEntry.DiscountAmount = 75;
            }
            else
            {
                dealEntry.DiscountAmount = 85;
            }

            dealEntry.Price = Convert.ToInt32(Math.Floor(originalPrice * (1 - (dealEntry.DiscountAmount / 100.00))));

            if (dealEntry.Price == 0)
            {
                dealEntry.Price = 1;
            }

            dealEntry.Expiration = DateTime.Today;

            return(dealEntry);
        }
예제 #2
0
        protected override string ProduceChatMessage(BotContext botContext)
        {
            if (botContext.FriendID.ConvertToUInt64().ToString().CompareTo("76561198030277114") != 0)
            {
                return("");
            }

            int numDeals = 1;

            try
            {
                numDeals = Convert.ToInt32(botContext.Command.Trim().Substring(6));
            }
            catch (Exception e)
            {
                if (e is OverflowException || e is FormatException)
                {
                    numDeals = 1; // no-op, essentially. just making it explicit
                }
            }

            int max = (dealPicker.Count() > numDeals) ? numDeals : dealPicker.Count();
            LinkedList <DealEntry> spunDeals = new LinkedList <DealEntry>();

            int iterator = numDeals;

            while (iterator > 0)
            {
                DealEntry tempDeal         = dealPicker.PickDeal();
                bool      dealHasBeenAdded = false;

                for (int i = 0; i < spunDeals.Count; i++)
                {
                    if (spunDeals.ElementAt(i).Name.CompareTo(tempDeal.Name) == 0)
                    {
                        dealHasBeenAdded = true;
                        break;
                    }

                    if (spunDeals.ElementAt(i).Name.CompareTo(tempDeal.Name) > 0)
                    {
                        spunDeals.AddBefore(spunDeals.Find(spunDeals.ElementAt(i)), tempDeal);
                        dealHasBeenAdded = true;
                        iterator--;
                        break;
                    }
                }

                if (!dealHasBeenAdded)
                {
                    spunDeals.AddLast(tempDeal);
                    iterator--;
                }
            }

            StringBuilder outputBuffer = new StringBuilder();

            foreach (DealEntry deal in spunDeals)
            {
                string tempStr = deal.Quantity + "\t" + deal.Price + " (" + deal.DiscountAmount + "%)" + ((deal.Price < 10) ? "\t\t" : "\t") + deal.Name + "\n";

                if (tempStr.Length + outputBuffer.Length > 2048)
                {
                    SendMessage(botContext, outputBuffer.ToString());

                    // don't want to attempt to send too many messages in a row
                    // this will cause the entire bot to sleep for up to a few seconds but as only one privleged person can invoke this command, that is ok

                    System.Threading.Thread.Sleep(1000);
                    outputBuffer.Clear();
                }

                outputBuffer.Append(tempStr);
            }

            return(outputBuffer.ToString());
        }
예제 #3
0
 public DealWrapper(DealEntry dealEntry)
 {
     this.dealEntry = dealEntry;
 }