Example #1
0
 public static bool AddCreature(creature npc)
 {
     if(npcList.ContainsKey(npc.creature_id))
         return false;
     npcList.Add(npc.creature_id,npc);
     return true;
 }
Example #2
0
 public static bool AddCreature(creature npc)
 {
     if (npcList.ContainsKey(npc.creature_id))
     {
         return(false);
     }
     npcList.Add(npc.creature_id, npc);
     return(true);
 }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Length == 0)
            {
                MessageBox.Show("The id cannot be blank.");
                return;
            }

            string str = textBox1.Text.Trim();
            Int64  value;
            bool   isNum = Int64.TryParse(str, out value);

            if (!isNum)
            {
                MessageBox.Show("The script id should be a number. Please enter a number.");
                return;
            }

            if (bIsCreature)
            {
                if (Datastores.dbused && !creatures.npcsAvailable.Contains(System.Convert.ToUInt32(textBox1.Text)))
                {
                    MessageBox.Show("This Creature is NOT in creature_template");
                    return;
                }

                creature newcreature = new creature(System.Convert.ToUInt32(textBox1.Text), "");
                if (!creatures.AddCreature(newcreature))
                {
                    MessageBox.Show("ID already Exists!");
                }
                else
                {
                    this.Hide();

                    (this.MdiParent as Hauptfenster).ShowNewForm(newcreature.creature_id);
                    (this.MdiParent as Hauptfenster).UpdateNPCListBox();
                }
            }
            else
            {
                db_script newscript = new db_script(System.Convert.ToUInt32(textBox1.Text));
                if (!db_scripts.AddScript(newscript))
                {
                    MessageBox.Show("ID already Exists!");
                }
                else
                {
                    this.Hide();

                    (this.MdiParent as Hauptfenster).ShowNewForm(newscript.id);
                    (this.MdiParent as Hauptfenster).UpdateNPCListBox();
                }
            }
        }
Example #4
0
        // Preview creature scripts
        public static string WriteCreatureToWindow(creature script)
        {
            if (script == null)
                return "";

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("-- Creature id: " + script.creature_id);
            sb.AppendLine(CreateCreatureTemplateQuery(script, false));
            sb.AppendLine(SQLcreator.CreateDeleteQuery(script, ""));
            sb.AppendLine(SQLcreator.CreateCreateQuery(script, ""));

            return sb.ToString();
        }
Example #5
0
        // Create creature script
        public static bool WriteCreatureToFile(creature npc, string file, bool reihe)
        {
            if (npc == null || npc.line.Count == 0)
                return false;

            StreamWriter sqlpatchfile = new StreamWriter(file, reihe);
            sqlpatchfile.WriteLine("-- Creature id: " + npc.creature_id);
            sqlpatchfile.WriteLine(SQLcreator.CreateDeleteQuery(npc, ""));
            sqlpatchfile.WriteLine(SQLcreator.CreateCreateQuery(npc, ""));
            sqlpatchfile.Close();
            return true;
        }
Example #6
0
        public static void ReloadDB()
        {
            if (!Datastores.dbused)
                return;

            MySqlDataReader reader = null;

            // Check for the creatureAI tables
            try
            {
                string sQuery = "SELECT information_schema.TABLES.table_name FROM information_schema.TABLES " +
                    "where information_schema.TABLES.table_name IN ('creature_ai_scripts','creature_ai_summons','creature_ai_texts') and information_schema.TABLES.Table_schema='" + Properties.Settings.Default.DBMANGOS + "'";
                MySqlCommand comm = new MySqlCommand(sQuery, SQLConnection.conn);
                reader = comm.ExecuteReader();

                while (reader.Read())
                {
                    if (!reader.HasRows)
                    {
                        MessageBox.Show("Your database doesn't contain the eventAI tables. The application won't use the database anymore");
                        dbused = false;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            reader.Close();

            if (Datastores.dbused)
            {
                // Select all creature scripts and creature names
                MySqlCommand c = new MySqlCommand("SELECT a.*, b.name FROM creature_ai_scripts a join creature_template b on a.creature_id = b.entry;", SQLConnection.conn);
                reader = c.ExecuteReader();

                creatures.npcList.Clear();
                summons.map.Clear();
                localized_texts.map.Clear();

                try
                {
                    while (reader.Read())
                    {
                        if (!creatures.npcList.ContainsKey(reader.GetUInt32("creature_id")))
                        {
                            creature temp = new creature(reader.GetUInt32("creature_id"), reader.GetString("name"));
                            creatures.npcList.Add(reader.GetUInt32("creature_id"), temp);
                        }

                        Event_dataset item = new Event_dataset();

                        item.script_id = reader.GetInt32("id");
                        item.event_type = reader.GetInt32("event_type");
                        item.event_inverse_phase_mask = reader.GetUInt32("event_inverse_phase_mask");
                        item.event_chance = reader.GetInt32("event_chance");
                        item.event_flags = reader.GetInt32("event_flags");
                        item.event_param1 = reader.GetInt32("event_param1");
                        item.event_param2 = reader.GetInt32("event_param2");
                        item.event_param3 = reader.GetInt32("event_param3");
                        item.event_param4 = reader.GetInt32("event_param4");
                        item.action1_type = reader.GetInt32("action1_type");
                        item.action1_param1 = reader.GetInt32("action1_param1");
                        item.action1_param2 = reader.GetInt32("action1_param2");
                        item.action1_param3 = reader.GetInt32("action1_param3");
                        item.action2_type = reader.GetInt32("action2_type");
                        item.action2_param1 = reader.GetInt32("action2_param1");
                        item.action2_param2 = reader.GetInt32("action2_param2");
                        item.action2_param3 = reader.GetInt32("action2_param3");
                        item.action3_type = reader.GetInt32("action3_type");
                        item.action3_param1 = reader.GetInt32("action3_param1");
                        item.action3_param2 = reader.GetInt32("action3_param2");
                        item.action3_param3 = reader.GetInt32("action3_param3");
                        item.comment = reader.GetString("comment");

                        creatures.npcList[reader.GetUInt32("creature_id")].line.Add(item);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                reader.Close();

                // Select all creature AI summons
                c.CommandText = "SELECT * FROM creature_ai_summons";
                reader.Close();
                reader = c.ExecuteReader();

                try
                {
                    while (reader.Read())
                    {
                        summon item = new summon(reader.GetUInt32("id"));
                        item.comment = reader.GetString("comment");
                        item.orientation = reader.GetFloat("orientation");
                        item.position_x = reader.GetFloat("position_x");
                        item.position_y = reader.GetFloat("position_y");
                        item.position_z = reader.GetFloat("position_z");
                        item.spawntimesecs = reader.GetInt32("spawntimesecs");

                        summons.map.Add(reader.GetUInt32("id"), item);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                // Select all creature AI texts
                c.CommandText = "SELECT * FROM creature_ai_texts";
                reader.Close();

                reader = c.ExecuteReader();

                try
                {
                    while (reader.Read())
                    {
                        localized_text item = new localized_text(reader.GetInt32("entry"));
                        item.locale_0 = reader.GetString("content_default");

                        int colIndex = reader.GetOrdinal("content_loc1");
                        if (!reader.IsDBNull(colIndex))
                            item.locale_1 = reader.GetString("content_loc1");
                        else
                            item.locale_1 = string.Empty;

                        colIndex = reader.GetOrdinal("content_loc2");
                        if (!reader.IsDBNull(colIndex))
                            item.locale_2 = reader.GetString("content_loc2");
                        else
                            item.locale_2 = string.Empty;

                        colIndex = reader.GetOrdinal("content_loc3");
                        if (!reader.IsDBNull(colIndex))
                            item.locale_3 = reader.GetString("content_loc3");
                        else
                            item.locale_3 = string.Empty;

                        colIndex = reader.GetOrdinal("content_loc4");
                        if (!reader.IsDBNull(colIndex))
                            item.locale_4 = reader.GetString("content_loc4");
                        else
                            item.locale_4 = string.Empty;

                        colIndex = reader.GetOrdinal("content_loc5");
                        if (!reader.IsDBNull(colIndex))
                            item.locale_5 = reader.GetString("content_loc5");
                        else
                            item.locale_5 = string.Empty;

                        colIndex = reader.GetOrdinal("content_loc6");
                        if (!reader.IsDBNull(colIndex))
                            item.locale_6 = reader.GetString("content_loc6");
                        else
                            item.locale_6 = string.Empty;

                        colIndex = reader.GetOrdinal("content_loc7");
                        if (!reader.IsDBNull(colIndex))
                            item.locale_7 = reader.GetString("content_loc7");
                        else
                            item.locale_7 = string.Empty;

                        colIndex = reader.GetOrdinal("content_loc8");
                        if (!reader.IsDBNull(colIndex))
                            item.locale_8 = reader.GetString("content_loc8");
                        else
                            item.locale_8 = string.Empty;

                        item.sound = reader.GetInt32("sound");
                        item.type = reader.GetInt32("type");
                        item.language = reader.GetInt32("language");
                        item.emote = reader.GetInt32("emote");

                        colIndex = reader.GetOrdinal("comment");
                        if (!reader.IsDBNull(colIndex))
                            item.comment = reader.GetString("comment");
                        else
                            item.comment = string.Empty;

                        localized_texts.map.Add(reader.GetInt32("entry"), item);
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                reader.Close();

                // Select creature entries
                SQLConnection.conn.ChangeDatabase(SQLConnection.dbworld);
                c.CommandText = "SELECT distinct entry FROM creature_template WHERE AIName='EventAI';";
                reader = c.ExecuteReader();

                try
                {
                    while (reader.Read())
                    {
                        if (creatures.npcList.ContainsKey(reader.GetUInt32("entry")))
                        {
                            creatures.npcList[reader.GetUInt32("entry")].activectemplate = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                reader.Close();

                c.CommandText = "SELECT distinct entry FROM creature_template;";
                reader = c.ExecuteReader();

                try
                {
                    while (reader.Read())
                    {
                        creatures.npcsAvailable.Add(reader.GetUInt32("entry"));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                reader.Close();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Length == 0)
            {
                MessageBox.Show("The id cannot be blank.");
                return;
            }

            string str = textBox1.Text.Trim();
            Int64 value;
            bool isNum = Int64.TryParse(str, out value);
            if (!isNum)
            {
                MessageBox.Show("The script id should be a number. Please enter a number.");
                return;
            }

            if (bIsCreature)
            {

                if (Datastores.dbused && !creatures.npcsAvailable.Contains(System.Convert.ToUInt32(textBox1.Text)))
                {
                    MessageBox.Show("This Creature is NOT in creature_template");
                    return;
                }

                creature newcreature = new creature(System.Convert.ToUInt32(textBox1.Text), "");
                if (!creatures.AddCreature(newcreature))
                    MessageBox.Show("ID already Exists!");
                else
                {
                    this.Hide();

                    (this.MdiParent as Hauptfenster).ShowNewForm(newcreature.creature_id);
                    (this.MdiParent as Hauptfenster).UpdateNPCListBox();
                }
            }
            else
            {
                db_script newscript = new db_script(System.Convert.ToUInt32(textBox1.Text));
                if (!db_scripts.AddScript(newscript))
                    MessageBox.Show("ID already Exists!");
                else
                {
                    this.Hide();

                    (this.MdiParent as Hauptfenster).ShowNewForm(newscript.id);
                    (this.MdiParent as Hauptfenster).UpdateNPCListBox();
                }
            }
        }