コード例 #1
0
        static Schema GetSchema(bool forceUpdate = false)
        {
            Schema schema = new Schema();
            Dictionary<int, ItemTemplate> itemSchema =  new Dictionary<int,ItemTemplate>();
            Dictionary<int, ItemAttributeTemplate> attrSchema = new Dictionary<int, ItemAttributeTemplate>();

            //if we're forcing an update, or the schema doesn't exist
            if (forceUpdate || !File.Exists("schema.txt"))
            {
                using (dynamic steamInterface = WebAPI.GetInterface("IEconItems_440", "7B35211AD579A53C622866CB86B847E8"))
                {
                    //get the item values from the schema
                    KeyValue items = steamInterface.GetSchema(language: "en")["items"];
                    //iterate the items, add to the schema
                    foreach (var item in items.Children)
                    {
                        ItemTemplate newItem = new ItemTemplate();
                        //add The if it's needed
                        newItem.Name = /*(item.Children[5].Value.Equals("1") ? "The " : "") +*/ item.Children[4].Value;
                        newItem.DefIndex = Convert.ToInt32(item.Children[1].Value);
                        if (newItem.Name.Contains("Strange Part:"))
                        {
                            newItem.StrangePartID = Convert.ToInt32(item["attributes"].Children[0]["value"].Value);
                        }
                        string type = item["item_slot"].Value;

                        //only really need 3 classes of items - hats, weapons, tools.
                        /*if (type.Contains("tf_weapon") || type.Contains("saxxy") || item["item_slot"].Value.Contains("secondary"))
                            newItem.Type = ItemType.Weapon;
                        else if(type.Contains("tf_wearable"))
                            newItem.Type = ItemType.Hat;
                        else if(type.Contains("tool") || type.Contains("craft_item") || type.Contains("upgrade") || type.Contains("powerup_bottle") ||
                            type.Contains("map_token") || type.Contains("bundle") || type.Contains("class_token") || type.Contains("slot_token") ||
                            type.Contains("supply_crate"))
                            newItem.Type = ItemType.Tool;
                        else
                            System.Diagnostics.Debugger.Break();*/
                        switch (type)
                        {
                            case "primary":
                            case "secondary":
                            case "melee":
                            case "pda":
                            case "pda2":
                            case "building":
                                newItem.Type = ItemType.Weapon;
                                //now we can add in the default level to make vintages easier
                                newItem.DefaultLevel = Convert.ToInt32(item["min_ilevel"].Value);
                                break;
                            case "head":
                            case "misc":
                                newItem.Type = ItemType.Hat;
                                break;
                            case "action":
                            case "craft_item":
                                newItem.Type = ItemType.Tool;
                                break;
                            default:
                                if (type == null)
                                {
                                    if (item["item_class"].Value == "craft_item")
                                        newItem.Type = ItemType.Tool;
                                }
                                else
                                    System.Diagnostics.Debugger.Break();
                                break;
                        }
                        itemSchema.Add(newItem.DefIndex, newItem);
                    }

                    KeyValue unus = steamInterface.GetSchema(language: "en")["attribute_controlled_attached_particles"];
                    foreach (var effect in unus.Children)
                    {
                        schema.UnusualNames.Add(Convert.ToInt32(effect["id"].Value), effect["name"].Value);
                    }

                    //now we get the attributes
                    KeyValue attrs = steamInterface.GetSchema(language: "en")["attributes"];

                    foreach (var attr in attrs.Children)
                    {
                        ItemAttributeTemplate newAttr = new ItemAttributeTemplate();
                        newAttr.Name = attr["name"].Value;
                        newAttr.DefIndex = Convert.ToInt32(attr["defindex"].Value);
                        attrSchema.Add(newAttr.DefIndex, newAttr);
                    }
                }
                //copy across, save, write
                schema.ItemSchema = itemSchema;
                schema.AttributeSchema = attrSchema;
                string json = JsonConvert.SerializeObject(schema, Formatting.Indented);
                using (StreamWriter writer = new StreamWriter("schema.txt"))
                {
                    writer.Write(json);
                }
            }
            else
            {
                using (StreamReader reader = new StreamReader("schema.txt"))
                {
                    schema = JsonConvert.DeserializeObject<Schema>(reader.ReadToEnd());
                }
            }
            //now set up the strange part db
            foreach(ItemTemplate t in schema.ItemSchema.Values.Where(x => x.StrangePartID != 0))
                schema.StrangePartNames.Add(t.StrangePartID, t.Name.Substring(t.Name.IndexOf(':')+2));
            Console.WriteLine("Schema read.");
            Program.itemSchema = schema;
            return schema;
        }
コード例 #2
0
        static Item ReadItem(KeyValue item, Schema schema)
        {
            Item newItem = new Item();
            newItem.Template = schema.ItemSchema[Convert.ToInt32(TryGetValue(item, "defindex", "", true))];
            newItem.Level = Convert.ToInt32(TryGetValue(item, "level", "5"));
            newItem.Quantity = Convert.ToInt32(TryGetValue(item, "quantity", "0"));
            newItem.IsTradable = TryGetValue(item, "flag_cannot_trade", "0") == "1" ? false : true;
            newItem.IsCraftable = TryGetValue(item, "flag_cannot_craft", "0") == "1" ? false : true;
            newItem.Quality = (Quality)Enum.Parse(typeof(Quality), TryGetValue(item, "quality", "6"));
            if (newItem.Name == "A Carefully Wrapped Gift")
                newItem.ContainedItem = ReadItem(item["contained_item"], schema);
            //379 - part 1 kills
            //380 - ??? 1106771968 31 posthumous?
            //381 -part 2 kills
            //382 ???
            //383 - part 3
            //384 ???

            //attributes
            foreach (var attr in item["attributes"].Children)
            {
                int defindex = Convert.ToInt32(attr["defindex"].Value);
                switch (defindex)
                {
                    case 500: //custom name
                        newItem.CustomName = attr["value"].Value;
                        break;
                    case 142: //painted
                        newItem.PaintCol = Convert.ToInt32(attr["float_value"].Value);
                        break;
                    case 229: //lowcraft
                        newItem.CraftNumber = Convert.ToInt32(attr["value"].Value);
                        break;
                    case 185:
                        newItem.IsGifted = true;
                        break;
                    case 380:
                    case 382:
                    case 384: //3 strange parts
                        newItem.StrangeParts.Add(Convert.ToInt32(attr["float_value"].Value));
                        break;
                    case 134: //unusual
                        newItem.Effect = schema.UnusualNames[Convert.ToInt32(attr["float_value"].Value)];
                        break;
                    case 153: //untradable
                    case 501: //description
                        break;
                    default:
                        break;
                }
            }
            return newItem;
        }