public Dictionary <string, Item> GetItemDictionary() { Dictionary <string, Item> items = new Dictionary <string, Item>(); SqliteCommand command = new SqliteCommand("SELECT * FROM items", this.Connection); SqliteDataReader reader = command.ExecuteReader(); // Columns: item_id, item_name, localized_name, localized_desc, default_slot, slots, equip_regions, attributes if (reader.HasRows) { while (reader.Read()) { Item item = new Item(Convert.ToInt32(reader["item_id"]), reader["item_name"].ToString()); item.LocalizedName = reader["localized_name"].ToString(); item.LocalizedDescription = reader["localized_desc"].ToString(); item.DefaultSlot = InventorySlotHelper.Cast(reader["default_slot"].ToString()); if (reader["slots"] != SQLHandler.Null) { MatchCollection matches = Regex.Matches(reader["slots"].ToString(), "\"([^\"]+)\":\"([^\"]+)\","); foreach (Match slotPair in matches) { item.AddSlot( PlayerClassHelper.Cast(slotPair.Groups[1].ToString()), InventorySlotHelper.Cast(slotPair.Groups[2].ToString()) ); } } if (reader["equip_regions"] != SQLHandler.Null) { MatchCollection matches = Regex.Matches(reader["equip_regions"].ToString(), "\"([^\"]+)\","); foreach (Match equipRegion in matches) { item.AddEquipRegion(equipRegion.Groups[1].ToString()); } } if (reader["attributes"] != SQLHandler.Null) { MatchCollection matches = Regex.Matches(reader["attributes"].ToString(), "\"([^\"]+)\":\"([^\"]+)\","); foreach (Match attributePair in matches) { item.AddAttribute( attributePair.Groups[1].ToString(), attributePair.Groups[2].ToString() ); } } items.Add(item.Name, item); } } reader.Close(); return(items); }
private void BuildItems() { List <VDFNode> tfItems = this.ItemsGame.Head.GetValueFromKey("items"); foreach (VDFNode entry in tfItems) { string itemName = entry.GetValueFromKey("name"); int itemID = itemName == "default" ? -1 : int.Parse(entry.Key); // The only item without a valid int ID is "default" Item item = new Item(itemID, itemName); // Import Prefabs if (entry.KeyExists("prefab")) { string prefabValue = entry.GetValueFromKey("prefab"); string[] inheritList = prefabValue.Split(' '); foreach (string prefabName in inheritList) { item.ImportPrefab(this.PrefabsTable, prefabName); } } // Localization if (entry.KeyExists("item_name")) { item.LocalizedName = entry.GetValueFromKey("item_name"); } if (entry.KeyExists("item_description")) { item.LocalizedDescription = entry.GetValueFromKey("item_description"); } // Attributes if (entry.KeyExists("attributes")) // Standard attributes { List <VDFNode> attributesList = entry.GetValueFromKey("attributes"); foreach (VDFNode attributeNode in attributesList) { item.AddAttribute(attributeNode.Key, attributeNode.GetValueFromKey("value")); } } if (entry.KeyExists("static_attrs")) // Static attributes { List <VDFNode> staticAttributesList = entry.GetValueFromKey("static_attrs"); foreach (VDFNode attributeNode in staticAttributesList) { item.AddAttribute(attributeNode.Key, attributeNode.Value); } } // Slots if (entry.KeyExists("item_slot") && ((string)entry.GetValueFromKey("item_slot")).Length > 0) // Default slot definition { InventorySlot inventorySlot = InventorySlotHelper.Cast(entry.GetValueFromKey("item_slot")); item.DefaultSlot = inventorySlot; } if (entry.KeyExists("used_by_classes")) // Direct slot definition { List <VDFNode> classesList = entry.GetValueFromKey("used_by_classes"); foreach (VDFNode classNode in classesList) { PlayerClass classType = PlayerClassHelper.Cast(classNode.Key); InventorySlot inventorySlot; if (classNode.Value == "1") { inventorySlot = InventorySlot.DEFAULT; } else { inventorySlot = InventorySlotHelper.Cast(classNode.Value); } item.AddSlot(classType, inventorySlot); } } // Equip region if (entry.KeyExists("equip_region")) { if (entry.GetNode("equip_region").Value is string) // Single region { item.AddEquipRegion(entry.GetValueFromKey("equip_region")); } else if (entry.GetNode("equip_region").Value is List <VDFNode> ) // Ambiguous multiple region (Valve error?) { List <VDFNode> regions = entry.GetValueFromKey("equip_region"); foreach (VDFNode equipRegion in regions) { if (equipRegion.Value == "1") { item.AddEquipRegion(equipRegion.Key); } } } else { throw new Exception("item equip_region type not found"); } } if (entry.KeyExists("equip_regions")) // Multiple region { List <VDFNode> regions = entry.GetValueFromKey("equip_regions"); foreach (VDFNode equipRegion in regions) { if (equipRegion.Value == "1") { item.AddEquipRegion(equipRegion.Key); } } } // Add to table ItemsSet.Add(item); } }
private void BuildPrefabs() { List <VDFNode> tfPrefabs = this.ItemsGame.Head.GetValueFromKey("prefabs"); foreach (VDFNode entry in tfPrefabs) { Prefab prefab = new Prefab(entry.Key); // Accummulate Prefabs (just store for later, don't do anything with them yet) if (entry.KeyExists("prefab")) { string prefabValue = entry.GetValueFromKey("prefab"); string[] inheritList = prefabValue.Split(' '); foreach (string prefabName in inheritList) { prefab.AddPrefab(prefabName); } } // Localization if (entry.KeyExists("item_name")) { prefab.LocalizedName = entry.GetValueFromKey("item_name"); } if (entry.KeyExists("item_description")) { prefab.LocalizedDescription = entry.GetValueFromKey("item_description"); } // Attributes if (entry.KeyExists("attributes")) // Standard attributes { List <VDFNode> attributesList = entry.GetValueFromKey("attributes"); foreach (VDFNode attributeNode in attributesList) { prefab.AddAttribute(attributeNode.Key, attributeNode.GetValueFromKey("value")); } } if (entry.KeyExists("static_attrs")) // Static attributes { List <VDFNode> staticAttributesList = entry.GetValueFromKey("static_attrs"); foreach (VDFNode attributeNode in staticAttributesList) { prefab.AddAttribute(attributeNode.Key, attributeNode.Value); } } // Slots if (entry.KeyExists("item_slot")) // Default slot definition { InventorySlot inventorySlot = InventorySlotHelper.Cast(entry.GetValueFromKey("item_slot")); prefab.DefaultSlot = inventorySlot; } if (entry.KeyExists("used_by_classes")) // Direct slot definition { List <VDFNode> classesList = entry.GetValueFromKey("used_by_classes"); foreach (VDFNode classNode in classesList) { PlayerClass classType = PlayerClassHelper.Cast(classNode.Key); InventorySlot inventorySlot; if (classNode.Value == "1") { inventorySlot = InventorySlot.DEFAULT; } else { inventorySlot = InventorySlotHelper.Cast(classNode.Value); } prefab.AddSlot(classType, inventorySlot); } } // Equip region if (entry.KeyExists("equip_region")) { if (entry.GetNode("equip_region").Value is string) // Single region { prefab.AddEquipRegion(entry.GetValueFromKey("equip_region")); } else if (entry.GetNode("equip_region").Value is List <VDFNode> ) // Ambiguous multiple region (Valve error?) { List <VDFNode> regions = entry.GetValueFromKey("equip_region"); foreach (VDFNode equipRegion in regions) { if (equipRegion.Value == "1") { prefab.AddEquipRegion(equipRegion.Key); } } } else { throw new Exception("prefab equip_region type not found"); } } if (entry.KeyExists("equip_regions")) // Multiple region { List <VDFNode> regions = entry.GetValueFromKey("equip_regions"); foreach (VDFNode equipRegion in regions) { if (equipRegion.Value == "1") { prefab.AddEquipRegion(equipRegion.Key); } } } // Add to table PrefabsTable.Add(prefab.Name, prefab); } }