示例#1
0
        public bool SaveData(ClientConnection pConnection)
        {
            int internalid = pConnection.CharacterInternalID = SaveCharacterInfo(pConnection);
            if (internalid == -1)
            {
                // Failure!
                return false;
            }

            using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items"))
            using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets"))
            {
                var info = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(Stats.ID, pConnection.WorldID);

                if (info != null)
                {
                    // Update info!
                    pConnection.CharacterID = Stats.ID;

                    CharacterInventory inventory = Inventory;

                    for (byte i = 0; i < Inventory.EquipmentItems.Length; i++)
                    {
                        var equips = Inventory.EquipmentItems[i];
                        foreach (var equipdata in equips)
                        {
                            short slot = equipdata.Key;
                            var equip = equipdata.Value;
                            bool addrow = false;

                            if (info.SlotHashes.ContainsKey(0) && info.SlotHashes[0].ContainsKey(slot))
                            {
                                int hash = info.SlotHashes[0][slot];
                                int objhash = equipdata.Value.GetChecksum();
                                if (hash != objhash)
                                {
                                    pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                    addrow = true;
                                }

                                info.SlotHashes[0].Remove(slot);
                            }
                            else
                            {
                                addrow = true;
                            }

                            if (addrow)
                                Queries.SaveItem(pConnection, 0, slot, equip, itemsTable, true);
                        }
                    }

                    pConnection.Logger_WriteLine("Done equips");

                    for (int i = 0; i < Inventory.InventoryItems.Length; i++)
                    {
                        var items = Inventory.InventoryItems[i];
                        foreach (var itemdata in items)
                        {
                            var item = itemdata.Value;
                            bool addrow = false;
                            if (info.SlotHashes.ContainsKey(i + 1) && info.SlotHashes[i + 1].ContainsKey(itemdata.Key))
                            {
                                int hash = info.SlotHashes[i + 1][itemdata.Key];
                                int objhash = itemdata.Value.GetChecksum();
                                if (hash != objhash)
                                {
                                    pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                    addrow = true;
                                }


                                info.SlotHashes[i + 1].Remove(itemdata.Key);
                            }
                            else
                            {
                                addrow = true;
                            }

                            if (addrow)
                            {
                                Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true);

                                if (item is ItemPet)
                                {
                                    Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                }
                            }
                        }
                    }
                    pConnection.Logger_WriteLine("Done items");

                    foreach (var bag in Inventory.BagItems)
                    {
                        ushort i = (ushort)bag.Key;
                        foreach (var itemdata in bag.Value.Items)
                        {
                            var item = itemdata.Value;
                            bool addrow = false;
                            if (info.SlotHashes.ContainsKey(i) && info.SlotHashes[i].ContainsKey(itemdata.Key))
                            {
                                int hash = info.SlotHashes[i][itemdata.Key];
                                int objhash = itemdata.Value.GetChecksum();
                                if (hash != objhash)
                                {
                                    pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                    addrow = true;
                                }


                                info.SlotHashes[i].Remove(itemdata.Key);
                            }
                            else
                            {
                                addrow = true;
                            }

                            if (addrow)
                            {
                                Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true);

                                if (item is ItemPet)
                                {
                                    Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                }
                            }
                        }
                    }

                    pConnection.Logger_WriteLine("Done bag items");

                    {
                        string removequery = "";
                        bool added = false;
                        foreach (var hashlist in info.SlotHashes)
                        {
                            foreach (var leftovers in hashlist.Value)
                            {
                                pConnection.Logger_WriteLine("Deleting item @ inv {0} slot {1}", hashlist.Key, leftovers.Key);
                                added = true;
                                removequery += string.Format("DELETE FROM items WHERE character_id = {2} AND inventory = {0} AND slot = {1};\r\n", hashlist.Key, leftovers.Key, internalid);
                            }
                        }
                        if (added)
                        {
                            System.IO.File.WriteAllText("removequery.sql", removequery);
                            MySQL_Connection.Instance.RunQuery(removequery);
                        }
                    }

                }
                else
                {

                    pConnection.Logger_WriteLine("Saving Items");

                    pConnection.CharacterInternalID = internalid;
                    pConnection.CharacterID = Stats.ID;

                    string itemlist = "";
                    itemlist += "INSERT INTO items VALUES ";
                    List<string> querylist = new List<string>();
                    for (byte i = 0; i < Inventory.EquipmentItems.Length; i++)
                    {
                        var equips = Inventory.EquipmentItems[i];
                        foreach (var equipdata in equips)
                        {
                            var equip = equipdata.Value;
                            Queries.SaveItem(pConnection, 0, equipdata.Key, equip, itemsTable, true);
                        }
                    }

                    pConnection.Logger_WriteLine("Done equips");

                    for (int i = 0; i < Inventory.InventoryItems.Length; i++)
                    {
                        var items = Inventory.InventoryItems[i];
                        foreach (var itemdata in items)
                        {
                            var item = itemdata.Value;

                            Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true);

                            if (item is ItemPet)
                            {
                                Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                            }
                        }
                    }

                    pConnection.Logger_WriteLine("Done items");

                    foreach (var bag in Inventory.BagItems)
                    {
                        ushort i = (ushort)(bag.Key);
                        foreach (var itemdata in bag.Value.Items)
                        {
                            var item = itemdata.Value;
                            Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true);

                            if (item is ItemPet)
                            {
                                Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                            }
                        }
                    }

                    pConnection.Logger_WriteLine("Done bag items");

                    AccountDataCache.Instance.LoadBaseData(Stats.Name);

                }

                itemsTable.RunQuery();

                pConnection.Logger_WriteLine("Saved item data");

                petTable.RunQuery();

                pConnection.Logger_WriteLine("Saved pet data");


                AccountDataCache.Instance.LoadInventoryHashes(internalid, true);



                MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running WHERE character_id = " + internalid);
                using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running"))
                {
                    questsTable.OnDuplicateUpdate = true;
                    questsTable.AddColumn("character_id", false);
                    questsTable.AddColumn("questid", true);
                    questsTable.AddColumn("data", true);

                    foreach (var quest in Quests.Running)
                    {
                        questsTable.AddRow(internalid, quest.Key, quest.Value);
                    }

                    questsTable.RunQuery("insert-update-quests.sql");
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done WHERE character_id = " + internalid);
                using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done"))
                {
                    doneTable.AddColumn("character_id", false);
                    doneTable.AddColumn("questid", false);
                    doneTable.AddColumn("time", false);

                    foreach (var quest in Quests.Done)
                    {
                        doneTable.AddRow(internalid, quest.Key, quest.Value);
                    }

                    doneTable.RunQuery("insert-update-quests-done.sql");
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running_party WHERE character_id = " + internalid);
                using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running_party"))
                {
                    questsTable.OnDuplicateUpdate = true;
                    questsTable.AddColumn("character_id", false);
                    questsTable.AddColumn("questid", true);
                    questsTable.AddColumn("data", true);

                    foreach (var quest in Quests.PartyQuestsRunning)
                    {
                        questsTable.AddRow(internalid, quest.Key, quest.Value);
                    }

                    questsTable.RunQuery();
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done_party WHERE character_id = " + internalid);
                using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done_party"))
                {
                    doneTable.AddColumn("character_id", false);
                    doneTable.AddColumn("questid", false);
                    doneTable.AddColumn("time", false);

                    foreach (var quest in Quests.PartyQuestsDone)
                    {
                        doneTable.AddRow(internalid, quest.Key, quest.Value);
                    }

                    doneTable.RunQuery();
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM skills WHERE character_id = " + internalid);
                using (InsertQueryBuilder skillTable = new InsertQueryBuilder("skills"))
                {
                    skillTable.OnDuplicateUpdate = true;
                    skillTable.AddColumn("character_id", false);
                    skillTable.AddColumn("skillid", false);
                    skillTable.AddColumn("level", true);
                    skillTable.AddColumn("maxlevel", true);
                    skillTable.AddColumn("expires", true);

                    foreach (var skill in Skills.SkillList)
                    {
                        skillTable.AddRow(internalid, skill.Key, skill.Value.Level, skill.Value.MasterLevel != -1 ? (object)skill.Value.MasterLevel : null, skill.Value.Expiration);
                    }

                    skillTable.RunQuery();
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM sp_data WHERE character_id = " + internalid);
                using (InsertQueryBuilder spTable = new InsertQueryBuilder("sp_data"))
                {
                    spTable.OnDuplicateUpdate = true;
                    spTable.AddColumn("character_id", false);
                    spTable.AddColumn("slot", false);
                    spTable.AddColumn("amount", true);

                    foreach (var kvp in Stats.SPData)
                    {
                        spTable.AddRow(internalid, kvp.Key, kvp.Value);
                    }

                    spTable.RunQuery();
                }

                using (InsertQueryBuilder teleportRocks = new InsertQueryBuilder("teleport_rock_locations"))
                {
                    teleportRocks.OnDuplicateUpdate = true;

                    teleportRocks.AddColumn("character_id");
                    for (int i = 0; i < 41; i++)
                        teleportRocks.AddColumn("map" + i, true);

                    teleportRocks.AddRowUnsafe(
                        pConnection.CharacterInternalID,
                        Inventory.TeleportRocks.ToList()
                        );

                    teleportRocks.RunQuery();
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM evolution_levels WHERE character_id = " + internalid);
                using (InsertQueryBuilder table = new InsertQueryBuilder("evolution_levels"))
                {
                    table.AddColumn("character_id");
                    table.AddColumn("block");
                    table.AddColumn("index");
                    table.AddColumn("card", true);
                    table.AddColumn("level", true);

                    foreach (var card in EvolutionCards)
                    {
                        table.AddRow(
                            pConnection.CharacterInternalID,
                            card.Block,
                            card.ID,
                            card.ItemID,
                            card.Level
                            );

                    }

                    table.RunQuery();
                }


                MySQL_Connection.Instance.RunQuery("DELETE FROM character_rings WHERE character_id = " + pConnection.CharacterInternalID);
                using (InsertQueryBuilder table = new InsertQueryBuilder("character_rings"))
                {
                    table.AddColumn("character_id");
                    table.AddColumn("friend_name");
                    table.AddColumn("cashid1");
                    table.AddColumn("cashid2");
                    table.AddColumn("type");

                    foreach (var ring in Rings)
                    {
                        string type = "";
                        switch (ring.RingType)
                        {
                            case Ring.Type.Couple: type = "couple"; break;
                            case Ring.Type.Marriage: type = "marriage"; break;
                            case Ring.Type.Friend: type = "friend"; break;
                        }

                        table.AddRow(
                            pConnection.CharacterInternalID,
                            ring.FriendName,
                            ring.RingCashID1,
                            ring.RingCashID1,
                            type
                            );

                    }

                    table.RunQuery();
                }


                MySQL_Connection.Instance.RunQuery("DELETE FROM character_abilities WHERE character_id = " + pConnection.CharacterInternalID);
                using (InsertQueryBuilder table = new InsertQueryBuilder("character_abilities"))
                {
                    table.AddColumn("character_id");
                    table.AddColumn("id");
                    table.AddColumn("skill_id");
                    table.AddColumn("level");

                    foreach (var stat in Abilities)
                    {
                        table.AddRow(
                            pConnection.CharacterInternalID,
                            stat.Item1,
                            stat.Item2,
                            stat.Item3
                            );
                    }

                    table.RunQuery();
                }

                return true;
            }
        }
示例#2
0
        public bool SaveData(ClientConnection pConnection)
        {
            int internalid = pConnection.CharacterInternalID = SaveCharacterInfo(pConnection);

            if (internalid == -1)
            {
                // Failure!
                return(false);
            }

            using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items"))
                using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets"))
                {
                    var info = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(Stats.ID, pConnection.WorldID);

                    if (info != null)
                    {
                        // Update info!
                        pConnection.CharacterID = Stats.ID;

                        CharacterInventory inventory = Inventory;

                        for (byte i = 0; i < Inventory.EquipmentItems.Length; i++)
                        {
                            var equips = Inventory.EquipmentItems[i];
                            foreach (var equipdata in equips)
                            {
                                short slot   = equipdata.Key;
                                var   equip  = equipdata.Value;
                                bool  addrow = false;

                                if (info.SlotHashes.ContainsKey(0) && info.SlotHashes[0].ContainsKey(slot))
                                {
                                    int hash    = info.SlotHashes[0][slot];
                                    int objhash = equipdata.Value.GetChecksum();
                                    if (hash != objhash)
                                    {
                                        pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                        addrow = true;
                                    }

                                    info.SlotHashes[0].Remove(slot);
                                }
                                else
                                {
                                    addrow = true;
                                }

                                if (addrow)
                                {
                                    Queries.SaveItem(pConnection, 0, slot, equip, itemsTable, true);
                                }
                            }
                        }

                        pConnection.Logger_WriteLine("Done equips");

                        for (int i = 0; i < Inventory.InventoryItems.Length; i++)
                        {
                            var items = Inventory.InventoryItems[i];
                            foreach (var itemdata in items)
                            {
                                var  item   = itemdata.Value;
                                bool addrow = false;
                                if (info.SlotHashes.ContainsKey(i + 1) && info.SlotHashes[i + 1].ContainsKey(itemdata.Key))
                                {
                                    int hash    = info.SlotHashes[i + 1][itemdata.Key];
                                    int objhash = itemdata.Value.GetChecksum();
                                    if (hash != objhash)
                                    {
                                        pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                        addrow = true;
                                    }


                                    info.SlotHashes[i + 1].Remove(itemdata.Key);
                                }
                                else
                                {
                                    addrow = true;
                                }

                                if (addrow)
                                {
                                    Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true);

                                    if (item is ItemPet)
                                    {
                                        Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                    }
                                }
                            }
                        }
                        pConnection.Logger_WriteLine("Done items");

                        foreach (var bag in Inventory.BagItems)
                        {
                            ushort i = (ushort)bag.Key;
                            foreach (var itemdata in bag.Value.Items)
                            {
                                var  item   = itemdata.Value;
                                bool addrow = false;
                                if (info.SlotHashes.ContainsKey(i) && info.SlotHashes[i].ContainsKey(itemdata.Key))
                                {
                                    int hash    = info.SlotHashes[i][itemdata.Key];
                                    int objhash = itemdata.Value.GetChecksum();
                                    if (hash != objhash)
                                    {
                                        pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                        addrow = true;
                                    }


                                    info.SlotHashes[i].Remove(itemdata.Key);
                                }
                                else
                                {
                                    addrow = true;
                                }

                                if (addrow)
                                {
                                    Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true);

                                    if (item is ItemPet)
                                    {
                                        Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                    }
                                }
                            }
                        }

                        pConnection.Logger_WriteLine("Done bag items");

                        {
                            string removequery = "";
                            bool   added       = false;
                            foreach (var hashlist in info.SlotHashes)
                            {
                                foreach (var leftovers in hashlist.Value)
                                {
                                    pConnection.Logger_WriteLine("Deleting item @ inv {0} slot {1}", hashlist.Key, leftovers.Key);
                                    added        = true;
                                    removequery += string.Format("DELETE FROM items WHERE character_id = {2} AND inventory = {0} AND slot = {1};\r\n", hashlist.Key, leftovers.Key, internalid);
                                }
                            }
                            if (added)
                            {
                                System.IO.File.WriteAllText("removequery.sql", removequery);
                                MySQL_Connection.Instance.RunQuery(removequery);
                            }
                        }
                    }
                    else
                    {
                        pConnection.Logger_WriteLine("Saving Items");

                        pConnection.CharacterInternalID = internalid;
                        pConnection.CharacterID         = Stats.ID;

                        string itemlist = "";
                        itemlist += "INSERT INTO items VALUES ";
                        List <string> querylist = new List <string>();
                        for (byte i = 0; i < Inventory.EquipmentItems.Length; i++)
                        {
                            var equips = Inventory.EquipmentItems[i];
                            foreach (var equipdata in equips)
                            {
                                var equip = equipdata.Value;
                                Queries.SaveItem(pConnection, 0, equipdata.Key, equip, itemsTable, true);
                            }
                        }

                        pConnection.Logger_WriteLine("Done equips");

                        for (int i = 0; i < Inventory.InventoryItems.Length; i++)
                        {
                            var items = Inventory.InventoryItems[i];
                            foreach (var itemdata in items)
                            {
                                var item = itemdata.Value;

                                Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true);

                                if (item is ItemPet)
                                {
                                    Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                }
                            }
                        }

                        pConnection.Logger_WriteLine("Done items");

                        foreach (var bag in Inventory.BagItems)
                        {
                            ushort i = (ushort)(bag.Key);
                            foreach (var itemdata in bag.Value.Items)
                            {
                                var item = itemdata.Value;
                                Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true);

                                if (item is ItemPet)
                                {
                                    Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                }
                            }
                        }

                        pConnection.Logger_WriteLine("Done bag items");

                        AccountDataCache.Instance.LoadBaseData(Stats.Name);
                    }

                    itemsTable.RunQuery();

                    pConnection.Logger_WriteLine("Saved item data");

                    petTable.RunQuery();

                    pConnection.Logger_WriteLine("Saved pet data");


                    AccountDataCache.Instance.LoadInventoryHashes(internalid, true);



                    MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running WHERE character_id = " + internalid);
                    using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running"))
                    {
                        questsTable.OnDuplicateUpdate = true;
                        questsTable.AddColumn("character_id", false);
                        questsTable.AddColumn("questid", true);
                        questsTable.AddColumn("data", true);

                        foreach (var quest in Quests.Running)
                        {
                            questsTable.AddRow(internalid, quest.Key, quest.Value);
                        }

                        questsTable.RunQuery("insert-update-quests.sql");
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done WHERE character_id = " + internalid);
                    using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done"))
                    {
                        doneTable.AddColumn("character_id", false);
                        doneTable.AddColumn("questid", false);
                        doneTable.AddColumn("time", false);

                        foreach (var quest in Quests.Done)
                        {
                            doneTable.AddRow(internalid, quest.Key, quest.Value);
                        }

                        doneTable.RunQuery("insert-update-quests-done.sql");
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running_party WHERE character_id = " + internalid);
                    using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running_party"))
                    {
                        questsTable.OnDuplicateUpdate = true;
                        questsTable.AddColumn("character_id", false);
                        questsTable.AddColumn("questid", true);
                        questsTable.AddColumn("data", true);

                        foreach (var quest in Quests.PartyQuestsRunning)
                        {
                            questsTable.AddRow(internalid, quest.Key, quest.Value);
                        }

                        questsTable.RunQuery();
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done_party WHERE character_id = " + internalid);
                    using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done_party"))
                    {
                        doneTable.AddColumn("character_id", false);
                        doneTable.AddColumn("questid", false);
                        doneTable.AddColumn("time", false);

                        foreach (var quest in Quests.PartyQuestsDone)
                        {
                            doneTable.AddRow(internalid, quest.Key, quest.Value);
                        }

                        doneTable.RunQuery();
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM skills WHERE character_id = " + internalid);
                    using (InsertQueryBuilder skillTable = new InsertQueryBuilder("skills"))
                    {
                        skillTable.OnDuplicateUpdate = true;
                        skillTable.AddColumn("character_id", false);
                        skillTable.AddColumn("skillid", false);
                        skillTable.AddColumn("level", true);
                        skillTable.AddColumn("maxlevel", true);
                        skillTable.AddColumn("expires", true);

                        foreach (var skill in Skills.SkillList)
                        {
                            skillTable.AddRow(internalid, skill.Key, skill.Value.Level, skill.Value.MasterLevel != -1 ? (object)skill.Value.MasterLevel : null, skill.Value.Expiration);
                        }

                        skillTable.RunQuery();
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM sp_data WHERE character_id = " + internalid);
                    using (InsertQueryBuilder spTable = new InsertQueryBuilder("sp_data"))
                    {
                        spTable.OnDuplicateUpdate = true;
                        spTable.AddColumn("character_id", false);
                        spTable.AddColumn("slot", false);
                        spTable.AddColumn("amount", true);

                        foreach (var kvp in Stats.SPData)
                        {
                            spTable.AddRow(internalid, kvp.Key, kvp.Value);
                        }

                        spTable.RunQuery();
                    }

                    using (InsertQueryBuilder teleportRocks = new InsertQueryBuilder("teleport_rock_locations"))
                    {
                        teleportRocks.OnDuplicateUpdate = true;

                        teleportRocks.AddColumn("character_id");
                        for (int i = 0; i < 41; i++)
                        {
                            teleportRocks.AddColumn("map" + i, true);
                        }

                        teleportRocks.AddRowUnsafe(
                            pConnection.CharacterInternalID,
                            Inventory.TeleportRocks.ToList()
                            );

                        teleportRocks.RunQuery();
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM evolution_levels WHERE character_id = " + internalid);
                    using (InsertQueryBuilder table = new InsertQueryBuilder("evolution_levels"))
                    {
                        table.AddColumn("character_id");
                        table.AddColumn("block");
                        table.AddColumn("index");
                        table.AddColumn("card", true);
                        table.AddColumn("level", true);

                        foreach (var card in EvolutionCards)
                        {
                            table.AddRow(
                                pConnection.CharacterInternalID,
                                card.Block,
                                card.ID,
                                card.ItemID,
                                card.Level
                                );
                        }

                        table.RunQuery();
                    }


                    MySQL_Connection.Instance.RunQuery("DELETE FROM character_rings WHERE character_id = " + pConnection.CharacterInternalID);
                    using (InsertQueryBuilder table = new InsertQueryBuilder("character_rings"))
                    {
                        table.AddColumn("character_id");
                        table.AddColumn("friend_name");
                        table.AddColumn("cashid1");
                        table.AddColumn("cashid2");
                        table.AddColumn("type");

                        foreach (var ring in Rings)
                        {
                            string type = "";
                            switch (ring.RingType)
                            {
                            case Ring.Type.Couple: type = "couple"; break;

                            case Ring.Type.Marriage: type = "marriage"; break;

                            case Ring.Type.Friend: type = "friend"; break;
                            }

                            table.AddRow(
                                pConnection.CharacterInternalID,
                                ring.FriendName,
                                ring.RingCashID1,
                                ring.RingCashID1,
                                type
                                );
                        }

                        table.RunQuery();
                    }


                    MySQL_Connection.Instance.RunQuery("DELETE FROM character_abilities WHERE character_id = " + pConnection.CharacterInternalID);
                    using (InsertQueryBuilder table = new InsertQueryBuilder("character_abilities"))
                    {
                        table.AddColumn("character_id");
                        table.AddColumn("id");
                        table.AddColumn("skill_id");
                        table.AddColumn("level");

                        foreach (var stat in Abilities)
                        {
                            table.AddRow(
                                pConnection.CharacterInternalID,
                                stat.Item1,
                                stat.Item2,
                                stat.Item3
                                );
                        }

                        table.RunQuery();
                    }

                    return(true);
                }
        }