Beispiel #1
0
        public static void AddCatalogueItem(string saleCode, FurniItem spriteData, int nextPageId, int definitionId)
        {
            sqlOutput.Append("INSERT INTO `catalogue_items` (`id`, `sale_code`, `page_id`, `order_id`, `price_coins`, `price_pixels`, `hidden`, `amount`, `definition_id`, `item_specialspriteid`, `is_package`) " +
                             "VALUES (" + NextCatalogueId + ", '" + (saleCode == null ? spriteData.FileName : saleCode) + "', '" + nextPageId + "', 2, 2, 0, 0, 1, " + definitionId + ", '', 0);");

            sqlOutput.Append("\n");
            sqlOutput.Append("\n");

            nextCatalogueItemsId++;
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            try
            {
                var fileContents  = File.ReadAllText(OUTPUT_DIR + "old_data/furnidata.txt");
                var furnidataList = JsonConvert.DeserializeObject <List <string[]> >(fileContents);

                foreach (var stringArray in furnidataList)
                {
                    itemList.Add(new FurniItem(stringArray));
                }

                var officialFileContents  = File.ReadAllText(OUTPUT_DIR + "official_furnidata.txt");
                var officialFurnidataList = JsonConvert.DeserializeObject <List <string[]> >(officialFileContents);

                foreach (var stringArray in officialFurnidataList)
                {
                    officialItemList.Add(new FurniItem(stringArray));
                }

                using (var connection = GetConnection())
                {
                    nextCatalogueItemsId   = connection.QueryFirst <int>("SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_NAME = 'catalogue_items'");
                    nextItemsDefinitionsId = connection.QueryFirst <int>("SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_NAME = 'items_definitions'");
                    PageId = connection.QueryFirst <int>("SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_NAME = 'catalogue_pages'") - 1;

                    Console.WriteLine("Query success: " + nextItemsDefinitionsId + " / " + nextCatalogueItemsId);
                }

                FurniItem previousItem = null;

                List <string>    processQueue   = new List <string>();
                List <FurniItem> processedFurni = new List <FurniItem>();

                foreach (var file in Directory.GetFiles("ccts"))
                {
                    var fileName = Path.GetFileName(file);

                    if (fileName.StartsWith("hh_furni_xx_s_"))
                    {
                        fileName = fileName.Replace("hh_furni_xx_s_", "hh_furni_xx_");
                    }

                    if (fileName.StartsWith("o_"))
                    {
                        fileName = fileName.Replace("o_", "hh_furni_xx_");
                    }

                    var className = fileName;

                    className = fileName.Replace("hh_furni_xx_", "");
                    className = Path.GetFileNameWithoutExtension(className);

                    if (className.Contains("#"))
                    {
                        string contents = className.Substring(className.IndexOf("#") + 1);

                        if (contents.Contains("-"))
                        {
                            string[] data = contents.Split('-');

                            int minimumRange = int.Parse(data[0]);
                            int maximumRange = int.Parse(data[1]);

                            for (int i = minimumRange; i <= maximumRange; i++)
                            {
                                var newClass = className.Replace("#" + minimumRange + "-" + maximumRange, "*" + i);

                                if (!processQueue.Contains(newClass))
                                {
                                    processQueue.Add(newClass);
                                }
                            }
                        }
                        else
                        {
                            className = className.Replace("#", "*");

                            if (!processQueue.Contains(className))
                            {
                                processQueue.Add(className);
                            }
                        }
                    }
                    else
                    {
                        if (!processQueue.Contains(className))
                        {
                            processQueue.Add(className);
                        }
                    }
                    //Console.WriteLine(Path.GetFileName(file));
                }

                foreach (var className in processQueue)
                {
                    if (processedFurni.Count(sprite => sprite.FileName == className) > 0)
                    {
                        continue;
                    }

                    var spriteData = RetrieveSpriteData(className, itemList);

                    if (spriteData == null)
                    {
                        var originalFileName = className;
                        var newFurniName     = className.Replace("_cmp", "").Replace("_camp", "");

                        if (newFurniName.EndsWith("cmp"))
                        {
                            newFurniName = newFurniName.TrimEnd("cmp".ToCharArray());
                        }

                        spriteData = RetrieveSpriteData(newFurniName, officialItemList);

                        if (spriteData != null)
                        {
                            if (originalFileName != newFurniName)
                            {
                                var newFurni = new FurniItem(spriteData.RawData);
                                newFurni.FileName = originalFileName;
                                newFurni.SpriteId = GetNextAvaliableSpriteId(spriteData.SpriteId);

                                if (itemList.Count(item => item.SpriteId == spriteData.SpriteId) > 0)
                                {
                                    newFurni.SpriteId = GetNextAvaliableSpriteId(spriteData.SpriteId);
                                }

                                Console.ForegroundColor = ConsoleColor.DarkYellow;
                                Console.WriteLine("The furniture \"" + originalFileName + "\" was missing but has now been added");
                                Console.ResetColor();

                                spriteData = newFurni;
                                itemList.Add(newFurni);
                            }
                            else
                            {
                                var newFurni = new FurniItem(spriteData.RawData);

                                if (itemList.Count(item => item.SpriteId == spriteData.SpriteId) > 0)
                                {
                                    newFurni.SpriteId = GetNextAvaliableSpriteId(spriteData.SpriteId);
                                }

                                Console.ForegroundColor = ConsoleColor.DarkYellow;
                                Console.WriteLine("The furniture \"" + originalFileName + "\" was missing but added and sprite id has been recalulated");
                                Console.ResetColor();

                                spriteData = newFurni;
                                itemList.Add(newFurni);
                            }
                        }
                    }

                    if (spriteData == null)
                    {
                        Console.WriteLine("Next sprite ID: " + GetNextAvaliableSpriteId(previousItem != null ? previousItem.SpriteId : 1000));
                        Console.WriteLine("The furni " + className + " has no furnidata");
                    }
                    else
                    {
                        if (HasItemEntry(className))
                        {
                            Console.WriteLine("The entry for " + className + " already exists in the database");
                        }
                        else
                        {
                            int defId            = nextItemsDefinitionsId;
                            int catalogueItemsId = nextCatalogueItemsId;

                            sqlOutput.Append("INSERT INTO `items_definitions` (`id`, `sprite`, `name`, `description`, `sprite_id`, `length`, `width`, `top_height`, `max_status`, `behaviour`, `interactor`, `is_tradable`, `is_recyclable`, `drink_ids`, `rental_time`, `allowed_rotations`) VALUES " +
                                             "(" + defId + ", '" + spriteData.FileName + "', '" + Escape(spriteData.Name) + "', '" + Escape(spriteData.Description) + "', " + spriteData.SpriteId + ", " + spriteData.Length + ", " + spriteData.Width + ", 0, '2', '" + (spriteData.Type == "i" ? "wall_item" : "solid") + "', 'default', 1, 1, '', -1, '0,2,4,6');");

                            sqlOutput.Append("\n");
                            sqlOutput.Append("\n");

                            AddCatalogueItem(null, spriteData, PageId, nextCatalogueItemsId);
                            nextItemsDefinitionsId++;


                            previousItem = spriteData;
                        }

                        processedFurni.Add(spriteData);
                    }
                }



                ProductData.AddItems(processedFurni);
                ProductData.HandleDeals();
                ProductData.WriteProducts(Program.OUTPUT_DIR + "productdata.txt");

                var sortedItems = ProductData.Items.Where(item => processQueue.Contains(item.SaleCode) && item.SaleCode.Length > 0).ToList().OrderBy(item => item.SaleCode).ToList();

                int orderId = 0;


                Console.WriteLine("Order ID start (blank for 0):");
                var orderIdValue = Console.ReadLine();

                if (orderIdValue.Length > 0)
                {
                    orderId = int.Parse(orderIdValue);
                }

                foreach (var item in sortedItems)
                {
                    sqlOutput.Append("UPDATE catalogue_items SET order_id = '" + orderId++ + "' WHERE sale_code = '" + item.SaleCode + "';");

                    sqlOutput.Append("\n");
                    sqlOutput.Append("\n");
                }

                File.WriteAllText(OUTPUT_DIR + "items.sql", sqlOutput.ToString());
                RebuildFurnidata(itemList, OUTPUT_DIR + "furnidata.txt");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.WriteLine("Done!");
            Console.Read();
        }