示例#1
0
        public static async void UpdateRegion(L2Object obj)
        {
            L2WorldRegion activeRegion = GetRegion(obj);
            L2WorldRegion lastRegion   = obj.Region;

            bool isPlayer    = obj is L2Player;
            bool isNewObject = obj.Region == null;

            if (obj.Region == activeRegion)
            {
                return;
            }

            obj.Region?.Remove(obj);
            activeRegion.Add(obj);
            obj.Region = activeRegion;

            IEnumerable <L2WorldRegion> regionsDiff;

            if (isNewObject && lastRegion != null)
            {
                regionsDiff = activeRegion.GetNeighbours()
                              .Where(x => !lastRegion.GetNeighbours().Contains(x))
                              .ToList();
            }
            else
            {
                regionsDiff = activeRegion.GetNeighbours().ToList();
            }

            foreach (L2Player p in regionsDiff.SelectMany(x => x.GetPlayers()))
            {
                if (isPlayer)
                {
                    await p.BroadcastUserInfoToObjectAsync(obj);
                }

                await obj.BroadcastUserInfoToObjectAsync(p);
            }

            if (isPlayer)
            {
                foreach (L2Object o in regionsDiff.SelectMany(x => x.GetObjects()))
                {
                    await o.BroadcastUserInfoToObjectAsync(obj);

                    await Task.Delay(25); // TODO: Move to config
                }
            }
        }