Beispiel #1
0
        private static SmartScript BuildSmartScript(DataRow row)
        {
            var smartScript = new SmartScript();

            smartScript.entryorguid      = row["entryorguid"] != DBNull.Value ? Convert.ToInt32(row["entryorguid"]) : -1;
            smartScript.source_type      = row["source_type"] != DBNull.Value ? Convert.ToInt32(row["source_type"]) : 0;
            smartScript.id               = row["id"] != DBNull.Value ? Convert.ToInt32(row["id"]) : 0;
            smartScript.link             = row["link"] != DBNull.Value ? Convert.ToInt32(row["link"]) : 0;
            smartScript.event_type       = row["event_type"] != DBNull.Value ? Convert.ToInt32(row["event_type"]) : 0;
            smartScript.event_phase_mask = row["event_phase_mask"] != DBNull.Value ? Convert.ToInt32(row["event_phase_mask"]) : 0;
            smartScript.event_chance     = row["event_chance"] != DBNull.Value ? Convert.ToInt32(row["event_chance"]) : 0;
            smartScript.event_flags      = row["event_flags"] != DBNull.Value ? Convert.ToInt32(row["event_flags"]) : 0;
            smartScript.event_param1     = row["event_param1"] != DBNull.Value ? Convert.ToInt32(row["event_param1"]) : 0;
            smartScript.event_param2     = row["event_param2"] != DBNull.Value ? Convert.ToInt32(row["event_param2"]) : 0;
            smartScript.event_param3     = row["event_param3"] != DBNull.Value ? Convert.ToInt32(row["event_param3"]) : 0;
            smartScript.event_param4     = row["event_param4"] != DBNull.Value ? Convert.ToInt32(row["event_param4"]) : 0;
            smartScript.action_type      = row["action_type"] != DBNull.Value ? Convert.ToInt32(row["action_type"]) : 0;
            smartScript.action_param1    = row["action_param1"] != DBNull.Value ? Convert.ToInt32(row["action_param1"]) : 0;
            smartScript.action_param2    = row["action_param2"] != DBNull.Value ? Convert.ToInt32(row["action_param2"]) : 0;
            smartScript.action_param3    = row["action_param3"] != DBNull.Value ? Convert.ToInt32(row["action_param3"]) : 0;
            smartScript.action_param4    = row["action_param4"] != DBNull.Value ? Convert.ToInt32(row["action_param4"]) : 0;
            smartScript.action_param5    = row["action_param5"] != DBNull.Value ? Convert.ToInt32(row["action_param5"]) : 0;
            smartScript.action_param6    = row["action_param6"] != DBNull.Value ? Convert.ToInt32(row["action_param6"]) : 0;
            smartScript.target_type      = row["target_type"] != DBNull.Value ? Convert.ToInt32(row["target_type"]) : 0;
            smartScript.target_param1    = row["target_param1"] != DBNull.Value ? Convert.ToInt32(row["target_param1"]) : 0;
            smartScript.target_param2    = row["target_param2"] != DBNull.Value ? Convert.ToInt32(row["target_param2"]) : 0;
            smartScript.target_param3    = row["target_param3"] != DBNull.Value ? Convert.ToInt32(row["target_param3"]) : 0;
            smartScript.target_x         = row["target_x"] != DBNull.Value ? Convert.ToInt32(row["target_x"]) : 0;
            smartScript.target_y         = row["target_y"] != DBNull.Value ? Convert.ToInt32(row["target_y"]) : 0;
            smartScript.target_z         = row["target_z"] != DBNull.Value ? Convert.ToInt32(row["target_z"]) : 0;
            smartScript.target_o         = row["target_o"] != DBNull.Value ? Convert.ToInt32(row["target_o"]) : 0;
            smartScript.comment          = row["comment"] != DBNull.Value ? (string)row["comment"] : String.Empty;
            return(smartScript);
        }
Beispiel #2
0
        static async void MainAsync(string[] args)
        {
WriteSqlInformation:
            Console.WriteLine("SQL Information:");
            Console.Write("Host: ");
            string host = Console.ReadLine();

            Console.Write("User: "******"Pass: "******"World DB: ");
            string worldDB = Console.ReadLine();

            Console.Write("Port: ");
            string portStr = Console.ReadLine();

            UInt32 port;

            if (!UInt32.TryParse(portStr, out port))
            {
                Console.WriteLine("\n\nThe specified port could not be converted to an unsigned integer. Please try again.\n");
                goto WriteSqlInformation;
            }

            WorldDatabase worldDatabase = new WorldDatabase(host, port, user, pass, worldDB);

            try
            {
                List <SmartScript> smartScripts = await worldDatabase.GetSmartScripts();

                if (smartScripts.Count == 0)
                {
                    Console.WriteLine("\n\nThe smart_script table is empty in your database.\n");
                    return;
                }

                File.Delete("output.sql");

                using (var outputFile = new StreamWriter("output.sql", true))
                {
                    int    lastEntryOrGuid = 0;
                    string entryOrGuidSET  = "@ENTRY";

                    for (int i = 0; i < smartScripts.Count; ++i)
                    {
                        SmartScript smartScript = smartScripts[i];

                        decimal _i    = (decimal)i;
                        decimal count = (decimal)smartScripts.Count;
                        decimal pct   = (_i / count) * 100;
                        ProgressBarHelper.RenderConsoleProgress((int)pct, '\u2590', Console.ForegroundColor, ((int)pct).ToString() + "%");

                        string      fullLine    = String.Empty;
                        int         entryorguid = smartScript.entryorguid;
                        SourceTypes sourceType  = (SourceTypes)smartScript.source_type;
                        bool        isCreatureOrGameobjectGuid = smartScript.entryorguid < 0 && (sourceType == SourceTypes.SourceTypeCreature || sourceType == SourceTypes.SourceTypeGameobject);

                        if (isCreatureOrGameobjectGuid)
                        {
                            entryorguid = await worldDatabase.GetObjectIdByGuidAndSourceType(-smartScript.entryorguid, (int)sourceType);
                        }

                        if (lastEntryOrGuid != smartScript.entryorguid)
                        {
                            fullLine += "-- " + await worldDatabase.GetObjectNameByIdAndSourceType(entryorguid, (int)sourceType) + " SAI\n";

                            if (isCreatureOrGameobjectGuid)
                            {
                                fullLine      += "SET @GUID := " + smartScript.entryorguid + ";\n";
                                entryOrGuidSET = "@GUID";
                            }
                            else
                            {
                                fullLine      += "SET @ENTRY := " + smartScript.entryorguid + ";\n";
                                entryOrGuidSET = "@ENTRY";
                            }

                            switch (sourceType)
                            {
                            case SourceTypes.SourceTypeCreature:
                                fullLine += "UPDATE `creature_template` SET `AIName`=" + '"' + "SmartAI" + '"' + " WHERE `entry`=" + entryOrGuidSET + ";\n";
                                break;

                            case SourceTypes.SourceTypeGameobject:
                                fullLine += "UPDATE `gameobject_template` SET `AIName`=" + '"' + "SmartGameObjectAI" + '"' + " WHERE `entry`=" + entryOrGuidSET + ";\n";
                                break;

                            case SourceTypes.SourceTypeAreaTrigger:
                                fullLine += "DELETE FROM `areatrigger_scripts` WHERE `entry`=" + entryOrGuidSET + ";\n";
                                fullLine += "INSERT INTO `areatrigger_scripts` VALUES (" + entryOrGuidSET + "," + '"' + "SmartTrigger" + '"' + ");\n";
                                break;

                            case SourceTypes.SourceTypeNone:
                            case SourceTypes.SourceTypeScriptedActionlist:
                                continue;
                            }

                            fullLine += "DELETE FROM `smart_scripts` WHERE `entryorguid`=" + entryOrGuidSET + " AND `source_type`=" + smartScript.source_type + ";\n";
                            fullLine += "INSERT INTO `smart_scripts` (`entryorguid`,`source_type`,`id`,`link`,`event_type`,`event_phase_mask`,`event_chance`,`event_flags`,`event_param1`,`event_param2`,`event_param3`,`event_param4`,`action_type`,`action_param1`,`action_param2`,`action_param3`,`action_param4`,`action_param5`,`action_param6`,`target_type`,`target_param1`,`target_param2`,`target_param3`,`target_x`,`target_y`,`target_z`,`target_o`,`comment`) VALUES\n";
                        }

                        string comment = smartScript.comment.Replace('"', '\'');

                        fullLine += "(" + entryOrGuidSET + "," + smartScript.source_type + "," + smartScript.id + "," + smartScript.link + "," + smartScript.event_type + "," +
                                    smartScript.event_phase_mask + "," + smartScript.event_chance + "," + smartScript.event_flags + "," + smartScript.event_param1 + "," +
                                    smartScript.event_param2 + "," + smartScript.event_param3 + "," + smartScript.event_param4 + "," + smartScript.action_type + "," +
                                    smartScript.action_param1 + "," + smartScript.action_param2 + "," + smartScript.action_param3 + "," + smartScript.action_param4 + "," +
                                    smartScript.action_param5 + "," + smartScript.action_param6 + "," + smartScript.target_type + "," + smartScript.target_param1 + "," +
                                    smartScript.target_param2 + "," + smartScript.target_param3 + "," + smartScript.target_x + "," + smartScript.target_y + "," +
                                    smartScript.target_z + "," + smartScript.target_o + "," + '"' + comment + '"' + ")";

                        if (smartScripts.Count > i + 1)
                        {
                            if (smartScripts[i + 1].entryorguid == smartScript.entryorguid)
                            {
                                fullLine += ",";
                            }
                            else
                            {
                                fullLine += ";\n";
                            }
                        }
                        else
                        {
                            fullLine += ";\n";
                        }

                        outputFile.WriteLine(fullLine);
                        lastEntryOrGuid = smartScript.entryorguid;
                    }
                }
            }
            catch (MySqlException ex)
            {
                Console.WriteLine("\n\n\n" + ex.Message);
                Console.WriteLine("\nPress 'Enter' to write new database information. Any other key exits the application.\n\n");

                if (Console.ReadKey().Key == ConsoleKey.Enter)
                {
                    goto WriteSqlInformation;
                }
                else
                {
                    Environment.Exit(0);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n\n\n" + ex.Message);
                Console.WriteLine("\nPress any key to exit.");
                Console.ReadKey();
                Environment.Exit(0);
                return;
            }

            Console.WriteLine("\n\n\nThe exporting has finished. If you wish to open the output file with your selected .sql file editor, press Enter.");

            if (Console.ReadKey().Key == ConsoleKey.Enter)
            {
                Process.Start("output.sql");
            }
        }