Пример #1
0
        /// <summary>
        /// Returns a <see cref="IReadOnlyList{T}"/> of type <see cref="HEntity"/> found in the <see cref="HMessage"/>.
        /// </summary>
        /// <param name="packet">The <see cref="HMessage"/> that contains the <see cref="HEntity"/> data to parse.</param>
        /// <returns></returns>
        public static IReadOnlyList<HEntity> Parse(HMessage packet)
        {
            int entityCount = packet.ReadInteger();
            var entityList = new List<HEntity>(entityCount);

            for (int i = 0; i < entityList.Capacity; i++)
            {
                int id = packet.ReadInteger();
                string name = packet.ReadString();
                string motto = packet.ReadString();
                string figureId = packet.ReadString();
                int index = packet.ReadInteger();
                int x = packet.ReadInteger();
                int y = packet.ReadInteger();

                var z = double.Parse(
                    packet.ReadString(), CultureInfo.InvariantCulture);

                packet.ReadInteger();
                int type = packet.ReadInteger();

                HGender gender = HGender.Unisex;
                string favoriteGroup = string.Empty;
                #region Switch Statement: type
                switch (type)
                {
                    case 1:
                    {
                        gender = SKore.ToGender(packet.ReadString());
                        packet.ReadInteger();
                        packet.ReadInteger();
                        favoriteGroup = packet.ReadString();
                        packet.ReadString();
                        packet.ReadInteger();
                        packet.ReadBoolean();

                        break;
                    }
                    case 2:
                    {
                        packet.ReadInteger();
                        packet.ReadInteger();
                        packet.ReadString();
                        packet.ReadInteger();
                        packet.ReadBoolean();
                        packet.ReadBoolean();
                        packet.ReadBoolean();
                        packet.ReadBoolean();
                        packet.ReadBoolean();
                        packet.ReadBoolean();
                        packet.ReadInteger();
                        packet.ReadString();
                        break;
                    }
                    case 4:
                    {
                        packet.ReadString();
                        packet.ReadInteger();
                        packet.ReadString();

                        for (int j = packet.ReadInteger(); j > 0; j--)
                            packet.ReadShort();

                        break;
                    }
                }
                #endregion

                var entity = new HEntity(id, index, name,
                    new HPoint(x, y, z), motto, gender, figureId, favoriteGroup);

                entityList.Add(entity);
            }
            return entityList;
        }