/// <summary> /// Loads bad words from database. /// </summary> /// <returns></returns> public static void Load() { DataRow[] rows = null; using (SqlDatabaseClient client = GameServer.Database.GetClient()) { DataTable table = client.ReadDataTable("SELECT word FROM bad_words"); rows = table.Select(); } foreach (DataRow row in rows) { badWords.Add(Convert.ToString(row[0])); } }
/// <summary> /// Constructs the npc manager. /// </summary> public NpcManager() { // Load definitions. this.definitions = NpcDefinition.Load(); // Load spawns. try { DataRow[] rows = null; // Get all spawns. using (SqlDatabaseClient client = GameServer.Database.GetClient()) { DataTable table = client.ReadDataTable("SELECT * FROM npc_spawns;"); if (table != null) { rows = table.Select(); } } // If there is any spawns in the database, spawn them in game. if (rows != null) { foreach (DataRow row in rows) { //DataRow row = rows[0]; short id = (short)row[1]; Location originalCoords = Location.Create((short)row[2], (short)row[3], (byte)row[4]); WalkType walkType = (WalkType)row[5]; Location minRange = Location.Create((short)row[6], (short)row[7], (byte)row[8]); Location maxRange = Location.Create((short)row[9], (short)row[10], (byte)row[11]); string[] messages = null; if (row[12] is string) { messages = ((string)row[12]).Split(';'); } Npc npc = new Npc(id, originalCoords, minRange, maxRange, walkType, definitions[id], messages); RegisterNpc(npc); } //Program.Logger.WriteInfo("Loaded " + this.definitions.Count + " npc definitions, and " + this.npcSpawns.Count + " spawn(s)."); } } catch (Exception ex) { Program.Logger.WriteException(ex); } }
public static Dictionary <short, NpcDefinition> Load() { DataRow[] rows = null; Dictionary <short, NpcDefinition> definitions = new Dictionary <short, NpcDefinition>(); try { // Get all npc definitions. using (SqlDatabaseClient client = GameServer.Database.GetClient()) { rows = client.ReadDataTable("SELECT * FROM npc_definitions").Select(); } // Parse the definitions. foreach (DataRow row in rows) { short id = (short)row[0]; string name = (string)row[1]; string examine = (string)row[2]; byte respawn = (byte)row[3]; byte combat = (byte)row[4]; byte hitpoints = (byte)row[5]; byte maxHit = (byte)row[6]; byte attackSpeed = (byte)row[7]; short attackAnim = (short)row[8]; short defenceAmin = (short)row[9]; short deathAnim = (short)row[10]; NpcDefinition definition = new NpcDefinition(id, name, examine, respawn, combat, hitpoints, maxHit, attackSpeed, attackAnim, defenceAmin, deathAnim); definitions.Add(id, definition); } } catch (Exception ex) { Program.Logger.WriteException(ex); } return(definitions); }
/// <summary> /// Constructs a new ground item manager. /// </summary> public GroundItemManager() { this.Items = new List <GroundItem>(); this.WaitList = new List <GroundItem>(); DataRow[] rows = null; using (SqlDatabaseClient client = GameServer.Database.GetClient()) { rows = client.ReadDataTable("SELECT * FROM item_spawns").Select(); } // Add in all (server-)spawned items. foreach (DataRow row in rows) { short id = (short)row[1]; int count = (int)row[2]; short x = (short)row[3]; short y = (short)row[4]; GroundItem gItem = new GroundItem(Location.Create(x, y, 0), id, count); gItem.Spawned = true; Add(gItem); } }
/// <summary> /// Gets a set of configurations specified by the SQL query. /// </summary> /// <param name="query">The query to execute.</param> /// <returns>Returns a System.Collections.Generic.Dictionary object /// containing all configurations loadaed from the given location.</returns> public SqlConfig Load(string query) { DataTable data = null; Dictionary <string, dynamic> configs = new Dictionary <string, dynamic>(); try { // Get the table from the database. using (SqlDatabaseClient client = GameServer.Database.GetClient()) { data = client.ReadDataTable(query); } // Only process if there's data. if (data != null && data.Rows.Count > 0) { DataRow[] allRows = data.Select(); // Get the configurations. foreach (DataRow row in allRows) { string key = row[1].ToString(); string type = row[2].ToString(); object value = row[3]; if (type.Equals("Boolean")) { configs.Add(key, Convert.ToBoolean(value)); } else if (type.Equals("Byte")) { configs.Add(key, Convert.ToByte(value)); } else if (type.Equals("Char")) { configs.Add(key, Convert.ToChar(value)); } else if (type.Equals("Decimal")) { configs.Add(key, Convert.ToDecimal(value)); } else if (type.Equals("Double")) { configs.Add(key, Convert.ToDouble(value)); } else if (type.Equals("Int16")) { configs.Add(key, Convert.ToInt16(value)); } else if (type.Equals("Int32")) { configs.Add(key, Convert.ToInt32(value)); } else if (type.Equals("Int64")) { configs.Add(key, Convert.ToInt64(value)); } else if (type.Equals("SByte")) { configs.Add(key, Convert.ToSByte(value)); } else if (type.Equals("Single")) { configs.Add(key, Convert.ToSingle(value)); } else if (type.Equals("String")) { configs.Add(key, Convert.ToString(value)); } else if (type.Equals("UInt16")) { configs.Add(key, Convert.ToUInt16(value)); } else if (type.Equals("UInt32")) { configs.Add(key, Convert.ToUInt32(value)); } else if (type.Equals("UInt64")) { configs.Add(key, Convert.ToUInt64(value)); } else if (type.Equals("DateTime")) { if (value.Equals(string.Empty)) { configs.Add(key, DateTime.Now); } else { configs.Add(key, Convert.ToDateTime(value)); } } } } } catch (Exception ex) { Program.Logger.WriteException(ex); } return(new SqlConfig(configs)); }
/// <summary> /// Loads the item defitions from mysql database and stores in a local array. /// </summary> /// <param name="destination">The array to store data to.</param> public static void Load() { // The largest item id value in the item_definitions table. int largestValue = 0; // The defitions storage. ItemDefinition[] definitions = null; // The raw definitions from mysql database. DataRow[] rows = null; try { using (SqlDatabaseClient client = GameServer.Database.GetClient()) { // Find the highest id value so we can make an array based on that value. largestValue = (short)client.ExecuteQuery("SELECT MAX(id) FROM item_definitions;"); // Get raw definitions. rows = client.ReadDataTable("SELECT * FROM item_definitions").Select(); } /* * Create the array with specified largest value + 1 (because items start at 0). */ definitions = new ItemDefinition[largestValue + 1]; // Parse definitions. foreach (DataRow row in rows) { // General definitions. short id = Convert.ToInt16(row[0]); string name = Convert.ToString(row[1]); string examine = Convert.ToString(row[2]); short equipId = Convert.ToInt16(row[3]); bool stackable = Convert.ToBoolean(row[4]); bool tradable = Convert.ToBoolean(row[5]); bool noted = Convert.ToBoolean(row[6]); short noteId = Convert.ToInt16(row[7]); // Price definitions. int[] prices = new int[3]; prices[0] = Convert.ToInt32(row[8]); // Minimum price. prices[1] = Convert.ToInt32(row[9]); // Normal price. prices[2] = Convert.ToInt32(row[10]); // Maximum price. // Bonus definitions. short[] bonuses = new short[16]; bonuses[0] = Convert.ToInt16(row[11]); // Attack Stab Bonus bonuses[1] = Convert.ToInt16(row[12]); // Attack Slash Bonus bonuses[2] = Convert.ToInt16(row[13]); // Attack Crush Bonus bonuses[3] = Convert.ToInt16(row[14]); // Attack Magic Bonus bonuses[4] = Convert.ToInt16(row[15]); // Attack Ranged Bonus bonuses[5] = Convert.ToInt16(row[16]); // Defence Stab Bonus bonuses[6] = Convert.ToInt16(row[17]); // Defence Slash Bonus bonuses[7] = Convert.ToInt16(row[18]); // Defence Crush Bonus bonuses[8] = Convert.ToInt16(row[19]); // Defence Magic Bonus bonuses[9] = Convert.ToInt16(row[20]); // Defence Ranged Bonus bonuses[10] = Convert.ToInt16(row[21]); // Defence Summoning Bonus bonuses[11] = Convert.ToInt16(row[22]); // Strength Bonus bonuses[12] = Convert.ToInt16(row[23]); // Prayer Bonus // Configure definition. definitions[id] = new ItemDefinition(id, name, examine, equipId, noted, noteId, stackable, tradable, prices, bonuses); } /* * This must be done so no errors are caused if there * are null items. If the player does somehow spawn * a null item, they'll recieve drawf remains instead. */ for (int i = 0; i < definitions.Length; i++) { if (definitions[i] == null) { definitions[i] = definitions[0]; } } //Program.Logger.WriteInfo("Loaded " + rows.Length + " item definitions."); } catch (Exception ex) { Program.Logger.WriteException(ex); } ItemDefinition.definitions = definitions; }