Пример #1
0
        /// <summary>
        /// Adds an item container (like "Pest Control" in a category (like "Minigames")
        /// </summary>
        /// <param name="itemCategory"></param>
        /// <param name="addition"></param>
        public void addToItemGroup(string itemCategory, ItemContainer addition)
        {
            MenuValue menuSpot = getValueByName(itemCategory);

            itemGroups[menuSpot].Add(addition);
        }
        public static void loadAllItems(ItemManager manager)
        {
            Dictionary <string, List <ItemContainer> > loadedValues = new Dictionary <string, List <ItemContainer> >();
            string contPath = folderPath + "\\Containers\\";

            if (Directory.Exists(contPath))
            {
                foreach (KeyValuePair <MenuValue, List <ItemContainer> > pair in manager.itemGroups)
                {
                    string containerPath = folderPath + "\\Containers\\" + pair.Key.menuItemName + "\\";

                    if (Directory.Exists(containerPath))
                    {
                        string[] files = Directory.GetFiles(containerPath);
                        foreach (string s in files)
                        {
                            string   fname    = s.Remove(0, containerPath.Length);
                            string   fileName = fname.Remove(fname.IndexOf("."), fname.Length - fname.IndexOf("."));
                            string[] entries  = File.ReadAllLines(s);

                            ItemContainer ic = new ItemContainer(fileName, fileName);

                            foreach (string line in entries)
                            {
                                int seperatorIndex1 = line.IndexOf(":");
                                int seperatorIndex2 = line.IndexOf("(");
                                int seperatorIndex3 = line.IndexOf(")");

                                string itemName   = line.Substring(0, seperatorIndex1);
                                int    itemID     = Convert.ToInt32(line.Substring(seperatorIndex1 + 1, seperatorIndex2 - seperatorIndex1 - 1));
                                int    itemAmount = Convert.ToInt32(line.Substring(seperatorIndex2 + 1, seperatorIndex3 - seperatorIndex2 - 1));
                                RSItem item       = new RSItem(itemName, itemID);
                                item.ownedAmount = itemAmount;
                                if (item.itemid == 0)
                                {
                                    item.shouldOnlyHaveOne = true;
                                }
                                ic.items.Add(item);

                                if (!manager.itemGroups[pair.Key].Contains(ic))
                                {
                                    manager.addToItemGroup(pair.Key.menuItemName, ic);
                                }
                            }
                        }
                    }
                    else
                    {
                        fillManagerWithResourceData(manager, pair.Key.menuItemName);
                    }
                }
            }
            else
            {
                //GET stuff from resources?
                foreach (KeyValuePair <MenuValue, List <ItemContainer> > pair in manager.itemGroups)
                {
                    fillManagerWithResourceData(manager, pair.Key.menuItemName);
                }
            }
        }