Beispiel #1
0
 public IEnumerable <Tuple <int, int> > GetNearestLinks(string linkName, int x, int y)
 {
     if (AreaLinks.ContainsKey(linkName))
     {
         return(AreaLinks[linkName].OrderBy(link => GameClient.DistanceBetween(x, y, link.Item1, link.Item2)));
     }
     return(null);
 }
Beispiel #2
0
        private void ProcessAreas()
        {
            if (_client.IsLoggedIn)
            {
                if (MapDump.Areas != null && MapDump.Areas.Count > 1)
                {
                    foreach (MAPAPI.Response.Area area in MapDump.Areas)
                    {
                        if (_client.PlayerX >= area.StartX && _client.PlayerX <= area.EndX && _client.PlayerY >= area.StartY && _client.PlayerY <= area.EndY)
                        {
                            CurrentArea = area;
                            DimensionX  = area.EndX;
                            DimensionY  = area.EndY;
                            break;
                        }
                    }
                }
                if (CurrentArea is null)
                {
                    DimensionX = Width;
                    DimensionY = Height;

                    if (MapDump.Areas is null is false && MapDump.Areas.Count == 1)
                    {
                        CurrentArea = MapDump.Areas.FirstOrDefault();
                        if (CurrentArea != null)
                        {
                            CurrentArea.EndX = Width;
                            CurrentArea.EndY = Height;
                            AreaUpdated?.Invoke();
                            return;
                        }
                    }

                    CurrentArea = new Area
                    {
                        AreaName = MapDump.Settings.MapName,
                        EndX     = Width,
                        EndY     = Height,
                        StartX   = 0,
                        StartY   = 0
                    };
                }
            }
            if (MapDump.Areas is null)
            {
                return;
            }
            foreach (var ar in MapDump.Areas)
            {
                var destination = ar.AreaName.ToUpperInvariant();
                if (!AreaLinks.ContainsKey(destination))
                {
                    AreaLinks.Add(destination, new List <Tuple <int, int> >());
                }
                var linky = ar.EndY;

                for (int y = ar.StartY; y <= ar.EndY; ++y)
                {
                    for (int x = ar.StartX; x <= ar.EndX; ++x)
                    {
                        if (GetCollider(x, y) != 1)
                        {
                            if (IsInArea(ar, x, y))
                            {
                                AreaLinks[destination].Add(new Tuple <int, int>(x, y));
                            }
                            else if (IsInArea(ar, x, y - 1) && !(y - 1 < ar.StartY))
                            {
                                AreaLinks[destination].Add(new Tuple <int, int>(x, y - 1));
                            }
                            else if (IsInArea(ar, x, y + 1) && !(y + 1 > ar.EndY))
                            {
                                AreaLinks[destination].Add(new Tuple <int, int>(x, y + 1));
                            }
                            else if (IsInArea(ar, x - 1, y) && !(x - 1 < ar.StartX))
                            {
                                AreaLinks[destination].Add(new Tuple <int, int>(x - 1, y));
                            }
                            else if (IsInArea(ar, x + 1, y) && !(x + 1 > ar.EndX))
                            {
                                AreaLinks[destination].Add(new Tuple <int, int>(x + 1, y));
                            }
                        }
                    }
                }
            }
        }