public static uint CreateMercenary(uint charId, string digiName, int digiModel, int digiScale, int digiSize, int intimacy)
        {
            uint digiId = 0;
            try
            {
                DigimonData dData = DigimonDB.GetDigimon(digiModel);
                using (MySqlConnection con = Connect())
                {
                    Query qry = new Query(Query.QueryMode.INSERT, "digimon");
                    qry.Add("digiName", digiName);
                    qry.Add("digiModel", digiModel);
                    qry.Add("digiType", digiModel);
                    qry.Add("characterId", charId);

                    qry.Add("digiScale", digiScale);
                    qry.Add("digiSize", digiSize);

                    qry.Add("maxHP", dData.HP);
                    qry.Add("maxDS", dData.DS);
                    qry.Add("HP", dData.HP);
                    qry.Add("DS", dData.DS);

                    qry.Add("DE", dData.DE);
                    qry.Add("AT", dData.AT);
                    qry.Add("sync", intimacy);
                    qry.Add("HT", dData.HT);
                    qry.Add("EV", dData.EV);
                    qry.Add("CR", dData.CR);
                    qry.Add("MS", dData.MS);
                    qry.Add("AS", dData.AS);

                    using (MySqlCommand cmd = qry.GetCommand(con))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }
                using (MySqlCommand
                cmd = new MySqlCommand(
                    "SELECT * FROM `digimon` WHERE `characterId` = @charId AND `digiName` = @charName",
                    Connect()))
                {
                    cmd.Parameters.AddWithValue("@charId", charId);
                    cmd.Parameters.AddWithValue("@charName", digiName);
                    using (MySqlDataReader read = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow))
                    {
                        if (read.HasRows && read.Read())
                        {
                            digiId = (uint)(int)read["digimonId"];
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: CreateDigimon()\n{0}", e);
            }
            return digiId;
        }
        public static void SaveTamerPosition(Client client)
        {
            int lastChar = -1, charId = -1;
            try
            {
                using (MySqlConnection con = Connect())
                using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM `acct` WHERE `accountId` = @acct", con))
                {
                    cmd.Parameters.AddWithValue("@acct", client.AccountID);

                    using (MySqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow))
                    {
                        if (dr.HasRows && dr.Read())
                        {
                            lastChar = (int)dr["lastChar"];
                            if (lastChar != -1)
                            {
                                charId = (int)dr[string.Format("char{0}", lastChar + 1)];
                            }
                        }
                    }
                }
                if (lastChar != -1)
                {
                    Character Tamer = client.Tamer;
                    using (MySqlConnection con = Connect())
                    {
                        Query qry = new Query(Query.QueryMode.UPDATE, "chars",new Tuple<string,object>("characterId", Tamer.CharacterId));
                        qry.Add("map", Tamer.Location.Map);
                        qry.Add("x", Tamer.Location.PosX);
                        qry.Add("y", Tamer.Location.PosY);
                        using (MySqlCommand cmd = qry.GetCommand(con))
                        {
                            cmd.ExecuteNonQuery();
                        }

                        for (int i = 0; i < Tamer.DigimonList.Length; i++)
                        {
                            if (Tamer.DigimonList[i] != null)
                                SaveDigimon(Tamer.DigimonList[i]);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        public static void SaveTamer(Client client)
        {
            int lastChar = -1, charId = -1;

            try
            {
                using (MySqlConnection con = Connect())
                using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM `acct` WHERE `accountId` = @acct", con))
                {
                    cmd.Parameters.AddWithValue("@acct", client.AccountID);
                    using (MySqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow))
                        if (dr.HasRows && dr.Read())
                        {
                            lastChar = (int)dr["lastChar"];
                            if (lastChar != -1)
                            {
                                charId = (int)dr[string.Format("char{0}", lastChar + 1)];
                            }
                        }
                }

                if (lastChar != -1)
                {
                    Character Tamer = client.Tamer;
                    using (MySqlConnection con = Connect())
                    {
                        Query qry = new Query(Query.QueryMode.UPDATE, "chars", new Tuple<string, object>("characterId", Tamer.CharacterId));
                        qry.Add("charModel", (int)Tamer.Model);
                        qry.Add("charName", Tamer.Name);
                        qry.Add("charLv", Tamer.Level);
                        qry.Add("experience", Tamer.EXP);
                        qry.Add("money", Tamer.Money);

                        qry.Add("partner", Tamer.DigimonList[0].DigiId);
                        if (Tamer.DigimonList[1] == null) qry.Add("mercenary1", null);
                        else qry.Add("mercenary1", Tamer.DigimonList[1].DigiId);
                        if (Tamer.DigimonList[2] == null) qry.Add("mercenary2", null);
                        else qry.Add("mercenary2", Tamer.DigimonList[2].DigiId);

                        qry.Add("map", Tamer.Location.Map);
                        qry.Add("x", Tamer.Location.PosX);
                        qry.Add("y", Tamer.Location.PosY);

                        qry.Add("inventoryLimit", Tamer.InventorySize);
                        qry.Add("storageLimit", Tamer.StorageSize);
                        qry.Add("archiveLimit", Tamer.ArchiveSize);

                        qry.Add("maxHP", Tamer.MaxHP);
                        qry.Add("maxDS", Tamer.MaxDS);
                        qry.Add("HP", Tamer.HP);
                        qry.Add("DS", Tamer.DS);
                        qry.Add("AT", Tamer.AT);
                        qry.Add("DE", Tamer.DE);
                        qry.Add("MS", Tamer.MS);
                        qry.Add("Fatigue", Tamer.Fatigue);

                        qry.Add("incubator", Tamer.Incubator);
                        qry.Add("incubatorLevel", Tamer.IncubatorLevel);

                        BinaryFormatter f = new BinaryFormatter();
                        using (MemoryStream m = new MemoryStream())
                        {
                            f.Serialize(m, Tamer.ArchivedDigimon);
                            qry.Add("archive", m.ToArray());
                        }

                        qry.Add("inventory", Tamer.Inventory.Serialize());
                        qry.Add("equipment", Tamer.Equipment.Serialize());
                        qry.Add("storage", Tamer.Storage.Serialize());
                        qry.Add("quests", Tamer.Quests.Serialize());

                        using (MySqlCommand cmd = qry.GetCommand(con))
                        {
                            cmd.ExecuteNonQuery();
                        }
                    }
                    for (int i = 0; i < Tamer.DigimonList.Length; i++)
                    {
                        if (Tamer.DigimonList[i] != null)
                            SaveDigimon(Tamer.DigimonList[i]);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        public static void SaveDigimon(Digimon digimon)
        {
            try
            {
                using (MySqlConnection connection = Connect())
                {
                    Query qry = new Query(Query.QueryMode.UPDATE, "digimon", new Tuple<string, object>("digimonId", digimon.DigiId));
                    qry.Add("digiModel", digimon.CurrentForm);

                    qry.Add("digiName", digimon.Name);
                    qry.Add("digiLv", digimon.Level);
                    qry.Add("exp", digimon.EXP);
                    qry.Add("digiSize", digimon.Size);

                    qry.Add("maxHP", digimon.Stats.MaxHP);
                    qry.Add("maxDS", digimon.Stats.MaxDS);
                    qry.Add("HP", digimon.Stats.HP);
                    qry.Add("DS", digimon.Stats.DS);
                    qry.Add("AT", digimon.Stats.AT);
                    qry.Add("DE", digimon.Stats.DE);
                    qry.Add("sync", digimon.Stats.Intimacy);
                    qry.Add("HT", digimon.Stats.HT);
                    qry.Add("EV", digimon.Stats.EV);
                    qry.Add("CR", digimon.Stats.CR);
                    qry.Add("MS", digimon.Stats.MS);

                    qry.Add("forms", digimon.Forms.Serialize());

                    using (MySqlCommand cmd = qry.GetCommand(connection))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: GetDigimon({1})\n{0}", e, digimon);
            }
        }
        public static int CreateCharacter(uint AcctId, int pos, int charModel, string charName, int digiModel)
        {
            int charId = -1;
            try
            {
                using (MySqlConnection con = Connect())
                {
                    Query qry = new Query(Query.QueryMode.INSERT,"chars");
                    qry.Add("charName", charName);
                    qry.Add("charModel", charModel);
                    qry.Add("accountId", AcctId);

                    qry.Add("inventory", new ItemList(63).Serialize());
                    qry.Add("storage", new ItemList(70).Serialize());
                    qry.Add("equipment", new ItemList(27).Serialize());
                    qry.Add("quests", new QuestList().Serialize());

                    qry.Add("maxHP", TamerData[charModel - 80001][2]);
                    qry.Add("maxDS", TamerData[charModel - 80001][3]);
                    qry.Add("HP", TamerData[charModel - 80001][2]);
                    qry.Add("DS", TamerData[charModel - 80001][3]);
                    qry.Add("AT", TamerData[charModel - 80001][0]);
                    qry.Add("DE", TamerData[charModel - 80001][1]);

                    using (MySqlCommand cmd = qry.GetCommand(con))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }
                using (MySqlConnection con = Connect())
                {
                    using (MySqlCommand cmd = new MySqlCommand(
                           "SELECT * FROM `chars` WHERE `accountId` = @acctId AND `charName` = @charName",
                           con))
                    {
                        cmd.Parameters.AddWithValue("@acctId", AcctId);
                        cmd.Parameters.AddWithValue("@charName", charName);

                        using (MySqlDataReader read = cmd.ExecuteReader(System.Data.CommandBehavior.SingleRow))
                        {
                            if (read.HasRows)
                            {
                                if (read.Read())
                                {
                                    charId = (int)read["characterId"];
                                }
                            }
                        }
                    }
                }
                using (MySqlConnection con = Connect())
                {
                    using (MySqlCommand
                        cmd = new MySqlCommand(
                            string.Format("UPDATE `acct` SET `char{0}` = @charId WHERE `accountId` = @acct", pos + 1),
                            con))
                    {
                        cmd.Parameters.AddWithValue("@charId", charId);
                        cmd.Parameters.AddWithValue("@acct", AcctId);
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: CreateCharacter()\n{0}", e);
            }
            return charId;
        }