Exemple #1
0
        public int GetItemPrice(string itemClassName, string steamId)
        {
            int price = 0;

            PlayersConfig.Classes playerClass = PlayersConfig.Classes.Pussy;

            if (string.IsNullOrEmpty(itemClassName))
            {
                throw new CustomException(ErrorCodes.Codes.NullData);
            }

            if (string.IsNullOrEmpty(steamId))
            {
                throw new CustomException(ErrorCodes.Codes.NullSteamId);
            }

            List <object> itemInfo   = GetItemInfo(itemClassName);
            List <object> playerInfo = new List <object>();

            try
            {
                Console.WriteLine("Trying to get player info");

                var data = dataWorker.ReadData(DataConfig.Lists.Main);

                playerInfo = data.Single(item => item.ElementAt(0).ToString() == steamId);
                Console.WriteLine("Player info getted");

                if (!string.IsNullOrEmpty(playerInfo.ElementAt(2).ToString()))
                {
                    playerClass = (PlayersConfig.Classes)playerInfo.ElementAt(2);
                }
            }
            catch
            {
                throw new CustomException(ErrorCodes.Codes.DataReading);
            }

            try
            {
                Console.WriteLine("Trying to get price");
                price = Convert.ToInt32(itemInfo.ElementAt(1).ToString());
                Console.WriteLine("Price getted");
            }
            catch
            {
                throw new CustomException(ErrorCodes.Codes.NullData);
            }

            price = price / 100 * Item.GetDiscount(playerClass, itemClassName);

            return((Item.IsInBlackList(itemClassName))
                                ? throw new CustomException(ErrorCodes.Codes.BlacklistedGear)
                                : price);
        }
Exemple #2
0
        public static int GetDiscount(PlayersConfig.Classes classname, string item)
        {
            int discount = 1;

            foreach (KeyValuePair <ItemDiscount, PlayersConfig.Classes> discountObj in PlayersConfig.Discounts.Values)
            {
                if (discountObj.Value == classname)
                {
                    if (discountObj.Key.Item == item)
                    {
                        discount = discountObj.Key.Discount;
                    }
                }
            }

            return(discount);
        }