コード例 #1
0
ファイル: L2World.cs プロジェクト: LFBRxD/L2dotNET
        public static void Initialize()
        {
            for (int i = 0; i <= RegionsX; i++)
            {
                for (int j = 0; j <= RegionsY; j++)
                {
                    _worldRegions[i, j] = new L2WorldRegion(i, j);
                }
            }

            for (int x = 0; x <= RegionsX; x++)
            {
                for (int y = 0; y <= RegionsY; y++)
                {
                    for (int a = -1; a <= 1; a++)
                    {
                        for (int b = -1; b <= 1; b++)
                        {
                            if (ValidRegion(x + a, y + b))
                            {
                                _worldRegions[x + a, y + b].AddSurroundingRegion(_worldRegions[x, y]);
                            }
                        }
                    }
                }
            }

            Log.Info($"WorldRegion grid ({RegionsX} by {RegionsY}) is now setted up.");
        }
コード例 #2
0
ファイル: L2World.cs プロジェクト: cygwin255/L2dotNET
        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
                }
            }
        }
コード例 #3
0
ファイル: L2WorldRegion.cs プロジェクト: Windex-/L2dotNET
 public void AddSurroundingRegion(L2WorldRegion region)
 {
     _surroundingRegions.Add(region);
 }