Exemplo n.º 1
0
        private void StructureInfo(Session session, Packet packet)
        {
            ICity      city;
            IStructure structure;

            uint cityId;
            uint objectId;

            try
            {
                cityId   = packet.GetUInt32();
                objectId = packet.GetUInt32();
            }
            catch (Exception)
            {
                ReplyError(session, packet, Error.Unexpected);
                return;
            }

            locker.Lock(cityId, objectId, out city, out structure).Do(() =>
            {
                if (city == null || structure == null)
                {
                    ReplyError(session, packet, Error.ObjectNotFound);
                    return;
                }

                var reply = new Packet(packet);
                reply.AddUInt16(structure.Stats.Base.Type);
                reply.AddByte(structure.Stats.Base.Lvl);
                if (session.Player == structure.City.Owner)
                {
                    reply.AddUInt16(structure.Stats.Labor);
                    reply.AddUInt16((ushort)structure.Stats.Hp);

                    foreach (var prop in propertyFactory.GetProperties(structure.Type))
                    {
                        switch (prop.Type)
                        {
                        case DataType.Byte:
                            reply.AddByte((byte)prop.GetValue(structure));
                            break;

                        case DataType.UShort:
                            reply.AddUInt16((ushort)prop.GetValue(structure));
                            break;

                        case DataType.UInt:
                            reply.AddUInt32((uint)prop.GetValue(structure));
                            break;

                        case DataType.String:
                            reply.AddString((string)prop.GetValue(structure));
                            break;

                        case DataType.Int:
                            reply.AddInt32((int)prop.GetValue(structure));
                            break;

                        case DataType.Float:
                            reply.AddFloat((float)prop.GetValue(structure));
                            break;
                        }
                    }
                }
                else
                {
                    foreach (var prop in propertyFactory.GetProperties(structure.Type, Visibility.Public))
                    {
                        switch (prop.Type)
                        {
                        case DataType.Byte:
                            reply.AddByte((byte)prop.GetValue(structure));
                            break;

                        case DataType.UShort:
                            reply.AddUInt16((ushort)prop.GetValue(structure));
                            break;

                        case DataType.UInt:
                            reply.AddUInt32((uint)prop.GetValue(structure));
                            break;

                        case DataType.String:
                            reply.AddString((string)prop.GetValue(structure));
                            break;

                        case DataType.Int:
                            reply.AddInt32((int)prop.GetValue(structure));
                            break;

                        case DataType.Float:
                            reply.AddFloat((float)prop.GetValue(structure));
                            break;
                        }
                    }
                }

                session.Write(reply);
            });
        }