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 ); }
protected void LoadInventory() { using (var data = Connection.RunQuery("SELECT mesos, equip_slots, use_slots, setup_slots, etc_slots, cash_slots FROM characters WHERE id = " + CharacterID) as MySqlDataReader) { data.Read(); Mesos = data.GetInt32("mesos"); SetInventorySlots(1, (byte)data.GetInt16("equip_slots"), false); SetInventorySlots(2, (byte)data.GetInt16("use_slots"), false); SetInventorySlots(3, (byte)data.GetInt16("setup_slots"), false); SetInventorySlots(4, (byte)data.GetInt16("etc_slots"), false); SetInventorySlots(5, (byte)data.GetInt16("cash_slots"), false); } SplitDBInventory.Load(Connection, "inventory", "charid = " + CharacterID, (type, inventory, slot, item) => { AddItem(inventory, slot, item, true); }); _cashItems.Load(); // Move items over to the inventory foreach (var cashItemsEquip in _cashItems.Equips) { Console.WriteLine("Adding cash equip on slot {0}", cashItemsEquip.InventorySlot); AddItem(1, cashItemsEquip.InventorySlot, cashItemsEquip, true); } foreach (var cashItemsBundle in _cashItems.Bundles) { Console.WriteLine("Adding bundle on slot {0}", cashItemsBundle.InventorySlot); AddItem(Constants.getInventory(cashItemsBundle.ItemID), cashItemsBundle.InventorySlot, cashItemsBundle, true); } foreach (var cashItemPets in _cashItems.Pets) { Console.WriteLine("Adding pet on slot {0}", cashItemPets.InventorySlot); AddItem(Constants.getInventory(cashItemPets.ItemID), cashItemPets.InventorySlot, cashItemPets, true); } _cashItems.Equips.Clear(); _cashItems.Bundles.Clear(); _cashItems.Pets.Clear(); using (var data = Connection.RunQuery("SELECT mapindex, mapid FROM teleport_rock_locations WHERE charid = " + CharacterID) as MySqlDataReader) { while (data.Read()) { TeleportRockLocations[data.GetByte("mapindex")] = data.GetInt32("mapid"); } } for (int i = 0; i < TeleportRockLocations.Length; i++) { if (TeleportRockLocations[i] == 0) { TeleportRockLocations[i] = Constants.InvalidMap; } } }