Esempio n. 1
0
        public static PriceSchema Get(IRequest request, bool cache=true)
        {
            //get the json
            String raw = request.GetJSON();

            dynamic fullJson = JsonConvert.DeserializeObject(raw);
            if (fullJson.success == 0)
                return null;
            if (cache)
                Cache.SaveJSON("backpacktf.txt", raw);
            dynamic json = fullJson.response;

            PriceSchema schema = new PriceSchema();

            //first, get the raw prices of buds/keys/ref.
            Price.RefPrice = json.raw_usd_value;
            Price.KeyPrice = json.items["Mann Co. Supply Crate Key"]["prices"]["6"]["Tradable"]
                ["Craftable"][0]["value_raw"];
            Price.BudsPrice = json["items"]["Earbuds"]["prices"]["6"]["Tradable"]["Craftable"][0]["value_raw"];

            foreach (dynamic item in json.items)
            {
                //we don't want Australium Gold
                bool isAus = item.Name.StartsWith("Australium") && !item.Name.Contains("Gold");
                if (item.Value.defindex.Count == 0)
                {
                    Console.WriteLine("Found an item with no defindex");
                    continue;
                }

                //it's changed - now defindices are defindex: [val]
                int defIndex = (int)item.Value.defindex[0].Value;
                //and now iterate all the qualities
                foreach (dynamic itemQuality in item.Value.prices)
                {
                    Quality quality = (Quality)Enum.Parse(typeof(Quality), itemQuality.Name);
                    foreach (dynamic tradableItem in itemQuality.Value)
                    {
                        //tradables, craftables
                        bool isTradable = (tradableItem.Name == "Tradable");
                        foreach (dynamic craftableItem in tradableItem.Value)
                        {
                            bool isCraftable = (craftableItem.Name == "Craftable");

                            //it's now split into some things being Craftability: [blah blah] and some being Craftability: attribute value : blah blah
                            //this is 0 for most things, but some things like unusuals and crates have values
                            foreach (dynamic attributes in craftableItem.Value)
                            {
                                //ignore it if it's 0.
                                bool isNested = !(craftableItem.Value is JArray);
                                int series = isNested ? Convert.ToInt32(attributes.Name) : 0;
                                dynamic priceObject = isNested ? attributes.Value : attributes;

                                Price price = new Price();
                                double lowPrice = priceObject["value"].Value;
                                double highPrice = priceObject["value_high"] == null ? lowPrice : priceObject["value_high"].Value;

                                String currency = priceObject["currency"].Value;

                                //normalise to refined
                                if (currency == "earbuds")
                                {
                                    lowPrice *= Price.BudsPrice;
                                    highPrice *= Price.BudsPrice;
                                }
                                else if (currency == "keys")
                                {
                                    lowPrice *= Price.KeyPrice;
                                    highPrice *= Price.KeyPrice;
                                }
                                else if (currency == "usd")
                                {
                                    lowPrice *= Price.RefPrice;
                                    highPrice *= Price.RefPrice;
                                }
                                price.LowRefPrice = lowPrice;
                                price.HighRefPrice = highPrice;

                                //separate australiums, unusuals/crates, and the other one
                                schema.PriceList[GetItemKey(quality, defIndex, isTradable, isCraftable, isAus, series)] = price;
                            }
                        }
                    }
                }
            }
            return schema;
        }
Esempio n. 2
0
 public void AddPriceBonus(String name, Price price)
 {
     this.PriceBonuses.Add(new PriceBonus() { Name = name, BonusPrice = price });
 }
Esempio n. 3
0
 public Price(Price price)
 {
     this.LowRefPrice = price.LowRefPrice;
     this.HighRefPrice = price.HighRefPrice;
 }