protected void SaveInventory(MySQL_Connection.LogAction dbgCallback = null) { string query = "UPDATE characters SET " + "mesos = " + Mesos + " ," + "equip_slots = " + MaxSlots[0] + ", " + "use_slots = " + MaxSlots[1] + ", " + "setup_slots = " + MaxSlots[2] + ", " + "etc_slots = " + MaxSlots[3] + ", " + "cash_slots = " + MaxSlots[4] + " " + "WHERE ID = " + CharacterID; Connection.RunTransaction(query, dbgCallback); Connection.RunTransaction(comm => { comm.CommandText = "DELETE FROM teleport_rock_locations WHERE charid = " + CharacterID; comm.ExecuteNonQuery(); var telerockSave = new StringBuilder(); telerockSave.Append("INSERT INTO teleport_rock_locations VALUES "); int idx = 0; telerockSave.Append(string.Join(", ", TeleportRockLocations.Select(location => "(" + CharacterID + ", " + (idx++) + ", " + location + ")"))); comm.CommandText = telerockSave.ToString(); comm.ExecuteNonQuery(); }, dbgCallback); SplitDBInventory.Save( Connection, "inventory", CharacterID + ", ", "charid = " + CharacterID, (type, inventory) => { switch (type) { case SplitDBInventory.InventoryType.Eqp: return(Equips.SelectMany(x => x.Where(y => y != null && y.CashId == 0)).Union(Items[0].Where(x => x != null && x.CashId == 0))); case SplitDBInventory.InventoryType.Bundle: return(Items[inventory - 1].Where(x => x != null && x.CashId == 0)); default: throw new Exception(); } }, dbgCallback ); }
public static void Save(MySQL_Connection connection, string baseTableName, string columnsBeforeItemInfo, string whereStatement, StoredItemsCallback callback, MySQL_Connection.LogAction dbgCallback) { #region bundle connection.RunTransaction(comm => { var tableName = GetInventoryTableName(InventoryType.Bundle, baseTableName); comm.CommandText = $"DELETE FROM {tableName} WHERE {whereStatement}"; comm.ExecuteNonQuery(); var itemQuery = new StringBuilder(); bool firstrun = true; // Inventories for (byte inventory = 2; inventory <= 5; inventory++) { var items = callback(InventoryType.Bundle, inventory); foreach (var item in items) { if (!(item is BundleItem)) { continue; } if (firstrun) { itemQuery.Append($"INSERT INTO {tableName} VALUES ("); firstrun = false; } else { itemQuery.Append(", ("); } itemQuery.Append(columnsBeforeItemInfo); itemQuery.Append(inventory + ", "); itemQuery.Append(item.InventorySlot + ", "); itemQuery.Append(item.GetFullSaveColumns()); itemQuery.AppendLine(")"); } } if (itemQuery.Length == 0) { return; } comm.CommandText = itemQuery.ToString(); comm.ExecuteNonQuery(); }, dbgCallback); #endregion #region eqp connection.RunTransaction(comm => { var tableName = GetInventoryTableName(InventoryType.Eqp, baseTableName); comm.CommandText = $"DELETE FROM {tableName} WHERE {whereStatement}"; comm.ExecuteNonQuery(); var itemQuery = new StringBuilder(); bool firstrun = true; var equips = callback(InventoryType.Eqp, 1); foreach (var item in equips) { if (item == null) { continue; } if (firstrun) { itemQuery.Append($"INSERT INTO {tableName} VALUES ("); firstrun = false; } else { itemQuery.Append(", ("); } itemQuery.Append(columnsBeforeItemInfo); itemQuery.Append(item.InventorySlot + ", "); itemQuery.Append(item.GetFullSaveColumns()); itemQuery.AppendLine(")"); } if (itemQuery.Length == 0) { return; } comm.CommandText = itemQuery.ToString(); comm.ExecuteNonQuery(); }, dbgCallback); #endregion }