Example #1
0
        /*
         * Given an item type's ID (i.e. `index' column contents), return the
         * item's defIndex and quality.
         *
         * Returns {nDefIndex, nQuality}.
         * If `nQuality' is -1, all qualities are accepted.
         *
         * Return {-256,-256,-256,-256,""} if something went wrong
         */
        public ItemType getItemAttribs(int itemID)
        {
            ItemType itemType;
            try
            {
                SqlCommand getItems = new SqlCommand("SELECT *  FROM items WHERE \"index\" = " + itemID, g_itemDatabase);
                SqlDataReader itemReader = getItems.ExecuteReader();
                itemReader.Read();
                itemType = new ItemType(itemID,
                                        Convert.ToInt32(itemReader["defindex"]),
                                        Convert.ToInt32(itemReader["quality"]),
                                        Convert.ToInt32(itemReader["class"]),
                                        Convert.ToString(itemReader["name"]));
                itemReader.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error getting Item Attributes: " + e.ToString());
                itemType  = new ItemType(-256,-256,-256,-256,"");
            }

            return itemType;
        }
Example #2
0
        /*
         * Returns a list of all the item types we want to trade
         *
         * Returns an empty list if something goes wrong.
         */
        public List<ItemType> getItemTypeList()
        {
            List<ItemType> nameList = new List<ItemType>();
            SqlCommand getItems = new SqlCommand("SELECT * FROM items", g_itemDatabase);
            SqlDataReader itemReader = getItems.ExecuteReader();

            try
            {
                while (itemReader.Read())
                {
                    ItemType nameAndIndex = new ItemType(Convert.ToInt32(itemReader["index"]),
                                                         Convert.ToInt32(itemReader["defindex"]),
                                                         Convert.ToInt32(itemReader["quality"]),
                                                         Convert.ToInt32(itemReader["class"]),
                                                         itemReader["name"].ToString());
                    nameList.Add(nameAndIndex);
                }

                itemReader.Close();
                return nameList;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error getting Item Name List: " + e.ToString());
                nameList.Clear();
                itemReader.Close();
                return nameList;
            }
        }
Example #3
0
        /*
         * Given some steam ID and an item class (as specified in the database),
         * return the CURRENT ratio of items of [itemClass] to the total number
         * of items in [listItems].
         *
         * Returns -256 if somethng went wrong.
         */
        public double getCurrentItemClassRatio(string steamID, int itemClass, List<Inventory.Item>listItems)
        {
            int nTotalItems = listItems.Count();
            int nItemsOfThisClass = 0;

            List<ItemType> itemTypesInClass = new List<ItemType>();

            // Get all the types of items of class [itemClass]
            SqlCommand getItemsOfClass = new SqlCommand("SELECT * FROM items WHERE \"class\" = " + itemClass, g_itemDatabase);
            SqlDataReader itemReader = getItemsOfClass.ExecuteReader();

            try
            {
                if (listItems.Count() == 0)
                {
                    // Empty backpack
                    return -256;
                }

                // Put each of the item types into a list
                while (itemReader.Read())
                {
                    ItemType itemType = new ItemType(Convert.ToInt32(itemReader["index"]),
                                                     Convert.ToInt32(itemReader["defindex"]),
                                                     Convert.ToInt32(itemReader["quality"]),
                                                     itemClass,
                                                     itemReader["name"].ToString());
                    itemTypesInClass.Add(itemType);
                }

                itemReader.Close();

                // Check each item in the backpack to see if it matches an item
                // type in the list, and add 1 to our cumulative total for each
                // one that does.
                foreach (Inventory.Item i in listItems)
                {
                    foreach (ItemType j in itemTypesInClass)
                    {
                        if ((i.Defindex == j.nDefIndex || (j.nDefIndex == 600 && i.IsNotCraftable)) &&
                            i.Quality == j.nQuality.ToString() )
                        {
                            nItemsOfThisClass++;
                        }
                    }
                }

                return (double)nItemsOfThisClass / nTotalItems;
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Error in calculating getItemClassRatio(): " + e.ToString());
                itemReader.Close();
                return -256;
            }
        }