public static ItemSchema Get(IRequest request, bool cache=true) { //get the json String raw = request.GetJSON(); if(cache) Cache.SaveJSON("schema.txt", raw); JToken json = JObject.Parse(raw)["result"]; ItemSchema schema = new ItemSchema(); foreach (JToken item in json["items"]) { ItemTemplate template = new ItemTemplate(); template.Name = item["item_name"].ToObject<String>(); int defIndex = item["defindex"].ToObject<int>(); if (template.Name.StartsWith("Strange Part:") || template.Name.StartsWith("Strange Cosmetic Part:")) { int id = item["attributes"][0]["value"].ToObject<int>(); schema.StrangePartIDs.Add(id, defIndex); schema.StrangePartNames.Add(id, template.Name.Substring(template.Name.IndexOf(':')+2)); } String type = item["item_slot"] == null ? "other" : item["item_slot"].ToObject<String>(); switch (type) { //weapons! case "primary": case "secondary": case "melee": case "pda": case "pda2": case "building": template.Type = ItemType.Weapon; //if it's got the same values, then add it to the vintage chart (we can safely ignore basically everything else) //of course, this does give a few things that you can't get in vintage or is entirely pointless, but *shrug* if (item["min_ilevel"].ToObject<int>() == item["max_ilevel"].ToObject<int>()) schema.DefaultVintageLevels.Add(defIndex, item["min_ilevel"].ToObject<int>()); break; case "head": case "misc": template.Type = ItemType.Cosmetic; break; default: template.Type = ItemType.Tool; break; } schema.Items.Add(defIndex, template); } return schema; }
public void LoadSchema(ItemSchema items) { foreach (Item i in Items) { i.Name = items.Items[i.DefIndex].Name; } }
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 } }