public MarketPricing(string hash, ulong lastUpdated, int volume, double priceUSD, GameSchema lookup) { Failed = false; MarketHash = hash; LastUpdated = lastUpdated; Volume = volume; PriceUSD = priceUSD; if (hash.StartsWith("restriction") || hash.EndsWith("Fabricator") || // don't even bother hash.Contains("Napolean") || // -facepalm- hash.StartsWith("Strange Part:") || hash.StartsWith("Strange Filter:") || hash.StartsWith("Strange Cosmetic Part:") || hash == "Naughty Winter Crate Key 2014" || // these aren't even usable anymore hash == "Nice Winter Crate Key 2014" || hash == "Strange Count Transfer Tool") { Failed = true; return; } Failed = _processHash(MarketHash, lookup); }
public ItemInstance(ItemInstanceJson json, GameSchema reference) { InstanceID = json.id; OriginalInstanceID = json.original_id; Item = reference.GetItem(json.defindex); Level = json.level; Count = json.quantity; Tradable = !json.flag_cannot_trade; Craftable = !json.flag_cannot_craft; Quality = (Quality)json.quality; CustomName = json.custom_name; CustomDescription = json.custom_desc; Style = json.style; InventoryLocationFlags flags = (InventoryLocationFlags)json.inventory; BackpackSlot = flags.GetBackpackPos(); IsNewToBackpack = flags.IsNewItem(); Attributes = new List<AppliedInstanceAttribute>(); if (json.attributes != null) { foreach (AppliedItemInstanceAttributeJson aiiaj in json.attributes) { Attributes.Add(new AppliedInstanceAttribute(aiiaj)); } } if (json.contained_item != null) { WrappedItem = new ItemInstance(json.contained_item, reference); } }
public Backpack(TF2BackpackResultJson json, GameSchema reference) { SlotCount = json.num_backpack_slots; List<ItemInstance> all = new List<ItemInstance>(); foreach (ItemInstanceJson iij in json.items) { all.Add(new ItemInstance(iij, reference)); } NewItems = all.FindAll((i) => i.IsNewToBackpack); int pageCount = SlotCount / 50; Pages = new BackpackPage[pageCount]; for (int p = 0; p < pageCount; p++) { BackpackPage page = new BackpackPage(all, p); Pages[p] = page; } /* ItemsOld = new List<ItemInstance>(); foreach (ItemInstanceJson iij in json.items) { ItemsOld.Add(new ItemInstance(iij, reference)); } ItemsOld.Sort((a, b) => a.BackpackPos - b.BackpackPos); */ }
public Item GetItemForm(GameSchema data) { foreach (Item i in data.Items) { if (i.UnlocalizedName == UnlocalizedName) { return i; } } return null; }
public MarketReference(MarketPriceDataJson json, GameSchema schema) { Pricings = new List<MarketPricing>(); if (json.response.success == 0) { VersatileIO.Error("Market price data failed: " + json.response.message); return; } foreach (KeyValuePair<string, MarketPricingJson> kvp in json.response.items) { MarketPricing p = new MarketPricing(kvp.Key, kvp.Value, schema); if (!p.Failed) { Pricings.Add(p); } } }
public MarketPricing(string hash, MarketPricingJson json, GameSchema lookup) : this(hash, json.last_updated, json.quantity, json.value / 100.0, lookup) { }
private bool _processHash(string hashStart, GameSchema lookup) { string hash = hashStart.Trim(); bool isFestive = hash.StartsWith("Festive "); if (isFestive) { hash = hash.Substring("Festive ".Length); } #region qualities bool hasQualitiesLeft = true; Quality? q = null; while (hasQualitiesLeft) // Sometimes items glitch into having multiple qualities. { // Only the first one counts here. Tuple<Quality, string> res = GetQualityFromHash(hash); if (q != null && res.Item1 == Quality.Unique) { hasQualitiesLeft = false; } else if (q == null) { q = res.Item1; } hash = res.Item2; } Quality = q.Value; #endregion qualities isFestive = hash.StartsWith("Festive "); if (isFestive) { hash = hash.Substring("Festive ".Length); } Tuple<KillstreakType, string> ksRes = GetKillstreakFromHash(hash); Killstreak = ksRes.Item1; string hashPreSkin = ksRes.Item2; Tuple<SkinWear?, string> swRes = GetWearFromHash(hashPreSkin); Wear = swRes.Item1; hash = swRes.Item2; #region skin foreach (Skin s in WeaponSkins.Skins) { if (s.GetMarketHash(Wear) == hashPreSkin) { GunMettleSkin = s; Item = s.GetItemForm(lookup); return false; } } if (Wear != null) { VersatileIO.Error("No skin was found for skin '{0}'.", hashPreSkin); return true; } if (isFestive) { hash = "Festive " + hash; } #endregion if (hash.StartsWith("Australium") && hashStart != "Australium Gold") { Australium = true; hash = hash.Substring("Australium ".Length); // the space is intentional } // items with "Vintage" in the actual name else if (hash == "Merryweather" || hash == "Tyrolean") { hash = "Vintage " + hash; } // item with "Haunted" in the actual name else if (hash == "Hat") { hash = "Haunted " + hash; } // make up your mind. if (hash == "Eternaween") { hash = "Enchantment: Eternaween"; } else if (hash == "RoboCrate Key") // general inconsistencies with robocrate keys { hash = "Robo Community Crate Key"; } else if (hash == "A Random RoboKey Gift") { hash = "A Random Robo Community Crate Key Gift"; } else if (hash == "Pile of RoboKey Gifts") { hash = "Pile of Robo Community Crate Key Gifts"; } if (hash.Contains("Creature’s Grin")) // yes, that is a stylized apostrophe { Item = lookup.GetItem(30525); // do it manually. } if (Item == null) { foreach (Item i in lookup.Items) { if (i.ImproperName.ToLower() == hash.ToLower()) { Item = i; break; } } } if (Item == null) // again { // nice goin valve... if (hash.StartsWith("The ")) { hash = hash.Substring("The ".Length); foreach (Item i in lookup.Items) { if (i.ImproperName.ToLower() == hash.ToLower()) { Item = i; return false; } } VersatileIO.Error("No item was found matching '{0}'.", hashStart); return true; } if (hash.EndsWith("Strangifier") || hashStart == "Strange Bacon Grease") { // screw these return true; #region strangifier #pragma warning disable CS0162 string targetName = hashStart.CutOffEnd(" Strangifier".Length); foreach (Item i in lookup.Items) { if (!i.IsStrangifier()) { continue; } long? targetID = i.GetTargetID(); if (targetID == null) { return true; } if (lookup.GetItem(targetID.Value).ImproperName == targetName) { Item = i; break; } } #pragma warning restore CS0162 #endregion } else if (hash.EndsWith("Kit") && Killstreak.HasKillstreak()) { // and these return true; #region killstreak kit #pragma warning disable CS0162 string targetName = hashStart.CutOffEnd(" Kit".Length); foreach (Item i in lookup.Items) { if (!i.IsKillstreakKit()) { continue; } // What is with these ones acting so funky? if (i.UnlocalizedName.EndsWith("Killstreakifier Basic")) { continue; } long? targetID = i.GetTargetID(); if (targetID == null) { return true; } if (lookup.GetItem(targetID.Value).ImproperName == targetName) { Item = i; break; } } #pragma warning restore CS0162 #endregion killstreak kit } else if (hash.Contains("Series #")) // it's a box! { int numSign = hash.LastIndexOf('#'); string sNum = hash.Substring(numSign + 1); int n = int.Parse(sNum); foreach (Item i in lookup.Items) { if (!i.IsSupplyCrate()) { continue; } if (i.GetSupplyCrateSeries().Value == n) { Item = i; break; } } } else if (hash.EndsWith("Chemistry Set")) { // Skip Collector's Chemistry Sets return true; } else { VersatileIO.Error("No item was found matching '{0}'.", hashStart); return true; } } return false; }
public Backpack(TF2BackpackJson json, GameSchema reference) : this(json.result, reference) { }
public static GameSchema TranslateItemsData() { if (SchemaRaw == null) { ParseItemsJson(); } Schema = new GameSchema(SchemaRaw); return Schema; }
public PriceReference(BpTfPriceDataJson json, GameSchema db) { Prices = new List<ItemPricing>(); foreach (KeyValuePair<string, ItemPriceJson> kvp0 in json.response.items) { ItemPriceJson ipj = kvp0.Value; // Skip "Random Craft Hat". It's not a real item. if (ipj.defindex.FirstOrDefault() == -2) { continue; } List<Item> items = new List<Item>(); foreach (long l in ipj.defindex) { Item i = db.GetItem(l); if (i != null) { items.Add(i); } } if (items.Count == 0 && ipj.defindex.HasItems()) { string s_ids = "[ "; foreach (long l in ipj.defindex) { s_ids += l + " "; } s_ids += "]"; VersatileIO.Error("Could not find item with any ID among " + s_ids); } bool australium = kvp0.Key.StartsWith("Australium "); foreach (KeyValuePair<string, TradabilityJson> kvp1 in ipj.prices) { int qid = int.Parse(kvp1.Key); Quality quality = (Quality)qid; if (kvp1.Value.Tradable != null) { CraftibilityJson cfj = kvp1.Value.Tradable; if (cfj.Craftable != null) { AddPricings(MakePricings(cfj.Craftable), items, quality, true, true, australium); } if (cfj.NonCraftable != null) { AddPricings(MakePricings(cfj.NonCraftable), items, quality, true, false, australium); } } if (kvp1.Value.NonTradable != null) { CraftibilityJson cfj = kvp1.Value.NonTradable; if (cfj.Craftable != null) { AddPricings(MakePricings(cfj.Craftable), items, quality, false, true, australium); } if (cfj.NonCraftable != null) { AddPricings(MakePricings(cfj.NonCraftable), items, quality, false, false, australium); } } } } }