public EntitySpawnPacket(Character character)
        {
            // TODO there are many things missing.
            Data = new byte[Length];
            Data[0] = Id;
            // VID 0x01 + 4
            BitConverter.GetBytes(character.Vid).CopyTo(Data, 0x1);
            // Position 0x9 + 8
            BitConverter.GetBytes(character.AbsolutePosition.X).CopyTo(Data, 0x9);
            BitConverter.GetBytes(character.AbsolutePosition.Y).CopyTo(Data, 0xD);
            // Vnum 0x16 + 2
            BitConverter.GetBytes(character.Race);
            // AtkSpeed, MovSpeed (stub) 0x18 + 2
            Data[0x18] = 100;
            Data[0x19] = 100;
            // TODO There are a lot of empty bytes, check them. I think they are "flags".
            // VID (again...) 0x28 + 2
            BitConverter.GetBytes(character.Vid).CopyTo(Data, 0x28);
            // Name 0x2D + ????
            Encoding.ASCII.GetBytes(character.Name).CopyTo(Data, 0x2D);
            // Empire 0x4E + 1
            Data[0x4E] = (byte) character.Empire;
            // Part_Main  0x46 +2
            BitConverter.GetBytes(character.Armor).CopyTo(Data, 0x46);
            // Part_Weapon 0x48 + 2

            BitConverter.GetBytes(character.Weapon).CopyTo(Data, 0x48);
            // Part_Unknown 0x4a + 2

            // Part_Hair 0x4C + 2
            BitConverter.GetBytes(character.Hair).CopyTo(Data, 0x4C);
        }
 public EnterGamePacket(Character character)
 {
     Data = new byte[Length];
     Data[0] = Id;
     Data[1] = 0x4;
     BitConverter.GetBytes(character.Vid ).CopyTo(Data,0x9);
     Data[8] = 0x71;
     Data[0xD] = character.Race;
     Encoding.ASCII.GetBytes(character.Name).CopyTo(Data,0xF);
 }
 public CharacterInfoPacket(int type, int quantity, Character character)
 {
     Data = new byte[Length];
     Data[0] = Id;
     // VID 0x4 + 4
     BitConverter.GetBytes(character.Vid).CopyTo(Data, 0x4);
     // Type 0x8 + 4?
     BitConverter.GetBytes(type).CopyTo(Data, 0x8);
     // Quantity 0xD + 4?
     BitConverter.GetBytes(quantity).CopyTo(Data, 0xD);
 }
        public CharacterListPacket(Character[] characters, byte empire)
        {
            Data = new byte[Length];
            Data[0] = Id;

            Header(empire).CopyTo(Data, 1);
            for (int i = 0; i < characters.Length; i++)
            {
                int offset = 17 + 63*i;
                CharStruct(characters[i], i).CopyTo(Data, offset);
            }
        }
 public CharacterStatsPacket(Character character)
 {
     Data = new byte[Length];
     Data[5] = character.Level;
     BitConverter.GetBytes(character.Exp).CopyTo(Data, 0xD);
     BitConverter.GetBytes(character.RequiredExp).CopyTo(Data, 0x11);
     BitConverter.GetBytes(character.CurHP).CopyTo(Data, 0x15);
     BitConverter.GetBytes(character.MaxHP).CopyTo(Data, 0x19);
     // TODO: Add Mana, MaxMana properties to Database's character table
     BitConverter.GetBytes(character.Gold).CopyTo(Data, 0x2D);
     BitConverter.GetBytes(character.Strong).CopyTo(Data, 0x31);
     BitConverter.GetBytes(character.Vitality).CopyTo(Data, 0x35);
     BitConverter.GetBytes(character.Dexterity).CopyTo(Data, 0x39);
     BitConverter.GetBytes(character.Intelligence).CopyTo(Data, 0x3D);
     // TODO: Add AttackSpeed, MovSpeed, CastSpeed, PhysicalAttack, PhysicalDefence, MagicalAttack, MagicalDefence properties to Database's character table
     BitConverter.GetBytes(character.StatPoints).CopyTo(Data, 0x69);
     BitConverter.GetBytes(character.SkillPoints).CopyTo(Data, 0x71);
 }
        private byte[] CharStruct(Character character, int index)
        {
            byte[] ret = new byte[63];
            // Player ID 0x0, 0x3
            byte[] pid = BitConverter.GetBytes(character.Pid);
            pid.CopyTo(ret, 0);
            // Name 0x4, 0x1C
            Encoding.ASCII.GetBytes(character.Name).CopyTo(ret, 0x4);
            // Race 0x1D
            ret[0x1D] = character.Race;
            // Level 0x1E
            ret[0x1E] = character.Level;
            // GameTime 0x1F, 0x22
            byte[] gametime = BitConverter.GetBytes(character.PlayTime);
            gametime.CopyTo(ret, 0x1F);
            // Status 0x23, 0x26
            ret[0x23] = (byte) character.Strong;
            ret[0x24] = (byte) character.Vitality;
            ret[0x25] = (byte) character.Dexterity;
            ret[0x26] = (byte) character.Intelligence;
            // Armor 0x27, 0x29
            byte[] armor = BitConverter.GetBytes(character.Armor);
            armor.CopyTo(ret, 0x27);
            // Hair 0x2A, 0x2C
            byte[] hair = BitConverter.GetBytes(character.Hair);
            hair.CopyTo(ret, 0x2A);

            // Guild
            byte[] guildID = BitConverter.GetBytes(character.Guild);
            guildID.CopyTo(Data, 0x10D + (index*4));
            byte[] guildName = Encoding.ASCII.GetBytes(character.GuildName);
            guildName.CopyTo(Data, 0x11D + (index*13));
            // EndGuild

            return ret;
        }
        internal Character GetCharacter(uint id)
        {
            Character character = null;
            string query = string.Format(
                "SELECT * FROM `character` WHERE `id`='{0}'", id);
            MySqlDataReader reader = _conn.Query(query);
            if (reader.Read())
            {
                character = new Character
                                {
                                    Race = reader.GetByte("race"),
                                    Level = reader.GetByte("level"),
                                    Job = reader.GetByte("job"),
                                    Name = reader.GetString("name"),
                                    Pid = reader.GetUInt32("id"),
                                    MapIndex = reader.GetInt32("map_index"),
                                    PlayTime = reader.GetInt32("playtime"),
                                    Strong = reader.GetUInt32("str"),
                                    Vitality = reader.GetUInt32("vit"),
                                    Dexterity = reader.GetUInt32("dex"),
                                    Intelligence = reader.GetUInt32("iq"),
                                    Exp = reader.GetUInt32("exp"),
                                    Gold = reader.GetUInt32("gold"),
                                    StatPoints = reader.GetUInt16("stat_point"),
                                    SkillPoints = reader.GetUInt16("skill_point"),
                                    Armor = reader.GetUInt16("armor"),
                                    Hair = reader.GetUInt16("hair"),
                                    Alignment = reader.GetInt32("alignment"),
                                    Guild = reader.GetUInt32("guild"),
                                    AbsolutePosition = new Position(reader.GetInt32("x"), reader.GetInt32("y")),
                                };
            }
            reader.Close();

            return character;
        }