Beispiel #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;
        }
Beispiel #2
0
        public void LoadPrices(ItemSchema items, PriceSchema prices)
        {
            foreach (Item i in Items)
            {
                //so we've got several things to consider for prices.
                //Strange parts
                //Paint
                //Killstreaks
                //Levels
                //Vintage levels
                //Craft numbers
                i.BasePrice = prices.GetPrice(i);

                //strange parts
                foreach(int attr in new int[]{ Attribute.StrangePart1, Attribute.StrangePart2, Attribute.StrangePart3})
                {
                    if (i.HasAttribute(attr))
                    {
                        Price sPart = prices.GetUniquePriceByDefindex(items.StrangePartIDs[(int)i.Attributes[attr].FloatValue]);
                        i.AddPriceBonus(items.StrangePartNames[(int)i.Attributes[attr].FloatValue], sPart*0.5);
                    }
                }

                //paint
                if (i.HasAttribute(Attribute.Paint))
                {
                    Price paint = prices.GetUniquePriceByDefindex(items.PaintIDs[(int)i.Attributes[Attribute.Paint].FloatValue]);
                    string paintName = items.PaintNames[(int)i.Attributes[Attribute.Paint].FloatValue];
                    i.AddPriceBonus(paintName, paint * 0.5);
                }

                //killstreaks
                //TODO

                //levels
                //IGNORE FOR NOW, TOOD

                //vintage levels
                //TODO

                //craft numbers
                //TODO
            }
        }