Beispiel #1
0
        /// <summary>
        /// 通过数据包获取房屋信息
        /// </summary>
        /// <param name="buffer">数据包Buffer</param>
        public HousingItem(HousingSlotSnapshot snapshot, int id, byte[] buffer)
        {
            Snapshot = snapshot;
            Id       = id;

            /*
             * struct HouseInfoEntry
             * {
             *   uint32_t housePrice;
             *   uint8_t infoFlags;
             *   Common::HousingAppeal houseAppeal[3];
             *   char estateOwnerName[32];
             * }
             */
            var nameHeader = buffer.SubArray(0, 8);

            Price = BitConverter.ToInt32(nameHeader, 0);
            Size  = (Price > 30000000) ? HouseSize.L : ((Price > 10000000) ? HouseSize.M : HouseSize.S);
            //读取房屋信息
            Flags = new HouseFlags(nameHeader[4]);
            //读取房屋展示信息
            for (var i = 0; i < 3; i++)
            {
                Tags[i] = (HouseTagsDefine)nameHeader[5 + i];
            }
            //读取房主姓名
            Owner = DecodeOwnerName(buffer.SubArray(8, 32));
            //获取所有者信息
            if (Flags.IsEstateOwned)
            {
                if (Flags.IsFreeCompanyEstate)
                {
                    OwnerType = HouseOwnerType.GUILD;
                }
                else
                {
                    OwnerType = HouseOwnerType.PERSON;
                }
            }
            else
            {
                OwnerType = HouseOwnerType.EMPTY;
            }
            //获取访问权限
            if (Flags.IsPublicEstate)
            {
                Access = HouseAccess.PUBLIC;
            }
            else
            {
                Access = HouseAccess.LOCKED;
            }
        }
        public void Insert(HousingSlotSnapshot snapshot)
        {
            if (!Snapshots.ContainsKey(snapshot.ServerId))
            {
                Snapshots.Add(snapshot.ServerId, new ServerHousingStorage());
            }
            var serverStorage = Snapshots[snapshot.ServerId];

            if (!serverStorage.ContainsKey(snapshot.Area))
            {
                serverStorage.Add(snapshot.Area, new AreaHousingStorage());
            }
            var areaStorage = serverStorage[snapshot.Area];

            areaStorage[snapshot.Slot] = snapshot;
        }
        void NetworkReceived(string connection, long epoch, byte[] message)
        {
            var opcode = BitConverter.ToUInt16(message, 18);

            if (opcode != 0x164 && message.Length != 2440)
            {
                return;
            }
            HousingSlotSnapshot snapshot;

            try
            {
                //解析数据包
                snapshot          = new HousingSlotSnapshot(message);
                snapshot.ServerId = GetServerId();

                /*foreach(var house in snapshot.HouseList.Values)
                 * {
                 *  Log("Debug", house.Id + ": " + house.Flags.ToString());
                 * }*/
                //存入存储
                SnapshotStorage.Insert(snapshot);
                AutoUploadSnapshot[new Tuple <HouseArea, int>(snapshot.Area, snapshot.Slot)] = snapshot;

                foreach (HousingOnSaleItem item in HousingList)
                {
                    if (item.Area == snapshot.Area && item.Slot == snapshot.Slot)
                    {
                        item.CurrentStatus = false;
                    }
                }

                HousingItem[] onSaleList = snapshot.GetOnSale();

                Monitor.Enter(this);
                foreach (var item in HousingList)
                {
                    if (item.Area == snapshot.Area && item.Slot == snapshot.Slot)
                    {
                        if (onSaleList.Where(x => x.Slot == item.Slot && x.IsEmpty)
                            .ToArray().Length == 0)
                        {
                            //空房已消失
                            item.CurrentStatus = false;
                            HousingListUpdated = true;
                            try
                            {
                                bindingSource1.ResetItem(HousingList.IndexOf(item));
                            }
                            catch (Exception ex)
                            {
                                Log("Error", ex, "刷新列表出错:");
                            }
                        }
                    }
                }

                int listIndex;
                //更新空房列表
                foreach (HousingItem house in onSaleList)
                {
                    HousingOnSaleItem onSaleItem = new HousingOnSaleItem(house);
                    Log("Info", string.Format("{0} 第{1}区 {2}号 {3}房在售 当前价格: {4}",
                                              onSaleItem.AreaStr, onSaleItem.DisplaySlot, onSaleItem.DisplayId,
                                              onSaleItem.SizeStr, onSaleItem.Price));

                    if (onSaleItem.Size == HouseSize.M || onSaleItem.Size == HouseSize.L)
                    {
                        Console.Beep(3000, 1000);
                    }

                    if ((listIndex = HousingList.IndexOf(onSaleItem)) != -1)
                    {
                        HousingList[listIndex].Update(house);
                        Log("Info", "重复土地,已更新。");
                    }
                    else
                    {
                        bindingSource1.Add(onSaleItem);
                    }
                    HousingListUpdated = true;
                }
                LastOperateTime = new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds(); //更新上次操作的时间

                Log("Info", string.Format("{0} 第{1}区查询完成",
                                          HousingItem.GetHouseAreaStr(snapshot.Area),
                                          snapshot.Slot + 1)); //输出翻页日志
                Monitor.Exit(this);
            }
            catch (Exception ex)
            {
                Log("Error", ex, "查询房屋列表出错:");
                return;
            }
        }