public bool SaveWeaponsEx(MySqlConnection connection, IInfoProvider2 dbq) { //HELPER VARIABLES IDataWeaponCollection weapons = dbq.createWeaponCollection(); MySqlCommand command = new MySqlCommand(_query_70, connection); try { //SERIALIZE ALL ITEMS byte[] buffer = new byte[375]; for (int i = 0; i < weapons.UnlockedWeaponSlots; i++) { Weapon current = weapons[i]; if (current == null) continue; Weapon.Serialize(current, buffer, i * 75); } //WRITE THE NUMBER OF ITEMS command.Parameters.AddWithValue("CharId", weapons.CharacterId); command.Parameters.AddWithValue("Weaponary", buffer); command.Parameters.AddWithValue("UnlockedWeaponCount", weapons.UnlockedWeaponSlots); command.Parameters.AddWithValue("PIndex", weapons.PrimaryWeaponIndex); command.Parameters.AddWithValue("SIndex", weapons.SeconairyWeaponIndex); command.Parameters.AddWithValue("AIndex", weapons.ActiveWeaponIndex); return command.ExecuteNonQuery() > 0; } catch (MySqlException e) { Trace.WriteLine(e.Message, "Database"); return false; } }
//Third generation methods weapon public bool LoadWeaponsEx(MySqlConnection connection, IInfoProvider2 dbq, bool continueOnError) { IDataWeaponCollection weapons = dbq.createWeaponCollection(); MySqlCommand command = new MySqlCommand(_query_69, connection); MySqlDataReader reader = null; command.Parameters.AddWithValue("CharId", weapons.CharacterId); try { reader = command.ExecuteReader(); while (reader.Read()) { if (reader.IsDBNull(0)) continue; byte[] buffer2 = new byte[375]; reader.GetBytes(1, 0, buffer2, 0, 375); weapons.UnlockedWeaponSlots = reader.GetByte(2); weapons.PrimaryWeaponIndex = reader.GetByte(3); weapons.SeconairyWeaponIndex = reader.GetByte(4); weapons.ActiveWeaponIndex = reader.GetByte(5); for (int i = 0; i < 5; i++) { Weapon weapon = Weapon.Deserialize(buffer2, i * 75); weapons[i] = weapon; } return true; } __dbtracelog.WriteError("Database", "player weapon-data of player with id {0} is missing", weapons.CharacterId); return continueOnError; } catch (MySqlException e) { Trace.WriteLine(e.Message, "Database"); return false; } finally { if (reader != null) reader.Close(); } }